Update pycatfile.py
[PyCatFile.git] / catfile.py
blobb6ee54a48b7bac6847a7ab0b975c1bf2f22e34d4
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 '''
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the Revised BSD License.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 Revised BSD License for more details.
13 Copyright 2018-2024 Cool Dude 2k - http://idb.berlios.de/
14 Copyright 2018-2024 Game Maker 2k - http://intdb.sourceforge.net/
15 Copyright 2018-2024 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
17 $FileInfo: catfile.py - Last Update: 2/11/2024 Ver. 0.0.2 RC 1 - Author: cooldude2k $
18 '''
20 from __future__ import absolute_import, division, print_function, unicode_literals;
21 import os, sys, logging, argparse, pycatfile;
22 from io import open as open;
24 teststringio = 0;
25 if(teststringio<=0):
26 try:
27 from cStringIO import StringIO as BytesIO;
28 teststringio = 1;
29 except ImportError:
30 teststringio = 0;
31 if(teststringio<=0):
32 try:
33 from StringIO import StringIO as BytesIO;
34 teststringio = 2;
35 except ImportError:
36 teststringio = 0;
37 if(teststringio<=0):
38 try:
39 from io import BytesIO;
40 teststringio = 3;
41 except ImportError:
42 teststringio = 0;
44 __project__ = pycatfile.__project__;
45 __program_name__ = pycatfile.__program_name__;
46 __project_url__ = pycatfile.__project_url__;
47 __version_info__ = pycatfile.__version_info__;
48 __version_date_info__ = pycatfile.__version_date_info__;
49 __version_date__ = pycatfile.__version_date__;
50 __version_date_plusrc__ = pycatfile.__version_date_plusrc__
51 __version__ = pycatfile.__version__;
52 __version_date_plusrc__ = pycatfile.__version_date_plusrc__;
53 __cat_header_ver__ = pycatfile.__cat_header_ver__;
55 argparser = argparse.ArgumentParser(description="Manipulating concatenate files", conflict_handler="resolve", add_help=True);
56 argparser.add_argument("-V", "--version", action="version", version=__program_name__ + " " + __version__);
57 argparser.add_argument("-i", "-f", "--input", help="files to concatenate or concatenate file extract", required=True);
58 argparser.add_argument("-d", "-v", "--verbose", action="store_true", help="print various debugging information");
59 argparser.add_argument("-c", "--create", action="store_true", help="concatenate files only");
60 argparser.add_argument("-checksum", "--checksum", default="crc32", help="checksum type to use default is crc32");
61 argparser.add_argument("-e", "-x", "--extract", action="store_true", help="extract files only");
62 argparser.add_argument("-l", "-t", "--list", action="store_true", help="list files only");
63 argparser.add_argument("-r", "--repack", action="store_true", help="reconcatenate files only fixing checksum errors");
64 argparser.add_argument("-o", "--output", default=None, help="extract concatenate files to or concatenate output name");
65 argparser.add_argument("-compression", "--compression", default="auto", help="concatenate files with compression");
66 argparser.add_argument("-level", "--level", default=None, help="concatenate files with compression level");
67 argparser.add_argument("-t", "--converttar", action="store_true", help="convert tar file to catfile");
68 argparser.add_argument("-z", "--convertzip", action="store_true", help="convert tar file to catfile");
69 argparser.add_argument("-T", "--text", action="store_true", help="read file locations from text file");
70 getargs = argparser.parse_args();
72 should_extract = False;
73 should_create = True;
74 should_list = False;
75 should_convert_tar = False;
76 should_convert_zip = False;
77 if(not getargs.extract and getargs.create and not getargs.list):
78 should_create = True;
79 should_extract = False;
80 should_list = False;
81 if(getargs.extract and not getargs.create and not getargs.list):
82 should_create = False;
83 should_extract = True;
84 should_list = False;
85 if(getargs.extract and getargs.create and not getargs.list):
86 should_create = True;
87 should_extract = False;
88 should_list = False;
89 if(not getargs.extract and not getargs.create and not getargs.list):
90 should_create = True;
91 should_extract = False;
92 should_list = False;
93 if(not getargs.extract and getargs.create and getargs.list):
94 should_create = True;
95 should_extract = False;
96 should_list = False;
97 if(getargs.extract and not getargs.create and getargs.list):
98 should_create = False;
99 should_extract = True;
100 should_list = False;
101 if(getargs.extract and getargs.create and getargs.list):
102 should_create = True;
103 should_extract = False;
104 should_list = False;
105 if(not getargs.extract and not getargs.create and getargs.list):
106 should_create = False;
107 should_extract = False;
108 should_list = True;
109 should_repack = False;
110 if(should_create and getargs.repack):
111 should_repack = True;
112 if(getargs.converttar):
113 should_convert_tar = True;
114 should_convert_zip = False;
115 if(getargs.convertzip and not should_convert_tar):
116 should_convert_zip = True;
117 should_convert_tar = False;
118 if(getargs.verbose):
119 logging.basicConfig(format="%(message)s", stream=sys.stdout, level=logging.DEBUG);
120 if(should_create and not should_extract and not should_list and not should_repack):
121 if(should_convert_tar):
122 pycatfile.PackCatFileFromTarFile(getargs.input, getargs.output, getargs.compression, getargs.level, getargs.checksum, getargs.verbose, False);
123 elif(should_convert_zip and not should_convert_tar):
124 pycatfile.PackCatFileFromZipFile(getargs.input, getargs.output, getargs.compression, getargs.level, getargs.checksum, getargs.verbose, False);
125 else:
126 pycatfile.PackCatFile(getargs.input, getargs.output, getargs.text, getargs.compression, getargs.level, False, getargs.checksum, getargs.verbose, False);
127 if(should_create and not should_extract and not should_list and should_repack):
128 pycatfile.RePackCatFile(getargs.input, getargs.output, 0, 0, getargs.compression, getargs.level, False, getargs.checksum, False, getargs.verbose, False);
129 if(not should_create and should_extract and not should_list):
130 pycatfile.UnPackCatFile(getargs.input, getargs.output, False, False, getargs.verbose, False);
131 if(not should_create and not should_extract and should_list):
132 if(should_convert_tar):
133 pycatfile.TarFileListFiles(getargs.input, getargs.verbose, False);
134 elif(should_convert_zip and not should_convert_tar):
135 pycatfile.ZipFileListFiles(getargs.input, getargs.verbose, False);
136 else:
137 pycatfile.CatFileListFiles(getargs.input, 0, 0, False, getargs.verbose, False);