-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfinglonger.py
98 lines (76 loc) · 2.49 KB
/
finglonger.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
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/python
import argparse
import os
import sys
import subprocess
import tempfile
import yaml
def validate_config(config):
max_tasks = config.get('max_tasks')
if max_tasks is None:
config['max_tasks'] = 5
return config
def validate_environment(config):
if os.path.isfile("tasks.yaml"):
pass
else:
print "Tasks file not found, are you in the right directory?"
sys.exit(1)
def git_cmd(command):
p = subprocess.Popen(command.split(' '),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = p.communicate()
return out, err
def process_task(task):
print "Finglongering..."
print task['name']
temp, temp_name = tempfile.mkstemp()
print temp_name
f = os.fdopen(temp, 'w')
f.write(task['shell'])
f.close()
os.chmod(temp_name, 0755)
p = subprocess.Popen(["/bin/bash", temp_name],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = p.communicate()
print out
print err
if __name__ == "__main__":
default_config = os.path.expanduser("~/.config/finglonger/config.yaml")
parser = argparse.ArgumentParser()
parser.add_argument('--config', default=default_config)
args = parser.parse_args()
if os.path.isfile(args.config):
with open(args.config) as f:
config = yaml.load(f.read())
else:
print "Config file not found: {0}".format(args.config)
sys.exit(1)
config = validate_config(config)
validate_environment(config)
git_cmd('git checkout master')
with open("tasks.yaml") as f:
master_tasks = yaml.load(f.read())
git_cmd('git checkout done')
with open("tasks.yaml") as f:
done_tasks = yaml.load(f.read())
git_cmd('git checkout master')
print "Tasks on master", len(master_tasks)
print "Tasks on done", len(done_tasks)
num_tasks = len(master_tasks) - len(done_tasks)
print "Tasks to do", num_tasks
if num_tasks > config['max_tasks']:
print "Error, too many tasks found ", num_tasks
print "Cowardly refusing to do anything"
print "If this is really what you want, modify max_tasks in config"
sys.exit(1)
for i in done_tasks:
master_tasks.remove(i)
for task in master_tasks:
process_task(task['task'])
git_cmd('git checkout done')
git_cmd('git merge master')
git_cmd('git push origin done')
git_cmd('git checkout master')