def get_configuration(url, passed_defaultsini, passed_personalini, options, chaptercount=None, output_filename=None): try: configuration = Configuration(adapters.getConfigSectionsFor(url), options.format) except exceptions.UnknownSite as e: if options.list or options.normalize or options.downloadlist: # list for page doesn't have to be a supported site. configuration = Configuration(['unknown'], options.format) else: raise e conflist = [] homepath = join(expanduser('~'), '.fanficdownloader') ## also look for .fanficfare now, give higher priority than old dir. homepath2 = join(expanduser('~'), '.fanficfare') xdgpath = os.environ.get('XDG_CONFIG_HOME', join(expanduser('~'),'.config')) xdgpath = join(xdgpath, 'fanficfare') if passed_defaultsini: # new StringIO each time rather than pass StringIO and rewind # for case of list download. Just makes more sense to me. configuration.readfp(StringIO(unicode(passed_defaultsini))) else: # don't need to check existance for our selves. conflist.append(join(dirname(__file__), 'defaults.ini')) conflist.append(join(homepath, 'defaults.ini')) conflist.append(join(homepath2, 'defaults.ini')) conflist.append(join(xdgpath, 'defaults.ini')) conflist.append('defaults.ini') if passed_personalini: # new StringIO each time rather than pass StringIO and rewind # for case of list download. Just makes more sense to me. configuration.readfp(StringIO(unicode(passed_personalini))) conflist.append(join(homepath, 'personal.ini')) conflist.append(join(homepath2, 'personal.ini')) conflist.append(join(xdgpath, 'personal.ini')) conflist.append('personal.ini') if options.configfile: conflist.extend(options.configfile) configuration.read(conflist) try: configuration.add_section('overrides') except configparser.DuplicateSectionError: # generally already exists in defaults.ini pass if options.force: configuration.set('overrides', 'always_overwrite', 'true') if options.update and chaptercount and output_filename: configuration.set('overrides', 'output_filename', output_filename) if options.update and not options.updatecover: configuration.set('overrides', 'never_make_cover', 'true') # images only for epub, even if the user mistakenly turned it # on else where. if options.format not in ('epub', 'html'): configuration.set('overrides', 'include_images', 'false') if options.options: for opt in options.options: (var, val) = opt.split('=') configuration.set('overrides', var, val) if options.progressbar: configuration.set('overrides','progressbar','true') return configuration
def get_configuration(url, passed_defaultsini, passed_personalini, options, chaptercount=None, output_filename=None): try: configuration = Configuration(adapters.getConfigSectionsFor(url), options.format) except exceptions.UnknownSite as e: if options.list or options.normalize or options.downloadlist: # list for page doesn't have to be a supported site. configuration = Configuration(['unknown'], options.format) else: raise conflist = [] homepath = join(expanduser('~'), '.fanficdownloader') ## also look for .fanficfare now, give higher priority than old dir. homepath2 = join(expanduser('~'), '.fanficfare') xdgpath = os.environ.get('XDG_CONFIG_HOME', join(expanduser('~'), '.config')) xdgpath = join(xdgpath, 'fanficfare') if passed_defaultsini: # new StringIO each time rather than pass StringIO and rewind # for case of list download. Just makes more sense to me. configuration.readfp(StringIO(unicode(passed_defaultsini))) else: # don't need to check existance for our selves. conflist.append(join(dirname(__file__), 'defaults.ini')) conflist.append(join(homepath, 'defaults.ini')) conflist.append(join(homepath2, 'defaults.ini')) conflist.append(join(xdgpath, 'defaults.ini')) conflist.append('defaults.ini') if passed_personalini: # new StringIO each time rather than pass StringIO and rewind # for case of list download. Just makes more sense to me. configuration.readfp(StringIO(unicode(passed_personalini))) conflist.append(join(homepath, 'personal.ini')) conflist.append(join(homepath2, 'personal.ini')) conflist.append(join(xdgpath, 'personal.ini')) conflist.append('personal.ini') if options.configfile: conflist.extend(options.configfile) configuration.read(conflist) try: configuration.add_section('overrides') except configparser.DuplicateSectionError: # generally already exists in defaults.ini pass if options.force: configuration.set('overrides', 'always_overwrite', 'true') if options.update and chaptercount and output_filename: configuration.set('overrides', 'output_filename', output_filename) if options.update and not options.updatecover: configuration.set('overrides', 'never_make_cover', 'true') # images only for epub, even if the user mistakenly turned it # on else where. if options.format not in ('epub', 'html'): configuration.set('overrides', 'include_images', 'false') if options.options: for opt in options.options: (var, val) = opt.split('=') configuration.set('overrides', var, val) if options.progressbar: configuration.set('overrides', 'progressbar', 'true') ## do page cache and cookie load after reading INI files because ## settings (like use_basic_cache) matter. ## only need browser cache if one of the URLs needs it, and it ## isn't saved or dependent on options.save_cache. This needs to ## be above basic_cache to avoid loading more than once anyway. if configuration.getConfig('use_browser_cache'): if not hasattr(options, 'browser_cache'): configuration.get_fetcher() # force browser cache read. options.browser_cache = configuration.get_browser_cache() else: configuration.set_browser_cache(options.browser_cache) ## Share basic_cache between multiple downloads. if not hasattr(options, 'basic_cache'): options.basic_cache = configuration.get_basic_cache() if options.save_cache: try: options.basic_cache.load_cache(global_cache) except Exception as e: logger.warning( "Didn't load --save-cache %s\nContinue without loading BasicCache" % e) options.basic_cache.set_autosave(True, filename=global_cache) else: configuration.set_basic_cache(options.basic_cache) # logger.debug(options.basic_cache.basic_cache.keys()) ## All CLI downloads are sequential and share one cookiejar, ## loaded the first time through here. if not hasattr(options, 'cookiejar'): options.cookiejar = configuration.get_cookiejar() if options.save_cache: try: options.cookiejar.load_cookiejar(global_cookies) except Exception as e: logger.warning( "Didn't load --save-cache %s\nContinue without loading cookies" % e) options.cookiejar.set_autosave(True, filename=global_cookies) else: configuration.set_cookiejar(options.cookiejar) return configuration