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

« back to all changes in this revision

Viewing changes to bin/ivle-fetchsubmissions

  • Committer: Matt Giuca
  • Date: 2009-05-12 15:08:45 UTC
  • mto: This revision was merged to the branch mainline in revision 1247.
  • Revision ID: matt.giuca@gmail.com-20090512150845-fg480l1qh7le0ypz
ivle-fetchsubmissions: In a stunningly awful hack, detects pre-Python2.6 and
    changes make_zip to behave correctly for the awful restriction in zipfile
    that you can't add directories.
    (Stops trying to add directories, and hacks in the footer writing if there
    is an empty file).

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
PYTHON26 = map(int, sys.version[:3].split('.')) >= [2, 6]
50
50
 
51
51
def fetch_submission(submission, target, svnclient, config, zip=False,
52
 
    txt=False, verbose=False):
 
52
    txt=False):
53
53
    """Fetch a submission from a user's repository, and dump it in a given
54
54
    directory.
55
55
    @param submission: Submission object, detailing the submission.
60
60
    @param zip: If True, zips up the submission.
61
61
    @param txt: If True, writes an extra text file with metadata about the
62
62
        submission.
63
 
    @param verbose: If True, writes the name of each submission to stdout.
64
63
    """
65
64
    # submission_name is the name of the user or group who owns the repo
66
65
    submission_name = submission.assessed.principal.short_name
69
68
                                submission.assessed.principal.short_name)
70
69
    target_final = target_final.encode('utf-8')
71
70
    if os.path.exists(target_final):
72
 
        # Remove the existing file or directory before re-checking out
73
 
        if os.path.isdir(target_final):
74
 
            ivle.util.safe_rmtree(target_final)
75
 
        else:
76
 
            os.remove(target_final)
 
71
        # Remove the existing directory before re-checking out
 
72
        ivle.util.safe_rmtree(target_final)
77
73
    url = get_repo_url(submission, config)
78
74
    revision = pysvn.Revision(pysvn.opt_revision_kind.number,
79
75
                              submission.revision)
89
85
    if zip:
90
86
        make_zip(target_final, target_final + ".zip")
91
87
        # Remove the target tree
92
 
        if os.path.isdir(target_final):
93
 
            ivle.util.safe_rmtree(target_final)
94
 
        else:
95
 
            os.remove(target_final)
96
 
 
97
 
    if verbose:
98
 
        print "Exported submission by: %s (%s)" % (
99
 
            submission.assessed.principal.short_name,
100
 
            submission.assessed.principal.display_name)
 
88
        ivle.util.safe_rmtree(target_final)
101
89
 
102
90
def get_repo_url(submission, config):
103
91
    """Gets a local (file:) URL to the repository for a given submission.
158
146
            raise OSError("Could not access a file (zipping)")
159
147
        for (dirpath, dirnames, filenames) in \
160
148
            os.walk(source, onerror=error):
161
 
            arc_dirpath = ivle.util.relpath(dirpath, relativeto)
 
149
            arc_dirpath = os.path.relpath(dirpath, relativeto)
162
150
            # Python < 2.6 errors if you add a directory
163
151
            # (This means you can't add an empty directory)
164
152
            if PYTHON26:
232
220
        action="store_true", dest="zip",
233
221
        help="Store each submission in a Zip file.",
234
222
        default=False)
235
 
    parser.add_option("-v", "--verbose",
236
 
        action="store_true", dest="verbose",
237
 
        help="Print out the name of each submission as it is extracted.",
238
 
        default=False)
239
223
    parser.add_option("--no-txt",
240
224
        action="store_false", dest="txt",
241
225
        help="Disable writing a text file with data about each submission.",
315
299
    for submission in project.latest_submissions:
316
300
        try:
317
301
            fetch_submission(submission, target_dir, svnclient, config,
318
 
                             zip=options.zip, txt=options.txt,
319
 
                             verbose=options.verbose)
 
302
                             zip=options.zip, txt=options.txt)
320
303
        except Exception, e:
321
304
            # Catch all exceptions (to ensure if one student has a problem, it
322
305
            # is reported, and we can continue)