first commit
This commit is contained in:
commit
999ce7ff3e
3
README.md
Normal file
3
README.md
Normal file
@ -0,0 +1,3 @@
|
||||
A script for convert minetest mods depends/description file in mod.conf
|
||||
|
||||
WIP: unusable now
|
132
mt_convert_conf.py
Executable file
132
mt_convert_conf.py
Executable file
@ -0,0 +1,132 @@
|
||||
#!/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()
|
Loading…
Reference in New Issue
Block a user