Skip to content

Commit

Permalink
Merge branch 'main' into automatic_restriction_lifting
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorax66 committed Feb 5, 2023
2 parents a52688a + 31c39d7 commit 7461acd
Show file tree
Hide file tree
Showing 9 changed files with 225 additions and 172 deletions.
2 changes: 1 addition & 1 deletion cms/grading/Sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,7 @@ def initialize_isolate(self):
+ (["--cg"] if self.cgroup else [])
+ ["--box-id=%d" % self.box_id, "--init"])
try:
subprocess.check_call(init_cmd)
subprocess.check_call(init_cmd, stdout=subprocess.DEVNULL)
except subprocess.CalledProcessError as e:
raise SandboxInterfaceException(
"Failed to initialize sandbox") from e
Expand Down
166 changes: 93 additions & 73 deletions cms/io/Repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ class Repository:
You have to use one repository object for all of these!
"""

def __init__(self, path, auto_sync=False):
def __init__(self, path, auto_sync=False, auto_push=False):
self.lock = Manager().Lock()
self.path = path
self.auto_sync = auto_sync
self.auto_push = auto_push

def __enter__(self):
self.lock.acquire()
Expand All @@ -56,82 +57,101 @@ def __exit__(self, type, value, traceback):
def _sync(self):
if self.auto_sync:
logger.info("Synchronizing {}".format(self.path))

with chdir(self.path):
gitout = ""

try:
gitout = check_output(["git", "pull"])
except:
logger.error("Couldn't sync with repository: " +
"{}".format(gitout))
else:
logger.info("Finished synchronization: " +
"{}".format(gitout))

gitout = ""

self._pull()
if self.auto_push:
self._push()

def _pull(self):
logger.info("Pulling {}".format(self.path))

with chdir(self.path):
gitout = ""

try:
gitout = check_output(["git", "pull"])
except:
logger.error("Couldn't pull from repository " +
"({})".format(gitout))
else:
logger.info("Finished pulling: " +
"{}".format(gitout))

def _push(self):
logger.info("Pushing {}".format(self.path))

with chdir(self.path):
gitout = ""

try:
gitout = check_output(["git", "push"])
except:
logger.error("Couldn't push to repository " +
"({})".format(gitout))
else:
logger.info("Finished pushing: " +
"{}".format(gitout))

# For GerTranslate
# TODO Show errors in web overview
def commit(self, file_path, file_identifier):
# TODO Only do this if it's a git repository
# if self.auto_sync:
logger.info("Committing {} in {}".format(file_path, self.path))

with chdir(self.path):
gitout = ""

try:
gitout = check_output(["git", "add",
file_path])
except:
logger.error("Couldn't add file to git staging area: " +
"{}".format(gitout))
else:
try:
gitout = check_output(["git", "push"])
gitout = ""
# NOTE file_path is relative to self.path, which isn't
# necessarily the root of the git repo. So the commit
# message might be confusing.
gitout = \
check_output(
["git", "commit",
"-o", file_path,
# TODO Provide meaningful commit message and
# author
"-m", "Changes to " +
file_identifier +
", uploaded via GerTranslate web "
"interface",
"--author", '"GerTranslate <GerTranslate@localhost>"']
)
except:
logger.error("Couldn't push to repository: " +
logger.error("Couldn't commit in repository: " +
"{}".format(gitout))
else:
logger.info("Finished pushing: " +
logger.info("Committed: " +
"{}".format(gitout))

#For GerTranslate
#TODO Show errors in web overview
def commit(self, file_path, file_identifier):
#TODO Only do this if it's a git repository
#if self.auto_sync:
logger.info("Committing {} in {}".format(file_path,self.path))

with chdir(self.path):
gitout = ""

try:
gitout = check_output(["git", "add",
file_path])
except:
logger.error("Couldn't add file to git staging area: " +
"{}".format(gitout))
else:
try:
gitout = ""
#NOTE file_path is relative to self.path, which isn't
#necessarily the root of the git repo. So the commit message
#might be confusing.
gitout = check_output(["git", "commit",
"-o", file_path,
"-m","Changes to "+file_identifier+", uploaded via GerTranslate web interface",
#TODO Provide meaningful commit message and author
"--author","\"GerTranslate <GerTranslate@localhost>\""])
except:
logger.error("Couldn't commit in repository: " +
"{}".format(gitout))
else:
logger.info("Committed: " +
"{}".format(gitout))

#For GerTranslate
#TODO Show errors in web overview
# For GerTranslate
# TODO Show errors in web overview
def getlog(self, file_path):
#TODO Only do this if it's a git repository
#if self.auto_sync:
with chdir(self.path):
gitout = ""

try:
#TODO Remove diff info lines
gitout = check_output(["git", "log",
'--pretty=format:Date: %ci%n%n %s%n',
"-p",
"--word-diff=color",
file_path])
except:
logger.error("Couldn't get log: " +
"{}".format(gitout))
else:
gitout = gitout.decode('utf-8')
return gitout
# TODO Only do this if it's a git repository
# if self.auto_sync:
with chdir(self.path):
gitout = ""

try:
# TODO Remove diff info lines
gitout = check_output(
["git", "log",
'--pretty=format:Date: %ci%n%n %s%n',
"-p",
"--word-diff=color",
file_path]
)
except:
logger.error("Couldn't get log: " +
"{}".format(gitout))
else:
gitout = gitout.decode('utf-8')
return gitout
Loading

0 comments on commit 7461acd

Please sign in to comment.