-
Notifications
You must be signed in to change notification settings - Fork 2
/
tangible.py
executable file
·113 lines (71 loc) · 2.85 KB
/
tangible.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env python3
import pluggy
from core_plugins import core, device_detector
from core_plugins.configure import Config
import sys
from plugins import esp32_plugin, pico_plugin, esp8266_plugin, db_storage
import os
import time
from loguru import logger
PLUGINS_LIST = [core, device_detector, esp32_plugin, pico_plugin, esp8266_plugin, db_storage]
# PLUGINS_SPEC = [core_spec,device_detector_spec,esp32_plugin_spec, pico_plugin_spec, esp8266_plugin_spec]
SETTINGS = {'download_path':'downloads',
'db_filename':'db.json'}
def device_setup(config):
config.pm.hook.detector_plugin(config=config) #core_plugins/device_detector.py
config.pm.hook.detect_micropython(config=config) #core_plugins/device_detector.py
config.pm.hook.ampy2_firmware_download(config=config)
config.pm.hook.ampy2_firmware_install(config=config)
config.pm.hook.ampy2_connection_setup(config=config)
config.pm.hook.device_verify_connection(config=config)
def main():
pm = pluggy.PluginManager('ampy2')
for plugin in PLUGINS_LIST:
pm.register(plugin)
# pm.check_pending()
config = Config(pm)
for setting_key,setting_value in SETTINGS.items():
config.store[setting_key]=setting_value
config.pm.hook.get_db_store(config=config,datatype='wifi')
wifi_dic = config.store.get('wifi')
logger.debug(wifi_dic)
if wifi_dic:
config.store['device'] = wifi_dic['device_name']
if sys.argv[1] == 'setup':
device_setup(config)
elif sys.argv[1] == 'rm':
file_or_folder_name = sys.argv[2]
config.pm.hook.device_remove_file(config=config, filename=file_or_folder_name)
elif sys.argv[1] == 'run':
filename = sys.argv[2]
pre,ext = os.path.splitext(filename)
config.pm.hook.device_run_file(config=config, filename=pre)
elif sys.argv[1] == 'ls':
config.pm.hook.device_files(config=config)
elif sys.argv[1] == 'shell':
config.pm.hook.device_shell(config=config)
elif sys.argv[1] == 'cp':
source = sys.argv[2]
destination = sys.argv[3]
config.pm.hook.device_copy(config=config,source=source, destination=destination)
elif sys.argv[1] == 'mkdir':
dir_name = sys.argv[2]
config.pm.hook.device_mkdir(config=config,dir_name=dir_name)
elif sys.argv[1] == 'connect':
'''
ampy2.py connect device_name device_pin ssid password ip
'''
config.store['wifi']['device_name'] = sys.argv[2]
config.store['wifi']['device_pin'] = sys.argv[3]
config.store['wifi']['SSID'] = sys.argv[4]
config.store['wifi']['password'] = sys.argv[5]
config.store['wifi']['ip_address'] = sys.argv[6]
config.store['mpy_installed'] = True
config.store['device'] = config.store['wifi']['device_name']
config.pm.hook.device_verify_connection(config=config)
elif sys.argv[1] == 'putdir':
source = os.path.join('projects',sys.argv[2])
dest = sys.argv[3]
config.pm.hook.device_send_file(config=config, source=source, dest=dest, project=True)
if __name__ == '__main__':
main()