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

« back to all changes in this revision

Viewing changes to bin/ivle-fetchsubmissions

ivle-fetchsubmissions: Now actually svn exports the submissions to the target
    directory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
import datetime
28
28
import optparse
29
29
 
 
30
import pysvn
 
31
 
30
32
if os.getuid() != 0:
31
33
    print >>sys.stderr, "Must run %s as root." % os.path.basename(sys.argv[0])
32
34
    sys.exit()
36
38
 
37
39
from ivle.database import Project, ProjectSet, Offering, Subject
38
40
 
39
 
def fetch_submission(submission, target, config):
 
41
def fetch_submission(submission, target, svnclient, config):
40
42
    """Fetch a submission from a user's repository, and dump it in a given
41
43
    directory.
42
44
    @param submission: Submission object, detailing the submission.
51
53
    if not os.path.exists(target_final):
52
54
        os.makedirs(target_final)
53
55
    # TODO: Actually get the repo and extract the files
54
 
    print "Submission by %s, path %s" % (
55
 
        submission.assessed.principal.name, submission.path)
 
56
    print "Submission by %s, path %s, revision %d" % (
 
57
        submission.assessed.principal.name, submission.path,
 
58
        submission.revision)
56
59
    url = get_repo_url(submission, config)
57
60
    print "    from %s" % url
 
61
    revision = pysvn.Revision(pysvn.opt_revision_kind.number,
 
62
                              submission.revision)
 
63
    svnclient.export(url, target_final, force=True,
 
64
        revision=revision, recurse=True)
58
65
 
59
66
def get_repo_url(submission, config):
60
67
    """Gets a local (file:) URL to the repository for a given submission.
144
151
    else:
145
152
        cutoff = None
146
153
 
 
154
    svnclient = pysvn.Client()
147
155
    config = ivle.config.Config(plugins=False)
148
156
    store = ivle.database.get_store(config)
149
157
 
197
205
        os.makedirs(target_dir)
198
206
 
199
207
    for submission in project.latest_submissions:
200
 
        fetch_submission(submission, target_dir, config)
 
208
        fetch_submission(submission, target_dir, svnclient, config)
201
209
 
202
210
if __name__ == "__main__":
203
211
    sys.exit(main(sys.argv))