diff --git a/pandora_client/__init__.py b/pandora_client/__init__.py index decda2c..1a31086 100755 --- a/pandora_client/__init__.py +++ b/pandora_client/__init__.py @@ -6,7 +6,7 @@ from __future__ import division, with_statement, print_function, absolute_import import getpass from glob import glob -import imp +import importlib.util import json import math import os @@ -226,23 +226,28 @@ class Client(object): def load_plugins(self, base=os.path.join(utils.basedir(), 'client.d')): global parse_path, example_path, ignore_file, sync_extensions, encode base = os.path.expanduser(base) + if not os.path.exists(base): + return for name in sorted(os.listdir(base)): if not name.endswith('.py'): continue path = os.path.join(base, name) - with open(path) as fp: - module = imp.load_source(os.path.basename(path).split('.')[0], base, fp) - if hasattr(module, 'parse_path'): - parse_path = module.parse_path - if hasattr(module, 'example_path'): - example_path = module.example_path - if hasattr(module, 'ignore_file'): - ignore_file = module.ignore_file - if hasattr(module, 'sync_extensions'): - sync_extensions = module.sync_extensions - if hasattr(module, 'encode'): - encode = module.encode + module_name = os.path.basename(path).split('.')[0] + spec = importlib.util.spec_from_file_location(module_name, path) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + + if hasattr(module, 'parse_path'): + parse_path = module.parse_path + if hasattr(module, 'example_path'): + example_path = module.example_path + if hasattr(module, 'ignore_file'): + ignore_file = module.ignore_file + if hasattr(module, 'sync_extensions'): + sync_extensions = module.sync_extensions + if hasattr(module, 'encode'): + encode = module.encode def _conn(self): db_conn = self._config['cache'] diff --git a/pandora_client/client.py b/pandora_client/client.py index 39f14af..f43abbb 100644 --- a/pandora_client/client.py +++ b/pandora_client/client.py @@ -40,6 +40,8 @@ class DistributedClient: def __init__(self, url, name, threads): self.url = url + while self.url and self.url[-1] == '/': + self.url = self.url[:-1] self.name = name self.threads = threads self.supported_formats = extract.supported_formats()