ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Active_prgs/Gromulus/Gromulus_Lib.py
Revision: 795
Committed: Fri Sep 8 15:11:11 2023 UTC (2 years, 6 months ago) by nino.borges
Content type: text/x-python
File size: 4112 byte(s)
Log Message:
Gromulus, which is a catalog inventory for roms, games and maybe one day applications.

File Contents

# User Rev Content
1 nino.borges 795 """
2     This creates the main library of methods for Gromulus.
3    
4     """
5    
6     import sqlite3
7     import xml.etree.ElementTree as ET
8     import Tool_Box.NinoGenTools, os
9    
10    
11    
12     conn = sqlite3.connect("GromulusDatabase.db")
13    
14    
15     def ImportNewNoIntroDat(datPath):
16     """Deletes all of the data in the two No_Intro tables and load the info from the new dat."""
17     tree = ET.parse(datPath)
18     root = tree.getroot()
19    
20     ## First gather information from header
21     for elm in root.findall('header'):
22     headerID = elm.find('id').text
23     headerName = elm.find('name').text
24     headerDesc = elm.find('description').text
25     headerVer = elm.find('version').text
26    
27     #print(headerID)
28     #print (headerName)
29     #print(headerDesc)
30     #print(headerVer)
31     conn.execute("""DELETE FROM no_intro_system""" )
32     conn.execute(f'INSERT INTO no_intro_system VALUES ({headerID}, "{headerName}", "{headerDesc}", "{headerVer}")')
33    
34     conn.execute("""DELETE FROM no_intro_main""" )
35     for elm in root.findall('game'):
36     gameName = elm.get('name')
37     gameID = elm.get('id')
38     gameCloneOfID = elm.get('cloneofid')
39     gameDesc = elm.find('description').text
40    
41     romName = elm.find('rom').get('name')
42     romSize = elm.find('rom').get('size')
43     romCRC = elm.find('rom').get('crc')
44     romMD5 = elm.find('rom').get('md5')
45     romSHA1 = elm.find('rom').get('sha1')
46     romSHA256 = elm.find('rom').get('sha256')
47     romStatus = elm.find('rom').get('status')
48     conn.execute(f'INSERT INTO no_intro_main VALUES ("{gameName}", "{gameID}", "{gameCloneOfID}", "{gameDesc}", "{romName}", "{romCRC}", "{romMD5}", "{romSHA1}", "{romSHA256}", "{romStatus}", {headerID})')
49    
50     conn.commit()
51     conn.close()
52    
53    
54     ## Next gather game information
55     def AddNewRoms(pathToRoms):
56     """Adding additional roms."""
57     res = conn.execute('SELECT md5 FROM main_app')
58     currentHashList = []
59     for h in res:
60     print(h[0])
61     currentHashList.append(h[0])
62     #print(currentHashList)
63     print(len(currentHashList))
64     hshr = Tool_Box.NinoGenTools.HashFileContents('md5')
65     for testFile in os.listdir(pathToRoms):
66     print(f"Now analyzing {testFile}...")
67     hashVal = hshr.HashFile(os.path.join(pathToRoms,testFile))
68     if hashVal in currentHashList:
69     print("This file is already in your collection, skipping.")
70     else:
71     print("This file is unique. Adding to collection.")
72     conn.execute(f'INSERT INTO main_app("file_name", "relative_file_path", "md5")VALUES("{testFile}","{pathToRoms}","{hashVal}")')
73     conn.commit()
74     conn.close()
75    
76     def GetGameListBySystem(systemName):
77     res = conn.execute("SELECT main_app.id, main_app.game_name, no_intro_main.game_name, main_app.file_name FROM main_app LEFT JOIN no_intro_main ON main_app.md5 = no_intro_main.md5")
78     gameNamesMatrix = {}
79     for h in res:
80     if h[1]:
81     gameNamesMatrix[h[1]] = h[0]
82     elif h[2]:
83     gameNamesMatrix[h[2]] = h[0]
84     else:
85     gameNamesMatrix[h[3]] = h[0]
86    
87     #for g in gameNamesList:
88     # print(g)
89     return gameNamesMatrix
90    
91     def GetSingleGameById(id):
92     res = conn.execute(f"""SELECT main_app.game_name, main_app.md5, main_app.file_name, main_app.relative_file_path, no_intro_main.game_name, no_intro_system.name FROM main_app
93     LEFT JOIN no_intro_main ON main_app.md5 = no_intro_main.md5
94     LEFT JOIN no_intro_system ON no_intro_main.no_intro_system_id = no_intro_system.id
95     WHERE main_app.id = {id}""")
96     for h in res:
97     gameTuple = h
98     print(h)
99     return gameTuple
100    
101    
102    
103     if __name__ == '__main__':
104     #ImportNewNoIntroDat("/home/nino/MyCode/Python/Active_prgs/Gromulus/_data/_dats/Nintendo - Super Nintendo Entertainment System (20230516-033614).dat")
105     #AddNewRoms('/mnt/smb/HomeData/ninoborges/Emulation/Roms/Snes/Random')
106     #res = conn.execute("SELECT * FROM main_app LEFT JOIN no_intro_main ON main_app.md5 = no_intro_main.md5")
107     #for h in res:
108     # print(h)
109     # print("\n")
110     #GetGameListBySystem('snes')
111     GetSingleGameById('224')
112