PyQt5/GUI Initial Commit
This commit is contained in:
parent
746a396902
commit
ba54082b60
@ -1,50 +1,26 @@
|
||||
import zipfile
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import logging
|
||||
from PyQt5.QtWidgets import QApplication, QWidget
|
||||
from PyQt5.QtGui import QIcon
|
||||
|
||||
|
||||
def get_mod_info(target_file):
|
||||
with zipfile.ZipFile(target_file) as z:
|
||||
info_files = [f for f in z.filelist if not f.is_dir() and '.info' in f.filename.lower()]
|
||||
rtn_json = json.loads(z.read(info_files[0]))[0]
|
||||
rtn_json['path'] = target_file
|
||||
return rtn_json
|
||||
class App(QWidget):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.title = 'Project Glowstone: Block Edition'
|
||||
self.left = 10
|
||||
self.top = 10
|
||||
self.width = 640
|
||||
self.height = 480
|
||||
self.initUI()
|
||||
|
||||
def initUI(self):
|
||||
self.setWindowTitle(self.title)
|
||||
self.setGeometry(self.left, self.top, self.width, self.height)
|
||||
self.show()
|
||||
|
||||
|
||||
def get_modpack_info(target_dir):
|
||||
for f in os.scandir(target_dir):
|
||||
if f.is_file():
|
||||
if '.jar' in f.name.lower():
|
||||
try:
|
||||
yield get_mod_info(f.path)
|
||||
except (KeyError, IndexError) as e:
|
||||
logging.warning(f'There is no .info in the file {f.name}!')
|
||||
logging.debug(f"{e}")
|
||||
except json.decoder.JSONDecodeError as e:
|
||||
logging.warning(f"The file {f.name} has a corrupted or malformed .info file - skipping!")
|
||||
except BaseException as e:
|
||||
logging.fatal(f"While parsing file {f.name}, encountered the following error: {e}")
|
||||
raise e
|
||||
|
||||
|
||||
def main(directory='.'):
|
||||
modpack_info = list(get_modpack_info(directory))
|
||||
root_mods = [mp for mp in modpack_info if not mp.get('dependencies')]
|
||||
# print(json.dumps(modpack_info, indent=2))
|
||||
# print(json.dumps(root_mods, indent=4))
|
||||
dependant_mods = [mp for mp in modpack_info if mp.get('dependencies')]
|
||||
|
||||
mod_tree = []
|
||||
for root_mod in root_mods:
|
||||
mod_tree.append({
|
||||
root_mod['modid']: [mod['modid'] for mod in dependant_mods if root_mod['modid'] in mod['dependencies']]
|
||||
})
|
||||
|
||||
print(json.dumps(mod_tree, indent=4))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
args = {arg.lower(): val for arg, val in (a[2:].split('=') for a in sys.argv if '--' in a.lower())}
|
||||
main(r"C:\Users\VY Canis Majoris\AppData\Roaming\.moddedminecraft\1.12\1.12.2\Sinkhole\mods")
|
||||
if __name__ == '__main__':
|
||||
app = QApplication(sys.argv)
|
||||
ex = App()
|
||||
sys.exit(app.exec_())
|
||||
|
50
GlowstoneDust.py
Normal file
50
GlowstoneDust.py
Normal file
@ -0,0 +1,50 @@
|
||||
import zipfile
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import logging
|
||||
|
||||
|
||||
def get_mod_info(target_file):
|
||||
with zipfile.ZipFile(target_file) as z:
|
||||
info_files = [f for f in z.filelist if not f.is_dir() and '.info' in f.filename.lower()]
|
||||
rtn_json = json.loads(z.read(info_files[0]))[0]
|
||||
rtn_json['path'] = target_file
|
||||
return rtn_json
|
||||
|
||||
|
||||
def get_modpack_info(target_dir):
|
||||
for f in os.scandir(target_dir):
|
||||
if f.is_file():
|
||||
if '.jar' in f.name.lower():
|
||||
try:
|
||||
yield get_mod_info(f.path)
|
||||
except (KeyError, IndexError) as e:
|
||||
logging.warning(f'There is no .info in the file {f.name}!')
|
||||
logging.debug(f"{e}")
|
||||
except json.decoder.JSONDecodeError as e:
|
||||
logging.warning(f"The file {f.name} has a corrupted or malformed .info file - skipping!")
|
||||
except BaseException as e:
|
||||
logging.fatal(f"While parsing file {f.name}, encountered the following error: {e}")
|
||||
raise e
|
||||
|
||||
|
||||
def main(directory='.'):
|
||||
modpack_info = list(get_modpack_info(directory))
|
||||
root_mods = [mp for mp in modpack_info if not mp.get('dependencies')]
|
||||
# print(json.dumps(modpack_info, indent=2))
|
||||
# print(json.dumps(root_mods, indent=4))
|
||||
dependant_mods = [mp for mp in modpack_info if mp.get('dependencies')]
|
||||
|
||||
mod_tree = []
|
||||
for root_mod in root_mods:
|
||||
mod_tree.append({
|
||||
root_mod['modid']: [mod['modid'] for mod in dependant_mods if root_mod['modid'] in mod['dependencies']]
|
||||
})
|
||||
|
||||
print(json.dumps(mod_tree, indent=4))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
args = {arg.lower(): val for arg, val in (a[2:].split('=') for a in sys.argv if '--' in a.lower())}
|
||||
main(r"C:\Users\VY Canis Majoris\AppData\Roaming\.moddedminecraft\1.12\1.12.2\Sinkhole\mods")
|
Loading…
x
Reference in New Issue
Block a user