Example #1
0
File: main.py Project: zz2/walkbox
    def GET(self):
        '''接受要下载的id, 然后压缩到一个可下载路径 '''
        x = web.input()
        print x
        selectids = (x.argv).split('-')
        print selectids
        teacherid = session.id
        jobs_path = os.path.join(JOBS_PATH, str(teacherid))
        if not os.path.isdir(jobs_path):
            return 'it is crazy, no teacher dir'

        file_paths = []
        not_exists = []
        for i in selectids:
            job_path = os.path.join(jobs_path, i)
            print 'job_path:%s'%job_path
            if not os.path.isfile(job_path):
                not_exists.append(i.split('__')[-1])
                continue
            file_paths.append(job_path)
        print file_paths

        download_path = os.path.join(APP_ROOT, 'static/download')
        utils.prepare(download_path)
        timestr = time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime())
        zfile_path = os.path.join(download_path, 
                timestr+"-"+str(uuid.uuid1())+'.zip')
        try:
            zip = zipfile.ZipFile(zfile_path, 'w', zipfile.ZIP_DEFLATED)
            for file_path in file_paths:
                zip.write(file_path, (file_path.split('/')[-1]).split('__')[-1])
            if not len(not_exists) == 0:
                not_exists.append('很抱歉,下面文件没能找到')
                zip.writestr('README', '\n'.join(not_exists[::-1]))
            zip.close()
        except Exception, err:
            #这个地方应该定义一个500错误
            raise web.internalerror()
Example #2
0
#!/usr/bin/env python
# -*- coding:utf-8 -*-

#用来创建数据库


import os
import sqlite3

from ggsddu import config
from ggsddu.common import utils

#创建walkbox_db
sql_path = config.SQL_PATH
db_path = config.DB_PATH
db_dir = os.path.dirname(db_path)
utils.prepare(db_dir)
if not os.path.exists(db_path):
    conn = sqlite3.connect(db_path)
    cursor = conn.cursor()
    cursor.executescript(open(sql_path).read())
    conn.commit()
    cursor.close()
    conn.close()
    print 'create db: %s'%(db_path)
else:
    msg = '没有执行创建db操作,数据库已存在, %s'%(db_path)
    print msg
    raise Exception, msg