-
Notifications
You must be signed in to change notification settings - Fork 0
/
pack.py
47 lines (37 loc) · 1.23 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
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: GPL-2.0
"""
Package tool
~~~~~~~~~~~~
Package tool
File: pack.py
Desc: 打包文件
Date: 2023-06-18
Auth: XiangYang<[email protected]>
"""
import os
from action import IAction
from zipfile import ZipFile, ZIP_DEFLATED
from project import Project, PackFileInfo, PackageFileInfo
class PackAction(IAction):
"""
打包zip的action
"""
def __init__(self, prj: Project, cfg: PackFileInfo):
self.project = prj
self.configure = cfg
def run(self):
output_file = self.project.get_output_fullpath(self.configure.target)
with ZipFile(output_file, 'w') as zip:
categories = self.configure.categories
# 写入源文件, 头文件等等的东东
for file in self.project.package.package_files:
if file.category in categories:
self._run_helper(zip, file)
def _run_helper(self, fs, file_info: PackageFileInfo):
sep = os.path.sep
base_dir = file_info.pack_dir
for file in file_info.files:
file_name = os.path.basename(file)
file_arhv = f'{base_dir}{sep}{file_name}'
fs.write(file, file_arhv, ZIP_DEFLATED, 9)