Skip to content

Commit c72f73e

Browse files
committed
feat!: custom input folder, auto-generate output zip file
1 parent 1767796 commit c72f73e

3 files changed

Lines changed: 40 additions & 22 deletions

File tree

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ Parcel is a Python script designed to simplify the distribution of add-on aircra
33

44
**There is no guarantee that this will work. Instead of contacting the developers like a sane person, I tried reverse-engineering how it works instead. Seemed easier than talking to someone.**
55

6-
To use:
7-
1. Drag your aircraft files into [workdir](./workdir).
8-
2. (Optional) Drag your .parcelignore file into the [same directory as the script](./). An example file is provided, and
9-
file or directory names are supported. Slashes should be omitted.
10-
3. Run the python script.
11-
4. The resulting files will be left in [workdir](./workdir). Enjoy?
6+
## Usage
7+
To use, run the following:
8+
```
9+
python parcel.py [input folder] [output file]
10+
```
11+
Where:
12+
* `input folder` is a copy aircraft root folder (with the .acf file) and
13+
* `output file` is the archive to output the aircraft to. You should include the file extension, as Parcel will automatically use that to determine what compression algorithm it uses.
1214

13-
After this is done, you can:
14-
1. Compress the files in [workdir](./workdir) to distribute as normal.
15-
2. Upload the files in [workdir](./workdir) alongside the `skunkscraft_updater_*list.txt` files in the [directory with the script](./).
15+
Important things to note:
16+
* **The input folder must be a copy!** Parcel will delete any file that is included in `.parcelignore` OR any file that starts with a period.
17+
* The output file does not include the `skunkcrafts_updater_*` files. Those files are copied into the `input folder` after the creation of the output file. You should have new users download the output file on first install, and upload the input folder to your server.

parcel.py

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import fnmatch
1818
import os
1919
import shutil
20+
import sys
2021
import zlib
2122
from pathlib import Path
2223

@@ -54,52 +55,67 @@ def crc32(fp: str) -> int:
5455
return checksum
5556

5657

57-
def iterate(fp: str, blacklist: list[str]) -> None:
58+
def clean_iterate(root: str, fp: str, blacklist: list[str]) -> None:
5859
"""
59-
Iterate through all files and determine what is necessary
60+
Iterate through all files and delete what is unnecessary
6061
Args:
62+
root (str): Root directory, used in generating skunkcrafts files
6163
fp (str): Folder to iterate through.
6264
blacklist (list[str]): Files to skip.
6365
"""
64-
for files in os.listdir(fp):
66+
for file_name in os.listdir(fp):
6567
skip = False
6668
for item in blacklist:
67-
if fnmatch.fnmatch(files, item) or files.startswith("."):
69+
if fnmatch.fnmatch(file_name, item) or file_name.startswith("."):
6870
skip = True
6971
break
7072

71-
file_path = os.path.join(fp, files)
73+
file_path = os.path.join(fp, file_name)
7274
if skip:
73-
if files == "skunkcrafts_updater.cfg" or files == "skunkcrafts_updater_beta.cfg":
74-
print("Preserving file " + file_path) # skip
75+
if file_name == "skunkcrafts_updater.cfg" or file_name == "skunkcrafts_updater_beta.cfg":
76+
print("Preserving file", file_path) # skip
7577
elif Path.is_dir(Path(file_path)):
76-
print("Clearing directory " + file_path)
78+
print("Clearing directory", file_path)
7779
shutil.rmtree(os.path.join(os.curdir, file_path))
7880
else:
79-
print("Clearing " + file_path)
81+
print("Clearing", file_path)
8082
os.remove(os.path.join(os.curdir, file_path))
8183

8284
elif os.path.isdir(file_path):
83-
iterate(file_path, blacklist)
85+
clean_iterate(root, file_path, blacklist)
8486
else:
85-
file_path_out = file_path.replace("workdir/", "", 1)
87+
file_path_out = file_path.replace(root + "/", "", 1)
8688
whitelist_file.write(f"{file_path_out}|{str(crc32(file_path))}\n")
8789
filesize_file.write(f"{file_path_out}|{str(size(file_path))}\n")
8890

8991

9092
def main():
91-
fp = Path.joinpath(Path(os.curdir), "workdir")
9293
blacklist: list[str] = []
9394

95+
input_folder = sys.argv[1]
96+
output_file = sys.argv[2]
97+
9498
if not blacklist_file.is_file():
9599
print("Ignore file does not exist! Extra files may be added!")
96100
else:
97101
blacklist = blacklist_file.open().read().splitlines()
98102

99-
iterate(fp.name, blacklist)
103+
clean_iterate(input_folder, input_folder, blacklist)
100104

101105
whitelist_file.close()
102106
filesize_file.close()
103107

108+
outputs = output_file.split(".", 1)
109+
110+
if outputs[1] == "tar.gz":
111+
outputs[1] = "gztar"
112+
elif outputs[1] == "tar.bz":
113+
outputs[1] = "bztar"
114+
elif outputs[1] == "tar.xz":
115+
outputs[1] = "xztar"
116+
117+
print("Generating", output_file)
118+
shutil.make_archive(outputs[0], outputs[1], input_folder)
119+
104120

105121
main()

workdir/PLACEHOLDER

Whitespace-only changes.

0 commit comments

Comments
 (0)