mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
pep8
This commit is contained in:
parent
105d13862d
commit
b4abd1f1b3
@ -32,11 +32,13 @@ else:
|
|||||||
from future_builtins import map
|
from future_builtins import map
|
||||||
from urlparse import urlparse
|
from urlparse import urlparse
|
||||||
import httplib
|
import httplib
|
||||||
|
|
||||||
def encode_for_subprocess(x):
|
def encode_for_subprocess(x):
|
||||||
if isinstance(x, unicode):
|
if isinstance(x, unicode):
|
||||||
x = x.encode(enc)
|
x = x.encode(enc)
|
||||||
return x
|
return x
|
||||||
|
|
||||||
|
|
||||||
class TerminalController: # {{{
|
class TerminalController: # {{{
|
||||||
BOL = '' #: Move the cursor to the beginning of the line
|
BOL = '' #: Move the cursor to the beginning of the line
|
||||||
UP = '' #: Move the cursor up one line
|
UP = '' #: Move the cursor up one line
|
||||||
@ -166,6 +168,7 @@ class TerminalController: # {{{
|
|||||||
else:
|
else:
|
||||||
return getattr(self, s[2:-1])
|
return getattr(self, s[2:-1])
|
||||||
|
|
||||||
|
|
||||||
class ProgressBar:
|
class ProgressBar:
|
||||||
BAR = '%3d%% ${GREEN}[${BOLD}%s%s${NORMAL}${GREEN}]${NORMAL}\n'
|
BAR = '%3d%% ${GREEN}[${BOLD}%s%s${NORMAL}${GREEN}]${NORMAL}\n'
|
||||||
HEADER = '${BOLD}${CYAN}%s${NORMAL}\n\n'
|
HEADER = '${BOLD}${CYAN}%s${NORMAL}\n\n'
|
||||||
@ -203,6 +206,7 @@ class ProgressBar:
|
|||||||
out.flush()
|
out.flush()
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
def prints(*args, **kwargs): # {{{
|
def prints(*args, **kwargs): # {{{
|
||||||
f = kwargs.get('file', sys.stdout.buffer if py3 else sys.stdout)
|
f = kwargs.get('file', sys.stdout.buffer if py3 else sys.stdout)
|
||||||
end = kwargs.get('end', b'\n')
|
end = kwargs.get('end', b'\n')
|
||||||
@ -220,6 +224,7 @@ def prints(*args, **kwargs): # {{{
|
|||||||
f.flush()
|
f.flush()
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
class Reporter: # {{{
|
class Reporter: # {{{
|
||||||
|
|
||||||
def __init__(self, fname):
|
def __init__(self, fname):
|
||||||
@ -244,6 +249,7 @@ class Reporter: # {{{
|
|||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
# Downloading {{{
|
# Downloading {{{
|
||||||
|
|
||||||
def clean_cache(cache, fname):
|
def clean_cache(cache, fname):
|
||||||
@ -251,6 +257,7 @@ def clean_cache(cache, fname):
|
|||||||
if fname not in x:
|
if fname not in x:
|
||||||
os.remove(os.path.join(cache, x))
|
os.remove(os.path.join(cache, x))
|
||||||
|
|
||||||
|
|
||||||
def check_signature(dest, signature):
|
def check_signature(dest, signature):
|
||||||
if not os.path.exists(dest):
|
if not os.path.exists(dest):
|
||||||
return None
|
return None
|
||||||
@ -261,12 +268,14 @@ def check_signature(dest, signature):
|
|||||||
if m.hexdigest().encode('ascii') == signature:
|
if m.hexdigest().encode('ascii') == signature:
|
||||||
return raw
|
return raw
|
||||||
|
|
||||||
|
|
||||||
class URLOpener(urllib.FancyURLopener):
|
class URLOpener(urllib.FancyURLopener):
|
||||||
|
|
||||||
def http_error_206(self, url, fp, errcode, errmsg, headers, data=None):
|
def http_error_206(self, url, fp, errcode, errmsg, headers, data=None):
|
||||||
''' 206 means partial content, ignore it '''
|
''' 206 means partial content, ignore it '''
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def do_download(dest):
|
def do_download(dest):
|
||||||
prints('Will download and install', os.path.basename(dest))
|
prints('Will download and install', os.path.basename(dest))
|
||||||
reporter = Reporter(os.path.basename(dest))
|
reporter = Reporter(os.path.basename(dest))
|
||||||
@ -300,6 +309,7 @@ def do_download(dest):
|
|||||||
raise SystemExit(1)
|
raise SystemExit(1)
|
||||||
prints('Downloaded %s bytes'%os.path.getsize(dest))
|
prints('Downloaded %s bytes'%os.path.getsize(dest))
|
||||||
|
|
||||||
|
|
||||||
def download_tarball():
|
def download_tarball():
|
||||||
fname = 'calibre-%s-i686.%s'%(calibre_version, 'txz')
|
fname = 'calibre-%s-i686.%s'%(calibre_version, 'txz')
|
||||||
if is64bit:
|
if is64bit:
|
||||||
@ -341,6 +351,7 @@ def download_tarball():
|
|||||||
return raw
|
return raw
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
# Get tarball signature securely {{{
|
# Get tarball signature securely {{{
|
||||||
|
|
||||||
def get_proxies(debug=True):
|
def get_proxies(debug=True):
|
||||||
@ -365,6 +376,7 @@ def get_proxies(debug=True):
|
|||||||
prints('Using proxies:', repr(proxies))
|
prints('Using proxies:', repr(proxies))
|
||||||
return proxies
|
return proxies
|
||||||
|
|
||||||
|
|
||||||
class HTTPError(ValueError):
|
class HTTPError(ValueError):
|
||||||
|
|
||||||
def __init__(self, url, code):
|
def __init__(self, url, code):
|
||||||
@ -374,9 +386,11 @@ class HTTPError(ValueError):
|
|||||||
self.code = code
|
self.code = code
|
||||||
self.url = url
|
self.url = url
|
||||||
|
|
||||||
|
|
||||||
class CertificateError(ValueError):
|
class CertificateError(ValueError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def _dnsname_match(dn, hostname, max_wildcards=1):
|
def _dnsname_match(dn, hostname, max_wildcards=1):
|
||||||
"""Matching according to RFC 6125, section 6.4.3
|
"""Matching according to RFC 6125, section 6.4.3
|
||||||
|
|
||||||
@ -426,6 +440,7 @@ def _dnsname_match(dn, hostname, max_wildcards=1):
|
|||||||
pat = re.compile(r'\A' + r'\.'.join(pats) + r'\Z', re.IGNORECASE)
|
pat = re.compile(r'\A' + r'\.'.join(pats) + r'\Z', re.IGNORECASE)
|
||||||
return pat.match(hostname)
|
return pat.match(hostname)
|
||||||
|
|
||||||
|
|
||||||
def match_hostname(cert, hostname):
|
def match_hostname(cert, hostname):
|
||||||
"""Verify that *cert* (in decoded format as returned by
|
"""Verify that *cert* (in decoded format as returned by
|
||||||
SSLSocket.getpeercert()) matches the *hostname*. RFC 2818 and RFC 6125
|
SSLSocket.getpeercert()) matches the *hostname*. RFC 2818 and RFC 6125
|
||||||
@ -477,6 +492,7 @@ def match_hostname(cert, hostname):
|
|||||||
raise CertificateError("no appropriate commonName or "
|
raise CertificateError("no appropriate commonName or "
|
||||||
"subjectAltName fields were found")
|
"subjectAltName fields were found")
|
||||||
|
|
||||||
|
|
||||||
if has_ssl_verify:
|
if has_ssl_verify:
|
||||||
class HTTPSConnection(httplib.HTTPSConnection):
|
class HTTPSConnection(httplib.HTTPSConnection):
|
||||||
|
|
||||||
@ -544,6 +560,7 @@ nR0=
|
|||||||
-----END CERTIFICATE-----
|
-----END CERTIFICATE-----
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
def get_https_resource_securely(url, timeout=60, max_redirects=5, ssl_version=None):
|
def get_https_resource_securely(url, timeout=60, max_redirects=5, ssl_version=None):
|
||||||
'''
|
'''
|
||||||
Download the resource pointed to by url using https securely (verify server
|
Download the resource pointed to by url using https securely (verify server
|
||||||
@ -602,6 +619,7 @@ def get_https_resource_securely(url, timeout=60, max_redirects=5, ssl_version=No
|
|||||||
return response.read()
|
return response.read()
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
def extract_tarball(raw, destdir):
|
def extract_tarball(raw, destdir):
|
||||||
prints('Extracting application files...')
|
prints('Extracting application files...')
|
||||||
with open('/dev/null', 'w') as null:
|
with open('/dev/null', 'w') as null:
|
||||||
@ -615,6 +633,7 @@ def extract_tarball(raw, destdir):
|
|||||||
prints('Extracting of application files failed with error code: %s' % p.returncode)
|
prints('Extracting of application files failed with error code: %s' % p.returncode)
|
||||||
raise SystemExit(1)
|
raise SystemExit(1)
|
||||||
|
|
||||||
|
|
||||||
def get_tarball_info():
|
def get_tarball_info():
|
||||||
global signature, calibre_version
|
global signature, calibre_version
|
||||||
print ('Downloading tarball signature securely...')
|
print ('Downloading tarball signature securely...')
|
||||||
@ -637,11 +656,13 @@ def download_and_extract(destdir):
|
|||||||
print('Extracting files to %s ...'%destdir)
|
print('Extracting files to %s ...'%destdir)
|
||||||
extract_tarball(raw, destdir)
|
extract_tarball(raw, destdir)
|
||||||
|
|
||||||
|
|
||||||
def check_version():
|
def check_version():
|
||||||
global calibre_version
|
global calibre_version
|
||||||
if calibre_version == '%version':
|
if calibre_version == '%version':
|
||||||
calibre_version = urllib.urlopen('http://code.calibre-ebook.com/latest').read()
|
calibre_version = urllib.urlopen('http://code.calibre-ebook.com/latest').read()
|
||||||
|
|
||||||
|
|
||||||
def run_installer(install_dir, isolated, bin_dir, share_dir):
|
def run_installer(install_dir, isolated, bin_dir, share_dir):
|
||||||
destdir = os.path.abspath(os.path.expanduser(install_dir or '/opt'))
|
destdir = os.path.abspath(os.path.expanduser(install_dir or '/opt'))
|
||||||
if destdir == '/usr/bin':
|
if destdir == '/usr/bin':
|
||||||
@ -669,9 +690,11 @@ def run_installer(install_dir, isolated, bin_dir, share_dir):
|
|||||||
prints('Run "%s/calibre" to start calibre' % destdir)
|
prints('Run "%s/calibre" to start calibre' % destdir)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def main(install_dir=None, isolated=False, bin_dir=None, share_dir=None):
|
def main(install_dir=None, isolated=False, bin_dir=None, share_dir=None):
|
||||||
run_installer(install_dir, isolated, bin_dir, share_dir)
|
run_installer(install_dir, isolated, bin_dir, share_dir)
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
__file__
|
__file__
|
||||||
from_file = True
|
from_file = True
|
||||||
|
Loading…
x
Reference in New Issue
Block a user