forked from Phlip/Morelia
-
Notifications
You must be signed in to change notification settings - Fork 1
/
fabfile.py
87 lines (60 loc) · 2 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
84
85
86
87
import sys, os
from fabric.api import *
import time
import os
import fabfile
def _sh(cmd):
local(cmd, capture=False)
def clean_pyc_files():
'erase them all, because they bug us'
_sh('find . -name \*.pyc -exec rm {} \;')
def autotest(cmd='fab test', sleep=1):
"""
spin until you change a file, then run the tests
It considers the fabfile.py directory as the project root directory, then
monitors changes in any inner python files.
Usage:
fab autotest
This is based on Jeff Winkler's nosy script.
"""
def we_like(f):
return f.endswith('.py') # or f.endswith('.html') or f.endswith('.json')
def checkSum():
'''
Return a long which can be used to know if any .py files have changed.
Looks in all project's subdirectory.
'''
def hash_stat(file):
from stat import ST_SIZE, ST_MTIME
stats = os.stat(file)
return stats[ST_SIZE] + stats[ST_MTIME]
hash_ = 0
base = os.path.dirname(fabfile.__file__)
for zone in (base, base + '/webcube/', base + '/simplecart/'):
for root, dirs, files in os.walk(zone):
# only python, json, & html files interest us
files = [os.path.join(root, f) for f in files if we_like(f)]
hash_ += sum(map(hash_stat, files))
return hash_
val = 0
while(True):
actual_val = checkSum()
if val != actual_val:
val = actual_val
os.system(cmd)
time.sleep(sleep)
def test(extra=''):
'run the short test batch for this project'
_sh('python tests/bdd4django_suite.py')
_sh('git commit -am developing')
def ci():
'stick it in GitHub'
test()
_sh('git push origin master')
def up():
'stick it in Pypi'
ci()
with cd('bdd4django'): _sh('python setup.py sdist upload')
def todo():
'nag messages from u to u'
_sh('git grep TO'+'DO `find . -name *.py` `find . -name *.feature` ')