This repository has been archived by the owner on May 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
push.py
71 lines (46 loc) · 1.66 KB
/
push.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os
import sys
import yaml
import re
from datetime import datetime
class Pusher(object):
def __init__(self):
with open('faya.yml', 'r') as yml:
self.__config = yaml.load(yml)
self.__old_ver = self.__config['ver']
self.__new_ver = ''
def push(self):
update_ver = input('update ver? enter y to continue: ')
if update_ver.lower() == 'y':
self.__new_ver = '.'.join(str(int(self.__old_ver.replace('.', '')) + 1))
self.update_md()
self.update_yml()
else:
self.__new_ver = self.__old_ver
print('ver remains %s' % self.__old_ver)
os.system('git add .')
info = input('commit: ')
os.system(f'git commit -m "{info}"')
yes = input('push? enter y to continue:')
if yes.lower() == 'y':
os.system('git push origin master')
else:
sys.exit()
update = datetime.now()
print('Success. ' + str(update))
print('faya ver: %s --> %s' % (self.__old_ver, self.__new_ver))
def update_yml(self):
self.__config['ver'] = self.__new_ver
with open('faya.yml', 'w') as yml:
yaml.dump(self.__config, yml, default_flow_style=False)
def update_md(self):
ver_reg = re.compile('当前版本:.+?♪')
with open('README.md', 'r') as md:
readme = md.read()
ver_info = '当前版本: ' + self.__new_ver + ' ♪'
new_readme = re.sub(ver_reg, ver_info, readme)
with open('README.md', 'w') as md:
md.write(new_readme)
if __name__ == '__main__':
pusher = Pusher()
pusher.push()