コード例 #1
0
ファイル: parser.py プロジェクト: jbartece/licorice
    def get_licenses(self, path):
        '''Parse given file for present license definitions. Returns a list
            of found licenses '''
        if not os.path.exists(path):
            raise IOError("File does not exist.")
        if not os.path.isfile(path):
            raise Exception("{} is not a file.".format(path))

        matches = list() # { (line number, word index): License }
        keywords = self.file_locations.keys()
        for word, line_number, word_index in FFG(path, 0, 0).get_words_with_coordinates():
            if line_number > config.LINE_LIMIT: break # limiting the portion of the file to be read

            if self.vague:
                for l in self.licenses_with_vague_words:
                    if l not in matches and word in l.vague_words:
                        matches.append(l)

            if word in keywords:
                for f in self.file_locations[word]:
                    if f.parent in matches:
                        continue
                    if self._matches(path, f, line_number, word_index, word):
                        logger.debug('Found {}'.format(f.parent.name))
                        matches.append(f.parent)

        return list(sorted(matches, key=lambda l: l.name))
コード例 #2
0
ファイル: workflow.py プロジェクト: jbartece/licorice
def get_license_parser(path, vague):
    logger.info("Loading license definitions:")
    parser = None
    try:
        parser = loaders.MainLicenseLoader().get_license_parser(vague)
        logger.debug('Keywords selected: {}'.format(' '.join(parser.file_locations.keys())))
    except OSError as e:
        logger.error("Loading licenses failed with this error: {0}".format(str(e)))
        sys.exit(1)
    logger.debug([f.short_name for f in parser.licenses])
    return parser
コード例 #3
0
ファイル: loaders.py プロジェクト: jbartece/licorice
 def load_directory(cls, path):
     '''Get files from a directory recursively
     :param path: Path to the directory
     '''
     filelist = set()
     if not os.path.isdir(path):
         raise IOError("{} is not a directory!".format(path))
     for filename in helper.get_files(path):
         logger.debug('Loading {}'.format(filename))
         if os.path.isdir(filename):
             filelist |= cls.load_directory(filename)
         elif cls.is_archive(filename):
             filelist |= cls.load_archive(filename)
         elif os.path.isfile(filename):
             filelist.add(cls.load_file(filename))
         else:
             logger.error('File does not exist or format not supported: {}'.format(filename))
     return filelist
コード例 #4
0
ファイル: loaders.py プロジェクト: jbartece/licorice
    def load_project(cls, destinations):
        '''Load contents of a software project - file, directory, archive
        :param path: Path where the project is to be found
        '''
        filelist = set()
        logger.debug('Loading {} files for analysis:'.format(len(destinations)))
        for path in destinations:
            logger.debug('Loading {}'.format(path))
            if os.path.isdir(path):
                filelist |= cls.load_directory(path)
            elif cls.is_archive(path):
                filelist |= cls.load_archive(path)
            elif os.path.isfile(path):
                filelist.add(cls.load_file(path))
            else:
                raise Exception('File does not exist or format not supported: {}'.format(path))

        return Project(os.path.basename(destinations[0]), sorted(filelist,
            key=lambda x: x.path))
コード例 #5
0
ファイル: workflow.py プロジェクト: jbartece/licorice
def detect_problems(project):
    logger.debug('Detecting problems...')
    problems.ProblemAnalyzer(project).detect()