minor improvements

This commit is contained in:
renaud gaudin 2015-06-07 12:42:01 +02:00
parent ad4d1a512c
commit 96debc91ae

View File

@ -92,10 +92,10 @@ ANDROID_PATH = tempfile.mkdtemp(prefix='android-custom-', dir=PARENT_PATH)
try: try:
import requests import requests
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
# check for convert (imagemagick)
except ImportError: except ImportError:
logger.error("Missing dependency: Unable to import requests.\n" logger.error("Missing dependency: Unable to import requests "
"Please install requests with " "or beautifulsoup.\n"
"Please install requests/beautifulsoup with "
"`pip install requests BeautifulSoup4 lxml` " "`pip install requests BeautifulSoup4 lxml` "
"either on your machine or in a virtualenv.") "either on your machine or in a virtualenv.")
sys.exit(1) sys.exit(1)
@ -153,12 +153,19 @@ def get_local_remote_fd(path):
def copy_to(src, dst): def copy_to(src, dst):
''' copy source content (local or remote) to local file ''' ''' copy source content (local or remote) to local file '''
local = None
if is_remote_path(src): if is_remote_path(src):
local = tempfile.NamedTemporaryFile(delete=False) local = tempfile.NamedTemporaryFile(delete=False)
local.write(get_remote_content(src)) download_remote_file(src, local.name)
local.close() src = local.name
src = local
shutil.copy(src, dst) shutil.copy(src, dst)
if local is not None:
os.remove(local.name)
def download_remote_file(url, path):
''' download url to path '''
syscall('wget -c -O {path} {url}'.format(path=path, url=url))
def get_remote_url_size(url): def get_remote_url_size(url):
@ -168,14 +175,6 @@ def get_remote_url_size(url):
return None return None
def download_remote_file(url, path):
''' download url to path '''
req = requests.get(url)
req.raise_for_status()
with open(path, 'w') as f:
f.write(req.text)
def get_file_size(path): def get_file_size(path):
''' file size in bytes of a path (either remote or local) ''' ''' file size in bytes of a path (either remote or local) '''
if is_remote_path(path): if is_remote_path(path):
@ -432,6 +431,7 @@ def step_embed_zimfile(jsdata, **options):
os.chdir(tmpd) os.chdir(tmpd)
syscall('zip -r -0 -y {} lib' syscall('zip -r -0 -y {} lib'
.format(os.path.join(ANDROID_PATH, 'content-libs.jar'))) .format(os.path.join(ANDROID_PATH, 'content-libs.jar')))
shutil.rmtree(tmpd)
def step_build_apk(jsdata, **options): def step_build_apk(jsdata, **options):