-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathutils.py
140 lines (109 loc) · 4.92 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import collections
import os.path
import shutil
import gamelist
GUIString = collections.namedtuple('GUIString', 'id label help order')
# Static data
dataDir = r"data"
confDir = r"conf"
# Configuration
confFilename = r"conf-{setKey}"
guiStringsFilename = r'gui-en-{setKey}.csv'
def getKeySetString(string, setKey):
return string.replace('{setKey}', setKey)
def getConfFilename(setKey):
return getKeySetString(confFilename, setKey) + '.conf'
def getConfBakFilename(setKey):
return getKeySetString(confFilename, setKey) + '.bak'
def getGuiStringsFilename(setKey):
return getKeySetString(guiStringsFilename, setKey)
# UI Strings
def loadUIStrings(scriptDir, guiStringsFilename):
guiStrings = dict()
file = open(os.path.join(scriptDir, 'GUI', guiStringsFilename), 'r', encoding="utf-8")
order = 0
for line in file.readlines()[1:]:
confLine = line.split(";")
if len(confLine) == 3:
guiStrings[confLine[0]] = GUIString(confLine[0], confLine[1], confLine[2].rstrip('\n\r '), order)
order = order + 1
file.close()
return guiStrings
# Sorting and generation
def setFileCopy(exportDir, romsetFile, genre, fileName, targetDir, useGenreSubFolder, dryRun):
if not dryRun:
if os.path.exists(romsetFile):
if useGenreSubFolder:
shutil.copy2(romsetFile, os.path.join(exportDir, targetDir, genre, fileName + ".zip"))
else:
shutil.copy2(romsetFile, os.path.join(exportDir, targetDir, fileName + ".zip"))
def setCHDCopy(exportDir, romsetCHD, genre, fileName, targetDir, useGenreSubFolder, dryRun):
if not dryRun:
if os.path.exists(romsetCHD) and os.path.isdir(romsetCHD):
if useGenreSubFolder:
shutil.copytree(romsetCHD, os.path.join(exportDir, targetDir, genre, fileName))
else:
shutil.copytree(romsetCHD, os.path.join(exportDir, targetDir, fileName))
def setImageCopy(exportDir, paths, fileName, targetDir, dryRun):
if not dryRun:
for path in paths.split('|'):
filePath = os.path.join(path.strip(), fileName)
if os.path.exists(filePath):
shutil.copy2(filePath, os.path.join(exportDir, targetDir, 'downloaded_images', fileName))
return
def writeCSV(csvFile, game, score, genre, dat, test, setKey):
if game in dat:
name = dat[game].description
year = dat[game].year
manufacturer = dat[game].manufacturer
else:
name, year, manufacturer = '', '', ''
if test is not None and setKey in test:
hardware = test[setKey].hardware
comments = test[setKey].comments
notes = test[setKey].notes
else:
hardware, comments, notes = '', '', ''
genreExport = genre.replace('[', '')
genreExport = genreExport.replace(']', '')
if score is not None:
csvFile.write("%i;%s;%s;%s;%s;%s;%s;%s;%s\n" % (score, genreExport, name, game, year,
manufacturer, hardware, comments, notes))
else:
csvFile.write(
"%s;%s;%s;%s;%s;%s;%s;%s\n" % (genreExport, name, game, year, manufacturer, hardware, comments, notes))
def writeGamelistHiddenEntry(gamelistFile, game, genre, useGenreSubFolder):
gamelist.writeGamelistHiddenEntry(gamelistFile, game + ".zip", genre, useGenreSubFolder)
def writeGamelistEntry(gamelistFile, game, image, dat, genre, useGenreSubFolder, test, setKey, testStatus):
frontPic = "./downloaded_images/" + image
if game in dat:
fullName = dat[game].description
fullName.replace('&', '&')
name = fullName
if '(' in name:
indPar = name.index('(')
name = name[:(indPar - 1)].strip()
if '[' in name:
indPar = name.index('[')
name = name[:(indPar - 1)].strip()
year = dat[game].year if dat[game].year else ''
developer = dat[game].manufacturer.replace('&', '&') if dat[game].manufacturer else ''
cloneof = dat[game].cloneof
else:
fullName, name, year, developer, cloneof = '', '', '', '', ''
if test is not None and setKey in test:
hardware = test[setKey].hardware
comments = test[setKey].comments
notes = test[setKey].notes
else:
hardware, comments, notes = '', '', ''
desc = ('Rom : ' + game + ' , Clone of : ' + cloneof + '\n') if cloneof else ('Rom : ' + game + '\n')
desc = desc + ('Fullname : ' + fullName + '\n')
if testStatus is not None:
desc = desc + ('Status : ' + testStatus + '\n')
desc = desc + (('Hardware : ' + hardware + '\n') if hardware else '')
desc = desc + ((comments + '\n') if comments else '')
desc = desc + ((notes + '\n') if notes else '')
desc = desc + ' '
gamelist.writeGamelistEntry(gamelistFile, game + ".zip", name, desc, year, frontPic, developer, developer, genre,
useGenreSubFolder)