~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to bin/ivle-fetchsubmissions

ivle.database.Assessed: Added property is_group.
ivle-fetchsubmissions: Now able to determine the path to the repo (locally),
    and print it out (doesn't yet extract from the repo).

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
 
37
37
from ivle.database import Project, ProjectSet, Offering, Subject
38
38
 
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
41
41
    directory.
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.
45
46
    """
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
 
58
 
 
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.
 
63
    """
 
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'],
 
74
                                'groups', namespace)
 
75
    else:
 
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'],
 
79
                                'users', username)
 
80
 
 
81
    # Attach "file://" to the front of the absolute path, to make it a URL
 
82
    return "file://" + os.path.abspath(repo_path)
55
83
 
56
84
def main(argv=None):
57
85
    global store
109
137
    else:
110
138
        cutoff = None
111
139
 
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)
113
142
 
114
143
    # Get the subject from the DB
115
144
    subject = store.find(Subject,
161
190
        os.makedirs(target_dir)
162
191
 
163
192
    for submission in project.latest_submissions:
164
 
        fetch_submission(submission, target_dir)
 
193
        fetch_submission(submission, target_dir, config)
165
194
 
166
195
if __name__ == "__main__":
167
196
    sys.exit(main(sys.argv))