Пример #1
0
    def __init__( self, tree=None, parent=None, name=None, statInfo=None, asDotEntry=False ):
        FileInfo.__init__(self, tree, parent, name, statInfo)

        self._isDotEntry           = False  # Flag: is this entry a "dot entry"?
        self._isMountPoint         = False  # Flag: is this a mount point?
        self._pendingReadJobs      = 0      # number of open directories in this subtree

        # Children management

        self._firstChild           = None   # pointer to the first child
        self._dotEntry             = None   # pseudo entry to hold non-dir children

        # Some cached values

        self._totalSize            = self._size
        self._totalArea            = self._area
        self._totalBlocks          = self._blocks
        self._totalItems           = 0
        self._totalSubDirs         = 0
        self._totalFiles           = 0
        self._latestMtime          = self._mtime

        self._summaryDirty         = False  # dirty flag for the cached values
        self._beingDestroyed       = False
        # [TODO] : Queue system
        self._readState            = None

        if asDotEntry :
            self._isDotEntry     = True
            self._dotEntry       = None
            self._name           = "."
        else :
            self._isDotEntry     = False
Пример #2
0
 def stat(self, params):
     self.assert_permission(Session.MODE_INFO)
     if params is None:
         params = ""
     tokens = params.split(" ", 1)
     asFile = tokens[0]!="N"
     if len(tokens)>1:
         path = tokens[1]
     else:
         path = "."
     path = self.makeabs(path)
     fi = FileInfo(path)
     if not fi.exists():
         self.control.write_message("500 Directory/file does not exist or cannot be accessed!")
         return Session.ACTION_CONTINUE
     if asFile or not fi.is_dir():
         file_list = [ fi ]
     else:
         file_list = [ FileInfo(os.path.normpath(os.path.join(path,p))) for p in os.listdir(path)]
     self.control.write_message("211- Sending file list")
     for f in file_list:
         try:
             self.control.write_message(" %s" % f.simple_list())
         except:
             # don't want to fail here
             pass
     self.control.write_message("211 End of file list")
     return Session.ACTION_CONTINUE
Пример #3
0
def search_file_by_str2(rootdir, strs, obj_result, o_redis, str_id):
    for root, dirs, files in os.walk(rootdir, followlinks=True):
        #for i in range(0,len(dirs)):
        #    str_dir_temp = os.path.join(root, dirs[i]) + "\\"
        #    #str_dir_temp = root + dirs[i] + "\\"
        #    search_file_by_str2(str_dir_temp,strs,obj_result,o_redis,str_id)

        for i in range(0, len(files)):
            for j in range(0, len(strs)):
                if files[i].endswith(strs[j]):
                    p = FileInfo()
                    p.fileDir = root
                    p.fileRoot = p.fileDir.split('\\')[0]
                    p.fileName = files[i]
                    p.fileFullPath = os.path.join(root, files[i])
                    p.fileExtension = strs[j]
                    fi = os.stat(p.fileFullPath)
                    p.fileIndex = fi.st_ino
                    p.fileSize = int(fi.st_size) / 1024 / 1024 / 1024
                    p.fileRootID = str_id
                    #封装消息
                    obj_result.code = 1
                    obj_result.msg = json_dict_to_str(p.__dict__)
                    str_result = json_dict_to_str(obj_result.__dict__)
                    redis_public(o_redis, str_result)
Пример #4
0
 def __setitem__(self, key, val):
   print('MP3FileInfo: call __setitem__')
   if  key == 'name' and val:
     self.__parse(val)
   # python searches and finds the class (UserDict) 
   # that defines __setitem__
   FileInfo.__setitem__(self, key, val)
Пример #5
0
 def __setitem__(self, key, val):
     print('MP3FileInfo: call __setitem__')
     if key == 'name' and val:
         self.__parse(val)
     # python searches and finds the class (UserDict)
     # that defines __setitem__
     FileInfo.__setitem__(self, key, val)
Пример #6
0
 def size(self, params):
     self.assert_permission(Session.MODE_INFO)
     path = self.makeabs(params)
     fi = FileInfo(path)
     if not fi.exists():
         msg = "500 Directory/file does not exist or cannot be accessed!"
     else:
         msg = "213 %s" % fi.size()
     self.control.write_message(msg)
     return Session.ACTION_CONTINUE
Пример #7
0
 def mlst(self,params):
     self.assert_permission(Session.MODE_INFO)
     if params is None:
         params = ""
     path = self.makeabs(params)
     fi = FileInfo(path)
     if not fi.exists():
         self.control.write_message("500 Directory/file does not exist or cannot be accessed!")
         return Session.ACTION_CONTINUE
     self.control.write_message("250- Listing %s" % path)
     self.control.write_message(" %s" % fi.as_mlist())
     self.control.write_message("250 End")
     return Session.ACTION_CONTINUE
Пример #8
0
    def parser(self, html_cont):
        '''
        :param html_cont: html内容
        :return:
        '''
        if html_cont is None:
            return None
        soup = BeautifulSoup(html_cont, 'html.parser', from_encoding='utf-8')
        subject = soup.find('div', class_="hd").get_text()
        links = soup.find_all('a', class_='J-media-item')
        html_down = HtmlDownloader()
        for link in links:
            fileinfo = FileInfo()
            # strip() 去除字符串前后空字符
            fileinfo.subject = subject.strip()
            fileinfo.filename = link.get_text().strip().replace(
                ':', '_').replace("\r\n", "").replace(u'开始学习',
                                                      "").replace(' ', '')
            fileinfo.mid = link['href'].split('/')[2]
            json = html_down.download(conf.DOWNLOAD_URL.format(
                fileinfo.mid)).decode('utf-8').replace('\/', '/')
            try:
                dic_json = eval(json)
            except:
                print('error')

            fileinfo.url['L'] = dic_json['data']['result']['mpath'][0]
            fileinfo.url['M'] = dic_json['data']['result']['mpath'][1]
            fileinfo.url['H'] = dic_json['data']['result']['mpath'][2]
            # 将
            self.res_data.append(fileinfo)

        return self.res_data
Пример #9
0
 def retr(self, params):
     self.assert_permission(Session.MODE_READ)
     path = self.makeabs(params)
     fi = FileInfo(path)
     if not fi.exists():
         self.control.write_message("500 Directory/file does not exist or cannot be accessed!")
         return Session.ACTION_CONTINUE
     if self.have_range:
         size = self.number_of_bytes
     else:
         size = fi.size()
         self.number_of_bytes = size - self.offset
     self.file_path = path
     self.control.write_message("150 OK %s bytes available for reading." % size)
     return Session.ACTION_RETRIEVE
Пример #10
0
 def __init__(self, editor):
     GObject.__init__(self)
     self.__init_attributes(editor)
     from FileInfo import FileInfo
     FileInfo(self, editor)
     from Window import Window
     Window(self, editor)
     from NameLabel import Label
     Label(self, editor)
     from TypeLabel import Label
     Label(self, editor)
     from SizeLabel import Label
     Label(self, editor)
     from LocationLabel import Label
     Label(self, editor)
     from MIMELabel import Label
     Label(self, editor)
     from LinesLabel import Label
     Label(self, editor)
     from WordsLabel import Label
     Label(self, editor)
     from CharactersLabel import Label
     Label(self, editor)
     from ModifiedLabel import Label
     Label(self, editor)
     from AccessedLabel import Label
     Label(self, editor)
Пример #11
0
 def upload(self, path='hello.txt'):
     with open(path, 'rb') as upload_file:
         upload_data = upload_file.read()
         file_info = os.stat(path)
     cur_file_info = FileInfo(file_info.st_mode, file_info.st_mtime, path,
                              os.path.getsize(path)).json_dump()
     # print((cur_file_info))
     cur_file_info = parse.quote(cur_file_info, safe='')
     # print((cur_file_info))
     upload_response = self.sess.post(cfg.URLS['upload'],
                                      params={'fileinfo': cur_file_info},
                                      data=upload_data)
     upload_res = upload_response.text
     print(upload_res)
     return False, '上传失败!'
Пример #12
0
 def build_infolist(self, type=''):
     filenames = self.build_filelist(type)
     dirnames = self.build_dirlist()
     # get information by creating a FileInfo object
     infos = []
     for fname in filenames:
         info = FileInfo(self.path, fname)
         infos.append(info)
     # deal with the inner directory
     for dirname in dirnames:
         new_path = join(self.path, dirname)
         newdir = DirInfo(new_path)
         new_infos = newdir.build_infolist(type)
         infos = infos + new_infos
     return infos
Пример #13
0
 def upload(self, path='123.txt'):
     with open(path, 'rb') as upload_file:
         upload_data = upload_file.read()
         file_info = os.stat(path)
     cur_file_info = FileInfo(file_info.st_mode, file_info.st_mtime, path,
                              os.path.getsize(path)).json_dump()
     print(cur_file_info)
     cur_file_info = parse.quote(cur_file_info, safe='')
     # print((cur_file_info))
     upload_response = self.sess.put(cfg.URLS['upload'] + '123.txt',
                                     data=upload_data)
     print(upload_data)
     upload_res = upload_response.text
     upload_res_dict = json.loads(upload_res)
     if upload_res_dict['status'] == 0:
         return True, '上传成功!'
     return False, '上传失败!'
Пример #14
0
 def send_directory_listing(self, path, mlsd=False, linux_mode=False):
     fi = FileInfo(path)
     if not fi.exists() or not fi.is_dir():
         self.control.write_message("500 Directory does not exist.")
         return Session.ACTION_CLOSE_DATA
     try:
         file_list = os.listdir(path)
     except Exception as e:
         self.control.write_message("500 Error listing <%s>: %s"% (path, str(e)))
         return Session.ACTION_CLOSE_DATA
     self.control.write_message("150 OK")
     for p in file_list:
         try:
             fi = FileInfo(os.path.normpath(os.path.join(path,p)))
             if mlsd:
                 self.data.write_message(fi.as_mlist())
             elif linux_mode:
                 self.data.write_message(fi.list())
             else:
                 self.data.write_message(fi.simple_list())
         except Exception as e:
             self.LOG.debug("Error listing %s : %s" % (p, str(e)) )
     self.post_transfer()
     return Session.ACTION_CLOSE_DATA
Пример #15
0
    def scan( self, rootpath=None ) :
        """Scan the rootpath and build the tree."""
        if rootpath :
            self._rootpath = rootpath
            self._root = None
        pathinfos = {}

        sizeColorProvider.reinitFileTree()
        for infopath in os.walk(self._rootpath,False) :
            #print "[%s]" % (pathinfos,)
            (path,subpaths,files) = infopath

            if path == self._rootpath :
                name = path
            else :
                name = os.path.split(path)[1]

            dirInfo = DirInfo( name=name, statInfo=os.lstat(path), tree=self )

            pathinfos[path] = dirInfo

            for file in files :
                completepath = os.path.join(path,file)
                try :
                    fileInfo = FileInfo( name=file, statInfo=os.lstat(completepath), tree=self, parent=dirInfo )
                    dirInfo.insertChild(fileInfo)
                except :
                    pass

            for subpath in subpaths :
                completepath = os.path.join(path,subpath)
                if completepath in pathinfos :
                    # print "[%s] : %d v (%s)" % (subpath,pathinfos[completepath].totalArea(),completepath)
                    dirInfo.insertChild(pathinfos[completepath])
                    # print "[%s] : %d ^ (%s)" % (subpath,pathinfos[completepath].totalArea(),completepath)
                    del pathinfos[completepath]

            dirInfo.finalizeLocal()

            if path == self._rootpath :
                self._root = dirInfo
        # print "[%s]" % (pathinfos,)
        return self._root
Пример #16
0
 def upload(self, path='hello.txt'):
     global user_cookie
     with open(path, 'rb') as upload_file:
         upload_data = upload_file.read()
         file_info = os.stat(path)
     # print(upload_data)
     # print(file_info)
     # return
     cur_file_info = FileInfo(file_info.st_mode, file_info.st_mtime, path,
                              os.path.getsize(path)).json_dump()
     print((cur_file_info))
     cur_file_info = parse.quote(cur_file_info, safe='')
     print((cur_file_info))
     upload_response = requests.post(cfg.URLS['upload'] + '?' +
                                     'fileinfo=' + cur_file_info,
                                     data=upload_data,
                                     cookies=user_cookie)
     upload_res = upload_response.text
     print(upload_res)
     return False, '上传失败!'
Пример #17
0
    def __init__(self, files: dict):
        self.code = str()
        self.filesList = list()
        for i, data in files.items():
            f = FileInfo()
            f.name = getKey(data, 'name')
            f.mimetype = getKey(data, 'mimetype')
            f.size = getKey(data, 'size')
            f.md5 = getKey(data, 'md5')
            self.filesList.append(f)

        self.server = str()
        self.views = int()
        self.number = int()
        self.totalSize = int()
        self.uploadTime = int()
        self.removalCode = str()
        self.adminCode = str()
        self.removalDate = int()
Пример #18
0
        relation[fnames[i]].append(args[j])

# determine the operations on one file
outputfile, desfile, prelistfile = "", "", ""
for fname in fnames:
    if '-o' in relation[fname]:
        outputfile = fname
    elif '-e' in relation[fname]:
        prelistfile = fname
    else:
        desfile = fname

# use dialog to open file
if args == ['-x']:
    path, fname = dialog_get()
    onefile = FileInfo(path, fname)
    print(onefile.char_num())
    print(onefile.line_num())
    print(onefile.word_num([]))
# dealing with the directory
elif desfile != '' and '-s' in relation[desfile]:
    directory = DirInfo(cur_file_dir())
    # determine the type needed
    tmplist = desfile.split('.')
    type = '.' + tmplist[-1]
    # get the required list
    localinfo = directory.build_infolist(type)
    for info in localinfo:
        str = ""
        if '-c' in relation[desfile]:
            print(info.char_num())
Пример #19
0
    def scan(self, rootpath=None):
        """Scan the rootpath and build the tree."""
        if rootpath:
            self._rootpath = rootpath
            self._root = None
        pathinfos = {}

        sizeColorProvider.reinitFileTree()

        exclude_list_re = []

        for exclude_item in self._exclude_list:
            exclude_list_re.append(
                re.compile(
                    '^' + str(exclude_item).replace('\\', '\\\\').replace(
                        '.', '\\.').replace('[', '\\[').replace(']', '\\]').
                    replace('(', '\\(').replace(')', '\\)').replace(
                        '+', '\\+').replace('*', '.*').replace('?', '.') +
                    '$'))

        for exclude_item_re in self._exclude_list_re:
            exclude_list_re.append(re.compile(exclude_item_re))

        for infopath in self.file_provider().walk():
            #print "[%s]" % (pathinfos,)
            (path, subpaths, files) = infopath

            if path == self._rootpath:
                name = path
            else:
                name = self.file_provider().split(path)[1]

            dirInfo = DirInfo(name=self.file_provider().get_clean_name(name),
                              statInfo=self.file_provider().stat(path),
                              tree=self)

            pathinfos[path] = dirInfo

            for file in files:
                exclude = False
                for exclude_item_re in exclude_list_re:
                    if exclude_item_re.match(file):
                        exclude = True
                if not (exclude):
                    completepath = self.file_provider().join(path, file)
                    try:
                        fileInfo = FileInfo(
                            name=self.file_provider().get_clean_name(file),
                            statInfo=self.file_provider().stat(completepath),
                            tree=self,
                            parent=dirInfo)
                        dirInfo.insertChild(fileInfo)
                    except:
                        pass

            for subpath in subpaths:
                exclude = False
                for exclude_item_re in exclude_list_re:
                    if exclude_item_re.match(subpath):
                        exclude = True
                if not (exclude):
                    completepath = self.file_provider().join(path, subpath)
                    if completepath in pathinfos:
                        # print "[%s] : %d v (%s)" % (subpath,pathinfos[completepath].totalArea(),completepath)
                        dirInfo.insertChild(pathinfos[completepath])
                        # print "[%s] : %d ^ (%s)" % (subpath,pathinfos[completepath].totalArea(),completepath)
                        del pathinfos[completepath]

            dirInfo.finalizeLocal()

            if path == self._rootpath:
                self._root = dirInfo
        # print "[%s]" % (pathinfos,)
        return self._root
Пример #20
0
def get_my_files(rootdir, dirs, exts1, exts2, obj_result, o_redis, str_id):
    str_root = rootdir
    for str in os.listdir(str_root):
        str_path = (str_root + os.sep + str)
        if os.path.isdir(str_path):
            if str in dirs:
                p = FileInfo()
                p.fileDir = disk_info.getUpUpDirPath(str_path)
                p.fileRoot = disk_info.getRootDir(str_path)
                p.fileName = disk_info.getUpDir(str_path)
                p.fileFullPath = disk_info.getUpDirPath(str_path)
                p.fileExtension = "DIR"
                #由于是文件夹,所以没有判定文件序列、大小
                #fi = os.stat(p.fileFullPath)
                #p.fileIndex = fi.st_ino
                #p.fileSize = int(fi.st_size) /1024/1024/1024
                p.fileIndex = "1"
                p.fileSize = get_dir_file_size(p.fileFullPath)
                p.fileRootID = str_id
                #封装消息
                obj_result.code = 1
                obj_result.msg = json_dict_to_str(p.__dict__)
                str_result = json_dict_to_str(obj_result.__dict__)
                redis_public(o_redis, str_result)
                return
        elif os.path.isfile(str_path):
            str_path = str_path.lower()
            for ext1 in exts1:
                if str_path.endswith(ext1):
                    p = FileInfo()
                    p.fileDir = disk_info.getUpUpDirPath(str_path)
                    p.fileRoot = disk_info.getRootDir(str_path)
                    p.fileName = disk_info.getCurrentDir(str_path)
                    p.fileFullPath = disk_info.getUpDirPath(str_path)
                    p.fileExtension = ext1
                    #fi = os.stat(p.fileFullPath)
                    #p.fileIndex = fi.st_ino
                    #p.fileSize = int(fi.st_size) /1024/1024/1024
                    p.fileIndex = "1"
                    p.fileSize = get_dir_file_size(p.fileFullPath)
                    p.fileRootID = str_id
                    #封装消息
                    obj_result.code = 1
                    obj_result.msg = json_dict_to_str(p.__dict__)
                    str_result = json_dict_to_str(obj_result.__dict__)
                    redis_public(o_redis, str_result)
                    return

            for ext2 in exts2:
                if str_path.endswith(ext2):
                    p = FileInfo()
                    p.fileDir = disk_info.getUpDirPath(str_path)
                    p.fileRoot = disk_info.getRootDir(str_path)
                    p.fileName = str
                    p.fileFullPath = str_path
                    p.fileExtension = ext1
                    fi = os.stat(p.fileFullPath)
                    p.fileIndex = fi.st_ino
                    p.fileSize = int(fi.st_size) / 1024 / 1024 / 1024
                    p.fileRootID = str_id
                    #封装消息
                    obj_result.code = 1
                    obj_result.msg = json_dict_to_str(p.__dict__)
                    str_result = json_dict_to_str(obj_result.__dict__)
                    redis_public(o_redis, str_result)

        if os.path.isdir(str_path):
            get_my_files(str_path, dirs, exts1, exts2, obj_result, o_redis,
                         str_id)