Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
def get_project(paths):
    if not paths:
        logger.error("You must specify files to be analysed")
        sys.exit(1)
    project = None
    try:
        logger.info("Loading project")
        if isinstance(paths, str): paths = [paths]
        project = loaders.ProjectLoader.load_project(list(map(helper.path, paths)))
        logger.info("Loading complete, {0} files loaded.".format(len(project.files)))
        return project
    except Exception as e:
        logger.error("Loading project failed with this error: {0}".format(str(e)))
        sys.exit(1)
Ejemplo n.º 3
0
 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
Ejemplo n.º 4
0
def get_projects_licenses(args, parser, filelist):
    licenses_found = set()
    queried_online = dict()
    for f in filelist:
        if args.query_online and f.error_unpacking:
            try:
                logger.info('Querying online {}'.format(f.path))
                query = online.Query.query(f.path, parser.licenses)
                f.licenses = query.licenses
                queried_online[f] = query
            except Exception as e:
                logger.error('Can not connect to server {}'.format(str(e)))
        else:
            try:
                logger.info("Processing {}".format(f.path))
                f.licenses = parser.get_licenses(f.path)
            except UnicodeDecodeError:
                f.error_reading = True
                logger.error("Error reading {}".format(f.path))
        licenses_found |= set(f.licenses)
    return licenses_found, queried_online