Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
opmlimport_parser.set_defaults(func=_command.opmlimport)
opmlimport_parser.add_argument(
'file', metavar='PATH', nargs='?',
help='path for imported OPML (defaults to stdin)')
opmlexport_parser = subparsers.add_parser(
'opmlexport', help=_command.opmlexport.__doc__.splitlines()[0])
opmlexport_parser.set_defaults(func=_command.opmlexport)
opmlexport_parser.add_argument(
'file', metavar='PATH', nargs='?',
help='path for exported OPML (defaults to stdout)')
args = parser.parse_args(*args, **kwargs)
if args.verbose:
_LOG.setLevel(max(_logging.DEBUG, _logging.ERROR - 10 * args.verbose))
# https://docs.python.org/3/library/logging.html#logrecord-attributes
formatter = _logging.Formatter('%(asctime)s [%(levelname)s] %(message)s')
for handler in _LOG.handlers: # type: _logging.Handler
handler.setFormatter(formatter)
if not getattr(args, 'func', None):
parser.error('too few arguments')
try:
if not args.config:
args.config = None
feeds = _feeds.Feeds(datafile=args.data, configfiles=args.config)
if args.func != _command.new:
lock = args.func not in [_command.list, _command.opmlexport]
feeds.load(lock=lock)
except ValueError as e:
_LOG.info('could not load data file using JSON')
data = self._load_pickled_data(self._datafile_lock)
version = data.get('version', None)
if version != self.datafile_version:
data = self._upgrade_state_data(data)
for state in data['feeds']:
feed = _feed.Feed(name='dummy-name')
feed.set_state(state)
if 'name' not in state:
raise _error.DataFileError(
feeds=self,
message='missing feed name in datafile {}'.format(
self.datafile))
feeds.append(feed)
_LOG.setLevel(level)
_LOG.handlers = handlers
self.extend(feeds)
if locktype == 0:
self._datafile_lock.close()
self._datafile_lock = None
for feed in self:
feed.load_from_config(self.config)
feed_names = set(feed.name for feed in self)
order = _collections.defaultdict(lambda: (1e3, ''))
for i,section in enumerate(self.config.sections()):
if section.startswith('feed.'):
name = section[len('feed.'):]
order[name] = (i, name)