Esempio n. 1
0
    def saveZipFile(self,data):
        try:
            db = DBService(Pic,Pic.__tablename__)
            file_name =data.get('filename')
            name,path =self.makedir("zip-"+file_name)
            #存入CACHE_PATH文件夹中
            with open(os.path.join(CACHE_PATH,file_name),"wb") as fp:
                fp.write(data.get('body'))
            zipfileData = zipfile.ZipFile(os.path.join(CACHE_PATH,file_name))
            files = []
            for each in zipfileData.filelist:
                name = str(zipfileData.extract(each,path))
                if os.path.splitext(name)[1]:
                    files.append(name.split(str(os.path.normpath(PIC_PATH)))[1])
            for each_file in files:
                db.addRecord(Pic(name=each_file.replace('\\','-') ,path=each_file))
            for each_file_a in files:
                children_list = []
                parent_id = db.searchRecord(Pic.path==each_file_a).id
                for each_file_b in files:
                    if os.path.split(each_file_b)[0]==os.path.splitext(each_file_a)[0]:
                        children_list.append(db.searchRecord(Pic.path==each_file_b).id)
                        db.updateRecord(Pic.path==each_file_b,Pic.parent,parent_id)
                db.updateRecord(Pic.path==each_file_a,Pic.children,str(children_list))


        except Exception as e:
            _result = -1,"Error\nexception message :"+e.message
Esempio n. 2
0
 def signup(self,**kwargs):
     user= User(
         name=kwargs.get("username"),
         realname=kwargs.get("realname"),
         password = kwargs.get("password"),
         email=kwargs.get("email")
     )
     db = DBService(User,User.__tablename__)
     db.addRecord(user)
     pass
Esempio n. 3
0
 def savePic(self,data):
     _result = 1,"ok"
     try:
         file_name =data.get('filename')
         filename,realpath = self.makedir(file_name)
         with open(os.path.join(realpath,file_name),"wb") as fp:
             fp.write(data.get('body'))
         db = DBService(Pic,Pic.__tablename__)
         db.addRecord(Pic(name=file_name,path=os.path.join('\\',filename, file_name).replace('\\','\\\\')))
     except Exception as e:
         _result = -1,"Error\nexception message :"+e.message
     finally:
         return _result