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
|
@ -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()
|
Loading…
Add table
Add a link
Reference in a new issue