Merge lp:~toelke+lp/doit/onlychanged-bug into lp:doit

Proposed by Philipp Tölke
Status: Merged
Merged at revision: not available
Proposed branch: lp:~toelke+lp/doit/onlychanged-bug
Merge into: lp:doit
Diff against target: 194 lines
4 files modified
lib/doit/dependency.py (+7/-5)
lib/doit/runner.py (+2/-2)
lib/doit/task.py (+14/-4)
tests/test_dependency.py (+11/-11)
To merge this branch: bzr merge lp:~toelke+lp/doit/onlychanged-bug
Reviewer Review Type Date Requested Status
schettino72 Approve
Review via email: mp+12434@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Philipp Tölke (toelke+lp) wrote :
Revision history for this message
schettino72 (schettino72) wrote :

merged. thanks a lot.
i've done a few changes. please review it.

ps. added your name on README file with a link to the launchpad page. if you want to change it let me know.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/doit/dependency.py'
2--- lib/doit/dependency.py 2009-08-22 12:40:22 +0000
3+++ lib/doit/dependency.py 2009-09-25 19:05:24 +0000
4@@ -119,23 +119,25 @@
5 by doit. they can only be cleared manualy.
6 @return: (bool) True if up to date, False needs to re-execute.
7 """
8+
9 # no dependencies means it is never up to date.
10 if (not dependencies) and (not runOnce):
11- return False
12+ return [], False
13
14 # user managed dependency always up-to-date if it exists
15 if runOnce:
16 if not self._get(taskId,''):
17- return False
18+ return [], False
19
20 # if target file is not there, task is not up to date
21 for targ in targets:
22 if not os.path.exists(targ):
23- return False
24+ return dependencies, False
25
26 # check for modified dependencies
27+ changed = []
28 for dep in tuple(dependencies):
29 if self.modified(taskId,dep):
30- return False
31+ changed.append(dep)
32
33- return True
34+ return changed, len(changed) == 0
35
36=== modified file 'lib/doit/runner.py'
37--- lib/doit/runner.py 2009-09-06 05:01:33 +0000
38+++ lib/doit/runner.py 2009-09-25 19:05:24 +0000
39@@ -42,7 +42,7 @@
40
41 # check if task is up-to-date
42 try:
43- task_uptodate = dependencyManager.up_to_date(task.name,
44+ task.dep_changed, task_uptodate = dependencyManager.up_to_date(task.name,
45 task.file_dep, task.targets, task.run_once)
46 # TODO: raise an exception here.
47 except:
48@@ -55,7 +55,7 @@
49 if not alwaysExecute and task_uptodate:
50 print "---", task.title()
51 else:
52- print task.title()
53+ print task.title() % {'targets' : " ".join(task.targets), 'changed': " ".join(task.dep_changed), 'dependencies': " ".join(["%s" % x for x in task.dependencies])}
54 # process folder dependency
55 for dep in task.folder_dep:
56 if not os.path.exists(dep):
57
58=== modified file 'lib/doit/task.py'
59--- lib/doit/task.py 2009-09-20 08:27:51 +0000
60+++ lib/doit/task.py 2009-09-25 19:05:24 +0000
61@@ -45,7 +45,7 @@
62 def __init__(self, action):
63 assert isinstance(action,str), "CmdAction must be a string."
64 self.action = action
65-
66+ self.task = None
67
68 def execute(self, capture_stdout=False, capture_stderr=False):
69 """
70@@ -68,8 +68,13 @@
71 else:
72 stderr = subprocess.PIPE
73
74+ if self.task:
75+ action = self.action % {'targets' : " ".join(self.task.targets), 'changed': " ".join(self.task.dep_changed), 'dependencies': " ".join(["%s" % x for x in self.task.dependencies])}
76+ else:
77+ action = self.action
78+
79 # spawn task process
80- process = subprocess.Popen(self.action,stdout=stdout,
81+ process = subprocess.Popen(action,stdout=stdout,
82 stderr=stderr, shell=True)
83
84 # log captured stream
85@@ -84,12 +89,12 @@
86 # it doesnt make so much difference to return as Error or Failed anyway
87 if process.returncode > 125:
88 raise TaskError("Command error: '%s' returned %s" %
89- (self.action,process.returncode))
90+ (action,process.returncode))
91
92 # task failure
93 if process.returncode != 0:
94 raise TaskFailed("Command failed: '%s' returned %s" %
95- (self.action,process.returncode))
96+ (action,process.returncode))
97
98 def __str__(self):
99 return "Cmd: %s" % self.action
100@@ -252,6 +257,7 @@
101 self.setup = setup
102 self.run_once = False
103 self.is_subtask = is_subtask
104+ self.dep_changed = []
105
106 if actions is None:
107 self.actions = []
108@@ -276,6 +282,10 @@
109 else:
110 self.doc = ''
111
112+ for action in self.actions:
113+ action.task = self
114+ open("log","a").write("%s -- %s\n" % (action.task, action))
115+
116 # there are 3 kinds of dependencies: file, task, and folder
117 self.folder_dep = []
118 self.task_dep = []
119
120=== modified file 'tests/test_dependency.py'
121--- tests/test_dependency.py 2009-08-19 14:01:23 +0000
122+++ tests/test_dependency.py 2009-09-25 19:05:24 +0000
123@@ -163,9 +163,9 @@
124 def test_upToDate_noDependency(self):
125 taskId = "task A"
126 # first time execute
127- assert not self.d.up_to_date(taskId,[],[],False)
128+ assert self.d.up_to_date(taskId,[],[],False) == ([], False)
129 # second too
130- assert not self.d.up_to_date(taskId,[],[],False)
131+ assert self.d.up_to_date(taskId,[],[],False) == ([], False)
132
133
134 # if there is a dependency the task is executed only if one of
135@@ -179,10 +179,10 @@
136 taskId = "task X";
137 dependencies = [filePath]
138 # first time execute
139- assert not self.d.up_to_date(taskId,dependencies,[],False)
140+ assert self.d.up_to_date(taskId,dependencies,[],False) == (dependencies, False)
141 self.d.save_dependencies(taskId,dependencies)
142 # second time no
143- assert self.d.up_to_date(taskId,dependencies,[],False)
144+ assert self.d.up_to_date(taskId,dependencies,[],False) == ([], True)
145
146 # a small change on the file
147 ff = open(filePath,"a")
148@@ -190,7 +190,7 @@
149 ff.close()
150
151 # execute again
152- assert not self.d.up_to_date(taskId,dependencies,[],False)
153+ assert self.d.up_to_date(taskId,dependencies,[],False) == (dependencies, False)
154
155
156 # if target file does not exist, task is outdated.
157@@ -203,7 +203,7 @@
158 if os.path.exists(filePath):
159 os.remove(filePath)
160
161- assert not self.d.up_to_date(taskId,dependencies,[filePath],False)
162+ assert self.d.up_to_date(taskId,dependencies,[filePath],False) == (dependencies, False)
163
164 def test_upToDate_targets(self):
165 filePath = get_abspath("data/target")
166@@ -216,7 +216,7 @@
167 targets = [filePath]
168 self.d.save_dependencies(taskId,dependencies)
169 # up-to-date because target exist
170- assert self.d.up_to_date(taskId,dependencies,targets,False)
171+ assert self.d.up_to_date(taskId,dependencies,targets,False) == ([], True)
172
173 def test_upToDate_targetFolder(self):
174 # folder not there. task is not up-to-date
175@@ -226,16 +226,16 @@
176 folderPath = get_abspath("data/target-folder")
177 if os.path.exists(folderPath):
178 os.rmdir(folderPath)
179- assert not self.d.up_to_date(taskId,dependencies,[folderPath],False)
180+ assert self.d.up_to_date(taskId,dependencies,[folderPath],False) == (dependencies, False)
181 # create folder. task is up-to-date
182 os.mkdir(folderPath)
183- assert self.d.up_to_date(taskId,dependencies,[folderPath],False)
184+ assert self.d.up_to_date(taskId,dependencies,[folderPath],False) == ([], True)
185
186 class TestRunOnceDependency(DependencyTestBase):
187
188 def test_upToDate_BoolDependency(self):
189 taskId = "task X"
190- assert not self.d.up_to_date(taskId,[],[],True)
191+ assert self.d.up_to_date(taskId,[],[],True) == ([], False)
192 self.d.save_run_once(taskId)
193- assert self.d.up_to_date(taskId,[],[],True)
194+ assert self.d.up_to_date(taskId,[],[],True) == ([], True)
195

Subscribers

People subscribed via source and target branches

to all changes: