Skip to content

Commit

Permalink
使用git管理整合包
Browse files Browse the repository at this point in the history
  • Loading branch information
kressety committed Nov 4, 2023
1 parent 2c4b71e commit fdfadb5
Showing 1 changed file with 23 additions and 25 deletions.
48 changes: 23 additions & 25 deletions packing.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
from configparser import ConfigParser
from json import load
from os import walk
from os.path import join, relpath, dirname, basename
from zipfile import ZipFile, ZIP_DEFLATED


def zipdir(directory_to_zip, zip_filename):
with ZipFile(zip_filename, 'w', ZIP_DEFLATED) as zipf:
for root, _, files in walk(directory_to_zip):
for file in files:
full_path = join(root, file)
# 使用ZIP文件的名称(不带后缀)作为前缀创建存储路径
archive_path = join(basename(zip_filename).rsplit('.', 1)[0], relpath(full_path, directory_to_zip))
zipf.write(full_path, archive_path)
from os import system, chdir
from os.path import join
from shutil import copytree

GIT_ROOT = r'E:\mealuet-serverpacks'

config = ConfigParser()
config.read('config.ini', encoding='UTF-8')
packing_path = config['server']['server_path']
with open(join(packing_path, 'server_meta.json'), 'r', encoding='UTF-8') as server_meta_file:
server_meta = load(server_meta_file)
packing_name = (server_meta['name']
.replace(' ', '_')
.replace('/', '_')
.replace('\\', '_')
.replace(':', '_')
.replace('*', '_')
.replace('?', '_')
.replace('"', '_')
.replace('<', '_')
.replace('>', '_')
.replace('|', '_') + '.zip')
zipdir(packing_path, join(dirname(packing_path), packing_name))
dst_name = (server_meta['name']
.replace(' ', '_')
.replace('/', '_')
.replace('\\', '_')
.replace(':', '_')
.replace('*', '_')
.replace('?', '_')
.replace('"', '_')
.replace('<', '_')
.replace('>', '_')
.replace('|', '_'))
dist_path = join(GIT_ROOT, dst_name)

copytree(packing_path, dist_path)
chdir(GIT_ROOT)
system('git pull')
system('git add .')
system(f'git commit -m "Update {server_meta['name']} serverpack. "')
system('git push origin main')

0 comments on commit fdfadb5

Please sign in to comment.