def OnBrowser(self, evt): # In this case we include a "New directory" button. dlg = wx.DirDialog(self, "Choose a directory:", style=wx.DD_DEFAULT_STYLE #| wx.DD_DIR_MUST_EXIST #| wx.DD_CHANGE_DIR ) # If the user selects OK, then we process the dialog's data. # This is done by getting the path data from the dialog - BEFORE # we destroy it. add_path = '' if dlg.ShowModal() == wx.ID_OK: add_path = dlg.GetPath().replace('\\','/') self.scan_path.SetValue(add_path) # Only destroy a dialog after you're done with it. dlg.Destroy() if add_path: strSql = 'replace into folders(type, partpath, path, needScan, scanning) values(?,?,?,1,0)' SqliteFunc.execSql(strSql, ('all', UtilFunc.getDiskPath(add_path), add_path)) ProfileFunc.addToLibrary(add_path, True, 'all', True) #ProfileFunc.getMainServer().scanFolderMoniter.setMediaFolder([{'folder':add_path,'type':'all'}],[]) time.sleep(0.5) self.file_panels.showList()
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 _updateFile(self, path, params): name = params.get('name', '') lastModify = params.get('lastModify', '') if name: newpath = os.path.join(os.path.dirname(path), name) if os.path.exists(newpath): raise cherrypy.HTTPError(469, 'Already Exist') os.rename(path, newpath) sqlStr = 'update fileCache set url = ?, name = ? where url = ?' #ProfileFunc.execSubLibrarySqlbyPath(path, sqlStr, (newpath, name, path,)) SqliteFunc.execSql(sqlStr, ( newpath, name, path, )) path = newpath if lastModify: UtilFunc.setFileTime(path, lastModify) sqlStr = 'update fileCache set lastModify =? where url = ?' #ProfileFunc.execSubLibrarySqlbyPath(path, sqlStr, (lastModify, path,)) SqliteFunc.execSql(sqlStr, ( lastModify, path, )) cherrypy.response.status = 205
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 _delNotExistImageThumb(self, disk): #files = ProfileFunc.execSubLibrarySqlbyPath(disk, 'select remarks from fileCache where fileType = "picture" or fileType = "video"', None) files = SqliteFunc.execSql( 'select remarks from fileCache where fileType = ? or fileType = ?', ( 'picture', 'video', )) hash_list = [] if not files: return for fileInfo in files: remarks = json.loads(fileInfo['remarks']) hash_list.append(remarks['thumbnail-small']) hash_list.append(remarks['thumbnail-large']) thumbImage_path = os.path.join(UtilFunc.getDiskPath(disk, True), ".popoCloud/ThumbImage").replace( "\\", "/") try: for folder in os.listdir(thumbImage_path): folder_path = os.path.join(thumbImage_path, folder).replace("\\", "/") if not os.path.isdir(folder_path): continue for thunmbNail in os.listdir(folder_path): file_path = os.path.join(folder_path, thunmbNail).replace("\\", "/") if not thunmbNail in hash_list: os.remove(file_path) if not os.listdir(folder_path): os.rmdir(folder_path) except Exception, e: Log.error("DelNotExistImageThumb Failed! Reason[%s]" % e)
def GET(self, *arg, **params): if not arg: raise cherrypy.HTTPError(460, 'Bad Parameter') intent = arg[0] if intent == 'all': sqlStr = 'select url, name, remarks from fileCache where fileType = "music"' return WebFunc.jsonResult({'songs': _formatRet(sqlStr, params)}) elif intent in ['albums', 'artists', 'genres']: key = ''.join(arg[1:]) if key: sqlStr = "select url, name, remarks from fileCache where fileType = 'music'" ret = [ x for x in _formatRet(sqlStr, {}) if str(x.get(intent[:-1], '')) == key ] return WebFunc.jsonResult( {'songs': UtilFunc.orderAndLimit(ret, params)}) else: ret = [] tempList = [] sqlStr = 'select remarks from fileCache where fileType = "music"' sqlret = SqliteFunc.execSql(sqlStr) for onefile in sqlret: remarks = json.loads(onefile['remarks']) if not remarks: continue if intent == 'albums': if remarks[ 'album'] and not remarks['album'] in tempList: tempList.append(remarks['album']) ret.append({ 'title': remarks['album'], 'artist': remarks['artist'], 'year': remarks['year'], 'composer': remarks['composer'], 'genre': remarks['genre'] }) else: if remarks[intent[:-1]] and not remarks[ intent[:-1]] in ret: ret.append(remarks[intent[:-1]]) return WebFunc.jsonResult( {intent: UtilFunc.orderAndLimit(ret, params)}) elif intent == 'folders': path = UtilFunc.formatPath(arg[1:]) if not path or not os.path.exists(path): raise cherrypy.HTTPError(464, 'Not Exist') if not os.path.isdir(path): raise cherrypy.HTTPError(460, 'Bad Parameter') folders, songs = UtilFunc.walkFolder(path, 'music', params) return WebFunc.jsonResult({'folders': folders, 'songs': songs}) elif intent == 'stream': return UtilFunc.mediaPlay(''.join(arg[1:])) else: raise cherrypy.HTTPError(460, 'Bad Parameter')
def _remove(self, all_del_set, flag=False): for fullpath in all_del_set: del_scan_path = UtilFunc.getSiteRoot(fullpath) if flag: ProfileFunc._execSql(ProfileFunc.getConfDb(UtilFunc.getDiskPath(fullpath)),\ "delete from mediafolder where url=?", (del_scan_path, )) ProfileFunc._execSql(ProfileFunc.getConfDb(UtilFunc.getDiskPath(fullpath)),\ "delete from selectfolder where url=?", (del_scan_path, )) del_scan_path_like = del_scan_path + '/%' ProfileFunc._execSql(ProfileFunc.getConfDb(UtilFunc.getDiskPath(fullpath)),\ "delete from mediafolder where url like ?", (del_scan_path_like, )) ProfileFunc._execSql(ProfileFunc.getConfDb(UtilFunc.getDiskPath(fullpath)),\ "delete from selectfolder where url like ?", (del_scan_path_like, )) SqliteFunc.execSql("delete from fileCache where folder like ?", (fullpath, )) if not self.stop_flag: ProfileFunc.removeFromLibrary(fullpath) else: break
def addShare(shareId, location, url, name, ext, isdir, access, validity, size): global _shareMutex _shareMutex.acquire() try: location = location.decode('utf-8') name = name.decode('utf-8') except: pass #ret = execSharesSql('select * from shares where shareId=?', (shareId,)) ret = SqliteFunc.tableSelect(SqliteFunc.TB_SHARES, [], 'shareId=?', (shareId,)) if not ret or len(ret) == 0: #ret = execSharesSql('insert into shares(shareId, location, url, name, contentType, isFolder, extractionCode, validity, contentlength, lastModify) values(?,?,?,?,?,?,?,?,?,?)', (shareId, location, url, name, ext, isdir, access, validity, size, UtilFunc.Now())) ret = SqliteFunc.tableInsert(SqliteFunc.TB_SHARES, ['shareId', 'location', 'url', 'name', 'contentType', 'isFolder', 'extractionCode', 'validity', 'contentlength', 'lastModify'],\ (shareId, location, url, name, ext, isdir, access, validity, size, UtilFunc.Now(),)) else: #ret = execSharesSql('update shares set location=?, url=?, name=?, contentType=?, isFolder=?, extractionCode=?, validity=?, contentlength=?, lastModify=? where shareId=?', (location, url, name, ext, isdir, access, validity, size, UtilFunc.Now(), shareId)) sqlStr = 'update shares set location=?, url=?, name=?, contentType=?, isFolder=?, extractionCode=?, validity=?, contentlength=?, lastModify=? where shareId=?' ret = SqliteFunc.execSql(sqlStr, (location, url, name, ext, isdir, access, validity, size, UtilFunc.Now(), shareId,)) _shareMutex.release() return ret
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 _formatRet(sqlStr, params): datas = SqliteFunc.execSql(sqlStr) return UtilFunc.formatMediaRet(datas, params)