Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AddedUserNameReq #542

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion regolith/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"):
Expand Down
34 changes: 19 additions & 15 deletions regolith/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see my comment on the other PR. It looks as we may need default_github_id in regolithrc.json

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


Expand All @@ -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)):
Expand Down Expand Up @@ -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):
Expand Down