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..5ff08c020 100644 --- a/regolith/storage.py +++ b/regolith/storage.py @@ -81,22 +81,26 @@ 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"] - 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) + 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') return @@ -110,11 +114,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 +183,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):