mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-04 15:38:43 +00:00
Enable migration from hostlist.conf.1.2 to hostlist.conf
This commit is contained in:
parent
c169d8909f
commit
eeccc47dde
1 changed files with 25 additions and 4 deletions
|
@ -10,6 +10,7 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
import time
|
import time
|
||||||
from hashlib import sha1
|
from hashlib import sha1
|
||||||
from socket import gaierror, gethostbyname
|
from socket import gaierror, gethostbyname
|
||||||
|
@ -55,8 +56,27 @@ def validate_host_info(hostname, port):
|
||||||
raise ValueError('Invalid port. Must be an integer')
|
raise ValueError('Invalid port. Must be an integer')
|
||||||
|
|
||||||
|
|
||||||
def _migrate_config_1_to_2(config):
|
def migrate_hostlist(old_filename, new_filename):
|
||||||
"""Mirgrates old hostlist config files to new format"""
|
"""Check for old hostlist filename and save details to new filename"""
|
||||||
|
old_hostlist = get_config_dir(old_filename)
|
||||||
|
if os.path.isfile(old_hostlist):
|
||||||
|
config_v2 = Config(old_filename, config_dir=get_config_dir())
|
||||||
|
config_v2.save(get_config_dir(new_filename))
|
||||||
|
del config_v2
|
||||||
|
|
||||||
|
try:
|
||||||
|
os.rename(old_hostlist, old_hostlist + '.old')
|
||||||
|
except OSError as ex:
|
||||||
|
log.exception(ex)
|
||||||
|
|
||||||
|
try:
|
||||||
|
os.remove(old_hostlist + '.bak')
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_config_2_to_3(config):
|
||||||
|
"""Mirgrates old hostlist config files to new file version"""
|
||||||
localclient_username, localclient_password = get_localhost_auth()
|
localclient_username, localclient_password = get_localhost_auth()
|
||||||
if not localclient_username:
|
if not localclient_username:
|
||||||
# Nothing to do here, there's no auth file
|
# Nothing to do here, there's no auth file
|
||||||
|
@ -71,8 +91,9 @@ def _migrate_config_1_to_2(config):
|
||||||
class HostList(object):
|
class HostList(object):
|
||||||
"""This class contains methods for adding, removing and looking up hosts in hostlist.conf."""
|
"""This class contains methods for adding, removing and looking up hosts in hostlist.conf."""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.config = Config('hostlist.conf', default_hostlist(), config_dir=get_config_dir(), file_version=2)
|
migrate_hostlist('hostlist.conf.1.2', 'hostlist.conf')
|
||||||
self.config.run_converter((0, 1), 2, _migrate_config_1_to_2)
|
self.config = Config('hostlist.conf', default_hostlist(), config_dir=get_config_dir(), file_version=3)
|
||||||
|
self.config.run_converter((1, 2), 3, migrate_config_2_to_3)
|
||||||
self.config.save()
|
self.config.save()
|
||||||
|
|
||||||
def check_info_exists(self, hostname, port, username, skip_host_id=None):
|
def check_info_exists(self, hostname, port, username, skip_host_id=None):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue