def init(args):
    encoding = args.get('--encoding')
    extra_ignore_dirs = args.get('--ignore')
    if extra_ignore_dirs:
        extra_ignore_dirs = extra_ignore_dirs.split(',')
    candidates = get_all_imports(args['<path>'], encoding=encoding, extra_ignore_dirs=extra_ignore_dirs)
    candidates = get_pkg_names(candidates)
    logging.debug(('Found imports: ' + ', '.join(candidates)))
    pypi_server = 'https://pypi.python.org/pypi/'
    proxy = None
    if args['--pypi-server']:
        pypi_server = args['--pypi-server']
    if args['--proxy']:
        proxy = {'http': args['--proxy'], 'https': args['--proxy']}
    if args['--use-local']:
        logging.debug('Getting package information ONLY from local installation.')
        imports = get_import_local(candidates, encoding=encoding)
    else:
        logging.debug('Getting packages information from Local/PyPI')
        local = get_import_local(candidates, encoding=encoding)
        difference = [x for x in candidates if (x.lower() not in [z['name'].lower() for z in local])]
        imports = (local + get_imports_info(difference, proxy=proxy, pypi_server=pypi_server))
    path = (args['--savepath'] if args['--savepath'] else os.path.join(args['<path>'], 'requirements.txt'))
    if args['--diff']:
        diff(args['--diff'], imports)
        return
    if args['--clean']:
        clean(args['--clean'], imports)
        return
    if ((not args['--print']) and (not args['--savepath']) and (not args['--force']) and os.path.exists(path)):
        logging.warning('Requirements.txt already exists, use --force to overwrite it')
        return
    if args['--print']:
        output_requirements(imports)
        logging.info('Successfully output requirements')
    else:
        generate_requirements_file(path, imports)
        logging.info(('Successfully saved requirements file in ' + path))
def init(args):
    encoding = args.get('--encoding')
    extra_ignore_dirs = args.get('--ignore')
    if extra_ignore_dirs:
        extra_ignore_dirs = extra_ignore_dirs.split(',')
    candidates = get_all_imports(args['<path>'], encoding=encoding, extra_ignore_dirs=extra_ignore_dirs)
    candidates = get_pkg_names(candidates)
    logging.debug(('Found imports: ' + ', '.join(candidates)))
    pypi_server = 'https://pypi.python.org/pypi/'
    proxy = None
    if args['--pypi-server']:
        pypi_server = args['--pypi-server']
    if args['--proxy']:
        proxy = {'http': args['--proxy'], 'https': args['--proxy']}
    if args['--use-local']:
        logging.debug('Getting package information ONLY from local installation.')
        imports = get_import_local(candidates, encoding=encoding)
    else:
        logging.debug('Getting packages information from Local/PyPI')
        local = get_import_local(candidates, encoding=encoding)
        difference = [x for x in candidates if (x.lower() not in [z['name'].lower() for z in local])]
        imports = (local + get_imports_info(difference, proxy=proxy, pypi_server=pypi_server))
    path = (args['--savepath'] if args['--savepath'] else os.path.join(args['<path>'], 'requirements.txt'))
    if args['--diff']:
        diff(args['--diff'], imports)
        return
    if args['--clean']:
        clean(args['--clean'], imports)
        return
    if ((not args['--print']) and (not args['--savepath']) and (not args['--force']) and os.path.exists(path)):
        logging.warning('Requirements.txt already exists, use --force to overwrite it')
        return
    if args['--print']:
        output_requirements(imports)
        logging.info('Successfully output requirements')
    else:
        generate_requirements_file(path, imports)
        logging.info(('Successfully saved requirements file in ' + path))