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

« back to all changes in this revision

Viewing changes to ivle/zip.py

  • Committer: Matt Giuca
  • Date: 2009-01-19 17:28:59 UTC
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: matt.giuca@gmail.com-20090119172859-htjq3rfpp0fhtpc9
ivle.worksheet: Added calculate_score. This is a nice clean Storm port of
    ivle.db.calculate_worksheet_score.
tutorial: Replaced use of ivle.db.calculate_worksheet_score with
    ivle.worksheet.calculate_score.
    Guess What!! Removed this module's dependency on ivle.db! Hooray!
    (Note: tutorialservice still depends on it).
bin/ivle-marks: Updated this script to use ivle.worksheet_calculate_score.
    Note that this DOES NOT execute properly -- it seems it didn't even
    before my changes (tries to call db.get_users). Not my fault; I'm
    committing and going to bed!
ivle.db: Removed calculate_worksheet_score.
    As this removes the dependency on get_problem_status, removed that too!
    Almost all the worksheet stuff is gone now!

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
 
87
87
    zip.close()
88
88
 
89
 
def unzip(path, file, overwrite=False):
 
89
def unzip(path, file):
90
90
    """Unzips a zip file (or file-like object) into a path.
91
91
    Note: All files go directly into the path. To avoid having a "zip bomb"
92
92
    situation, the zip file should have a single directory in it with all the
93
93
    files.
94
94
    The path is an absolute path in the current filesystem
95
 
    (if this code is executed inside the jail, then it's inside the jail).
 
95
    (if this code is executed inside the jail, then it's inside the jail,
 
96
    if it's not then it's not).
96
97
    """
97
 
    # XXX: Really bad, but circular imports need avoiding.
98
 
    from ivle.fileservice_lib.exceptions import WillNotOverwrite
99
 
 
100
98
    zip = zipfile.ZipFile(file, 'r')
101
99
    # First test the zip file
102
100
    if zip.testzip() is not None:
103
101
        raise OSError("ZIP: Bad zip file")
104
102
 
105
 
    if (not overwrite):
106
 
        for filename in zip.namelist():
107
 
            localpath = os.path.join(path, filename)
108
 
            if os.path.exists(localpath):
109
 
                raise WillNotOverwrite(filename)
110
 
 
111
103
    for filename in zip.namelist():
112
104
        localpath = os.path.join(path, filename)
113
105
        # Create directory for filename
114
106
        (file_dir, _) = os.path.split(localpath)
115
107
        if not os.path.exists(file_dir):
116
108
            os.makedirs(file_dir)
117
 
        
 
109
 
118
110
        if filename.endswith(os.sep):
119
111
            # Is a directory make the directory
120
112
            if not os.path.exists(localpath):