forked from CodyKochmann/battle_tested
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commit-update.py
75 lines (62 loc) · 2.36 KB
/
commit-update.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
72
73
74
75
from os import popen, chdir
from datetime import datetime
chdir("/Users/cody/git/battle_tested/")
def bash(command, check=True):
if check:
raw_input('about to run: {} [enter to continue]'.format(command))
return popen(command).read()
def list_tags():
''' returns a list of the tags in the repo '''
return bash('git tag', False).strip().split('\n')
def next_tag():
''' returns the next tag that will be used '''
def latest_tag():
""" returns the latest tag used """
out = ''
for i in sorted(list_tags()):
out = i
return out
def create_next_tag():
""" creates a tag based on the date and previous tags """
date = datetime.utcnow()
date_tag = '{}.{}.{}'.format(date.year, date.month, date.day)
if date_tag in latest_tag(): # if there was an update already today
latest = latest_tag().split('.') # split by spaces
if len(latest) == 4: # if it is not the first revision of the day
latest[-1]= str(int(latest[-1])+1)
else: # if it is the first revision of the day
latest+=['1']
date_tag = '.'.join(latest)
return date_tag
def replace_all_in_file(file_path, old, new):
with open(file_path, 'r') as reader:
file_text = reader.read()
file_text = file_text.replace(old, new)
with open(file_path, 'w') as writer:
writer.write(file_text)
def update_setup():
args = 'setup.py', latest_tag(), create_next_tag()
raw_input("about to replace {1:} with {2:} in {0:}".format(*args))
replace_all_in_file(*args)
def sync_readmes():
""" just copies README.md into README for pypi documentation """
print("syncing README")
with open("README.md", 'r') as reader:
file_text = reader.read()
with open("README", 'w') as writer:
writer.write(file_text)
# make this part automated later, Im tired...
update_setup()
sync_readmes()
commit_message = raw_input('Enter your commit message: ')
bash("git status", False)
bash('git add .')
bash("git commit -m '{}'".format(commit_message))
bash("git push origin master")
bash("git tag {} -m '{}'".format(create_next_tag(), commit_message))
bash("git push --tags origin master")
bash("git status", False)
#bash("python setup.py register -r pypitest")
bash("python setup.py sdist upload -r pypitest")
#bash("python setup.py register -r pypi")
bash("python setup.py sdist upload -r pypi")