support py2 and 3
This commit is contained in:
parent
b6412c116d
commit
a6a35e18d4
6 changed files with 24 additions and 19 deletions
|
@ -2,6 +2,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
# GPL 2012
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
@ -27,11 +28,11 @@ if __name__ == '__main__':
|
|||
(opts, args) = parser.parse_args()
|
||||
|
||||
if opts.version:
|
||||
print "%s %s" % (os.path.basename(sys.argv[0]), pandora_client.__version__)
|
||||
print("%s %s" % (os.path.basename(sys.argv[0]), pandora_client.__version__))
|
||||
sys.exit(0)
|
||||
opts.config = os.path.expanduser(opts.config)
|
||||
if (args and args[0] not in ('config', 'client') and not os.path.exists(opts.config)):
|
||||
print 'no configuration found, run "%s config" or specify one with -c' % sys.argv[0]
|
||||
print('no configuration found, run "%s config" or specify one with -c' % sys.argv[0])
|
||||
sys.exit(1)
|
||||
|
||||
if None in (opts.config, ):
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
# GPL 2012-2016
|
||||
from __future__ import division, with_statement, print_function
|
||||
from __future__ import division, with_statement, print_function, absolute_import
|
||||
|
||||
import getpass
|
||||
from glob import glob
|
||||
|
@ -16,12 +16,14 @@ import sys
|
|||
import tempfile
|
||||
import time
|
||||
import pkg_resources
|
||||
from urlparse import urlparse
|
||||
|
||||
from six.moves.urllib.parse import urlparse
|
||||
from six import string_types
|
||||
|
||||
import ox
|
||||
|
||||
import extract
|
||||
import utils
|
||||
from . import extract
|
||||
from . import utils
|
||||
|
||||
|
||||
DEBUG = False
|
||||
|
@ -142,7 +144,7 @@ class Client(object):
|
|||
_configfile = None
|
||||
|
||||
def __init__(self, config, offline=False):
|
||||
if isinstance(config, basestring):
|
||||
if isinstance(config, string_types):
|
||||
self._configfile = os.path.expanduser(config)
|
||||
with open(config) as f:
|
||||
try:
|
||||
|
@ -235,7 +237,7 @@ class Client(object):
|
|||
|
||||
def _conn(self):
|
||||
db_conn = self._config['cache']
|
||||
if isinstance(db_conn, str):
|
||||
if isinstance(db_conn, bytes):
|
||||
db_conn = db_conn.decode('utf-8')
|
||||
db_conn = os.path.expanduser(db_conn)
|
||||
if not os.path.exists(os.path.dirname(db_conn)):
|
||||
|
@ -277,7 +279,7 @@ class Client(object):
|
|||
prefixes = [prefix]
|
||||
else:
|
||||
prefixes = self.active_volumes().values()
|
||||
prefixes = [p.decode('utf-8') if isinstance(prefix, str) else p for p in prefixes]
|
||||
prefixes = [p.decode('utf-8') if isinstance(prefix, bytes) else p for p in prefixes]
|
||||
_info = self.info(oshash)
|
||||
for path in self.path(oshash):
|
||||
for prefix in prefixes:
|
||||
|
@ -385,7 +387,7 @@ class Client(object):
|
|||
modified = time.mktime(time.localtime())
|
||||
created = modified
|
||||
|
||||
if isinstance(path, str):
|
||||
if isinstance(path, bytes):
|
||||
path = path.decode('utf-8')
|
||||
|
||||
sql = u'SELECT atime, ctime, mtime, size, created, info FROM file WHERE deleted < 0 AND path=?'
|
||||
|
@ -507,7 +509,7 @@ class Client(object):
|
|||
path = os.path.normpath(path)
|
||||
if not path.endswith(os.sep):
|
||||
path += os.sep
|
||||
if isinstance(path, str):
|
||||
if isinstance(path, bytes):
|
||||
path = path.decode('utf-8')
|
||||
if os.path.exists(path):
|
||||
volumes[name] = path
|
||||
|
@ -1029,7 +1031,7 @@ class API(ox.API):
|
|||
form.add_field('action', 'upload')
|
||||
form.add_field('id', str(oshash))
|
||||
fname = os.path.basename(filename)
|
||||
if isinstance(fname, unicode):
|
||||
if not isinstance(fname, bytes):
|
||||
fname = fname.encode('utf-8')
|
||||
form.add_file('file', fname, open(filename, 'rb'))
|
||||
r = self._json_request(self.url, form)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# encoding: utf-8
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
from __future__ import print_function
|
||||
from __future__ import division, with_statement, print_function, absolute_import
|
||||
|
||||
import os
|
||||
import json
|
||||
import subprocess
|
||||
|
@ -10,7 +11,7 @@ import sys
|
|||
|
||||
import requests
|
||||
|
||||
import extract
|
||||
from . import extract
|
||||
|
||||
class DistributedClient:
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
# GPL 2010
|
||||
from __future__ import division, with_statement, print_function
|
||||
from __future__ import division, with_statement, print_function, absolute_import
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
|
@ -11,7 +11,7 @@ import shutil
|
|||
|
||||
import ox
|
||||
|
||||
from utils import AspectRatio, run_command, basedir
|
||||
from .utils import AspectRatio, run_command, basedir
|
||||
|
||||
|
||||
def command(program):
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# encoding: utf-8
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
from __future__ import print_function
|
||||
from __future__ import division, with_statement, print_function, absolute_import
|
||||
|
||||
import os
|
||||
import json
|
||||
|
@ -16,8 +16,8 @@ from twisted.web.static import File
|
|||
from twisted.web.server import Site
|
||||
from twisted.internet import reactor
|
||||
|
||||
import extract
|
||||
from utils import hash_prefix
|
||||
from . import extract
|
||||
from .utils import hash_prefix
|
||||
|
||||
class UploadThread(Thread):
|
||||
def __init__(self, server):
|
||||
|
|
1
setup.py
1
setup.py
|
@ -51,6 +51,7 @@ setup(
|
|||
],
|
||||
install_requires=[
|
||||
'ox >= 2.1.541,<3',
|
||||
'six',
|
||||
'requests >= 1.1.0'
|
||||
],
|
||||
keywords = [
|
||||
|
|
Loading…
Reference in a new issue