| 1 |
#!/usr/bin/env python3 |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# |
| 5 |
# gPodder - A media aggregator and podcast client |
| 6 |
# Copyright (c) 2005-2018 The gPodder Team |
| 7 |
# |
| 8 |
# gPodder is free software; you can redistribute it and/or modify |
| 9 |
# it under the terms of the GNU General Public License as published by |
| 10 |
# the Free Software Foundation; either version 3 of the License, or |
| 11 |
# (at your option) any later version. |
| 12 |
# |
| 13 |
# gPodder is distributed in the hope that it will be useful, |
| 14 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
# GNU General Public License for more details. |
| 17 |
# |
| 18 |
# You should have received a copy of the GNU General Public License |
| 19 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
# |
| 21 |
|
| 22 |
|
| 23 |
# gpodder-migrate2tres - Migrate data from gPodder 2.x to gPodder 3 |
| 24 |
# by Thomas Perl <[email protected]>; 2011-04-28 |
| 25 |
|
| 26 |
|
| 27 |
import configparser |
| 28 |
import os |
| 29 |
import shutil |
| 30 |
import sys |
| 31 |
|
| 32 |
gpodder_script = sys.argv[0] |
| 33 |
gpodder_script = os.path.realpath(gpodder_script) |
| 34 |
gpodder_dir = os.path.join(os.path.dirname(gpodder_script), '..') |
| 35 |
prefix = os.path.abspath(os.path.normpath(gpodder_dir)) |
| 36 |
|
| 37 |
src_dir = os.path.join(prefix, 'src') |
| 38 |
|
| 39 |
if os.path.exists(os.path.join(src_dir, 'gpodder', '__init__.py')): |
| 40 |
# Run gPodder from local source folder (not installed) |
| 41 |
sys.path.insert(0, src_dir) |
| 42 |
|
| 43 |
import gpodder # isort:skip |
| 44 |
|
| 45 |
gpodder.prefix = prefix |
| 46 |
|
| 47 |
from gpodder import schema, util # isort:skip |
| 48 |
|
| 49 |
old_database = os.path.expanduser('~/.config/gpodder/database.sqlite') |
| 50 |
new_database = gpodder.database_file |
| 51 |
|
| 52 |
old_config = os.path.expanduser('~/.config/gpodder/gpodder.conf') |
| 53 |
new_config = gpodder.config_file |
| 54 |
|
| 55 |
if not os.path.exists(old_database): |
| 56 |
print(""" |
| 57 |
Turns out that you never ran gPodder 2. |
| 58 |
Can't find this required file: |
| 59 |
|
| 60 |
%(old_database)s |
| 61 |
""" % locals(), file=sys.stderr) |
| 62 |
sys.exit(1) |
| 63 |
|
| 64 |
old_downloads = None |
| 65 |
|
| 66 |
if os.path.exists(old_config): |
| 67 |
parser = configparser.RawConfigParser() |
| 68 |
parser.read(old_config) |
| 69 |
try: |
| 70 |
old_downloads = parser.get('gpodder-conf-1', 'download_dir') |
| 71 |
except configparser.NoSectionError: |
| 72 |
# The file is empty / section (gpodder-conf-1) not found |
| 73 |
pass |
| 74 |
except configparser.NoOptionError: |
| 75 |
# The section is available, but the key (download_dir) is not |
| 76 |
pass |
| 77 |
|
| 78 |
if old_downloads is None: |
| 79 |
# The user has no configuration. This usually happens when |
| 80 |
# only the CLI version of gPodder is used. In this case, the |
| 81 |
# download directory is most likely the default (bug 1434) |
| 82 |
old_downloads = os.path.expanduser('~/gpodder-downloads') |
| 83 |
|
| 84 |
new_downloads = gpodder.downloads |
| 85 |
|
| 86 |
if not os.path.exists(old_downloads): |
| 87 |
print(""" |
| 88 |
Old download directory does not exist. Creating empty one. |
| 89 |
""", file=sys.stderr) |
| 90 |
os.makedirs(old_downloads) |
| 91 |
|
| 92 |
if any(os.path.exists(x) for x in (new_database, new_downloads)): |
| 93 |
print(""" |
| 94 |
Existing gPodder 3 user data found. |
| 95 |
To continue, please remove: |
| 96 |
|
| 97 |
%(new_database)s |
| 98 |
%(new_downloads)s |
| 99 |
""" % locals(), file=sys.stderr) |
| 100 |
sys.exit(1) |
| 101 |
|
| 102 |
print(""" |
| 103 |
Would carry out the following actions: |
| 104 |
|
| 105 |
Move downloads from %(old_downloads)s |
| 106 |
to %(new_downloads)s |
| 107 |
|
| 108 |
Convert database from %(old_database)s |
| 109 |
to %(new_database)s |
| 110 |
|
| 111 |
""" % locals(), file=sys.stderr) |
| 112 |
|
| 113 |
result = input('Continue? (Y/n) ') |
| 114 |
|
| 115 |
if result in 'Yy': |
| 116 |
util.make_directory(gpodder.home) |
| 117 |
schema.convert_gpodder2_db(old_database, new_database) |
| 118 |
if not os.path.exists(new_database): |
| 119 |
print('Could not convert database.', file=sys.stderr) |
| 120 |
sys.exit(1) |
| 121 |
|
| 122 |
shutil.move(old_downloads, new_downloads) |
| 123 |
if not os.path.exists(new_downloads): |
| 124 |
print('Could not move downloads.', file=sys.stderr) |
| 125 |
sys.exit(1) |
| 126 |
|
| 127 |
print('Done. Have fun with gPodder 3!') |