-
Notifications
You must be signed in to change notification settings - Fork 1
/
neocatfile.py
executable file
·117 lines (107 loc) · 5.64 KB
/
neocatfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
This program is free software; you can redistribute it and/or modify
it under the terms of the Revised BSD License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Revised BSD License for more details.
Copyright 2018-2024 Cool Dude 2k - http://idb.berlios.de/
Copyright 2018-2024 Game Maker 2k - http://intdb.sourceforge.net/
Copyright 2018-2024 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
$FileInfo: neocatfile.py - ast Update: 10/22/2024 Ver. 0.14.2 RC 1 - Author: cooldude2k $
'''
from __future__ import absolute_import, division, print_function, unicode_literals, generators, with_statement, nested_scopes
import argparse
import pycatfile
# Compatibility layer for Python 2 and 3 input
try:
input = raw_input
except NameError:
pass
# Determine if rar file support is enabled
rarfile_support = pycatfile.rarfile_support
py7zr_support = pycatfile.py7zr_support
# Set up the argument parser
argparser = argparse.ArgumentParser(
description="Manipulates concatenated files for various operations like creation, extraction, and validation.")
argparser.add_argument("-V", "--version", action="version", version="{0} {1}".format(
pycatfile.__program_name__, pycatfile.__version__), help="Displays the program's version.")
argparser.add_argument("-i", "--input", required=True,
help="Specifies input file(s) for processing.")
argparser.add_argument(
"-o", "--output", help="Specifies the output file name.")
argparser.add_argument("-d", "--verbose", action="store_true",
help="Enables verbose mode for detailed information.")
argparser.add_argument("-c", "--create", action="store_true",
help="Creates a new concatenated file from input.")
argparser.add_argument("-e", "--extract", action="store_true",
help="Extracts files from a concatenated archive.")
argparser.add_argument("-l", "--list", action="store_true",
help="Lists contents of a specified concatenated file.")
argparser.add_argument("-r", "--repack", action="store_true",
help="Repacks an existing concatenated file.")
argparser.add_argument("-v", "--validate", action="store_true",
help="Validates a concatenated file's integrity.")
argparser.add_argument("--checksum", default="crc32",
help="Specifies the checksum type (default: crc32).")
argparser.add_argument("--compression", default="auto",
help="Specifies the compression method (default: auto).")
argparser.add_argument("--level", help="Specifies the compression level.")
argparser.add_argument("--preserve", action="store_true",
help="Preserves file attributes when extracting.")
argparser.add_argument("--convert", choices=['tar', 'zip', '7zip', 'rar'],
help="Convert from an archive format (tar, zip, 7zip, rar) to a concatenated file.")
args = argparser.parse_args()
# Determine the primary action based on user input
primary_action = None
if args.create:
primary_action = 'create'
elif args.repack:
primary_action = 'repack'
elif args.extract:
primary_action = 'extract'
elif args.list:
primary_action = 'list'
elif args.validate:
primary_action = 'validate'
# Functionality mappings
if primary_action == 'create':
if args.convert == 'tar':
pycatfile.PackArchiveFileFromTarFile(args.input, args.output, args.compression, args.level, args.checksum, [
], pycatfile.__file_format_list__, args.verbose, False)
elif args.convert == 'zip':
pycatfile.PackArchiveFileFromZipFile(args.input, args.output, args.compression, args.level, args.checksum, [
], pycatfile.__file_format_list__, args.verbose, False)
elif py7zr_support and args.convert == '7zip':
pycatfile.PackArchiveFileFromSevenZipFile(args.input, args.output, args.compression, args.level, args.checksum, [
], pycatfile.__file_format_list__, args.verbose, False)
elif rarfile_support and args.convert == 'rar':
pycatfile.PackArchiveFileFromRarFile(args.input, args.output, args.compression, args.level, args.checksum, [
], pycatfile.__file_format_list__, args.verbose, False)
else:
pycatfile.PackArchiveFile(args.input, args.output, args.verbose, args.compression, args.level,
False, args.checksum, [], pycatfile.__file_format_list__, args.verbose, False)
elif primary_action == 'repack':
pycatfile.RePackArchiveFile(
args.input, args.output, args.compression, args.level, args.checksum, args.verbose)
elif primary_action == 'extract':
pycatfile.UnPackArchiveFile(
args.input, args.output, args.verbose, args.preserve)
elif primary_action == 'list':
if args.convert == 'tar':
pycatfile.TarFileListFiles(args.input, verbose=args.verbose)
elif args.convert == 'zip':
pycatfile.ZipFileListFiles(args.input, verbose=args.verbose)
elif args.convert == '7zip':
pycatfile.SevenZipFileListFiles(args.input, verbose=args.verbose)
elif rarfile_support and args.convert == 'rar':
pycatfile.RarFileListFiles(args.input, verbose=args.verbose)
else:
pycatfile.ArchiveFileListFiles(args.input, verbose=args.verbose)
elif primary_action == 'validate':
is_valid = pycatfile.ArchiveFileValidate(args.input, args.verbose)
result_msg = "Validation result for {0}: {1}".format(
args.input, 'Valid' if is_valid else 'Invalid')
print(result_msg)