-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpack.py
59 lines (53 loc) · 1.56 KB
/
pack.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
import os
import sys
import argparse
from fatx import FATX
def walkfs(fs):
with os.scandir(".") as it:
for entry in it:
if entry.is_file():
with open(entry.name, "rb") as f:
fs.import_file(entry.name, f.read())
else:
fs.create_dir(entry.name)
os.chdir(entry.name)
walkfs(fs.get(entry.name))
os.chdir("..")
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Imports all files and folder from a given path into a new image"
)
parser.add_argument(
"--sector-size",
dest="sector_size",
default=512,
type=int,
help="sector size used for this image(default: 512)",
)
parser.add_argument(dest="size", type=int, help="size of the new partition")
parser.add_argument(
dest="src",
type=str,
nargs=1,
action="store",
help="src directory for the content of the new image",
)
parser.add_argument(
dest="image",
type=str,
nargs=1,
action="store",
help="an FATX filesystem image"
)
args = parser.parse_args()
size = args.size
src = args.src[0]
file = args.image[0]
if not os.path.isdir(src):
sys.exit("Fatal: src-dir is not a valid directory")
if os.path.exists(file):
sys.exit("Fatal: target file already exists")
FATX.READ_ONLY = False
fs = FATX.Filesystem.new(size, file, args.sector_size)
os.chdir(src)
walkfs(fs.root)