37
37
from ivle.database import Project, ProjectSet, Offering, Subject
39
def fetch_submission(submission, target):
39
def fetch_submission(submission, target, config):
40
40
"""Fetch a submission from a user's repository, and dump it in a given
42
42
@param submission: Submission object, detailing the submission.
43
43
@param target: Target directory for the project (will create a
44
44
subdirectory for each submission).
45
@param config: Config object.
46
47
# submission_name is the name of the user or group who owns the repo
47
48
submission_name = submission.assessed.principal.name
52
53
# TODO: Actually get the repo and extract the files
53
54
print "Submission by %s, path %s" % (
54
55
submission.assessed.principal.name, submission.path)
56
url = get_repo_url(submission, config)
57
print " from %s" % url
59
def get_repo_url(submission, config):
60
"""Gets a local (file:) URL to the repository for a given submission.
61
@param submission: Submission object, detailing the submission.
62
@param config: Config object.
64
# NOTE: This code is mostly copied from services/usrmgt-server
65
if submission.assessed.is_group:
66
# The offering this group is in
67
offering = submission.assessed.project.project_set.offering
68
groupname = submission.assessed.principal.name
69
# The name of the repository directory within 'groups' is
70
# SUBJECT_YEAR_SEMESTER_GROUP
71
namespace = "_".join([offering.subject.short_name,
72
offering.semester.year, offering.semester.semester, groupname])
73
repo_path = os.path.join(config['paths']['svn']['repo_path'],
76
# The name of the repository directory within 'users' is the username
77
username = submission.assessed.principal.name
78
repo_path = os.path.join(config['paths']['svn']['repo_path'],
81
# Attach "file://" to the front of the absolute path, to make it a URL
82
return "file://" + os.path.abspath(repo_path)
56
84
def main(argv=None):
112
store = ivle.database.get_store(ivle.config.Config(plugins=False))
140
config = ivle.config.Config(plugins=False)
141
store = ivle.database.get_store(config)
114
143
# Get the subject from the DB
115
144
subject = store.find(Subject,
161
190
os.makedirs(target_dir)
163
192
for submission in project.latest_submissions:
164
fetch_submission(submission, target_dir)
193
fetch_submission(submission, target_dir, config)
166
195
if __name__ == "__main__":
167
196
sys.exit(main(sys.argv))