Skip to content

Commit 6085a8d

Browse files
committed
Load data from config
1 parent ea594ee commit 6085a8d

File tree

3 files changed

+51
-11
lines changed

3 files changed

+51
-11
lines changed

remo/__init__.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
_sdk = None
66

77

8-
def connect(server: str = '', email: str = '', password: str = '', viewer: str = 'browser', remo_home: str = None):
8+
def connect(server: str = None, email: str = None, password: str = None, viewer: str = None, remo_home: str = None):
99
"""
1010
Connect to a remo server.
1111
If no parameters are passed, it connects to a local running remo server. To connect to a remote remo, specify connection details.
@@ -18,17 +18,23 @@ def connect(server: str = '', email: str = '', password: str = '', viewer: str =
1818
(optional) remo_home: location of remo home
1919
"""
2020

21+
from .config import Config, set_remo_home, set_remo_home_from_default_remo_config
2122
if remo_home:
22-
from .config import set_remo_home
2323
set_remo_home(remo_home)
24+
else:
25+
set_remo_home_from_default_remo_config()
2426

27+
config = Config.load()
2528
if not (server and email and password):
26-
from .config import Config
27-
config = Config.load()
28-
server, email, password, viewer = config.server_url(), config.user_email, config.user_password, config.viewer
29+
server, email, password = config.server_url(), config.user_email, config.user_password
30+
31+
if not viewer:
32+
viewer = config.viewer
2933

3034
global _sdk
3135
_sdk = SDK(server, email, password, viewer)
36+
if config.public_url:
37+
_sdk.set_public_url(config.public_url)
3238
# set access to public SDK methods
3339
import sys
3440

remo/config.py

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,50 @@
33
from pathlib import Path
44

55
REMO_HOME_ENV = 'REMO_HOME'
6+
default_remo_home = str(Path.home().joinpath('.remo'))
7+
default_colab_remo_home = '/gdrive/My Drive/RemoApp'
68

79

810
def 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

1216
def 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+
1829
class 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))

remo/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.1.7'
1+
__version__ = '0.1.8'

0 commit comments

Comments
 (0)