def DELETE(self, *arg, **params): if arg: if arg[0] == 'tags': tags = params.get('tags',[]) filetype = params.get('fileType', 'picture') if not tags: raise cherrypy.HTTPError(460, 'Bad Parameter') tags = json.loads(tags) for tag in tags: #ProfileFunc.removeLabels(tag) SqliteFunc.tableRemove(SqliteFunc.TB_TAGS, 'tag = ? and fileType= ?', (tag,filetype,)) elif arg[0] == 'date': dates = params.get('dates',[]) if not dates:raise cherrypy.HTTPError(460, 'Bad Parameter') dates = json.loads(dates) for date in dates: photos = SqliteFunc.tableSelect(SqliteFunc.TB_CACHE, ['url'], 'groupTime = "%s"'%date) for photo in photos: if os.path.exists(photo['url']): os.remove(photo['url']) SqliteFunc.tableRemove(SqliteFunc.TB_CACHE, 'groupTime = "%s"'%date) else: raise cherrypy.HTTPError(460, 'Bad Parameter') cherrypy.response.status = 205 return
def optionTags(path, tags=[], action='add',fileType='picture'): # dbpath = UtilFunc.getDiskPath(path, True) # conn = getConfDb(dbpath) # cur = conn.cursor() # if not tags: # cur.execute('delete from fileCache where url = ?', (path,)) # conn.commit() # else: # for tag in tags: # if action == 'add': # sqlStr = 'replace into fileCache(url, fileType, tag) values(?, ? ,?)' # else: # sqlStr = 'delete from fileCache where url = ? and fileType = ? and tag = ?' # cur.execute(sqlStr, (path, fileType, tag,)) # conn.commit() # cur.close() # conn.close() if not tags: SqliteFunc.tableRemove('tags', 'url = ?', (path,)) else: for tag in tags: if action == 'add': sqlStr = 'replace into tags(url, fileType, tag) values(?, ? ,?)' else: sqlStr = 'delete from tags where url = ? and fileType = ? and tag = ?' SqliteFunc.execSql(sqlStr, (path, fileType, tag,))
def delPath(self, evt=None): if UtilFunc.isWindowsSystem(): self.path = self.path.decode(defaultCode) if self.path != ProfileFunc.GetPictureFolder(): SqliteFunc.tableRemove(SqliteFunc.TB_FOLDER, 'path = ?',(self.path,)) ProfileFunc.removeFromLibrary(self.path) time.sleep(0.5) self.filepannel.showList()
def removeFromLibrary(path): mainServer = getMainServer() if UtilFunc.isWindowsSystem(): mainServer.folderMoniter.delFolder(path) mainServer.folderMoniter.notifyConfigChanged() #execSubLibrarySqlbyPath(path, "delete from fileCache where url like ?", (path+'/%',)) SqliteFunc.tableRemove(SqliteFunc.TB_CACHE, 'url like ?', (path+'/%',)) mainServer.scanFolderMoniter.removeFolder(path) SqliteFunc.execSql('delete from folders where path = ?',(path,))
def _deleteShare(ids): ids = UtilFunc.strToList(ids) sqlStr = ','.join(["'" + urlId + "'" for urlId in ids]) #ProfileFunc.execSharesSql("delete from shares where url in (%s)"%sqlStr) SqliteFunc.tableRemove( SqliteFunc.TB_SHARES, 'url in (%s)' % sqlStr, ) conn = ProfileFunc.getMsgChannel() msg = {'urlIds': ids} conn.send(msg, 0x0043)
def delFileCache(filePath): #ret = execSubLibrarySqlbyPath(filePath, 'select * from fileCache where url=?', (filePath,)) ret = SqliteFunc.tableSelect(SqliteFunc.TB_CACHE, [], 'url = ?', (filePath,)) if not ret: return None if len(ret) > 0: delThumbImage(filePath) #execSubLibrarySqlbyPath(filePath, 'delete from fileCache where url=?', (filePath,)) SqliteFunc.tableRemove(SqliteFunc.TB_CACHE, 'url = ?', (filePath,)) else: removeFolderCache(filePath)
def _getShares(self): #ret = ProfileFunc.execSharesSql('select * from shares') ret = SqliteFunc.tableSelect(SqliteFunc.TB_SHARES) shares = [] for share in ret: validity = _getvalidity(share['lastModify'], share['validity']) if not os.path.exists(share[2]) or ( validity <= 0 and str(share['validity']) != '-1'): #ProfileFunc.execSharesSql('delete from shares where id = ?',(share[0],)) SqliteFunc.tableRemove(SqliteFunc.TB_SHARES, 'id = ?', (share[0], )) continue shares.append(_formatShare(share)) return shares
def _getImageGroup(self, groupType, params): orderBy = params.get('order', None) limit = int(params.get('limit',1)) groupDict = {'date':'groupTime','folders':'folders','tags':'tag'} if not groupType in groupDict.keys(): raise cherrypy.HTTPError(460,'Bad Parameter') group_name = groupDict[groupType] scan_list_p = [] if group_name == 'folders' and not ProfileFunc.getAllMediaFolders(): raise cherrypy.HTTPError(464, 'Not Exist') if groupType == 'tags': #sqlStr = 'select tag, count(*) from (select * from fileCache where fileType="picture") group by tag' #groups = ProfileFunc.execAllScanFolderSql(sqlStr) sqlStr = 'select tag, count(*) from (select * from tags where fileType="picture") group by tag' groups = SqliteFunc.execSql(sqlStr) return WebFunc.jsonResult({'tags':[{'name':file['tag'],'total':file['count(*)']} for file in groups]}) elif groupType == 'folders': SqliteFunc.tableRemove(SqliteFunc.TB_CACHE, "folder is ''") scan_list= ProfileFunc.getAllSetFolders() for path_ele in set(scan_list): if not UtilFunc.is_sub_folder(path_ele, scan_list): scan_list_p.append(path_ele) ret_list_info = [] for ret_path in scan_list_p: if os.path.exists(ret_path): ret_list_info.append(ProfileFunc.dir_info(ret_path)) else: SqliteFunc.tableRemove(SqliteFunc.TB_CACHE, 'url=?', (ret_path,)) return WebFunc.jsonResult({'groupType' : group_name, 'folders' : UtilFunc.formatPhotoRet(ret_list_info, params)}) else: start = params.get('start', '1970-01') end = params.get('end', '9999-12') baseStr = 'select * from fileCache where fileType="picture" and groupTime >= "%s" and groupTime <="%s"'%(start,end) sqlStr = 'select groupTime, count(*) from (%s) group by groupTime order by lastModify asc'%baseStr #groups = SqliteFunc.execSql(sqlStr) groups = SqliteFunc.execSql(sqlStr) if not groups: for disk in ProfileFunc.GetBoxDisks(): if ProfileFunc.getMainServer().diskState.has_key(disk) and \ ProfileFunc.getMainServer().diskState[disk] == 2: raise cherrypy.HTTPError(463, 'Not Permitted') if UtilFunc.isLowDiskSpace(disk): raise cherrypy.HTTPError(467, 'Not Enough Disk Space') ret, ret_count, tmp_ret_dict = [], 0, {} for fileInfo in groups: if not tmp_ret_dict.has_key(fileInfo[group_name]): tmp_ret_dict[fileInfo[group_name]] = ret_count else: ret[tmp_ret_dict[fileInfo[group_name]]]['total'] += fileInfo['count(*)'] continue ret_count += 1 dbList = SqliteFunc.execFileCacheTags(' and a.%s = "%s"'%(group_name, fileInfo[group_name])) photos = UtilFunc.formatPhotoRet(dbList, params) if not photos: continue ret.append({'name' : fileInfo[group_name], 'total' : fileInfo['count(*)'], 'photos': photos}) if orderBy: cmpInfo = UtilFunc.httpArgToCmpInfo(orderBy) if len(cmpInfo) > 0 : ret.sort(lambda x,y: UtilFunc.dictInfoCmp(x, y, cmpInfo)) return WebFunc.jsonResult({groupType:ret})
def removeFolderCache(path): SqliteFunc.tableRemove(SqliteFunc.TB_CACHE, 'url like ?', (path + '/%',))