Merge lp:~milo/linaro-patchmetrics/bug1012037 into lp:linaro-patchmetrics

Proposed by Milo Casagrande
Status: Merged
Approved by: Milo Casagrande
Approved revision: 365
Merged at revision: 362
Proposed branch: lp:~milo/linaro-patchmetrics/bug1012037
Merge into: lp:linaro-patchmetrics
Diff against target: 131 lines (+31/-24)
1 file modified
apps/patchwork/utils.py (+31/-24)
To merge this branch: bzr merge lp:~milo/linaro-patchmetrics/bug1012037
Reviewer Review Type Date Requested Status
Deepti B. Kalakeri (community) Approve
Review via email: mp+111203@code.launchpad.net

Description of the change

This is a duplicate merge request: the previous one had to be removed since we couldn't push anything in Launchpad, and the code was in an external git repo. Now we have a Launchpad Bazaar branch here.

Pasting the old review comment:

With this merge the timeout errors should be resolved.

I re-arranged also the messages we have in case of error, in order to be a little bit more verbose so to have a better idea of where and what is happening.

I removed the file handle for stderr on the call to "git clone", since only in that case we are experiencing the timeouts. This will lead to output to be printed on the cmdline, because even redirecting it with "2>/dev/null" is not working (at least locally).

I also removed the reference to "HEAD" in git pull operations since it is only a reference, and if we have to switch branch for some reasons, this will not work.

To post a comment you must log in.
Revision history for this message
Deepti B. Kalakeri (deeptik) wrote :

This looks good. Just a small comment on the alignment, can we use a similar alignment this fits well within 80 columns and looks readable as well ?

=== modified file 'apps/patchwork/utils.py'
--- apps/patchwork/utils.py 2012-06-18 14:37:25 +0000
+++ apps/patchwork/utils.py 2012-06-20 13:23:12 +0000
@@ -186,13 +186,11 @@
     root = os.path.join(settings.PATCHWORK_GIT_REPOS_DIR, project.linkname)

     if os.path.exists(root):
- proc = subprocess.Popen(
- ['git', 'pull', 'origin'], cwd=root,
- stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ proc = subprocess.Popen(['git', 'pull', 'origin'], cwd=root,
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     else:
- proc = subprocess.Popen(
- ['git', 'clone', project.source_tree, root],
- stdout=subprocess.PIPE)
+ proc = subprocess.Popen(['git', 'clone', project.source_tree, root],
+ stdout=subprocess.PIPE)

Also, I ran pep8 on the file and there are couple of fixes which needs to be done, would you please incorporate them as well. Otherwise looks good.

review: Needs Fixing
365. By Milo Casagrande

Final PEP8 fixes and style.

Revision history for this message
Milo Casagrande (milo) wrote :

Hello Deepti,

as you suggested, I fixed the final bits about PEP8 and also the indentation style.
Thanks.

Revision history for this message
Deepti B. Kalakeri (deeptik) wrote :

+1. Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'apps/patchwork/utils.py'
2--- apps/patchwork/utils.py 2012-01-26 15:36:57 +0000
3+++ apps/patchwork/utils.py 2012-06-21 07:20:25 +0000
4@@ -31,10 +31,11 @@
5 from django.shortcuts import get_object_or_404
6
7
8-GIT_TIMEOUT = 45 * 60
9-
10-
11-def get_patch_ids(d, prefix = 'patch_id'):
12+# Timeout for git operations.
13+GIT_TIMEOUT = 55 * 60
14+
15+
16+def get_patch_ids(d, prefix='patch_id'):
17 ids = []
18
19 for (k, v) in d.items():
20@@ -49,6 +50,7 @@
21
22 return ids
23
24+
25 class Order(object):
26 order_map = {
27 'date': 'date',
28@@ -59,7 +61,7 @@
29 }
30 default_order = ('date', True)
31
32- def __init__(self, str = None, editable = False):
33+ def __init__(self, str=None, editable=False):
34 self.reversed = False
35 self.editable = editable
36 (self.order, self.reversed) = self.default_order
37@@ -102,7 +104,10 @@
38 q = '-' + q
39 return q
40
41+
42 bundle_actions = ['create', 'add', 'remove']
43+
44+
45 def set_bundle(user, project, action, data, patches, context):
46 # set up the bundle
47 bundle = None
48@@ -111,24 +116,21 @@
49 if not bundle_name:
50 return ['No bundle name was specified']
51
52- bundle = Bundle(owner = user, project = project,
53- name = bundle_name)
54+ bundle = Bundle(owner=user, project=project, name=bundle_name)
55 bundle.save()
56 context.add_message("Bundle %s created" % bundle.name)
57-
58- elif action =='add':
59- bundle = get_object_or_404(Bundle, id = data['bundle_id'])
60-
61- elif action =='remove':
62- bundle = get_object_or_404(Bundle, id = data['removed_bundle_id'])
63+ elif action == 'add':
64+ bundle = get_object_or_404(Bundle, id=data['bundle_id'])
65+ elif action == 'remove':
66+ bundle = get_object_or_404(Bundle, id=data['removed_bundle_id'])
67
68 if not bundle:
69 return ['no such bundle']
70
71 for patch in patches:
72 if action == 'create' or action == 'add':
73- bundlepatch_count = BundlePatch.objects.filter(bundle = bundle,
74- patch = patch).count()
75+ bundlepatch_count = BundlePatch.objects.filter(bundle=bundle,
76+ patch=patch).count()
77 if bundlepatch_count == 0:
78 bundle.append_patch(patch)
79 context.add_message("Patch '%s' added to bundle %s" % \
80@@ -139,7 +141,7 @@
81
82 elif action == 'remove':
83 try:
84- bp = BundlePatch.objects.get(bundle = bundle, patch = patch)
85+ bp = BundlePatch.objects.get(bundle=bundle, patch=patch)
86 bp.delete()
87 context.add_message("Patch '%s' removed from bundle %s\n" % \
88 (patch.name, bundle.name))
89@@ -184,16 +186,17 @@
90 # dependencies.
91 def ensure_source_checkout_for_project(project, timeout=GIT_TIMEOUT):
92 root = os.path.join(settings.PATCHWORK_GIT_REPOS_DIR, project.linkname)
93- if not os.path.exists(root):
94- proc = subprocess.Popen(
95- ['git', 'clone', project.source_tree, root],
96- stdout=subprocess.PIPE, stderr=subprocess.PIPE)
97+
98+ if os.path.exists(root):
99+ proc = subprocess.Popen(['git', 'pull', 'origin'], cwd=root,
100+ stdout=subprocess.PIPE, stderr=subprocess.PIPE)
101 else:
102- proc = subprocess.Popen(
103- ['git', 'pull', 'origin', 'HEAD'], cwd=root,
104- stdout=subprocess.PIPE, stderr=subprocess.PIPE)
105+ proc = subprocess.Popen(['git', 'clone', project.source_tree, root],
106+ stdout=subprocess.PIPE)
107+
108 wait = 0
109 wait_increment = 5
110+
111 while wait < timeout:
112 proc.poll()
113 if proc.returncode is not None:
114@@ -202,7 +205,10 @@
115 time.sleep(wait_increment)
116
117 if proc.returncode is None:
118- msg = "Timeout when fetching %s." % project.source_tree
119+ msg = "Timeout (%d/%d seconds) when fetching '%s' (%s).\n" % \
120+ (wait, timeout, project.name, project.linkname)
121+ msg += " Project path: %s\n Project tree:%s\n" % \
122+ (root, project.source_tree)
123
124 # Kill the subprocess we started and all its children. This is
125 # necessary because 'git pull' will actually run a shell script
126@@ -239,6 +245,7 @@
127 raise FailedToFetchGitRepo(
128 "Failed to fetch %s.\nstdout:%s\nstderr:%s" % (
129 project.source_tree, stdout, stderr))
130+
131 return root
132
133

Subscribers

People subscribed via source and target branches