Skip to content

Commit

Permalink
Fixed problem with different mods using the same download
Browse files Browse the repository at this point in the history
  • Loading branch information
A.J. Venter authored and A.J. Venter committed Oct 12, 2016
1 parent 2b354f5 commit 9c9f72a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion libPyKAN/ckanRepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def update_repository_data(self):
util.SaveJsonToFile(RepoListFile,util.download_json(util.repository_list))
uris = []
for i in self.settings.repos():
uris.append({'uri': i, 'sha': None})
uris.append({'uri': i, 'sha': None, 'id': None})
repofiles = util.download_files(uris,
self.cachedir,
self.settings['DownLoadRetryMax'])
Expand Down
9 changes: 5 additions & 4 deletions libPyKAN/modmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ def __get_sha__(self, repoentry):


def download(self):
urilist = [{'uri':i['download'],'sha':self.__get_sha__(i)} for i in self.repoentries]
util.debug(urilist)
util.debug(self.repoentries)
urilist = [{'uri':i['download'],'sha':self.__get_sha__(i),'id':i['identifier']} for i in self.repoentries]
util.debug('URILIST %s' % urilist)
self.cachedir = os.path.join(self.settings.KSPDIR,'PYKAN','cache')
util.mkdir_p(self.cachedir)
self.modfiles = util.download_files(urilist,self.cachedir,self.settings['DownLoadRetryMax'])
Expand All @@ -70,9 +71,9 @@ def clear_the_way(self,find,install_to,is_regex=False, matches_files=False):

def install(self):
modlist = {}
util.debug(self.modfiles)
util.debug('MODFILES %s' %self.modfiles)
for i in self.modfiles:
mod = [m for m in self.repoentries if self.__get_sha__(m) == i[1]][0]
mod = [m for m in self.repoentries if self.__get_sha__(m) == i[1] and m['identifier'] == i[2]][0]
print("Installing module ",mod['identifier'])
modfiles = []
for target in mod.get('install',[{'PYKANBASIC':True,'install_to':'GameData'}]):
Expand Down
6 changes: 4 additions & 2 deletions libPyKAN/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def __download_file__(dl_data):
before = ''
if dl_data['sha']:
before = '%s_' % dl_data['sha'][:8]
if dl_data['id']:
before += '_%s' % dl_data['id']
filename = dl_data['uri'].replace(':','').replace('/','_')
filename = os.path.join(dl_data['cachedir'],'%s%s' %(before,filename))
print("Filename: %s" %filename)
Expand Down Expand Up @@ -70,12 +72,12 @@ def __download_file__(dl_data):
if not dl_data['sha']:
return filename
else:
return (filename,dl_data['sha'])
return (filename,dl_data['sha'],dl_data['id'])

def download_files(urilist, cachedir, retries):
dl_data = []
for uri in urilist:
dl_data.append({"uri": uri['uri'],"cachedir": cachedir, 'retries': retries, 'sha': uri['sha']})
dl_data.append({'id':'id' in uri and uri['id'] or '',"uri": uri['uri'],"cachedir": cachedir, 'retries': retries, 'sha': uri['sha']})
pool = multiprocessing.Pool()
return pool.map(__download_file__, dl_data)

Expand Down
6 changes: 3 additions & 3 deletions pyKAN
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ if __name__ == '__main__':
return
if options.installed:
for i in INSTALLED.list_modules():
print('%s: %s | %s (%s)' %(i['identifier'],i['name'],i['version'],i['status']))
print('%s : %s | %s (%s)' %(i['identifier'],i['name'],i['version'],i['status']))
return
if options.allmods:
filtermethods = []
Expand All @@ -157,7 +157,7 @@ if __name__ == '__main__':
filterargs['kspversion'] = options.kspversion
for i in repo.list_modules(filtermethods, filterargs):
if options.allversions:
print("%s: %s | version: %s (%s)" %(i['identifier'],i.get('name',i),i.get('version'),INSTALLED.modstatus(i.get('name',i))))
print("%s : %s | version: %s (%s)" %(i['identifier'],i.get('name',i),i.get('version'),INSTALLED.modstatus(i.get('name',i))))
else:
name = i.get('name','')
version = i.get('version','')
Expand All @@ -166,7 +166,7 @@ if __name__ == '__main__':
result[modid] = {'name': name, 'version': version}
if result:
for i in result:
print("%s: %s | %s (%s)" %(i,result[i]['name'],result[i]['version'],INSTALLED.modstatus(i)))
print("%s : %s | %s (%s)" %(i,result[i]['name'],result[i]['version'],INSTALLED.modstatus(i)))

def show_module():
if not options.module:
Expand Down

0 comments on commit 9c9f72a

Please sign in to comment.