PyArchiveFile 0.17.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2018, Game Maker 2k
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ * Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ * Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ * Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,47 @@
1
+ Metadata-Version: 2.2
2
+ Name: PyArchiveFile
3
+ Version: 0.17.4
4
+ Summary: A tar like file format name archivefile after unix cat command (concatenate files) .
5
+ Home-page: https://github.com/GameMaker2k/PyArchiveFile
6
+ Download-URL: https://github.com/GameMaker2k/PyArchiveFile/archive/master.tar.gz
7
+ Author: Kazuki Przyborowski
8
+ Author-email: kazuki.przyborowski@gmail.com
9
+ Maintainer: Kazuki Przyborowski
10
+ Maintainer-email: kazuki.przyborowski@gmail.com
11
+ License: Revised BSD License
12
+ Keywords: cat archivefile cat-archive archivefile-archive pyarchivefile python python-archivefile neko nekofile neko-archive nekofile-archive pynekofile python python-nekofile compression tarball gzip tar bzip2 tar-archive lzma xz gz lzma2 xz2 tarlike tarlite hairball
13
+ Platform: OS Independent
14
+ Classifier: Development Status :: 5 - Production/Stable
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Intended Audience :: Other Audience
17
+ Classifier: License :: OSI Approved
18
+ Classifier: License :: OSI Approved :: BSD License
19
+ Classifier: Natural Language :: English
20
+ Classifier: Operating System :: MacOS
21
+ Classifier: Operating System :: MacOS :: MacOS X
22
+ Classifier: Operating System :: Microsoft
23
+ Classifier: Operating System :: Microsoft :: Windows
24
+ Classifier: Operating System :: OS/2
25
+ Classifier: Operating System :: OS Independent
26
+ Classifier: Operating System :: POSIX
27
+ Classifier: Operating System :: Unix
28
+ Classifier: Programming Language :: Python
29
+ Classifier: Topic :: Utilities
30
+ Classifier: Topic :: Software Development
31
+ Classifier: Topic :: Software Development :: Libraries
32
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
33
+ License-File: LICENSE
34
+ Dynamic: author
35
+ Dynamic: author-email
36
+ Dynamic: classifier
37
+ Dynamic: description
38
+ Dynamic: download-url
39
+ Dynamic: home-page
40
+ Dynamic: keywords
41
+ Dynamic: license
42
+ Dynamic: maintainer
43
+ Dynamic: maintainer-email
44
+ Dynamic: platform
45
+ Dynamic: summary
46
+
47
+ A tar like file format name archivefile after unix cat command (concatenate files) .
@@ -0,0 +1,47 @@
1
+ Metadata-Version: 2.2
2
+ Name: PyArchiveFile
3
+ Version: 0.17.4
4
+ Summary: A tar like file format name archivefile after unix cat command (concatenate files) .
5
+ Home-page: https://github.com/GameMaker2k/PyArchiveFile
6
+ Download-URL: https://github.com/GameMaker2k/PyArchiveFile/archive/master.tar.gz
7
+ Author: Kazuki Przyborowski
8
+ Author-email: kazuki.przyborowski@gmail.com
9
+ Maintainer: Kazuki Przyborowski
10
+ Maintainer-email: kazuki.przyborowski@gmail.com
11
+ License: Revised BSD License
12
+ Keywords: cat archivefile cat-archive archivefile-archive pyarchivefile python python-archivefile neko nekofile neko-archive nekofile-archive pynekofile python python-nekofile compression tarball gzip tar bzip2 tar-archive lzma xz gz lzma2 xz2 tarlike tarlite hairball
13
+ Platform: OS Independent
14
+ Classifier: Development Status :: 5 - Production/Stable
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Intended Audience :: Other Audience
17
+ Classifier: License :: OSI Approved
18
+ Classifier: License :: OSI Approved :: BSD License
19
+ Classifier: Natural Language :: English
20
+ Classifier: Operating System :: MacOS
21
+ Classifier: Operating System :: MacOS :: MacOS X
22
+ Classifier: Operating System :: Microsoft
23
+ Classifier: Operating System :: Microsoft :: Windows
24
+ Classifier: Operating System :: OS/2
25
+ Classifier: Operating System :: OS Independent
26
+ Classifier: Operating System :: POSIX
27
+ Classifier: Operating System :: Unix
28
+ Classifier: Programming Language :: Python
29
+ Classifier: Topic :: Utilities
30
+ Classifier: Topic :: Software Development
31
+ Classifier: Topic :: Software Development :: Libraries
32
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
33
+ License-File: LICENSE
34
+ Dynamic: author
35
+ Dynamic: author-email
36
+ Dynamic: classifier
37
+ Dynamic: description
38
+ Dynamic: download-url
39
+ Dynamic: home-page
40
+ Dynamic: keywords
41
+ Dynamic: license
42
+ Dynamic: maintainer
43
+ Dynamic: maintainer-email
44
+ Dynamic: platform
45
+ Dynamic: summary
46
+
47
+ A tar like file format name archivefile after unix cat command (concatenate files) .
@@ -0,0 +1,12 @@
1
+ LICENSE
2
+ README.md
3
+ archivefile.py
4
+ neoarchivefile.py
5
+ pyarchivefile.py
6
+ setup.cfg
7
+ setup.py
8
+ PyArchiveFile.egg-info/PKG-INFO
9
+ PyArchiveFile.egg-info/SOURCES.txt
10
+ PyArchiveFile.egg-info/dependency_links.txt
11
+ PyArchiveFile.egg-info/top_level.txt
12
+ PyArchiveFile.egg-info/zip-safe
@@ -0,0 +1 @@
1
+ pyarchivefile
@@ -0,0 +1 @@
1
+ A tar like file format name ArchiveFile
@@ -0,0 +1,250 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ '''
5
+ This program is free software; you can redistribute it and/or modify
6
+ it under the terms of the Revised BSD License.
7
+
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.
12
+
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
16
+
17
+ $FileInfo: archivefile.py - Last Update: 1/26/2025 Ver. 0.17.4 RC 1 - Author: cooldude2k $
18
+ '''
19
+
20
+ from __future__ import absolute_import, division, print_function, unicode_literals, generators, with_statement, nested_scopes
21
+ import os
22
+ import sys
23
+ import argparse
24
+ import pyarchivefile
25
+ import binascii
26
+
27
+ # Conditional import and signal handling for Unix-like systems
28
+ if os.name != 'nt': # Not Windows
29
+ import signal
30
+
31
+ def handler(signum, frame):
32
+ pyarchivefile.VerbosePrintOut(
33
+ "Received SIGPIPE, exiting gracefully.", "info")
34
+ sys.exit(0)
35
+ signal.signal(signal.SIGPIPE, handler)
36
+
37
+ rarfile_support = pyarchivefile.rarfile_support
38
+ py7zr_support = pyarchivefile.py7zr_support
39
+
40
+ if(sys.version[0] == "2"):
41
+ try:
42
+ from io import StringIO, BytesIO
43
+ except ImportError:
44
+ try:
45
+ from cStringIO import StringIO
46
+ from cStringIO import StringIO as BytesIO
47
+ except ImportError:
48
+ from StringIO import StringIO
49
+ from StringIO import StringIO as BytesIO
50
+ elif(sys.version[0] >= "3"):
51
+ from io import StringIO, BytesIO
52
+ else:
53
+ teststringio = 0
54
+ if(teststringio <= 0):
55
+ try:
56
+ from cStringIO import StringIO as BytesIO
57
+ teststringio = 1
58
+ except ImportError:
59
+ teststringio = 0
60
+ if(teststringio <= 0):
61
+ try:
62
+ from StringIO import StringIO as BytesIO
63
+ teststringio = 2
64
+ except ImportError:
65
+ teststringio = 0
66
+ if(teststringio <= 0):
67
+ try:
68
+ from io import BytesIO
69
+ teststringio = 3
70
+ except ImportError:
71
+ teststringio = 0
72
+
73
+ __project__ = pyarchivefile.__project__
74
+ __program_name__ = pyarchivefile.__program_name__
75
+ __file_format_name__ = pyarchivefile.__file_format_name__
76
+ __file_format_lower__ = pyarchivefile.__file_format_lower__
77
+ __file_format_magic__ = pyarchivefile.__file_format_magic__
78
+ __file_format_len__ = pyarchivefile.__file_format_len__
79
+ __file_format_hex__ = pyarchivefile.__file_format_hex__
80
+ __file_format_delimiter__ = pyarchivefile.__file_format_delimiter__
81
+ __file_format_dict__ = pyarchivefile.__file_format_dict__
82
+ __file_format_default__ = pyarchivefile.__file_format_default__
83
+ __file_format_multi_dict__ = pyarchivefile.__file_format_multi_dict__
84
+ __use_new_style__ = pyarchivefile.__use_new_style__
85
+ __use_advanced_list__ = pyarchivefile.__use_advanced_list__
86
+ __use_alt_inode__ = pyarchivefile.__use_alt_inode__
87
+ __project_url__ = pyarchivefile.__project_url__
88
+ __version_info__ = pyarchivefile.__version_info__
89
+ __version_date_info__ = pyarchivefile.__version_date_info__
90
+ __version_date__ = pyarchivefile.__version_date__
91
+ __version_date_plusrc__ = pyarchivefile.__version_date_plusrc__
92
+ __version__ = pyarchivefile.__version__
93
+
94
+ # Initialize the argument parser
95
+ argparser = argparse.ArgumentParser(
96
+ description="Manipulate archive files.", conflict_handler="resolve", add_help=True)
97
+
98
+ # Version information
99
+ argparser.add_argument("-V", "--version", action="version",
100
+ version=__program_name__ + " " + __version__)
101
+ # Input and output specifications
102
+ argparser.add_argument(
103
+ "-i", "--input", nargs="+", help="Specify the file(s) to concatenate or the archive file to extract.", required=True)
104
+ argparser.add_argument("-o", "--output", default=None,
105
+ help="Specify the name for the extracted or output archive files.")
106
+ # Operations
107
+ argparser.add_argument("-c", "--create", action="store_true",
108
+ help="Perform only the concatenation operation.")
109
+ argparser.add_argument("-e", "--extract", action="store_true",
110
+ help="Perform only the extraction operation.")
111
+ argparser.add_argument("-t", "--convert", action="store_true",
112
+ help="Convert a tar/zip/rar/7zip file to a archive file.")
113
+ argparser.add_argument("-r", "--repack", action="store_true",
114
+ help="Re-concatenate files, fixing checksum errors if any.")
115
+ # File manipulation options
116
+ argparser.add_argument(
117
+ "-F", "--format", default="auto", help="Specify the format to use.")
118
+ argparser.add_argument(
119
+ "-D", "--delimiter", default=__file_format_dict__['format_delimiter'], help="Specify the delimiter to use.")
120
+ argparser.add_argument(
121
+ "-m", "--formatver", default=__file_format_dict__['format_ver'], help="Specify the format version.")
122
+ argparser.add_argument("-l", "--list", action="store_true",
123
+ help="List files included in the archive file.")
124
+ # Compression options
125
+ argparser.add_argument("-P", "--compression", default="auto",
126
+ help="Specify the compression method to use for concatenation.")
127
+ argparser.add_argument("-L", "--level", default=None,
128
+ help="Specify the compression level for concatenation.")
129
+ argparser.add_argument("-W", "--wholefile", action="store_true",
130
+ help="Whole file compression method to use for concatenation.")
131
+ # Checksum and validation
132
+ argparser.add_argument("-v", "--validate", action="store_true",
133
+ help="Validate archive file checksums.")
134
+ argparser.add_argument("-C", "--checksum", default="crc32",
135
+ help="Specify the type of checksum to use. The default is crc32.")
136
+ argparser.add_argument("-s", "--skipchecksum", action="store_true",
137
+ help="Skip the checksum check of files.")
138
+ # Permissions and metadata
139
+ argparser.add_argument("-p", "--preserve", action="store_false",
140
+ help="Do not preserve permissions and timestamps of files.")
141
+ # Miscellaneous
142
+ argparser.add_argument("-d", "--verbose", action="store_true",
143
+ help="Enable verbose mode to display various debugging information.")
144
+ argparser.add_argument("-T", "--text", action="store_true",
145
+ help="Read file locations from a text file.")
146
+ # Parse the arguments
147
+ getargs = argparser.parse_args()
148
+
149
+ fname = getargs.format
150
+ fnamelower = fname.lower()
151
+ if(getargs.format=="auto"):
152
+ fnamedict = __file_format_multi_dict__
153
+ __file_format_default__ = getargs.format
154
+ else:
155
+ fnamemagic = fname
156
+ fnamelen = len(fname)
157
+ fnamehex = binascii.hexlify(fname.encode("UTF-8")).decode("UTF-8")
158
+ __file_format_default__ = fnamemagic
159
+ fnamesty = __use_new_style__
160
+ fnamelst = __use_advanced_list__
161
+ fnameino = __use_alt_inode__
162
+ fnamedict = {'format_name': fname, 'format_magic': fnamemagic, 'format_lower': fnamelower, 'format_len': fnamelen, 'format_hex': fnamehex,
163
+ 'format_delimiter': getargs.delimiter, 'format_ver': getargs.formatver, 'new_style': fnamesty, 'use_advanced_list': fnamelst, 'use_alt_inode': fnameino}
164
+
165
+ # Determine the primary action based on user input
166
+ actions = ['create', 'extract', 'list', 'repack', 'validate']
167
+ active_action = next(
168
+ (action for action in actions if getattr(getargs, action)), None)
169
+ input_file = getargs.input[0]
170
+
171
+ # Execute the appropriate functions based on determined actions and arguments
172
+ if active_action:
173
+ if active_action == 'create':
174
+ if getargs.convert:
175
+ checkcompressfile = pyarchivefile.CheckCompressionSubType(
176
+ input_file, fnamedict, True)
177
+ if((IsNestedDict(fnamedict) and compresscheck in fnamedict) or (IsSingleDict(fnamedict) and compresscheck==fnamedict['format_magic'])):
178
+ tmpout = pyarchivefile.RePackArchiveFile(input_file, getargs.output, getargs.compression, getargs.wholefile, getargs.level, pyarchivefile.compressionlistalt, False, 0, 0, [getargs.checksum, getargs.checksum, getargs.checksum], getargs.skipchecksum, [], fnamedict, getargs.verbose, False)
179
+ else:
180
+ tmpout = pyarchivefile.PackArchiveFileFromInFile(
181
+ input_file, getargs.output, __file_format_default__, getargs.compression, getargs.wholefile, getargs.level, pyarchivefile.compressionlistalt, [getargs.checksum, getargs.checksum, getargs.checksum], [], fnamedict, getargs.verbose, False)
182
+ if(not tmpout):
183
+ sys.exit(1)
184
+ else:
185
+ pyarchivefile.PackArchiveFile(getargs.input, getargs.output, getargs.text, __file_format_default__, getargs.compression, getargs.wholefile, getargs.level, pyarchivefile.compressionlistalt, False, [getargs.checksum, getargs.checksum, getargs.checksum], [], fnamedict, getargs.verbose, False)
186
+ elif active_action == 'repack':
187
+ if getargs.convert:
188
+ checkcompressfile = pyarchivefile.CheckCompressionSubType(
189
+ input_file, fnamedict, True)
190
+ if((IsNestedDict(fnamedict) and compresscheck in fnamedict) or (IsSingleDict(fnamedict) and compresscheck==fnamedict['format_magic'])):
191
+ pyarchivefile.RePackArchiveFile(input_file, getargs.output, getargs.compression, getargs.wholefile, getargs.level, pyarchivefile.compressionlistalt,
192
+ False, 0, 0, [getargs.checksum, getargs.checksum, getargs.checksum], getargs.skipchecksum, [], fnamedict, getargs.verbose, False)
193
+ else:
194
+ pyarchivefile.PackArchiveFileFromInFile(input_file, getargs.output, __file_format_default__, getargs.compression, getargs.wholefile, getargs.level, pyarchivefile.compressionlistalt, [getargs.checksum, getargs.checksum, getargs.checksum], [], fnamedict, getargs.verbose, False)
195
+ if(not tmpout):
196
+ sys.exit(1)
197
+ else:
198
+ pyarchivefile.RePackArchiveFile(input_file, getargs.output, getargs.compression, getargs.wholefile, getargs.level, pyarchivefile.compressionlistalt,
199
+ False, 0, 0, [getargs.checksum, getargs.checksum, getargs.checksum], getargs.skipchecksum, [], fnamedict, getargs.verbose, False)
200
+ elif active_action == 'extract':
201
+ if getargs.convert:
202
+ checkcompressfile = pyarchivefile.CheckCompressionSubType(
203
+ input_file, fnamedict, True)
204
+ tempout = BytesIO()
205
+ if((IsNestedDict(fnamedict) and compresscheck in fnamedict) or (IsSingleDict(fnamedict) and compresscheck==fnamedict['format_magic'])):
206
+ tmpout = pyarchivefile.RePackArchiveFile(input_file, tempout, getargs.compression, getargs.wholefile, getargs.level, pyarchivefile.compressionlistalt, False, 0, 0, [getargs.checksum, getargs.checksum, getargs.checksum], getargs.skipchecksum, [], fnamedict, False, False)
207
+ else:
208
+ tmpout = pyarchivefile.PackArchiveFileFromInFile(
209
+ input_file, tempout, __file_format_default__, getargs.compression, getargs.wholefile, getargs.level, pyarchivefile.compressionlistalt, [getargs.checksum, getargs.checksum, getargs.checksum], [], fnamedict, False, False)
210
+ if(not tmpout):
211
+ sys.exit(1)
212
+ input_file = tempout
213
+ pyarchivefile.UnPackArchiveFile(input_file, getargs.output, False, 0, 0, getargs.skipchecksum,
214
+ fnamedict, getargs.verbose, getargs.preserve, getargs.preserve, False)
215
+ elif active_action == 'list':
216
+ if getargs.convert:
217
+ checkcompressfile = pyarchivefile.CheckCompressionSubType(
218
+ input_file, fnamedict, True)
219
+ if((IsNestedDict(fnamedict) and compresscheck in fnamedict) or (IsSingleDict(fnamedict) and compresscheck==fnamedict['format_magic'])):
220
+ tmpout = pyarchivefile.ArchiveFileListFiles(input_file, "auto", 0, 0, getargs.skipchecksum, fnamedict, getargs.verbose, False)
221
+ else:
222
+ tmpout = pyarchivefile.InFileListFiles(input_file, getargs.verbose, fnamedict, False)
223
+ if(not tmpout):
224
+ sys.exit(1)
225
+ else:
226
+ pyarchivefile.ArchiveFileListFiles(input_file, "auto", 0, 0, getargs.skipchecksum, fnamedict, getargs.verbose, False)
227
+ elif active_action == 'validate':
228
+ if getargs.convert:
229
+ checkcompressfile = pyarchivefile.CheckCompressionSubType(
230
+ input_file, fnamedict, True)
231
+ tempout = BytesIO()
232
+ if((IsNestedDict(fnamedict) and compresscheck in fnamedict) or (IsSingleDict(fnamedict) and compresscheck==fnamedict['format_magic'])):
233
+ tmpout = pyarchivefile.RePackArchiveFile(input_file, tempout, getargs.compression, getargs.wholefile, getargs.level, pyarchivefile.compressionlistalt, False, 0, 0, [getargs.checksum, getargs.checksum, getargs.checksum], getargs.skipchecksum, [], fnamedict, False, False)
234
+ else:
235
+ tmpout = pyarchivefile.PackArchiveFileFromInFile(
236
+ input_file, tempout, __file_format_default__, getargs.compression, getargs.wholefile, getargs.level, pyarchivefile.compressionlistalt, [getargs.checksum, getargs.checksum, getargs.checksum], [], fnamedict, False, False)
237
+ input_file = tempout
238
+ if(not tmpout):
239
+ sys.exit(1)
240
+ fvalid = pyarchivefile.ArchiveFileValidate(
241
+ input_file, "auto", fnamedict, getargs.verbose, False)
242
+ if(not getargs.verbose):
243
+ import sys
244
+ import logging
245
+ logging.basicConfig(format="%(message)s",
246
+ stream=sys.stdout, level=logging.DEBUG)
247
+ if(fvalid):
248
+ pyarchivefile.VerbosePrintOut("File is valid: \n" + str(input_file))
249
+ else:
250
+ pyarchivefile.VerbosePrintOut("File is invalid: \n" + str(input_file))
@@ -0,0 +1,137 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ '''
5
+ This program is free software; you can redistribute it and/or modify
6
+ it under the terms of the Revised BSD License.
7
+
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.
12
+
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
16
+
17
+ $FileInfo: neoarchivefile.py - Last Update: 1/26/2025 Ver. 0.17.4 RC 1 - Author: cooldude2k $
18
+ '''
19
+
20
+ from __future__ import absolute_import, division, print_function, unicode_literals, generators, with_statement, nested_scopes
21
+ import argparse
22
+ import pyarchivefile
23
+
24
+ __project__ = pyarchivefile.__project__
25
+ __program_name__ = pyarchivefile.__program_name__
26
+ __file_format_name__ = pyarchivefile.__file_format_name__
27
+ __file_format_lower__ = pyarchivefile.__file_format_lower__
28
+ __file_format_magic__ = pyarchivefile.__file_format_magic__
29
+ __file_format_len__ = pyarchivefile.__file_format_len__
30
+ __file_format_hex__ = pyarchivefile.__file_format_hex__
31
+ __file_format_delimiter__ = pyarchivefile.__file_format_delimiter__
32
+ __file_format_dict__ = pyarchivefile.__file_format_dict__
33
+ __file_format_default__ = pyarchivefile.__file_format_default__
34
+ __use_new_style__ = pyarchivefile.__use_new_style__
35
+ __use_advanced_list__ = pyarchivefile.__use_advanced_list__
36
+ __use_alt_inode__ = pyarchivefile.__use_alt_inode__
37
+ __project_url__ = pyarchivefile.__project_url__
38
+ __version_info__ = pyarchivefile.__version_info__
39
+ __version_date_info__ = pyarchivefile.__version_date_info__
40
+ __version_date__ = pyarchivefile.__version_date__
41
+ __version_date_plusrc__ = pyarchivefile.__version_date_plusrc__
42
+ __version__ = pyarchivefile.__version__
43
+
44
+ # Compatibility layer for Python 2 and 3 input
45
+ try:
46
+ input = raw_input
47
+ except NameError:
48
+ pass
49
+
50
+ # Determine if rar file support is enabled
51
+ rarfile_support = pyarchivefile.rarfile_support
52
+ py7zr_support = pyarchivefile.py7zr_support
53
+
54
+ # Set up the argument parser
55
+ argparser = argparse.ArgumentParser(
56
+ description="Manipulates archive files for various operations like creation, extraction, and validation.")
57
+ argparser.add_argument("-V", "--version", action="version", version="{0} {1}".format(
58
+ __program_name__, __version__), help="Displays the program's version.")
59
+ argparser.add_argument("-i", "--input", nargs="+", required=True,
60
+ help="Specifies input file(s) for processing.")
61
+ argparser.add_argument(
62
+ "-o", "--output", help="Specifies the output file name.")
63
+ argparser.add_argument("-d", "--verbose", action="store_true",
64
+ help="Enables verbose mode for detailed information.")
65
+ argparser.add_argument("-c", "--create", action="store_true",
66
+ help="Creates a new archive file from input.")
67
+ argparser.add_argument("-e", "--extract", action="store_true",
68
+ help="Extracts files from a archive archive.")
69
+ argparser.add_argument("-l", "--list", action="store_true",
70
+ help="Lists contents of a specified archive file.")
71
+ argparser.add_argument("-r", "--repack", action="store_true",
72
+ help="Repacks an existing archive file.")
73
+ argparser.add_argument("-v", "--validate", action="store_true",
74
+ help="Validates a archive file's integrity.")
75
+ argparser.add_argument("--checksum", default="crc32",
76
+ help="Specifies the checksum type (default: crc32).")
77
+ argparser.add_argument("--compression", default="auto",
78
+ help="Specifies the compression method (default: auto).")
79
+ argparser.add_argument("--level", help="Specifies the compression level.")
80
+ argparser.add_argument("--preserve", action="store_true",
81
+ help="Preserves file attributes when extracting.")
82
+ argparser.add_argument("--convert", choices=['tar', 'zip', '7zip', 'rar'],
83
+ help="Convert from an archive format (tar, zip, 7zip, rar) to a archive file.")
84
+ args = argparser.parse_args()
85
+
86
+ # Determine the primary action based on user input
87
+ primary_action = None
88
+ if args.create:
89
+ primary_action = 'create'
90
+ elif args.repack:
91
+ primary_action = 'repack'
92
+ elif args.extract:
93
+ primary_action = 'extract'
94
+ elif args.list:
95
+ primary_action = 'list'
96
+ elif args.validate:
97
+ primary_action = 'validate'
98
+ input_file = args.input[0]
99
+ # Functionality mappings
100
+ if primary_action == 'create':
101
+ if args.convert == 'tar':
102
+ pyarchivefile.PackArchiveFileFromTarFile(input_file, args.output, args.compression, args.level, pyarchivefile.compressionlistalt, [args.checksum, args.checksum, args.checksum], [
103
+ ], pyarchivefile.__file_format_dict__, args.verbose, False)
104
+ elif args.convert == 'zip':
105
+ pyarchivefile.PackArchiveFileFromZipFile(input_file, args.output, args.compression, args.level, pyarchivefile.compressionlistalt, [args.checksum, args.checksum, args.checksum], [
106
+ ], pyarchivefile.__file_format_dict__, args.verbose, False)
107
+ elif py7zr_support and args.convert == '7zip':
108
+ pyarchivefile.PackArchiveFileFromSevenZipFile(input_file, args.output, args.compression, args.level, pyarchivefile.compressionlistalt, [args.checksum, args.checksum, args.checksum], [
109
+ ], pyarchivefile.__file_format_dict__, args.verbose, False)
110
+ elif rarfile_support and args.convert == 'rar':
111
+ pyarchivefile.PackArchiveFileFromRarFile(input_file, args.output, args.compression, args.level, pyarchivefile.compressionlistalt, [args.checksum, args.checksum, args.checksum], [
112
+ ], pyarchivefile.__file_format_dict__, args.verbose, False)
113
+ else:
114
+ pyarchivefile.PackArchiveFile(args.input, args.output, args.verbose, args.compression, args.level, pyarchivefile.compressionlistalt,
115
+ False, [args.checksum, args.checksum, args.checksum], [], pyarchivefile.__file_format_dict__, args.verbose, False)
116
+ elif primary_action == 'repack':
117
+ pyarchivefile.RePackArchiveFile(
118
+ input_file, args.output, args.compression, args.level, pyarchivefile.compressionlistalt, [args.checksum, args.checksum, args.checksum], args.verbose)
119
+ elif primary_action == 'extract':
120
+ pyarchivefile.UnPackArchiveFile(
121
+ input_file, args.output, args.verbose, args.preserve)
122
+ elif primary_action == 'list':
123
+ if args.convert == 'tar':
124
+ pyarchivefile.TarFileListFiles(input_file, verbose=args.verbose)
125
+ elif args.convert == 'zip':
126
+ pyarchivefile.ZipFileListFiles(input_file, verbose=args.verbose)
127
+ elif args.convert == '7zip':
128
+ pyarchivefile.SevenZipFileListFiles(input_file, verbose=args.verbose)
129
+ elif rarfile_support and args.convert == 'rar':
130
+ pyarchivefile.RarFileListFiles(input_file, verbose=args.verbose)
131
+ else:
132
+ pyarchivefile.ArchiveFileListFiles(input_file, verbose=args.verbose)
133
+ elif primary_action == 'validate':
134
+ is_valid = pyarchivefile.ArchiveFileValidate(input_file, verbose=args.verbose)
135
+ result_msg = "Validation result for {0}: {1}".format(
136
+ input_file, 'Valid' if is_valid else 'Invalid')
137
+ print(result_msg)