|
| 1 | +# Copyright 2025 Stasia Michalska <hel@lcp.world> |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import os |
| 16 | +import sys |
| 17 | +import argparse |
| 18 | +import pathlib |
| 19 | + |
| 20 | +from pbpack import ResourcePack |
| 21 | + |
| 22 | +def main(): |
| 23 | + parser = argparse.ArgumentParser(description= |
| 24 | + 'Pack a directory content into pbpacked data.') |
| 25 | + parser.add_argument('directory', type=str, help='directory to pack') |
| 26 | + parser.add_argument('--output', type=str, default='app_resources.pbpack', help='the directory to output the files to') |
| 27 | + parser.add_argument('--app', default=False, action='store_true', |
| 28 | + help='Indicate this pbpack is an app pbpack') |
| 29 | + args = parser.parse_args() |
| 30 | + |
| 31 | + if os.path.exists(args.directory): |
| 32 | + resource_pack = ResourcePack(not args.app) |
| 33 | + |
| 34 | + for input_file in os.listdir(args.directory): |
| 35 | + if not os.path.isfile(os.path.join(args.directory, input_file)): |
| 36 | + continue |
| 37 | + with open(os.path.join(args.directory, input_file),'rb') as f: |
| 38 | + resource_pack.add_resource(f.read()) |
| 39 | + |
| 40 | + with open(args.output, 'wb') as f: |
| 41 | + resource_pack.serialize(f) |
| 42 | + |
| 43 | + |
| 44 | +if __name__ == '__main__': |
| 45 | + main() |
0 commit comments