11#!/usr/bin/env python3
2+ from check_jsonschema .formats .implementations .iso8601_time import N
23
34import argparse
45import grp
1516VARIANTS = ["appci" , "before-install" , "build-and-lint" , "core-tests" , "demo" , "dev" ]
1617BRANCHES = ["stable" , "testing" , "unstable" ]
1718
19+ YNH_DEV_DIR = Path (__file__ ).parent .parent
20+
1821
1922def main_host () -> None :
2023 parser = argparse .ArgumentParser ()
2124 sub = parser .add_subparsers (title = "host actions" , required = True , dest = "action" )
25+ sub .add_parser ("init" , help = "Download source repositories" )
2226 sub .add_parser ("start" , help = "(Create and) starts a box" )
2327 sub .add_parser ("attach" , help = "Attach an already started box" )
2428 sub .add_parser ("destroy" , help = "Destroy the ynh-dev box" )
@@ -40,6 +44,8 @@ def main_host() -> None:
4044 incus = Incus ()
4145
4246 match args .action :
47+ case "init" :
48+ init ()
4349 case "start" :
4450 if not incus .image_exists (image ):
4551 logging .info (f"Downloading { image } ..." )
@@ -58,7 +64,7 @@ def main_host() -> None:
5864 "ynh-dev-shared-folder" ,
5965 "disk" ,
6066 "path=/ynh-dev" ,
61- f"source={ Path . cwd () } " ,
67+ f"source={ YNH_DEV_DIR } " ,
6268 )
6369
6470 incus .execute (container , "dhclient" )
@@ -72,6 +78,23 @@ def main_host() -> None:
7278 incus .instance_delete (container )
7379
7480
81+
82+ def clone_or_pull (url : str , path : Path ) -> None :
83+ if path .exists ():
84+ subprocess .check_call (["git" , "pull" ], cwd = path )
85+ else :
86+ subprocess .check_call (["git" , "clone" , url , str (path )])
87+
88+
89+ def init () -> None :
90+ clone_or_pull ("https://github.com/YunoHost/moulinette" , YNH_DEV_DIR / "moulinette" )
91+ clone_or_pull ("https://github.com/YunoHost/yunohost" , YNH_DEV_DIR / "yunohost" )
92+ clone_or_pull ("https://github.com/YunoHost/yunohost-admin" , YNH_DEV_DIR / "yunohost-admin" )
93+ clone_or_pull ("https://github.com/YunoHost/SSOwat ssowat" , YNH_DEV_DIR / "SSOwat ssowat" )
94+ clone_or_pull ("https://github.com/YunoHost/yunohost-portal" , YNH_DEV_DIR / "yunohost-portal" )
95+ (YNH_DEV_DIR / "apps" ).mkdir (exist_ok = True )
96+
97+
7598def attach (incus : Incus , container : str ) -> None :
7699 logging .info (f"Attaching to { container } ." )
77100 incus .execute (container , "/bin/bash" , cwd = "/ynh-dev" , exec_ = True )
0 commit comments