2018-08-27 11:06:04 -04:00
|
|
|
import os, shutil, sys, fnmatch, glob, pyboard_util
|
2018-07-16 18:04:42 -04:00
|
|
|
|
2018-08-27 11:06:04 -04:00
|
|
|
def sync(args, patterns, resources, verbose, skip_wifi):
|
2018-08-18 17:18:22 -04:00
|
|
|
root = get_root(verbose)
|
2018-07-16 18:04:42 -04:00
|
|
|
|
|
|
|
# Add all paths that are already files
|
2018-07-27 18:35:39 -04:00
|
|
|
paths = set([p for p in (patterns or []) if os.path.isfile(os.path.join(root, p))])
|
2018-07-16 18:04:42 -04:00
|
|
|
|
2018-07-27 18:35:39 -04:00
|
|
|
# Always copy boot.py
|
|
|
|
paths.add("boot.py")
|
2018-07-16 18:04:42 -04:00
|
|
|
|
2018-07-27 18:35:39 -04:00
|
|
|
# wifi.json
|
2018-08-26 15:27:23 -04:00
|
|
|
if not skip_wifi:
|
|
|
|
wifi_path = os.path.join(root, "wifi.json")
|
|
|
|
if os.path.isfile(wifi_path):
|
|
|
|
paths.add(wifi_path)
|
2018-07-16 18:04:42 -04:00
|
|
|
|
2018-07-27 18:35:39 -04:00
|
|
|
if not patterns:
|
|
|
|
patterns = ["*"]
|
|
|
|
|
2018-07-29 12:33:46 -04:00
|
|
|
synced_resources = []
|
2018-07-27 18:35:39 -04:00
|
|
|
for pattern in patterns:
|
|
|
|
found = False
|
|
|
|
for key, resource in resources.items():
|
|
|
|
if fnmatch.fnmatch(key, pattern):
|
|
|
|
found = True
|
2018-07-29 12:33:46 -04:00
|
|
|
synced_resources.append(key)
|
2018-07-27 18:35:39 -04:00
|
|
|
if verbose:
|
|
|
|
print("Resource %s is going to be synced" % key)
|
|
|
|
for path in resource['files'].keys():
|
|
|
|
paths.add(path)
|
2018-08-26 15:27:23 -04:00
|
|
|
if not found and (pattern not in paths):
|
2018-07-27 18:35:39 -04:00
|
|
|
print("WARN: No resources to copy found for pattern %s" % patterns)
|
2018-08-27 11:06:04 -04:00
|
|
|
pyboard_util.init_copy_via_repl(args)
|
2018-07-27 18:35:39 -04:00
|
|
|
if not verbose:
|
2018-08-21 15:47:39 -04:00
|
|
|
print("Copying %s files: " % len(paths), end="", flush=True)
|
2018-07-16 18:04:42 -04:00
|
|
|
for path in paths:
|
2018-07-27 18:35:39 -04:00
|
|
|
if not path:
|
|
|
|
continue
|
2018-07-16 18:04:42 -04:00
|
|
|
rel_path = os.path.relpath(path, root)
|
2018-07-27 18:35:39 -04:00
|
|
|
if rel_path.startswith(".") or os.path.isdir(path) or os.path.islink(path):
|
2018-07-16 18:04:42 -04:00
|
|
|
continue
|
2018-08-27 11:06:04 -04:00
|
|
|
|
|
|
|
updated = pyboard_util.copy_via_repl(args, path, rel_path)
|
2018-07-27 18:35:39 -04:00
|
|
|
if verbose:
|
2018-08-27 11:06:04 -04:00
|
|
|
print("Copied %s, updated: %s" % (rel_path, updated))
|
2018-07-27 18:35:39 -04:00
|
|
|
else:
|
2018-08-27 11:06:04 -04:00
|
|
|
if updated:
|
|
|
|
print("+", end="", flush=True)
|
|
|
|
else:
|
|
|
|
print("=", end="", flush=True)
|
|
|
|
pyboard_util.end_copy_via_repl(args)
|
2018-07-16 18:04:42 -04:00
|
|
|
|
2018-07-27 18:35:39 -04:00
|
|
|
if verbose:
|
2018-07-16 18:04:42 -04:00
|
|
|
print("Files copied successfully")
|
2018-07-27 18:35:39 -04:00
|
|
|
else:
|
|
|
|
print(" DONE")
|
2018-07-29 12:33:46 -04:00
|
|
|
return synced_resources
|
2018-07-16 18:04:42 -04:00
|
|
|
|
2018-08-27 11:06:04 -04:00
|
|
|
def clean(args):
|
|
|
|
pyboard_util.clean_via_repl(args)
|
2018-08-26 15:27:23 -04:00
|
|
|
|
2018-08-27 11:06:04 -04:00
|
|
|
def set_boot_app(args, app_to_boot):
|
|
|
|
content = app_to_boot + "\n"
|
|
|
|
pyboard_util.write_via_repl(args, content.encode("utf8"), 'once.txt')
|
2018-07-27 18:35:39 -04:00
|
|
|
if app_to_boot:
|
|
|
|
print("setting next boot to %s" % app_to_boot)
|
2018-07-16 18:04:42 -04:00
|
|
|
|
2018-08-27 11:06:04 -04:00
|
|
|
def set_no_boot(args):
|
|
|
|
pyboard_util.write_via_repl(args, b"\n", 'no_boot')
|
2018-08-05 17:14:31 -04:00
|
|
|
|
2018-08-18 17:18:22 -04:00
|
|
|
def get_root(verbose=False):
|
2018-07-16 18:04:42 -04:00
|
|
|
root = os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..'))
|
|
|
|
if not os.path.isfile(os.path.join(root, "boot.py")):
|
|
|
|
print("Path %s doesn't contain a boot.py, aborting. Something is probably wrong with your setup.")
|
|
|
|
sys.exit(1)
|
|
|
|
return root
|