remove old script

finish script
This commit is contained in:
Crabman77 2022-07-07 18:45:21 +02:00
parent aec76ca07d
commit 03671af8a2
3 changed files with 112 additions and 171 deletions

View File

@ -1,3 +1,2 @@
A script for convert minetest mods depends/description file in mod.conf
WIP: unusable now

View File

@ -1,132 +0,0 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import sys, os
import re
class Mod_conf:
def __init__(self):
self.name = ""
self.description = ""
self.depends = []
self.optional_depends = []
def set_name(self, txt):
self.name = txt.strip()
def set_depends(self, ltxt):
print(ltxt)
for txt in ltxt.split(","):
txt = txt.strip()
print(txt)
if len(txt) > 1 and not txt in self.depends:
self.depends.append(txt)
def set_optional_depends(self, ltxt):
for txt in ltxt.split(","):
txt = txt.strip()
if len(txt) > 1 and not txt in self.optional_depends:
self.optional_depends.append(txt)
def add_depends(self, txt):
if len(txt) > 1 and txt not in self.depends:
self.depends.append(txt)
def add_optional_depends(self, txt):
if len(txt) > 1 and txt not in self.optional_depends:
self.optional_depends.append(txt)
def set_description(self, txt):
self.description = txt
def get_name(self):
return(self.name)
def get_depends(self):
return(self.depends)
def get_optional_depends(self):
return(self.optional_depends)
def get_description(self):
return(self.description)
def get_formated(self):
data = "name: %s\ndepends: %s\noptional_depends: %s\ndescription: %s" % (self.get_name(), self.get_depends(), self.get_optional_depends(), self.get_description())
return(data)
def convert(mod_name):
is_ok = False
conf = Mod_conf()
file_conf = os.path.join(mod_name, "mod.conf")
file_depends = os.path.join(mod_name, "depends.txt")
file_description = os.path.join(mod_name, "description.txt")
"""
if os.path.exists(file_conf):
print("file_conf: %s" % file_conf)
with open(file_conf) as f:
data = f.readlines()
for v in data:
if v.startswith("name") and v.find("="):
conf.set_name(v.split("=", 1)[1].strip())
elif v.startswith("depends") and v.find("="):
conf.set_depends(v.split("=", 1)[1])
elif v.startswith("optional_depends") and v.find("="):
conf.set_optional_depends(v.split("=", 1)[1].strip())
elif v.startswith("description") and v.find("="):
conf.set_description(v.split("=", 1)[1].strip())
is_ok = True
else:
"""
if os.path.exists(file_depends):
print("file_depends: %s" % file_depends)
print("## exist")
with open(file_depends) as f:
data = f.readlines()
for v in data:
v = v.strip()
if len(v) > 2:
if v.endswith('?'):
print(v[:-1])
conf.add_optional_depends(v[:-1])
else:
conf.add_depends(v)
if not is_ok:
print("")
print("")
print(conf.get_formated())
#print("name: %s" % conf.get_name())
#print("depends: %s" % conf.get_depends())
#print("optional_depends: %s" % conf.get_optional_depends())
#print("description: %s" % conf.get_description())
def check():
path = os.getcwd()
print("path %s" % path)
mod_path = os.path.basename(path)
if mod_path != "mods":
print("Doit être lancer d'un dossier 'mods'!")
sys.exit(1)
print("Recherche de fichiers depents et description pour convertir en mod.conf.")
mods = os.listdir(path)
for mod_name in mods:
if os.path.isdir(mod_name):
print("#### %s ####" % mod_name)
convert(mod_name)
print("########")
print("")
print("")
print("")
if __name__ == '__main__':
check()

View File

@ -1,16 +1,30 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
Lancer le script depuis un dossier "mods", ou utiliser [-p --path] pour indiquer le dossier.
Utiliser [-m, --mod] si c'est pour vérifier un mod en particulier.
Utiliser [-c, --check] pour ajouter aussi le contenu brut de depends.txt et description.txt dans le mod.conf pour pouvoir vérifier et compléter le fichier mod.conf
Sans [-m, --mod] il va créer le fichier "prepared_modconf" en dehors de mods(à coté) puis remplir les mod.conf automatiquement pour tout les mod qui n'en n'ont pas et
les mettres dedans avec le nom(du modpack si c'est un modpack), le nom du mod, formaté ainsi "modpack-modname-mod.conf".
"""
import sys, os
import argparse
ignore = [".git", "locale", "models", "sounds", "textures", "src"]
VERBOSE = False
CHECK = False
ignore = ["locale", "models", "sounds", "textures", "src"]
"""
lancer le script depuis un dossier "mods", il va creer le fichier "prepared_modconf" en dehors de mods(à coté) puis remplir le mod.conf automatiquement
et le mettre dedans avec le path(du modpack si c'est un modpack), le nom du mod "modpack-mod-mod.conf"
"""
def my_print(data):
if VERBOSE:
print(data)
sys.stdout.flush()
class Mod_conf:
@ -51,7 +65,7 @@ class Mod_conf:
def get_depends(self):
return(', '.join(self.depends))
def get_optional_depends(self):
return(', '.join(self.optional_depends))
@ -63,20 +77,18 @@ class Mod_conf:
return(data)
def prepare(mod_name, prepared_path):
def prepare(mod_name, prepared_path, write_inside=False):
conf = Mod_conf()
modname = os.path.basename(mod_name)
#print(modname)
my_print("Prepare check mod dir: %s, mod name: %s" % (mod_name, modname))
file_conf = os.path.join(mod_name, "mod.conf")
file_depends = os.path.join(mod_name, "depends.txt")
file_description = os.path.join(mod_name, "description.txt")
if os.path.exists(file_conf):
return
if write_inside:
print("le fichier mod.conf %s existe déjà!" % file_conf)
return (0)
if os.path.exists(file_depends):
file_conf = "%s-mod.conf" % (mod_name.replace('/', '-'))
#print(file_conf)
#print("file_depends: %s" % file_depends)
#print("## exist")
data_depends = []
data_description = ""
with open(file_depends) as f:
@ -93,25 +105,32 @@ def prepare(mod_name, prepared_path):
with open(file_description) as f:
data_description = f.read()
with open(os.path.join(prepared_path, file_conf) , "w") as f:
if write_inside:
new_file_conf = "mod.conf"
else:
new_file_conf = "%s-mod.conf" % (mod_name.replace('/', '-'))
with open(os.path.join(prepared_path, new_file_conf) , "w") as f:
f.write(conf.get_formated())
f.write('\n\n\n\n### INFO DE VERIF ###\n# depends.txt\n')
for line in data_depends:
f.write(line)
f.write('\n### description.txt\n')
f.write(data_description)
if CHECK:
f.write('\n\n\n\n### INFO VERIFICATION ###\n# depends.txt\n')
for line in data_depends:
f.write(line)
f.write('\n### description.txt\n')
f.write(data_description)
my_print("Ajouté: %s." % new_file_conf)
return (1)
else:
print("%s: Ce dossier n'a pas de fichier depends.txt, ce n'est pas un mod!" % modname)
return (0)
def check():
path = os.getcwd()
print("path %s" % path)
def check_global(path):
total = 0
my_print("path %s" % path)
os.chdir(path)
prepared_path = os.path.join(os.path.dirname(path),"prepared_modconf")
mod_path = os.path.basename(path)
if mod_path != "mods":
print("Doit être lancer en etant dans un dossier 'mods'!")
sys.exit(1)
if not os.path.exists(prepared_path):
try:
os.mkdir(prepared_path)
@ -119,20 +138,75 @@ def check():
print(error)
sys.exit(1)
print("Recherche de fichiers depends et description pour convertir en mod.conf.")
mods = os.listdir(path)
#print(mods)
for mod_name in mods:
if os.path.isdir(mod_name) and mod_name not in ignore:
if os.path.exists( os.path.join(mod_name, "modpack.txt")): #it's a modpack
#print(" it's a modpack %s" % mod_name)
path_mod = os.path.join(path, mod_name)
if os.path.isdir(mod_name) and not mod_name.startswith(".") and mod_name not in ignore:
if os.path.exists( os.path.join(mod_name, "modpack.txt")) or os.path.exists( os.path.join(mod_name, "modpack.conf")): #it's a modpack
my_print("C'est un modpack: %s" % mod_name)
modspack = os.listdir(mod_name)
for modpack_name in modspack:
if os.path.isdir(os.path.join(mod_name, modpack_name)) and modpack_name not in ignore:
#print("#### %s ####" % modpack_name)
prepare( os.path.join(mod_name, modpack_name), prepared_path)
if os.path.isdir(os.path.join(mod_name, modpack_name)) and not modpack_name.startswith(".") and modpack_name not in ignore:
total += prepare( os.path.join(mod_name, modpack_name), prepared_path)
else:
prepare(mod_name, prepared_path)
print("les fichiers mod.conf à faire si il y en a, sont dans %s" % prepared_path)
total += prepare(mod_name, prepared_path)
if total > 0:
print("%s fichier(s) mod.conf préparé(s), dans %s." % (total, prepared_path) )
else:
print("Aucun mod.conf fait.")
def check_mod(path):
os.chdir(path)
if os.path.exists(os.path.join(path, "modpack.txt")) or os.path.exists(os.path.join(path, "modpack.conf")): #it's a modpack
my_print("C'est un modpack: %s" % path)
modspack = os.listdir(path)
for modpack_name in modspack:
if os.path.isdir(os.path.join(path, modpack_name)) and not modpack_name.startswith(".") and modpack_name not in ignore:
prepared_path = os.path.join(path, modpack_name)
prepare( prepared_path, prepared_path, True)
else:
prepare(path, path, True)
if __name__ == '__main__':
check()
path = os.getcwd()
parser = argparse.ArgumentParser()
parser.add_argument("-v", "--verbose", help="Affiche plus de messages",
action="store_true")
parser.add_argument("-p", "--path", help="dossier de recherche")
parser.add_argument("-m", "--mod", help="cherche dans un dossier de mod seul et ajoute le mod.conf dedans",
action="store_true")
parser.add_argument("-c", "--check", help="ajoute les infos de verification(contenu de depends.txt et description.txt) pour controler/completer le fichier manuellement",
action="store_true")
args = parser.parse_args()
if args.verbose:
VERBOSE = True
if args.check:
CHECK = True
if args.path:
if os.path.exists(args.path) and os.path.isdir(args.path):
path = args.path
else:
print("Erreur: '%s' n'est pas un dossier ou n'existe pas." % args.path)
sys.exit(1)
if args.mod:
print("Check un dossier mod seulement dans: %s." % path)
check_mod(path)
else:
mod_path = os.path.basename(path)
if mod_path != "mods":
if args.path:
print("path doit être un dossier 'mods' ou utiliser [-m, --mod] pour un mod specific!")
else:
print("Doit être lancer en etant dans un dossier 'mods' ou utiliser [-m, --mod] pour un mod specifique!")
sys.exit(1)
print("Check depuis le repertoire mod %s" % path)
check_global(path)