fixup for initial updater code

This commit is contained in:
Kevin Cathcart 2017-12-09 12:25:53 -05:00
parent 073ab728c1
commit 0372896bc6
1 changed files with 3 additions and 3 deletions

6
Gui.py
View File

@ -350,19 +350,19 @@ class SpriteSelector(object):
def update_official_sprites(self): def update_official_sprites(self):
# need to wrap in try catch. We don't want errors getting the json or downloading the files to break us. # need to wrap in try catch. We don't want errors getting the json or downloading the files to break us.
sprites_arr = json.loads(temp_sprites_json) sprites_arr = json.loads(temp_sprites_json)
current_sprites = [os.path.basename(file) for file in glob('sprites/official/*')] current_sprites = [os.path.basename(file) for file in glob('data/sprites/official/*')]
official_sprites = [(sprite['file'], os.path.basename(urlparse(sprite['file']).path)) for sprite in sprites_arr] official_sprites = [(sprite['file'], os.path.basename(urlparse(sprite['file']).path)) for sprite in sprites_arr]
needed_sprites = [(sprite_url, filename) for (sprite_url, filename) in official_sprites if filename not in current_sprites] needed_sprites = [(sprite_url, filename) for (sprite_url, filename) in official_sprites if filename not in current_sprites]
for (sprite_url, filename) in needed_sprites: for (sprite_url, filename) in needed_sprites:
target = os.path.join('sprites/official',filename) target = os.path.join('data/sprites/official',filename)
with urlopen(sprite_url) as response, open(target, 'wb') as out: with urlopen(sprite_url) as response, open(target, 'wb') as out:
shutil.copyfileobj(response, out) shutil.copyfileobj(response, out)
official_filenames = [filename for (_, filename) in official_sprites] official_filenames = [filename for (_, filename) in official_sprites]
obsolete_sprites = [sprite for sprite in current_sprites if sprite not in official_filenames] obsolete_sprites = [sprite for sprite in current_sprites if sprite not in official_filenames]
for sprite in obsolete_sprites: for sprite in obsolete_sprites:
os.remove(os.path.join('sprites/official', sprite)) os.remove(os.path.join('data/sprites/official', sprite))
self.window.destroy() self.window.destroy()
SpriteSelector(self.parent, self.callback) SpriteSelector(self.parent, self.callback)