/usr/lib/python3/dist-packages/rss2email/main.py is in rss2email 1:3.9-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | # Copyright (C) 2012-2013 W. Trevor King <wking@tremily.us>
#
# This file is part of rss2email.
#
# rss2email is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 2 of the License, or (at your option) version 3 of
# the License.
#
# rss2email is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# rss2email. If not, see <http://www.gnu.org/licenses/>.
"""Define the rss2email command line interface
"""
import argparse as _argparse
import logging as _logging
import os as _os
import sys as _sys
from . import __doc__ as _PACKAGE_DOCSTRING
from . import __version__
from . import LOG as _LOG
from . import command as _command
from . import error as _error
from . import feeds as _feeds
from . import version as _version
class FullVersionAction (_argparse.Action):
def __call__(self, *args, **kwargs):
for package,version in _version.get_versions():
print('{} {}'.format(package, version))
_sys.exit(0)
def v2_database_exists():
path = _os.path.expanduser('~/.rss2email/feeds.dat')
return _os.path.isfile(path)
def run(*args, **kwargs):
"""The rss2email command line interface
Arguments passed to this function are forwarded to the parser's
`.parse_args()` call without modification.
"""
parser = _argparse.ArgumentParser(
prog='rss2email', description=_PACKAGE_DOCSTRING)
parser.add_argument(
'-v', '--version', action='version',
version='%(prog)s {}'.format(__version__))
parser.add_argument(
'--full-version', action=FullVersionAction, nargs=0,
help='print the version information of all related packages and exit')
parser.add_argument(
'-c', '--config', metavar='PATH', default=[], action='append',
help='path to the configuration file')
parser.add_argument(
'-d', '--data', metavar='PATH',
help='path to the feed data file')
parser.add_argument(
'-V', '--verbose', default=0, action='count',
help='increment verbosity')
subparsers = parser.add_subparsers(title='commands')
new_parser = subparsers.add_parser(
'new', help=_command.new.__doc__.splitlines()[0])
new_parser.set_defaults(func=_command.new)
new_parser.add_argument(
'email', nargs='?',
help='default target email for the new feed database')
email_parser = subparsers.add_parser(
'email', help=_command.email.__doc__.splitlines()[0])
email_parser.set_defaults(func=_command.email)
email_parser.add_argument(
'email', default='',
help='default target email for the email feed database')
add_parser = subparsers.add_parser(
'add', help=_command.add.__doc__.splitlines()[0])
add_parser.set_defaults(func=_command.add)
add_parser.add_argument(
'name', help='name of the new feed')
add_parser.add_argument(
'url', help='location of the new feed')
add_parser.add_argument(
'email', nargs='?',
help='target email for the new feed')
run_parser = subparsers.add_parser(
'run', help=_command.run.__doc__.splitlines()[0])
run_parser.set_defaults(func=_command.run)
run_parser.add_argument(
'-n', '--no-send', dest='send',
default=True, action='store_const', const=False,
help="fetch feeds, but don't send email")
run_parser.add_argument(
'index', nargs='*',
help='feeds to fetch (defaults to fetching all feeds)')
list_parser = subparsers.add_parser(
'list', help=_command.list.__doc__.splitlines()[0])
list_parser.set_defaults(func=_command.list)
pause_parser = subparsers.add_parser(
'pause', help=_command.pause.__doc__.splitlines()[0])
pause_parser.set_defaults(func=_command.pause)
pause_parser.add_argument(
'index', nargs='*',
help='feeds to pause (defaults to pausing all feeds)')
unpause_parser = subparsers.add_parser(
'unpause', help=_command.unpause.__doc__.splitlines()[0])
unpause_parser.set_defaults(func=_command.unpause)
unpause_parser.add_argument(
'index', nargs='*',
help='feeds to ununpause (defaults to unpausing all feeds)')
delete_parser = subparsers.add_parser(
'delete', help=_command.delete.__doc__.splitlines()[0])
delete_parser.set_defaults(func=_command.delete)
delete_parser.add_argument(
'index', nargs='+',
help='feeds to delete')
reset_parser = subparsers.add_parser(
'reset', help=_command.reset.__doc__.splitlines()[0])
reset_parser.set_defaults(func=_command.reset)
reset_parser.add_argument(
'index', nargs='*',
help='feeds to reset (defaults to resetting all feeds)')
opmlimport_parser = subparsers.add_parser(
'opmlimport', help=_command.opmlimport.__doc__.splitlines()[0])
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))
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)
if v2_database_exists() and not feeds:
print("A rss2email 2.x database exists, but it can't be used "
"directly by this version of rss2email (3.x).\n"
"You can migrate your data using r2e-migrate.\n"
"Please see /usr/share/doc/rss2email/NEWS.Debian.gz\n"
"and r2e-migrate(1) for more information.")
args.func(feeds=feeds, args=args)
except _error.RSS2EmailError as e:
e.log()
if _logging.ERROR - 10 * args.verbose < _logging.DEBUG:
raise # don't mask the traceback
_sys.exit(1)
if __name__ == '__main__':
run()
|