-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathdbUpLauncher.py
150 lines (107 loc) · 4.46 KB
/
dbUpLauncher.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
141
142
143
144
145
146
147
148
149
150
from builtins import str
from builtins import object
import os
import sys
import xbmc, xbmcgui, xbmcaddon
# Shared resources
addon = xbmcaddon.Addon(id='script.games.rom.collection.browser')
addonPath = addon.getAddonInfo('path')
BASE_RESOURCE_PATH = os.path.join(addonPath, "resources")
sys.path.append(os.path.join(BASE_RESOURCE_PATH, "lib"))
sys.path.append(os.path.join(BASE_RESOURCE_PATH, "lib", "pyscraper"))
from gamedatabase import GameDataBase
import util
import dbupdate
import config
from config import Site
monitor = xbmc.Monitor()
class HandleAbort(object):
orig_scraping_mode = ''
def __enter__(self):
xbmc.log("HandleAbort enter")
settings = util.getSettings()
settings.setSetting(util.SETTING_RCB_SCRAPEONSTARTUPACTION, 'update')
#set scraping mode to accurate
self.orig_scraping_mode = settings.getSetting(util.SETTING_RCB_SCRAPINGMODE)
settings.setSetting(util.SETTING_RCB_SCRAPINGMODE, util.SCRAPING_OPTION_AUTO_ACCURATE_TXT)
return True
def __exit__(self, type, value, traceback):
xbmc.log("HandleAbort exit")
settings = util.getSettings()
settings.setSetting(util.SETTING_RCB_SCRAPEONSTARTUPACTION, 'nothing')
#restore original scraping mode
settings.setSetting(util.SETTING_RCB_SCRAPINGMODE, self.orig_scraping_mode)
class ProgressDialogBk(xbmcgui.DialogProgressBG):
itemCount = 0
heading = ""
def writeMsg(self, message, count=0):
xbmc.log('writeMsg')
scrapeOnStartupAction = addon.getSetting(util.SETTING_RCB_SCRAPEONSTARTUPACTION)
xbmc.log('scrapeOnStartupAction = ' + scrapeOnStartupAction)
if scrapeOnStartupAction == 'cancel':
self.update(100, 'Rom Collection Browser', 'Update canceled')
return False
if count > 0:
percent = int(count * (float(100) / self.itemCount))
else:
percent = 0
self.update(percent, self.heading, message)
return True
def runUpdate():
xbmc.log('RCB: runUpdate')
gdb = GameDataBase(util.getAddonDataPath())
gdb.connect()
#create db if not existent and maybe update to new version
gdb.checkDBStructure()
configFile = config.Config(None)
configFile.readXml()
selectedRomCollection = ''
selectedScraper = ''
xbmc.log('RCB: parameters = %s' % sys.argv)
for arg in sys.argv:
param = str(arg)
xbmc.log('RCB: param = %s' % param)
if 'selectedRomCollection' in param:
selectedRomCollection = param.replace('selectedRomCollection=', '')
if 'selectedScraper' in param:
selectedScraper = param.replace('selectedScraper=', '')
romCollections = configFile.romCollections
if selectedRomCollection and selectedScraper:
romCollections = prepareRomCollections(configFile, selectedRomCollection, selectedScraper)
progress = ProgressDialogBk()
progress.heading = util.SCRIPTNAME
progress.create(util.SCRIPTNAME, 'Update DB')
with HandleAbort():
dbupdate.DBUpdate().updateDB(gdb, progress, romCollections, False)
progress.close()
def prepareRomCollections(config, selectedRC, siteName):
xbmc.log('prepareRomCollections')
#32120 = All
if selectedRC == util.localize(32120):
romCollections = config.romCollections
else:
romCollections = {}
romCollection = config.getRomCollectionByName(selectedRC)
romCollections[romCollection.id] = romCollection
for rcId in list(romCollections.keys()):
romCollection = config.romCollections[rcId]
sites = []
for site in romCollection.scraperSites:
# check if it is the selected scraper or
# 32804 = Use configured default scrapers
# search for default scraper or check if we only have one scraper and use this one
if site.name == siteName or (siteName == util.localize(32804) and
(site.default or len(romCollection.scraperSites) == 1)):
sites.append(site)
break
# if we did not find a scraper lets assume the selected scraper is not available in current rom collection
# create it and set it to default
if len(sites) == 0:
site = Site()
site.name = siteName
site.default = True
sites.append(site)
romCollection.scraperSites = sites
return romCollections
if __name__ == "__main__":
runUpdate()