示例#1
0
    def get(self):
        """GET request; takes path as an argument."""
        path = self.get_path()
        base = util.get_base_path_adjustment()

        files = []
        try:
            file_list = os.listdir(os.path.join(base, path))
            for i in file_list:
                try:
                    filename = os.path.join(base, path, i)
                    is_file = os.path.isfile(filename)
                    confirm = ''
                    if is_file and os.path.getsize(filename) > 10485760:
                        confirm = 'large'
                    if is_file and not util.is_text_file(filename):
                        confirm = 'binary'
                    files.append({
                        'name': i,
                        'is_file': is_file,
                        'confirm': confirm
                    })
                except IOError as error:
                    log.warn(error)
        except Exception as error:  # pylint: disable=W0703
            log.warn(error)

        self.do_output(files, base)
示例#2
0
文件: search.py 项目: shaurz/devo
 def _search_file(self, filepath):
     if self.quit:
         raise SearchAborted()
     self.output.begin_file(self, filepath)
     if not is_text_file(filepath):
         return
     with open(filepath, "r") as f:
         matched_file = False
         for line_num, line in enumerate(f, 1):
             line = line.rstrip("\r\n")
             try:
                 line = line.decode(self.encoding)
             except UnicodeDecodeError:
                 line = line.decode("latin-1")
             if self.match(line):
                 if not matched_file:
                     self.output.add_file(self, filepath)
                     matched_file = True
                 self.output.add_line(self, line_num, line)
             if self.quit:
                 raise SearchAborted()
         if matched_file:
             self.output.end_file(self)
示例#3
0
文件: file.py 项目: crm1122/cider
    def get(self):
        """GET request; takes path as an argument."""
        path = self.get_path()
        base = util.get_base_path_adjustment()

        files = []
        try:
            file_list = os.listdir(os.path.join(base, path))
            for i in file_list:
                try:
                    filename = os.path.join(base, path, i)
                    is_file = os.path.isfile(filename)
                    confirm = ""
                    if is_file and os.path.getsize(filename) > 10485760:
                        confirm = "large"
                    if is_file and not util.is_text_file(filename):
                        confirm = "binary"
                    files.append({"name": i, "is_file": is_file, "confirm": confirm})
                except IOError as error:
                    log.warn(error)
        except Exception as error:  # pylint: disable=W0703
            log.warn(error)

        self.do_output(files, base)