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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| #!/usr/bin/env python # -*- coding: utf-8 -*- import subprocess import shlex import os import shutil import zipfile import sys def converter(filePath): if any([filePath.endswith(extension) for extension in '.php,.sql'.split(',')]): with open(filePath, "rb") as F: text = F.read().decode("utf-8").encode("cp1251") if filePath.endswith('.sql'): filePath += '.cp1251' with open(filePath, "wb") as f: f.write(text) f.close() F.close() def zipdir(path, zip, folder): rootlen = len(path)-len(folder) - 1 for root, dirs, files in os.walk(path): for file in files: fn = os.path.join(root, file) zip.write(fn,fn[rootlen:]) def mklastversion(last_version, curdir): if os.path.exists(last_version): shutil.rmtree(last_version) os.mkdir(last_version) for item in os.listdir(curdir): if item!='.git' and item!='.last_version' and item!="update" and item != scriptname and item != ".gitignore": path = curdir+"\"+item if os.path.isdir(path): shutil.copytree(path,last_version + "\"+item) elif os.path.isfile(path): shutil.copy(path,last_version + "\"+item) for item in os.walk(last_version): for f in item[2]: path = item[0]+"\"+f converter(path) zip = zipfile.ZipFile(curdir+"\\.last_version.zip", 'w') zipdir(curdir+"\\.last_version", zip,".last_version") zip.close() shutil.move(curdir+"\\.last_version.zip",curdir+"\\.last_version") curdir = os.path.abspath(os.curdir) last_version = curdir +"\\.last_version" scriptname = os.path.basename(__file__) mklastversion(last_version, curdir) git_tag = 'git tag' args = shlex.split(git_tag) p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) tags = p.communicate()[0].split("\n")[:-1] if len(tags)==1 or len(tags)==0: sys.exit(0) prev_version = tags[-2] cur_version = tags[-1] git_diff = 'git diff '+prev_version+' '+cur_version+ ' --name-only' args = shlex.split(git_diff) p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) update_list = p.communicate()[0].split("\n")[:-1] update_path = curdir+"\\update\"+cur_version if os.path.exists(update_path): shutil.rmtree(update_path) os.mkdir(update_path) for filename in update_list: dirname = "\".join((update_path+"\"+filename.replace('/',"\")).split("\")[:-1]) if not os.path.exists(dirname): os.makedirs(dirname) shutil.copyfile(last_version+"\"+filename,update_path+"\"+filename.replace('/',"\")) desc = raw_input("Description: ") f = open(curdir+"\\update\"+cur_version+"\\description.ru",'wb') f.write(desc.decode("cp866").encode("cp1251")) f.close() zip = zipfile.ZipFile(curdir+"\\update\"+cur_version+".zip", 'w') zipdir(update_path, zip,cur_version) zip.close() |