From 2734a580d11e50feb4908c47755381e19b1768a7 Mon Sep 17 00:00:00 2001 From: "Dusty.P" Date: Sun, 6 May 2018 23:54:41 -0800 Subject: [PATCH] File Processing Framework --- exts/imports/process_zip.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 exts/imports/process_zip.py diff --git a/exts/imports/process_zip.py b/exts/imports/process_zip.py new file mode 100644 index 0000000..b915a28 --- /dev/null +++ b/exts/imports/process_zip.py @@ -0,0 +1,37 @@ +import zipfile +import os + + +class MissingFile(Exception): + pass + + +def open_zip(file: str) -> zipfile.ZipFile: + if file.endswith('.zip'): + return zipfile.ZipFile(file) + else: + raise FileNotFoundError('File name must end in .zip') + + +def process_game_ini(file): + return 1 + + +def process_dino_ini(file): + return 1 + + +def process_files(z): + dino_data = [] + game_text = None + for filename in z.namelist(): + if filename.endswith('.ini'): # ignore any files that don't end with .ini + if filename == 'Game.ini': + game_text = process_game_ini(z.open(filename)) + elif 'DinoExport' in filename: + dino_data.append(process_dino_ini(z.open(filename))) + return game_text, dino_data + # if game_text is None: + # raise MissingFile('Game.ini') + # if dino_data is []: + # raise MissingFile('DinoExport')