mirror of
https://github.com/iiab/iiab.git
synced 2025-03-09 15:40:17 +00:00
upgrade to restructured scripts
This commit is contained in:
parent
e406149a6e
commit
edaecab6c6
5 changed files with 150 additions and 9 deletions
|
@ -14,7 +14,7 @@ import shlex
|
|||
import configparser
|
||||
import xml.etree.ElementTree as ET
|
||||
import argparse
|
||||
import iiab.iiab_const as cons
|
||||
import iiab.iiab_const as CONST
|
||||
|
||||
lang_codes = {}
|
||||
|
||||
|
@ -39,8 +39,8 @@ def get_zim_list(path):
|
|||
files_processed[zimname] = zimidx
|
||||
zimname = content + filename + ".zim"
|
||||
zimidx = index + filename + ".zim.idx"
|
||||
if filename in cons.old_zim_map: # handle old names that don't parse
|
||||
perma_ref = cons.old_zim_map[filename]
|
||||
if filename in CONST.old_zim_map: # handle old names that don't parse
|
||||
perma_ref = CONST.old_zim_map[filename]
|
||||
else:
|
||||
ulpos = filename.rfind("_")
|
||||
# but old gutenberg and some other names are not canonical
|
||||
|
@ -78,7 +78,7 @@ def read_library_xml(lib_xml_file, kiwix_exclude_attr=[""]): # duplicated from i
|
|||
return zims_installed, path_to_id_map
|
||||
|
||||
def rem_libr_xml(id):
|
||||
command = cons.kiwix_manage + " " + kiwix_library_xml + " remove " + id
|
||||
command = CONST.kiwix_manage + " " + kiwix_library_xml + " remove " + id
|
||||
#print command
|
||||
args = shlex.split(command)
|
||||
try:
|
||||
|
@ -88,7 +88,7 @@ def rem_libr_xml(id):
|
|||
print(outp)
|
||||
|
||||
def add_libr_xml(kiwix_library_xml, zim_path, zimname, zimidx):
|
||||
command = cons.kiwix_manage + " " + kiwix_library_xml + " add " + cons.zim_path + "/" + zimname
|
||||
command = CONST.kiwix_manage + " " + kiwix_library_xml + " add " + CONST.zim_path + "/" + zimname
|
||||
if zimidx:
|
||||
command += " -i " + zim_path + "/" + zimidx
|
||||
#print command
|
||||
|
@ -102,7 +102,7 @@ def add_libr_xml(kiwix_library_xml, zim_path, zimname, zimidx):
|
|||
|
||||
def read_lang_codes():
|
||||
global lang_codes
|
||||
with open(cons.lang_codes_path,"r") as f:
|
||||
with open(CONST.lang_codes_path,"r") as f:
|
||||
reads = f.read()
|
||||
#print("menu.json:%s"%reads)
|
||||
lang_codes = json.loads(reads)
|
||||
|
@ -146,7 +146,7 @@ def get_iiab_env(name):
|
|||
iiab_env = {}
|
||||
iiab_env_var = ''
|
||||
try:
|
||||
fd = open(cons.iiab_env_file,"r")
|
||||
fd = open("/etc/iiab/iiab.env","r")
|
||||
for line in fd:
|
||||
line = line.lstrip()
|
||||
line = line.rstrip('\n')
|
||||
|
|
|
@ -97,7 +97,7 @@
|
|||
with_items:
|
||||
- { src: 'kiwix-serve.service.j2', dest: '/etc/systemd/system/kiwix-serve.service', mode: '0644'}
|
||||
- { src: 'iiab-make-kiwix-lib', dest: '/usr/bin/iiab-make-kiwix-lib', mode: '0755'}
|
||||
- { src: 'iiab-make-kiwix-lib.py', dest: '/usr/bin/iiab-make-kiwix-lib.py', mode: '0755'}
|
||||
- { src: 'iiab-make-kiwix-lib3.py', dest: '/usr/bin/iiab-make-kiwix-lib.py', mode: '0755'}
|
||||
- { src: 'kiwix.conf.j2', dest: '/etc/{{ apache_config_dir }}/kiwix.conf', mode: '0644'}
|
||||
|
||||
- name: Add 'kiwix_installed' variable values to {{ iiab_state_file }}
|
||||
|
|
82
roles/kiwix/templates/iiab-make-kiwix-lib3.py
Normal file
82
roles/kiwix/templates/iiab-make-kiwix-lib3.py
Normal file
|
@ -0,0 +1,82 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
"""
|
||||
|
||||
Creates temp library.xml file for kiwix from contents of /zims/content and index
|
||||
Updated to handle incremental additions and deletions
|
||||
|
||||
Author: Tim Moody <tim(at)timmoody(dot)com>
|
||||
Contributors: Jerry Vonau <jvonau3(at)gmail.com>
|
||||
|
||||
"""
|
||||
|
||||
import os, sys, syslog
|
||||
import pwd, grp
|
||||
import argparse
|
||||
import iiab.iiab_lib as iiab
|
||||
|
||||
try:
|
||||
import iiab.adm_lib as adm
|
||||
adm_cons_installed = True
|
||||
except:
|
||||
adm_cons_installed = False
|
||||
pass
|
||||
|
||||
def main():
|
||||
zim_path = iiab.CONST.zim_path
|
||||
zim_version_idx_dir = adm.CONST.zim_version_idx_dir
|
||||
|
||||
args = parse_args()
|
||||
# args.device is either value or None
|
||||
if args.device: # allow override of path
|
||||
zim_path = args.device + zim_path
|
||||
zim_version_idx_dir = args.device + zim_version_idx_dir
|
||||
kiwix_library_xml = zim_path + "/library.xml"
|
||||
|
||||
if not args.no_tmp: # don't append .tmp
|
||||
kiwix_library_xml += ".tmp"
|
||||
|
||||
# remove existing file if force
|
||||
if args.force:
|
||||
try:
|
||||
os.remove(kiwix_library_xml)
|
||||
except OSError:
|
||||
pass
|
||||
zims_installed = {}
|
||||
path_to_id_map = {}
|
||||
else:
|
||||
zims_installed, path_to_id_map = iiab.read_library_xml(kiwix_library_xml)
|
||||
|
||||
zim_files, zim_versions = iiab.get_zim_list(zim_path)
|
||||
|
||||
# Remove zims not in file system from library.xml
|
||||
remove_list_str = ""
|
||||
for item in path_to_id_map:
|
||||
if item not in zim_files:
|
||||
iiab.rem_libr_xml(path_to_id_map[item])
|
||||
|
||||
# Add zims from file system that are not in library.xml
|
||||
for item in zim_files:
|
||||
if item not in path_to_id_map:
|
||||
iiab.add_libr_xml(kiwix_library_xml, zim_path, item, zim_files[item])
|
||||
|
||||
# Create zim_versions_idx if Admin Console installed
|
||||
if adm_cons_installed:
|
||||
print("Writing zim_versions_idx")
|
||||
iiab.read_lang_codes() # needed by following
|
||||
adm.write_zim_versions_idx(zim_versions, kiwix_library_xml, zim_version_idx_dir)
|
||||
sys.exit()
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser(description="Create library.xml for Kiwix.")
|
||||
parser.add_argument("--device", help="no trailing /. change the target device from internal storage to something else like /media/usb0")
|
||||
parser.add_argument("--no_tmp", help="don't append .tmp to the library.xml name", action="store_true")
|
||||
parser.add_argument("-f", "--force", help="force complete rebuild of library.xml", action="store_true")
|
||||
parser.add_argument("-v", "--verbose", help="Print messages.", action="store_true")
|
||||
return parser.parse_args()
|
||||
|
||||
# Now start the application
|
||||
if __name__ == "__main__":
|
||||
|
||||
# Run the main routine
|
||||
main()
|
|
@ -50,7 +50,7 @@
|
|||
|
||||
- name: Install /usr/bin/iiab-update-map for updating of Map Pack catalog & descriptions
|
||||
template:
|
||||
src: iiab-update-map
|
||||
src: iiab-update-map3.py
|
||||
dest: /usr/bin/iiab-update-map
|
||||
mode: "0755"
|
||||
|
||||
|
|
59
roles/osm-vector-maps/templates/iiab-update-map3.py
Normal file
59
roles/osm-vector-maps/templates/iiab-update-map3.py
Normal file
|
@ -0,0 +1,59 @@
|
|||
#!/usr/bin/env python3
|
||||
# Scan the osm-vector-maps directory, update the osm-vector-maps-idx.json, add menu-defs
|
||||
|
||||
import json
|
||||
|
||||
import iiab.iiab_lib as iiab
|
||||
|
||||
try:
|
||||
import iiab.adm_lib as adm
|
||||
adm_cons_installed = True
|
||||
except:
|
||||
adm_cons_installed = False
|
||||
pass
|
||||
|
||||
def main():
|
||||
adm.get_map_catalog()
|
||||
#print(json.dumps(map_catalog,indent=2))
|
||||
|
||||
map_menu_def_list = adm.get_map_menu_defs()
|
||||
#print((json.dumps(map_menu_def_list,indent=2)))
|
||||
|
||||
previous_idx = adm.read_vector_map_idx()
|
||||
|
||||
installed_maps = adm.get_installed_regions()
|
||||
print(installed_maps)
|
||||
|
||||
adm.write_vector_map_idx(installed_maps)
|
||||
|
||||
# For installed regions, check that a menu def exists, and it's on home page
|
||||
for fname in installed_maps:
|
||||
region = adm.extract_region_from_filename(fname)
|
||||
if region == 'maplist': # it is the splash page, display only if no others
|
||||
menu_ref = 'en-map_test'
|
||||
item = { "perma_ref" : "en-map_test" }
|
||||
if len(installed_maps) == 1:
|
||||
adm.update_menu_json(menu_ref)
|
||||
return
|
||||
elif region not in adm.map_catalog['regions']:
|
||||
print("Skipping unknown map " + fname)
|
||||
continue
|
||||
else:
|
||||
item = adm.map_catalog['regions'][region]
|
||||
menu_ref = item['perma_ref']
|
||||
if not (menu_ref in map_menu_def_list):
|
||||
print(('creating menu def for %s'%item['perma_ref']))
|
||||
adm.create_map_menu_def(region,item['perma_ref'] + '.json')
|
||||
# if autoupdate allowed and this is a new region then add to home menu
|
||||
if adm.fetch_menu_json_value('autoupdate_menu') and item['perma_ref'] not in previous_idx:
|
||||
print(('autoudate of menu items is enabled:%s. Adding %s'%(\
|
||||
adm.fetch_menu_json_value('autoupdate_menu'),region,)))
|
||||
adm.update_menu_json(menu_ref)
|
||||
# redirect from box/maps to an installed map rather than test page
|
||||
with open(adm.CONST.map_doc_root + '/index.html','w') as fp:
|
||||
outstr = """<head> \n<meta http-equiv="refresh" content="0; URL=/osm-vector-maps/en-osm-omt_%s " />\n</head>"""%fname
|
||||
fp.write(outstr)
|
||||
|
||||
if __name__ == '__main__':
|
||||
if adm_cons_installed:
|
||||
main()
|
Loading…
Add table
Add a link
Reference in a new issue