33from pathlib import Path
44
55REMO_HOME_ENV = 'REMO_HOME'
6+ default_remo_home = str (Path .home ().joinpath ('.remo' ))
7+ default_colab_remo_home = '/gdrive/My Drive/RemoApp'
68
79
810def get_remo_home ():
9- return os .getenv (REMO_HOME_ENV , str (Path .home ().joinpath ('.remo' )))
11+ for path in (os .getenv (REMO_HOME_ENV , default_remo_home ), default_colab_remo_home ):
12+ if path and os .path .exists (path ):
13+ return path
1014
1115
1216def set_remo_home (path : str ):
13- if not os .path .exists (path ):
14- os .makedirs (path )
17+ os .makedirs (path , exist_ok = True )
1518 os .environ [REMO_HOME_ENV ] = path
1619
1720
21+ def set_remo_home_from_default_remo_config () -> bool :
22+ if os .path .exists (Config .default_path ()):
23+ config = Config .load (Config .default_path ())
24+ if config and config .remo_home :
25+ set_remo_home (config .remo_home )
26+ return True
27+
28+
1829class Config :
1930 """
2031 Remo Config
2132
2233 This class is used to initialise various settings.
2334 #TODO: add description of how those are initiliased from code vs from config file
2435 """
25- __slots__ = ['port' , 'server' , 'user_name' , 'user_email' , 'user_password' , 'viewer' ]
36+
37+ name = 'remo.json'
38+ __slots__ = [
39+ 'port' ,
40+ 'server' ,
41+ 'user_name' ,
42+ 'user_email' ,
43+ 'user_password' ,
44+ 'viewer' ,
45+ 'uuid' ,
46+ 'public_url' ,
47+ 'remo_home' ,
48+ 'cloud_platform' ,
49+ ]
2650 _default_port = 8123
2751 _default_server = 'http://localhost'
2852 _default_user_name = 'Admin User'
@@ -40,7 +64,7 @@ def server_url(self):
4064 @staticmethod
4165 def load (config_path : str = None ):
4266 if not config_path :
43- config_path = str (os .path .join (get_remo_home (), 'remo.json' ))
67+ config_path = str (os .path .join (get_remo_home (), Config . name ))
4468
4569 if not os .path .exists (config_path ):
4670 raise Exception (f'Config file not found, file { config_path } not exists' )
@@ -49,3 +73,13 @@ def load(config_path: str = None):
4973 config = json .load (cfg_file )
5074
5175 return Config (config )
76+
77+ @staticmethod
78+ def default_path ():
79+ return Config .path (default_remo_home )
80+
81+ @staticmethod
82+ def path (dir_path : str = None ):
83+ if not dir_path :
84+ dir_path = get_remo_home ()
85+ return str (os .path .join (dir_path , Config .name ))
0 commit comments