Skip to content

Instantly share code, notes, and snippets.

@requeijaum
Created July 3, 2019 14:12
Show Gist options
  • Save requeijaum/b1b25414a0813b1b9276beedbeaeda6d to your computer and use it in GitHub Desktop.
Save requeijaum/b1b25414a0813b1b9276beedbeaeda6d to your computer and use it in GitHub Desktop.
Work In Progress: Koha Perl Dependencies Helper Script (Python 3 )
'''
Helper script for Koha 19.05.01 - Tarball stable - on armhf Ubuntu Xenial - running on my Odroid C2
It installs the most missing modules using CPAN from root shell !
Instructions:
- After running:
# perl -MCPAN -e "install Modern::Perl"
- You need to pipe the output from the PERL Dependencies Script to "missing_mods.txt":
# ./koha_perl_deps.pl -m -u > ./missing_mods.txt
- And then: run this script using Python 3.*
'''
import os, subprocess, re
from os import path
missing_mods = "./missing_mods.txt"
modules_to_install = []
commands_to_run = []
def searchMissingModules():
if path.exists(missing_mods) :
print ("File " + missing_mods + " exists: " + str(path.exists(missing_mods) ))
# is it empty, though?
if str(open(missing_mods, 'r').read()) == "":
subprocess.call(["rm", missing_mods])
else:
runPerlDepsScript = ["./koha_perl_deps.pl", "-m", "-u"]
#print(runPerlDepsScript)
f = open(missing_mods, 'w')
try:
subprocess.call(runPerlDepsScript, stdout=f)
pass
except subprocess.CalledProcessError : # as exception :
#print(exception)
print("Não encontrei o script 'koha_deps_perl' !")
exit
def createModuleArray():
if path.exists(missing_mods):
modules_list = open(missing_mods, 'r').read()
#x = re.findall("((\w{5,})|(\w{0,}(::)\w{0,}))|(\d\.\d{0,})", modules_list)
#x = re.findall("(\w{0,}(::)\w{0,})|(\d\.\d{0,})", modules_list)
#x = re.findall("\\w{2,}::\\w{2,}", modules_list)
x = re.findall("\\w{2,}.*\\d.\\d{1,}", modules_list)
#print(x)
for match in x:
edited = re.sub("(\\ {0,})", "", match).replace("0*", " ")
edited = re.sub("\\d.\\d{1,}\\*", " ", edited)
modules_to_install.append(edited.split(" "))
def runCPANCommands():
if path.exists(missing_mods) :
for module in modules_to_install:
try:
# perl -MCPAN -e "install Modern::Perl"
command = ["perl" , "-MCPAN", "-e", "install " + module[0] ] #, module[1] ] # how to specify the version for installation? IDK :-(
#print(to_run)
commands_to_run.append(command)
except IndexError:
print("[ERROR] Index " + module[0] + " have subsequent indexes unacessible...\n\n")
for command in commands_to_run:
try:
print(command)
# .run or .call
subprocess.run(command, shell=False, check=True)
except subprocess.CalledProcessError as exception :
print(exception)
if __name__ == "__main__":
searchMissingModules()
createModuleArray()
runCPANCommands()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment