This repository has been archived by the owner on Jun 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
fabfile.py
executable file
·83 lines (76 loc) · 2.99 KB
/
fabfile.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
76
77
78
79
80
81
82
83
#!/usr/bin/env python
#
# fabfile for smashlib
#
# this file is a self-hosting fabfile, meaning it
# supports direct invocation with standard option
# parsing, including --help and -l (for listing commands).
#
# summary of commands/arguments:
#
# * fab pypi_repackage: update this package on pypi
#
import os, re, sys
from fabric.api import env, run
from fabric.colors import red
from fabric.api import lcd, local, quiet, settings
from fabric.contrib.console import confirm
from fabric.colors import red
_ope = os.path.exists
_mkdir = os.mkdir
_expanduser = os.path.expanduser
_dirname = os.path.dirname
ldir = _dirname(__file__)
VERSION_DELTA = .01
def pypi_repackage():
ldir = _dirname(__file__)
print red("warning:") + (" by now you should have commited local"
" master and bumped version string")
ans = confirm('proceed with pypi update in "{0}"?'.format(ldir))
if not ans: return
with lcd(ldir):
with settings(warn_only=True):
local("git checkout -b pypi") # in case this has never been done before
local("git reset --hard master")
local("python setup.py register -r pypi")
local("python setup.py sdist upload -r pypi")
def version_bump():
""" bump the version number """
sandbox = {}
version_file = os.path.join('smashlib', 'version.py')
err = 'version file not found in expected location: ' + version_file
assert os.path.exists(version_file), err
execfile(version_file, sandbox)
current_version = sandbox['__version__']
new_version = current_version + VERSION_DELTA
with open(version_file, 'r') as fhandle:
version_file_contents = [x for x in fhandle.readlines() if x.strip()]
new_file = version_file_contents[:-1]+["__version__={0}".format(new_version)]
new_file = '\n'.join(new_file)
print red("warning:") + " version will be changed to {0}".format(new_version)
print
print red("new version file will look like this:\n")
print new_file
ans = confirm('proceed with version change?'.format(ldir))
if not ans:
print 'aborting.'
return
with open(version_file,'w') as fhandle:
fhandle.write(new_file)
print 'version has been rewritten.'
if __name__ == '__main__':
# a neat hack that makes this file a "self-hosting" fabfile,
# ie it is invoked directly but still gets all the fabric niceties
# like real option parsing, including --help and -l (for listing
# commands). note that as of fabric 1.10, the file for some reason
# needs to end in .py, despite what the documentation says. see:
# http://docs.fabfile.org/en/1.4.2/usage/fabfiles.html#fabfile-discovery
#
# the .index() manipulation below should make this work regardless of
# whether this is invoked from shell as "./foo.py" or "python foo.py"
import sys
from fabric.main import main as fmain
patched_argv = ['fab', '-f', __file__,] + \
sys.argv[sys.argv.index(__file__)+1:]
sys.argv = patched_argv
fmain()