-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
23 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |