/usr/bin/r2e-migrate is in rss2email 1:3.9-2.
This file is owned by root:root, with mode 0o755.
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 | #! /usr/bin/python2.7
#
# Migrate data from the rss2email 2.x format to the 3.x format.
#
# Copyright (c) 2013, Etienne Millon <me@emillon.org>
# Redistributable under the GPL version 2 or later
#
# Please report bugs and suggestion on the Debian bugtracker using the
# "reportbug rss2email" command.
#
# Changelog:
#
# v5 (2015-07-04)
# - support per-feed addresses
#
# v4 (2014-06-10)
# - support XDG directories
#
# v3 (2014-02-04)
# - Write status file (already-seen DB)
# - Fix path in error message
#
# v2 (2013-09-17)
# - Preserve paused status (Denis Laxalde)
#
# v1 (2013-08-12)
# - Migrate feed names only.
#
import json
import os.path
import pickle
import string
import subprocess
import sys
import xdg.BaseDirectory
class Feed:
def __init__(self, url, to):
self.url, self.etag, self.modified, self.seen = url, None, None, {}
self.active = True
self.to = to
def __repr__(self):
fmt = '\n'.join(['Feed(url={url},',
' etag={etag},',
' modified={modified},',
' seen={seen},',
' active={active},',
' to={to},',
')',
])
return fmt.format(**self.__dict__)
def not_empty(g):
try:
g.next()
return True
except StopIteration:
return False
def new_db_exists():
config = xdg.BaseDirectory.load_config_paths('rss2email.cfg')
data = xdg.BaseDirectory.load_data_paths('rss2email.json')
return not_empty(config) or not_empty(data)
def set_email(s):
return subprocess.call(['r2e', 'email', s])
def slugify_char(c):
allowed = string.ascii_letters + string.digits + '._-'
if c in allowed:
return c
else:
return '_'
def slugify(s):
return ''.join([slugify_char(c) for c in s])
def add(url, name, to):
extra_args = []
if to is not None:
extra_args = [to]
return subprocess.call(['r2e', 'add', name, url] + extra_args)
def pause(name):
return subprocess.call(['r2e', 'pause', name])
def main():
if new_db_exists():
print """
It seems that a rss2email 3.x database already exists, exiting.
If you want to import your old (rss2email 2.x) database, please remove
~/.config/rss2email.cfg and ~/.local/share/rss2email.json (or XDG
equivalents) and re-run r2e-migrate.
"""
sys.exit(1)
old_feed_data_file = os.path.expanduser('~/.rss2email/feeds.dat')
with open(old_feed_data_file) as f:
data = pickle.load(f)
email = data[0]
feeds = data[1:]
status = {'version': 2,
'feeds': [],
}
print 'Default email address: {}'.format(email)
set_email(email)
print 'Adding feeds:'
for feed in feeds:
url = feed.url
print url
name = slugify(url)
add(url, name, feed.to)
if not feed.active:
pause(name)
modified = None
if feed.modified:
modified = unicode(feed.modified)
feed_status = {'seen': {},
'etag': feed.etag,
'name': unicode(name),
'modified': modified,
}
for k, v in feed.seen.items():
feed_status['seen'][k] = {'id': v}
status['feeds'].append(feed_status)
# save_data_path would work but rss2email uses a bare file
data_dir = xdg.BaseDirectory.xdg_data_home
new_status_file = os.path.join(data_dir, 'rss2email.json')
with open(new_status_file, 'w') as statf:
json.dump(status, statf)
if __name__ == '__main__':
main()
|