コード例 #1
0
    def run(self, output=True, echo=True):
        if echo:
            print("I'm going to extract %s lines from %s." %
                  (self.info.lines_to_extract, self.info.project_root))
        self.info.lines_extracted = 0
        project_processor = ProjectProcessor(self.info)
        file_processor = FileProcessor()
        # 1. Process and collect the files
        self.files = project_processor.process()
        # 2. Process each file
        for file in self.files:
            for output in file_processor.process(file):
                self.export(output)
                file.extracted_line()
                if self.info.has_extracted_enough_lines():
                    break
            # collect file summary
            self.info.lines_skipped_blank += file.blank_lines
            self.info.lines_skipped_comments += file.comment_lines
            if self.info.has_extracted_enough_lines():
                break
        # self.output_file.close()
        print('current file = ', __file__)
        self.output_file.save(self.output_path)
        if echo:
            self.print_summary()

        if not self.info.has_extracted_enough_lines():
            print("Warning!! Not enough source code to extract %s lines!" %
                  self.info.lines_to_extract)
        return
コード例 #2
0
ファイル: project_processor.py プロジェクト: xaibeing/ramile
class ProjectProcessor(object):
    def __init__(self, project):
        self.project = project
        self.files = []
        self.file_processor = FileProcessor()
        return

    def process(self):
        self.find_files()
        self.sort_files()
        return self.files

    def find_files(self):
        for root, dirs, files in os.walk(self.project.source_root):
            if self.is_ignored(root):
                continue
            for file_name in files:
                file_path = os.path.join(root, file_name)
                if self.is_ignored(file_path):
                    continue
                name, extension = os.path.splitext(file_name)
                if self.is_interested_file(name, extension):
                    info = FileInfo(file_path, file_name, extension)
                    self.files.append(info)
        return

    def walk(self):
        return

    def is_ignored(self, path):
        """ Checks whether the specified path is ignored.
        """
        for ignore in self.project.ignore:
            # .ramileconfig.json中配置的ignore路径只需从项目根目录开始,为根目录下的子目录
            ignore = os.path.join(self.project.source_root, ignore)
            # print("ignore =", ignore)
            if path.startswith(ignore):
                print("ignore!!!", path)
                return True
        return False

    def is_interested_file(self, filename, extension):
        is_interested = True
        if len(self.project.filters) > 0:
            is_interested = False
            for filter in self.project.filters:
                if extension == filter:
                    is_interested = True
                    break

        if is_interested:
            return self.file_processor.has_interest(extension)
        else:
            return False

    def sort_files(self):
        return
コード例 #3
0
 def whatcanido(self):
     processor = FileProcessor()
     print(
         "I can extract source code from files with these extensions: %s" %
         processor.print_processors())
     return
コード例 #4
0
ファイル: project_processor.py プロジェクト: xaibeing/ramile
 def __init__(self, project):
     self.project = project
     self.files = []
     self.file_processor = FileProcessor()
     return