Пример #1
0
    def index(self, *arg, **params):
        try:
            if params.get('storages'):
                storages = params.get('storages')
            elif params.get('disk') and not UtilFunc.isWindowsSystem():
                storages = params.get('disk')
                storages = ProfileFunc.get_name_label(storages)
            else:
                storages = ProfileFunc.GetBoxDisks(False)[0]
            
            global file_dir
            file_dir = storages
            tmpl = env.get_template('popoCloud.html')
            s_stores = []
            list_files = []
            extInfo = {}
            extInfo['limit'] = 1000 
            extInfo = UtilFunc.getOptParamsInfo(extInfo)
    
            if os.path.exists(storages):
                for file_info in UtilFunc.getFileList(storages, extInfo):
                    list_files.append({"path":file_info.get('url').split("/")[-1],"size":file_info.get("contentLength"),"modify":file_info.get("lastModify")})

            
            if UtilFunc.isWindowsSystem():
                if ProfileFunc.GetBoxDisks(False):
                    names = [u'我的磁盘一']
            else:
                for s_store in ProfileFunc.GetBoxDisks(False):
                    s_stores.append(ProfileFunc.get_label_name(s_store))
                    names = s_stores
            return tmpl.render(names=names, list_files = list_files)

        except Exception,e:
            Log.exception('index Failed! Reason[%s]'%e)
Пример #2
0
    def _scanFolder(self, scanPath, diskPath, recursive=False, scanType='all'):
        folder = unicode(scanPath.replace('\\', '/'))
        if not os.path.exists(folder): return
        for sub_file in os.listdir(folder):
            if not recursive and not {
                    'folder': scanPath,
                    'type': scanType
            } in self.folders[diskPath]['folders']:
                return
            if sub_file == '.popoCloud' or sub_file == '.cameraApp': continue

            path = unicode(os.path.join(folder, sub_file))
            if not os.path.exists(path) or sub_file[
                    -4:] == ".lnk" or UtilFunc.isHiddenFile(path):
                continue

            if UtilFunc.isShorcut(path):
                path = UtilFunc.getShortcutRealPath(path)
                if path and os.path.isdir(path):
                    self.mainService.folderMoniter.addDisk(path)

            if os.path.isdir(path):
                if recursive:
                    self._scanFolder(path, diskPath, recursive)
                continue
            ProfileFunc.addFileCache(path, scanType)
Пример #3
0
    def _getTraversalResult(self, arg, params):
        id = WebFunc.checkId(arg, self.traversalMap)
        start = int(params.get('offset', 0))
        limit = int(params.get('limit', -1))

        try:
            ret = []
            end = 0
            traversalInfo = self.traversalMap[id]['info']
            traversalInfo['lastTime'] = int(time.time())
            if limit > 0: end = start + limit
            result = ProfileFunc.getTraversalTBWithId(id, start, end)
            resultLen = len(result)
            if resultLen < limit:
                limit = resultLen
                end = start + limit
            ProfileFunc.delTraversalTBWithId(id, end)
            traversalInfo['start'] = end
            Log.info(
                'Get TraversalFolder Result:start[%d], limit[%d], count[%d]' %
                (start, limit, len(result)))
            return WebFunc.jsonResult({'files':result, 'finish':traversalInfo['finished'], \
                        'fileCount':traversalInfo['fileCount'], 'folderCount':traversalInfo['folderCount']})
        except Exception, e:
            Log.error("Get Traversal Folder Result Failed! Reason[%s]" % e)
            return cherrypy.HTTPError(462, 'Operation Failed')
Пример #4
0
    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()
Пример #5
0
def getPictureHashPath(hash):
    for disk in ProfileFunc.getAllDisks():
        path = os.path.join(disk, ".popoCloud/ThumbImage", hash[:2], hash)
        path = ProfileFunc.slashFormat(path)
        if os.path.exists(path):
            return path
    return None
Пример #6
0
 def _dellabel(self, params):
     names = params.get('names', None)
     names = UtilFunc.strToList(names)
     SqlStr = "delete from fileCache where label=?"
     for name in names:
         ProfileFunc.execAllScanFolderSql(SqlStr, (name, ))
     cherrypy.response.status = 205
     return
Пример #7
0
def getDefaultPath(path=None):
    if path:
        if not getDiskPath(path):
            return os.path.join(
                ProfileFunc.GetBoxDisks(False)[0],
                path[1:] if path.startswith('/') else path)
        return path
    else:
        return ProfileFunc.GetBoxDisks(False)[0]
Пример #8
0
 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()
Пример #9
0
    def run(self):
        dirName = self.dirPath
        hdir = win32file.CreateFile(
            dirName, GENERIC_READ | GENERIC_WRITE,
            FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
            win32security.SECURITY_ATTRIBUTES(), OPEN_EXISTING,
            FILE_FLAG_BACKUP_SEMANTICS, 0)

        filter = FILE_NOTIFY_CHANGE_FILE_NAME | \
                        FILE_NOTIFY_CHANGE_DIR_NAME \
                        | FILE_NOTIFY_CHANGE_ATTRIBUTES | \
                        FILE_NOTIFY_CHANGE_LAST_WRITE | \
                        FILE_NOTIFY_CHANGE_SIZE

        win32Handle = win32file.FindFirstChangeNotification(
            dirName, True, filter)

        while UtilFunc.programIsRunning():
            results =  win32file.ReadDirectoryChangesW(
                hdir,
                819600,
                True,
                FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME | \
                FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_LAST_WRITE | \
                FILE_NOTIFY_CHANGE_CREATION,
                #                FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_LAST_ACCESS |FILE_NOTIFY_CHANGE_SECURITY
                None,
                None
                )

            for action, file in results:
                path = file
                if path == 'Thumbs.db':
                    continue

                path = os.path.join(dirName, path)
                path = path.replace('\\', '/')
                if '/.popoCloud/' in path or os.path.basename(
                        path) == '.popoCloud':
                    continue


#                print str(action) + " " + path

                if action == 1 or action == 5:
                    if os.path.isdir(path):
                        ProfileFunc.addToLibrary(path)
                    else:
                        ProfileFunc.addFileCache(path)
                elif action == 2 or action == 4:
                    ProfileFunc.delFileCache(path)
                elif action == 3:
                    if not os.path.isdir(path):
                        ProfileFunc.delFileCache(path)
                        ProfileFunc.addFileCache(path)

            win32file.FindNextChangeNotification(win32Handle)
Пример #10
0
    def _onMessage(self, msg):
        (clientMsg, ) = self.parseData(msg, ('message', ))
        command = clientMsg.get('command', '')
        if command == 'UNBIND':
            ProfileFunc.clearLibraryDB()
            os._exit(0)

        elif command == 'RESTART':
            Log.info('[Hub]PopoBox ReStart!')
            os._exit(0)
Пример #11
0
    def make_file(self, binary=None):
        """Overridable: return a readable & writable file.

        The file will be used as follows:
        - data is written to it
        - seek(0)
        - data is read from it

        The 'binary' argument is unused -- the file is always opened
        in binary mode.

        This version opens a temporary file for reading and writing,
        and immediately deletes (unlinks) it.  The trick (on Unix!) is
        that the file can still be used, but it can't be opened by
        another process, and it will automatically be deleted when it
        is closed or when the current process terminates.

        If you want a more permanent file, you derive a class which
        overrides this method.  If you want a visible temporary file
        that is nevertheless automatically deleted when the script
        terminates, try defining a __del__ method in a derived class
        which unlinks the temporary files you have created.

        """
        import tempfile
        import ProfileFunc

        if self.parent and 'path' in self.parent:
            fullpath = unicode(
                ProfileFunc.slashFormat(self.parent['path'].value))
            dname, fname = os.path.split(fullpath)
            if not os.path.exists(dname) and ProfileFunc.isPathValid(dname):
                os.makedirs(dname)
            #Need check the folder 'dname' is exist?
            if dname and fname:
                f = tempfile.NamedTemporaryFile('w+b',
                                                dir=dname,
                                                prefix='.popotmp_',
                                                delete=False)
                #f = file(fullpath, 'w+b')
            else:
                f = tempfile.NamedTemporaryFile('w+b',
                                                prefix=tmp_prefix,
                                                delete=True)
            return f
        else:
            try:
                #TODO: should not always use first disk/partition!!!
                dir = ProfileFunc.GetBoxDisks()[0] + "/.popoCloud/tmp"
                if not os.path.exists(dir) and ProfileFunc.isPathValid(dir):
                    os.makedirs(dir)
                flag = False
            except:
                dir = None
            return tempfile.NamedTemporaryFile(dir=dir, delete=False)
Пример #12
0
    def _cancelTraversalFolder(self, arg):
        sid = WebFunc.checkId(arg, self.traversalMap)
        try:
            traversalMapEntry = self.traversalMap[sid]
            traversalInfo = traversalMapEntry['info']
            traversalInfo['finished'] = 1

            del self.traversalMap[sid]
            ProfileFunc.delTraversalCacheDB(sid)
            Log.info('Cancel Traversal Folder!!!!')
        except Exception, e:
            Log.exception("Cancel Traversal Folder Failed! Reason[%s]" % e)
            raise cherrypy.HTTPError(462, 'Operation Failed')
Пример #13
0
    def DELETE(self, *arg, **params):
        sid = WebFunc.checkId(arg, self.searchMap)
        try:
            searchInfo = self.searchMap[sid]['info']
            searchInfo['finished'] = 1

            del self.searchMap[sid]
            ProfileFunc.delSearchCacheDB(sid)
            Log.debug('Cancel Search!!!!')

        except Exception, e:
            Log.error("Cancel Search Failed! Reason[%s]" % e)
            raise cherrypy.HTTPError(462, 'Operation Failed')
Пример #14
0
 def _getStorageInfo(self, path):
     ret = {}
     ret['root'] = UtilFunc.toLinuxSlash(path)
     sid = ProfileFunc.getMainServer().diskInfo.get(path,{}).get('id','')
     name = ProfileFunc.getMainServer().diskInfo.get(path,{}).get('name','')
     if sid == '':
         sid, fs, name = Command.getDiskInfo(path)
         ProfileFunc.getMainServer().diskInfo[path] = {'id':sid,'name':name,'fs':fs}
     ret['id'] = sid
     ret['name'] = name
     ret['free'], ret['capacity'] = UtilFunc.getRemainSpace(path)
     if ProfileFunc.isMediaFolder(path): ret['isMediaFolder'] = '1' 
     else: ret['isMediaFolder'] = '0'
     return ret
Пример #15
0
    def _traversalFolder(self, path):
        if not path:
            raise cherrypy.HTTPError(460, 'Bad Parameter')

        if not os.path.exists(path):
            raise cherrypy.HTTPError(464, 'Not Exist')

        if UtilFunc.isLinuxSystem():
            if UtilFunc.isLinuxDiskReadOnly(path):
                raise cherrypy.HTTPError(463, 'Not Permitted')
            if UtilFunc.isLowDiskSpace(path):
                raise cherrypy.HTTPError(467, 'Not Enough Disk Space')

        try:
            traversalInfo = {}
            traversalInfo['path'] = ''
            traversalInfo['fileCount'] = 0
            traversalInfo['folderCount'] = 0
            traversalInfo['totalSize'] = 0
            traversalInfo['finished'] = 0
            traversalInfo['start'] = 0
            traversalInfo['folder'] = ''
            traversalInfo['startTime'] = int(time.time())
            traversalInfo['lastTime'] = int(time.time())
            traversalInfo['success'] = 0
            Log.info('Start Traversal Folder!!!!')
            uuidStr = None
            while True:
                uuidStr = str(uuid.uuid4())
                if uuidStr not in self.traversalMap:
                    ProfileFunc.initTraversalDB(uuidStr)
                    traversalInfo['id'] = uuidStr
                    thread = TraversalFolderThread(traversalInfo, path)
                    threadStatus = TraversalFolderThreadStatus(
                        traversalInfo, self.traversalMap)
                    self.traversalMap[uuidStr] = {
                        'thread': thread,
                        'threadStatus': threadStatus,
                        'info': traversalInfo
                    }
                    thread.start()
                    threadStatus.start()
                    break
            cherrypy.response.status = 202
            return WebFunc.jsonResult({"id": uuidStr})
        except Exception, e:
            Log.error("Traversal Folder Failed! Reason[%s]" % e)
            raise cherrypy.HTTPError(462, 'Operation Failed')
Пример #16
0
def is_sub_folder(ele_path, scan_list):
    for scan_path in scan_list:
        if len(ele_path.split('/')) > len(
                scan_path.split('/')) and ProfileFunc.compare_path(
                    ele_path, scan_path):
            return True
    return False
Пример #17
0
    def DELETE(self, *arg, **params):
        intent = params.get('intent', None)
        if intent == 'traversal':
            return self._cancelTraversalFolder(arg)
        path = self._formatPath(arg, params)
        try:
            if os.path.isdir(path):
                shutil.rmtree(path)
            else:
                os.remove(path)
                ProfileFunc.delFileCache(path)
#                 removeSql = "delete from fileCache where url='%s'"%path
#                 ProfileFunc.execSubLibrarySqlbyPath(path, removeSql)
        except Exception, e:
            Log.exception('Files DELETE Excepted! Reason[%s]' % e)
            raise cherrypy.HTTPError(463, 'Not Permitted')
Пример #18
0
 def POST(self, *arg, **params):
     if not ProfileFunc.GetBoxDisks():
         raise cherrypy.HTTPError(465, 'Not Exist Disk')
     intent = params.get('intent', 'set')
     if intent == 'set':
         return self._setlabel(params)
     return
Пример #19
0
    def _downloadShare(self, path):
        if not os.path.exists(path):
            return WebFunc.jsonResult({'errCode': 464})
        if os.path.isdir(path):
            folderPath = ProfileFunc.slashFormat(path)
            filename = os.path.basename(folderPath)
            filename = filename + '.zip'
            request = cherrypy.serving.request
            filename = UtilFunc.StringUrlEncode(filename)

            response = cherrypy.response
            response.headers['Content-Type'] = 'application/zip'
            response.headers['Last-Modified'] = time.time()
            User_Agent = request.headers.get('User-Agent')
            if 'Firefox' in User_Agent:
                response.headers[
                    'Content-Disposition'] = 'attachment;filename*="%s"' % filename
            else:
                response.headers[
                    'Content-Disposition'] = 'attachment;filename="%s"' % filename

            zipobj = ZipStream(folderPath)
            return zipobj.__iter__()
        else:
            filename = os.path.basename(path)
            filename = UtilFunc.StringUrlEncode(filename)
            return PostStatic.serve_download(path, filename)
Пример #20
0
def getContactBackupDir():
    disks = ProfileFunc.GetBoxDisks()
    if not disks:
        return None
    filePath = os.path.join(disks[0], '.popoCloud')
    folder = os.path.join(filePath, 'Contact Backup').replace('\\', '/')
    return folder
Пример #21
0
    def POST(self, *arg, **params):
        if not arg:
            raise cherrypy.HTTPError(460, 'Bad Parameters')

        storageId = arg[0]
        if not ProfileFunc.GetBoxDisks() or not storageId in ProfileFunc.getStorageIds():
            raise cherrypy.HTTPError(465, 'Not Exist Disk')
        folders, delpaths = params.get('folders',[]), params.get('except',[])
        if not folders and not delpaths: 
            raise cherrypy.HTTPError(460, 'Bad Parameter')
        folders = UtilFunc.strToList(folders)
        delpaths = UtilFunc.strToList(delpaths)
        ret = ProfileFunc.getMainServer().scanFolderMoniter.setMediaFolder(folders,delpaths)
        
        cherrypy.response.status = 205
        return WebFunc.jsonResult(ret)
Пример #22
0
    def __init__(self, parent):
        wx.Window.__init__(self, parent, -1, pos=(12, 73), size=(526,281))
        self.SetBackgroundColour(wx.RED)

        self.parent = parent

        imgPath = os.path.join(UtilFunc.module_path(), '%s/%s'%(parent_dir,set_cloudset))
        bgpng = wx.Image(imgPath, wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        size = bgpng.GetSize()
        self.SetClientSize(size)
        self.bgParent = BGPanel(self, size=size, bmp=bgpng)

        imgPath = os.path.join(UtilFunc.module_path(), '%s/%s'%(parent_dir, set_add))
        set_add_one  = wx.Image(imgPath, wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        self.set_add_bt = wx.BitmapButton(self.bgParent, -1, set_add_one, pos=(347, 33), style = wx.NO_BORDER)

        imgPath = os.path.join(UtilFunc.module_path(), '%s/%s'%(parent_dir, set_add_choose))
        set_add_one  = wx.Image(imgPath, wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        self.set_add_bt.SetBitmapHover(set_add_one)
        self.Bind(wx.EVT_BUTTON, self.OnBrowser, self.set_add_bt)

        self.scan_path= wx.TextCtrl(self.bgParent, -1, ProfileFunc.GetPictureFolder() , (118,36), size=(218,22))
        self.scan_path.SetBackgroundColour((0xFF, 0xFF, 0xFF))
        self.scan_path.Disable()

        self.file_panels = FileScanListPannel(self.bgParent)
        self.file_panels.showList()
Пример #23
0
 def createfile(self, *arg, **params):
     global file_dir
     if not file_dir:
         file_dir = ProfileFunc.GetBoxDisks(False)[0]
     if params.get("docname"):
         file_path = os.path.join(file_dir,params.get("docname"))
         createFile(file_path,False,{'size':1})
     return self.index(storages=file_dir)
Пример #24
0
    def start(self):
        folderInfos = ProfileFunc.execLibrarySql('select * from folders')

        for folderInfo in folderInfos:
            folderId = folderInfo[0]
            folderPath = unicode(folderInfo['path'])

            self.addFolder(folderPath, folderId)
Пример #25
0
def initDBTables():
    dropDBTable(TB_CACHE)
    createDBTables()
    if UtilFunc.isPCMode() and not tableSelect(TB_FOLDER):
        path = ProfileFunc.GetPictureFolder()
        tableInsert(TB_FOLDER,
                    ['type', 'partpath', 'path', 'scanning', 'needScan'],
                    ['all', UtilFunc.getDiskPath(path), path, '0', '1'])

    for disk in ProfileFunc.GetBoxDisks():
        did, fs, name = Command.getDiskInfo(disk)
        path = UtilFunc.getDiskPath(disk, True)
        ProfileFunc._fileService.diskInfo[path] = {
            'id': did,
            'fs': fs,
            'name': name
        }
Пример #26
0
def getDBConnection():
    dbPath = ProfileFunc.getUserDBPath()
    if not dbPath: return None
    try:
        db_connect = sqlite3.connect(os.path.join(dbPath, 'es_base.db'))
    except Exception, e:
        Log.error("ConnectDB Error : %e" % e)
        return None
Пример #27
0
def getRealPathByName(name):
    num = 1
    for disk in ProfileFunc.GetBoxDisks():
        diskname = u'Storage' + str(num)
        if diskname in name:
            return disk
        num += 1
    return None
Пример #28
0
 def __init__(self, _searchInfo, _keyword, _folder, _recursive):
     threading.Thread.__init__(self)
     self.searchInfo = _searchInfo
     self.ret = []
     self.keyword = _keyword
     self.recursive = _recursive
     if UtilFunc.isWindowsSystem() and UtilFunc.isSlash(_folder):
         rootDirs = ProfileFunc.getRootFolders()
         rootDirs = UtilFunc.mergeSubFolder(rootDirs, 'url')
         self.folders = []
         for dirInfo in rootDirs:
             self.folders.append(dirInfo['url'])
     else:
         if PopoConfig.Hardware == "1.5" and _folder == '/':
             self.folders = ProfileFunc.GetBoxDisks()
         else:
             self.folders = [_folder]
Пример #29
0
def formatAutoUploadPath(parentFolder):
    disk = ProfileFunc.GetBoxDisks()
    if not disk: return None
    disk_path = os.path.join(disk[0], "Camera Uploads")
    if not os.path.exists(disk_path): os.mkdir(disk_path)
    parentFolder = parentFolder.replace(
        parentFolder.split("Camera Uploads")[0], disk[0] + "/")
    return parentFolder
Пример #30
0
 def GET(self, **params):
     return WebFunc.jsonResult({'deviceType'     : UtilFunc.getDeviceType(),
                                'serverVersion'  : PopoConfig.VersionInfo,
                                'system'         :'Linux/PopoBox',
                                'systemVersion'  : UtilFunc.getSystemVersion(),
                                'ImgVersion'     : UtilFunc.getIMGVersion()['ver'],
                                'hardwareVersion': PopoConfig.Hardware,
                                'ecsVersion'     : ProfileFunc.getMainServer().ecsModule.version() if hasattr(ProfileFunc.getMainServer(), 'ecsModule') else 'NoECS',
                                })