コード例 #1
0
ファイル: code.py プロジェクト: Tangdongle/CHESS
 def POST(self, cin, fname, is_l):
     form = self.form()
     i = web.input(repofile={})
     web.debug(i['repofile'].filename)
     web.debug(i['repofile'])
     if 'repofile' in i:
         copy_num = -1
         filepath = i.repofile.filename.replace('\\','/')
         filename = filepath.split('/')[-1]
         filepath = REPO_DIR + str(session.cin) + '/' + 'latest' + '/' + filename
         old_filepath = REPO_DIR + str(session.cin) + '/' + 'old' + '/' + filename
         base_repo_dir = REPO_DIR + str(session.cin)
         if not ospath.exists(base_repo_dir):
             os.mkdir(base_repo_dir)
         if not ospath.exists(base_repo_dir + '/' + 'latest'):
             os.mkdir(base_repo_dir + '/' + 'latest')
         if os.path.exists(filepath):
             if not ospath.exists(base_repo_dir + '/' + 'old'):
                 os.mkdir(base_repo_dir + '/' + 'old')
             move(filepath, old_filepath)
         outfd = open(filepath,'wb')
         try:
             outfd.write(i.repofile.file.read())
             outfd.close()
             last_rev = model.add_repo_resource(session.cin, filename)
             if last_rev >= 0:
                 new_fn = filename[:filename.find('.')] + str(last_rev) + filename[filename.find('.'):]
                 copy(old_filepath, REPO_DIR + str(session.cin) + '/' + 'old' + '/' + new_fn)
             raise web.seeother('/repository/succ')
         except IOError:
             resources = (list(set([(i.resourcefname, i.is_latest, datetime.fromtimestamp(i.mod_timestamp)) for i in model.get_client_repo(session.cin)])))
             return render.repository(form, resources, "File upload failed")
コード例 #2
0
ファイル: code.py プロジェクト: Tangdongle/CHESS
 def GET(self, cin, fname, is_l):
     if not logged_in():
         raise web.seeother('/login')
     form = self.form()
     resources = (list(set([(i.resourcefname, i.is_latest, datetime.fromtimestamp(i.mod_timestamp)) for i in model.get_client_repo(session.cin)])))
     # If filename has been retrieved with a GET request
     web.debug(fname, cin, is_l)
     if fname == 'succ' and not cin:
         return render.repository(form, resources, 'File upload successful!')
     if fname and cin:
         fpath = REPO_DIR + str(cin) + '/'
         if is_l == 'T':
             fpath += 'latest' + '/' + fname
         else:
             fpath += 'old' + '/' + fname
         web.debug(fpath)
         if ospath.exists(fpath):
             web.debug(fpath)
             resource = file(fpath,'r')
             #TODO: Add download counter/statistic recorder here
             web.header('Content-Type','attachment/octet-stream')
             web.header('Content-transfer-encoding','base64')
             return resource.read()
     else:
         return render.repository(form, resources)