This repository has been archived by the owner on Nov 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPon3Ark.py
executable file
·102 lines (90 loc) · 3.25 KB
/
Pon3Ark.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# File: Pon3Ark.py
# by Arzaroth Lekva
#
from __future__ import print_function, absolute_import, unicode_literals
import os
import sys
import getpass
try:
PRGM = os.path.basename(__file__)
except NameError:
PRGM = os.path.basename(sys.argv[0])
VERSION = "v1.1.0"
__doc__ = """
{prgm} {ver}
Let's open ark files with some music.
Usage:
{prgm} -x [-vf FILE] [-o DIR] <ark_file> [FILE...]
{prgm} -c [-vsf FILE] <ark_file> FILE...
{prgm} -a [-vsf FILE] <ark_file> FILE...
{prgm} -t [-vf FILE] <ark_file>
{prgm} -h
{prgm} --version
Arguments:
ark_file Path to ark file.
FILE Files to put into the ark file. See "How to create".
Options:
-x Extract files from the ark file. When given, they specify names of the archive members to be extracted.
-c Create the ark file.
-a Append files to the ark file.
-t List the content of the ark file.
-f --passfile=FILE Take password from file instead of standard input.
-s --squash-path Squash file path inside the ark file.
-v Enable verbose.
-o --output=DIR Write files to DIR [default: out].
-V --version Show version number.
-h --help Show this help and exit.
How to create:
When creating a new ark file, you can prepand the filename with special characters:
- Add @ to compress the file inside the archive.
- Add : to encrypt the file inside the archive.
- Add + to do both.
- Add = to keep the file unencrypted and uncompressed.
The "=" is the default and should be used only if the filename starts with one of the specified characters.
Listing flags:
See "How to create".
Notes:
- The code of this tool is currently open source. If you experiment issues, feel free to report or improve it.
Author:
Original program by Arzaroth <[email protected]>
""".format(prgm=PRGM, ver=VERSION)
def get_password(opts):
if opts['--passfile']:
try:
with open(opts['--passfile'], 'rb') as f:
passwd = f.read()
except Exception as e:
print('Unable to retrieve password from file (%s)' % str(e),
file=sys.stderr)
sys.exit(1)
else:
passwd = getpass.getpass('Enter password: ')
if opts['-x'] and passwd != getpass.getpass('Verify password: '):
print('Password verification failed', file=sys.stderr)
sys.exit(1)
passwd = passwd.encode('utf-8')
return passwd
if __name__ == '__main__':
from pon3ark import ArkManager, ArkError
from pon3ark import do_list
from pon3ark import do_extract
from pon3ark import do_create
from docopt import docopt
opts = docopt(__doc__, version=VERSION)
passwd = get_password(opts)
try:
with ArkManager(opts['<ark_file>'], passwd,
opts['-c'], opts['-a']) as ark:
if opts['-t']:
do_list(ark, opts)
elif opts['-x']:
do_extract(ark, opts)
elif opts['-c'] or opts['-a']:
do_create(ark, opts)
except ArkError as e:
print(str(e), file=sys.stderr)
sys.exit(0)