mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-16 02:48:08 -04:00
Automatically download remote zim files
This commit is contained in:
parent
8230ab8435
commit
c867390e35
@ -180,6 +180,9 @@ def get_remote_url_size(url):
|
|||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def get_remote_file_name(url):
|
||||||
|
''' returns remote filename of final redirect '''
|
||||||
|
return urllib2.urlopen(url).geturl().split('/')[-1];
|
||||||
|
|
||||||
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) '''
|
||||||
@ -606,9 +609,17 @@ def main(jspath, **options):
|
|||||||
.format(", ".join(REQUIRED_FIELDS)))
|
.format(", ".join(REQUIRED_FIELDS)))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# update relative paths to absolute
|
|
||||||
if not is_remote_path(jspath):
|
|
||||||
json_file_dir = os.path.abspath(os.path.dirname(jspath))
|
json_file_dir = os.path.abspath(os.path.dirname(jspath))
|
||||||
|
|
||||||
|
# download remote zim file
|
||||||
|
if is_remote_path(jsdata.get('zim_file')):
|
||||||
|
zimfile_url = jsdata.get('zim_file')
|
||||||
|
remote_filename = get_remote_file_name(zimfile_url)
|
||||||
|
local_file_path = os.path.join(json_file_dir, remote_filename)
|
||||||
|
download_remote_file(zimfile_url, local_file_path)
|
||||||
|
jsdata.update({'zim_file': local_file_path})
|
||||||
|
|
||||||
|
# update relative paths to absolute
|
||||||
os.chdir(json_file_dir)
|
os.chdir(json_file_dir)
|
||||||
jsdata.update({'zim_file': os.path.abspath(jsdata.get('zim_file'))})
|
jsdata.update({'zim_file': os.path.abspath(jsdata.get('zim_file'))})
|
||||||
jsdata.update({'ic_launcher': os.path.abspath(jsdata.get('ic_launcher'))})
|
jsdata.update({'ic_launcher': os.path.abspath(jsdata.get('ic_launcher'))})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user