From 41927aa4a6c6353a4cfd83abf8b69164f5365ca8 Mon Sep 17 00:00:00 2001 From: zthatch Date: Wed, 8 Jul 2020 14:22:40 -0400 Subject: [PATCH 1/2] AddedusernamerequirementtoBroker --- regolith/broker.py | 5 ++++- regolith/storage.py | 13 ++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/regolith/broker.py b/regolith/broker.py index c8b51bf73..cfe84b90a 100644 --- a/regolith/broker.py +++ b/regolith/broker.py @@ -2,11 +2,14 @@ from regolith.database import dump_database, open_dbs from regolith.runcontrol import DEFAULT_RC, load_rcfile, filter_databases from regolith.storage import store_client, push +import os def load_db(rc_file="regolithrc.json"): """Create a Broker instance from an rc file""" rc = DEFAULT_RC + if os.path.exists(rc.user_config): + rc._update(load_rcfile(rc.user_config)) rc._update(load_rcfile(rc_file)) filter_databases(rc) return Broker(rc) @@ -56,7 +59,7 @@ def add_file(self, document, name, filepath): document["files"][name] = output_path for db in self.rc.databases: dump_database(db, self.db_client, self.rc) - push(self.store.store, self.store.path) + push(self.store.store, self.store.path, self.rc) @classmethod def from_rc(cls, rc_file="regolithrc.json"): diff --git a/regolith/storage.py b/regolith/storage.py index 9e4b01f44..ca938cd56 100644 --- a/regolith/storage.py +++ b/regolith/storage.py @@ -81,12 +81,15 @@ def copydocs(store, path, rc): shutil.copy2(doc, dst) -def push_git(store, path): +def push_git(store, path, rc): """Pushes the local documents via git.""" storedir, _ = os.path.split(path) cmd = ["git", "add", "."] subprocess.check_call(cmd, cwd=storedir) - cmd = ["git", "commit", "-m", "regolith auto-store commit"] + if "default_user_id" in rc: + cmd = ["git", "commit", "-m", f"{rc.default_user_id} regolith auto-store commit"] + else: + print('Please add default_user_id to user.json in .config/regolith folder') try: subprocess.check_call(cmd, cwd=storedir) except subprocess.CalledProcessError: @@ -110,11 +113,11 @@ def push_hg(store, path): client.push() -def push(store, path): +def push(store, path, rc): """Pushes the local documents.""" url = store["url"] if url.startswith("git") or url.endswith(".git"): - push_git(store, path) + push_git(store, path, rc) elif url.startswith("hg+"): push_hg(store, path) elif not os.path.exists(os.path.expanduser(url)): @@ -179,7 +182,7 @@ def store_client(rc): path = storage_path(store, rc) sync(store, path) yield StorageClient(rc, store, path) - push(store, path) + push(store, path, rc) def main(rc): From 6d3aca997a69ea44339734cfb459aadffb03f80f Mon Sep 17 00:00:00 2001 From: zthatch Date: Wed, 8 Jul 2020 14:44:36 -0400 Subject: [PATCH 2/2] fixed previous change --- regolith/storage.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/regolith/storage.py b/regolith/storage.py index ca938cd56..5ff08c020 100644 --- a/regolith/storage.py +++ b/regolith/storage.py @@ -88,18 +88,19 @@ def push_git(store, path, rc): subprocess.check_call(cmd, cwd=storedir) if "default_user_id" in rc: cmd = ["git", "commit", "-m", f"{rc.default_user_id} regolith auto-store commit"] + try: + subprocess.check_call(cmd, cwd=storedir) + except subprocess.CalledProcessError: + warn("Could not git commit to " + storedir, RuntimeWarning) + return + cmd = ["git", "push"] + try: + subprocess.check_call(cmd, cwd=storedir) + except subprocess.CalledProcessError: + warn("Could not git push from " + storedir, RuntimeWarning) + return else: print('Please add default_user_id to user.json in .config/regolith folder') - try: - subprocess.check_call(cmd, cwd=storedir) - except subprocess.CalledProcessError: - warn("Could not git commit to " + storedir, RuntimeWarning) - return - cmd = ["git", "push"] - try: - subprocess.check_call(cmd, cwd=storedir) - except subprocess.CalledProcessError: - warn("Could not git push from " + storedir, RuntimeWarning) return