diff --git a/.gitignore b/.gitignore index 6f4f2d9..5f37b10 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ __pycache__/ bluezip.db flashpoint.sqlite DB_PATH +.venv \ No newline at end of file diff --git a/bin/7za b/bin/7za new file mode 100755 index 0000000..5a20bd9 Binary files /dev/null and b/bin/7za differ diff --git a/bin/Compress.pdb b/bin/Compress.pdb new file mode 100644 index 0000000..71b01d8 Binary files /dev/null and b/bin/Compress.pdb differ diff --git a/bin/RVIO.pdb b/bin/RVIO.pdb new file mode 100644 index 0000000..ccdddae Binary files /dev/null and b/bin/RVIO.pdb differ diff --git a/bin/TrrntZip.NET.pdb b/bin/TrrntZip.NET.pdb new file mode 100644 index 0000000..ab026d6 Binary files /dev/null and b/bin/TrrntZip.NET.pdb differ diff --git a/bin/Trrntzip.pdb b/bin/Trrntzip.pdb new file mode 100644 index 0000000..b4dd9ac Binary files /dev/null and b/bin/Trrntzip.pdb differ diff --git a/bin/trrntzip b/bin/trrntzip new file mode 100755 index 0000000..0b762d2 Binary files /dev/null and b/bin/trrntzip differ diff --git a/bluezip.py b/bluezip.py index 631d555..fd473ae 100755 --- a/bluezip.py +++ b/bluezip.py @@ -18,7 +18,7 @@ import re import os -import yaml +from ruamel.yaml import YAML import bluezip_dat import bluezip_hook from util import TermColor, pcolor @@ -71,7 +71,6 @@ def __iter__(self): class Game: uid: str title: str - platform: str content_path: str def game_from_curation(uid, curation): @@ -84,30 +83,29 @@ def game_from_curation(uid, curation): with open(meta, 'r', encoding='utf-8') as f: try: - meta = yaml.safe_load(f) + yaml = YAML(typ="safe") + meta: dict = yaml.load(f) except yaml.YAMLError as e: raise ValueError('Malformed metadata') from e - if not 'Title' in meta or not 'Platform' in meta: + if not 'Title' in meta: raise ValueError('Incomplete metadata') - return Game(uid, meta['Title'], meta['Platform'], content) + return Game(uid, meta['Title'], content) def game_from_fp_database(uid, content_path): fp_db = util.open_db() c = fp_db.cursor() - c.execute('SELECT title, platform FROM game WHERE id = ?', (uid,)) + c.execute('SELECT title FROM game WHERE id = ?', (uid,)) game = c.fetchone() fp_db.close() if not game: raise ValueError(f'No game found by UUID: {uid}') - title, platform = game - return Game(uid, title, platform, content_path) + return Game(uid, game[0], content_path) -def create_torrentzip(uid, platform, build_dir, dist_file): +def create_torrentzip(uid, build_dir, dist_file): content_meta = { 'version': 1, - 'uniqueId': uid, - 'platform': platform + 'uniqueId': uid } with open(os.path.join(build_dir, 'content.json'), 'w', encoding='utf-8', newline='\r\n') as f: json.dump(content_meta, f, indent=4) @@ -196,7 +194,7 @@ def process_game(self, game): revision, prev_sha256, prev_title = c.fetchone() or (1, None, None) os.mkdir(build_dir) shutil.move(game.content_path, os.path.join(build_dir, 'content')) - sha256 = create_torrentzip(game.uid, game.platform, build_dir, dist) + sha256 = create_torrentzip(game.uid, build_dir, dist) outfile = os.path.join(DIST_DIR, f'{game.uid}.zip') shutil.move(dist, outfile) if prev_sha256: @@ -218,7 +216,7 @@ def process_game(self, game): if prev_title and prev_title != game.title: pcolor('yellow', f'Warning: {game.uid} has been renamed ({prev_title} -> {game.title})') try: - self.db.execute('INSERT INTO game VALUES (?,?,?,?,?,?)', (game.uid, revision, sha256, game.title, game.platform, self.session)) + self.db.execute('INSERT INTO game VALUES (?,?,?,?,?,?)', (game.uid, revision, sha256, game.title, "unused", self.session)) except sqlite3.IntegrityError as e: pcolor('red', f'Error: {e} when storing {game.title}. Skipped.') return @@ -228,6 +226,7 @@ def process_game(self, game): self.cleanup_obsolete(game, sha256) def process_game_from_path(self, uid, path, from_db): + print('proccing') if from_db: game = game_from_fp_database(uid, path) else: @@ -237,19 +236,13 @@ def process_game_from_path(self, uid, path, from_db): def process_archive(self, fname, from_db=False): tmp = tempfile.mkdtemp() path = os.path.join(tmp, 'curation') - subprocess.check_call(['bin/7za', 'x', f'-o{path}', fname], stdout=subprocess.DEVNULL) + subprocess.check_call(['./bin/7za', 'x', f'-o{path}', fname], stdout=subprocess.DEVNULL) entries = os.listdir(path) if len(entries) == 1: # must be root folder uid = entries[0] - if not util.validate_uuid(uid): - pcolor('red', f'\nError: Root folder in {fname} not a valid UUID. Skipped.') - return path = os.path.join(path, uid) else: uid, _ = os.path.splitext(os.path.basename(fname)) - if not util.validate_uuid(uid): - pcolor('red', f'\nError: No root folder in {fname} and archive filename not a valid UUID. Skipped.') - return if util.is_gamezip(entries): path = os.path.join(path, 'content') try: @@ -258,6 +251,7 @@ def process_archive(self, fname, from_db=False): shutil.rmtree(tmp) def process_auto(self, path, from_db=False): + print('auto') kind = 'Content' if from_db else 'Curation' fname = os.path.basename(path) exts = self.settings['archive_extensions'].split(',') @@ -331,6 +325,7 @@ def log_session(operation): except FileExistsError: pass + print(args.path) bluezip = Bluezip(db, settings, session, args) if args.path: if args.batch: diff --git a/bluezip_test.py b/bluezip_test.py index f036fd8..5b26152 100644 --- a/bluezip_test.py +++ b/bluezip_test.py @@ -59,9 +59,8 @@ def test_incomplete_meta(self): def test_integrity(self): self.mkdir('content') title = 'Alien Hominid' - platform = 'Flash' - meta = { 'Title': title, 'Platform': platform } - expect = bluezip.Game(RANDOM_UUID, title, platform, self.join('content')) + meta = { 'Title': title } + expect = bluezip.Game(RANDOM_UUID, title, self.join('content')) with open(self.join('meta.yaml'), 'w') as f: yaml.dump(meta, f) game = bluezip.game_from_curation(RANDOM_UUID, self.cwd) @@ -82,7 +81,7 @@ def test_ok(self, util): util.open_db.return_value = self.db args = (RANDOM_UUID, 'Alien Hominid', 'Flash') self.db.execute('INSERT INTO game VALUES (?,?,?)', args) - expect = bluezip.Game(*args, '') + expect = bluezip.Game(*args[:-1], '') self.assertEqual(expect, bluezip.game_from_fp_database(RANDOM_UUID, '')) class Test_create_torrentzip(TestTempFile): @@ -94,7 +93,7 @@ def test_ok(self): self.write('game.swf') self.write('assets/data.xml') self.mkdir('music') - digest = bluezip.create_torrentzip(RANDOM_UUID, 'Flash', build, dist) + digest = bluezip.create_torrentzip(RANDOM_UUID, build, dist) self.assertEqual(expect, digest.hex()) if __name__ == '__main__': diff --git a/requirements.txt b/requirements.txt index 9a6d88d..19572ce 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -pyyaml +ruamel.yaml lxml