Merge lp:~joetalbott/utah/fetch_url into lp:utah

Proposed by Joe Talbott
Status: Merged
Merged at revision: 703
Proposed branch: lp:~joetalbott/utah/fetch_url
Merge into: lp:utah
Diff against target: 212 lines (+195/-0)
3 files modified
utah/client/common.py (+66/-0)
utah/client/tests/test_vcs_bzr.py (+53/-0)
utah/client/tests/test_vcs_git.py (+76/-0)
To merge this branch: bzr merge lp:~joetalbott/utah/fetch_url
Reviewer Review Type Date Requested Status
Javier Collado (community) Approve
Joe Talbott (community) Needs Resubmitting
Review via email: mp+128322@code.launchpad.net

Description of the change

This update added several VCS related classes to support bzr and git repositories.

To post a comment you must log in.
Revision history for this message
Javier Collado (javier.collado) wrote :

@Joe

I see the new VCSHandler classes, but I don't see where they are used. Is this supposed to be followed by more merge requests that replace fetch_cmd with fetch_url and fetch_type?

Aside from this, I think my only comment is that you can replace None checks like this one:
self.assertTrue(bzr is not None)

with something like:
self.assertIsNotNone(bzr)

review: Needs Information
lp:~joetalbott/utah/fetch_url updated
699. By Joe Talbott

vcs tests - Use assertIsNotNone() in place of assertTrie(... is not None)

Suggested-By: Javier Collado <email address hidden>

Revision history for this message
Joe Talbott (joetalbott) wrote :

@Javier

Yes this is just the foundation for the upcoming transition to 'fetch_method' and 'fetch_location'. I wanted to get it reviewed before proceeding.

I updated the the assertions. Thanks for the tip.

review: Needs Resubmitting
Revision history for this message
Javier Collado (javier.collado) wrote :

@Joe

Ok, I understand now. Looking forward to the next changes.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'utah/client/common.py'
2--- utah/client/common.py 2012-10-03 09:09:49 +0000
3+++ utah/client/common.py 2012-10-09 15:27:21 +0000
4@@ -355,3 +355,69 @@
5 match = pattern.match(host_info['media-info'])
6
7 return match.group(1) if match else '?'
8+
9+# VCS Support
10+# XXX: This maybe ought to be moved to another file
11+REPO_DEFAULT_DIR = "."
12+
13+class VCSHandler(object):
14+ """
15+ Base class for Version Ccontrol System support.
16+ """
17+ repo = ""
18+
19+ def get(self, directory=REPO_DEFAULT_DIR):
20+ """
21+ Method to retrieve a copy of the repository
22+ """
23+ run_cmd(self.get_command, cwd=directory)
24+
25+ def revision(self, directory=REPO_DEFAULT_DIR):
26+ """
27+ get the revision number
28+ """
29+ retval = None
30+ result = run_cmd(self.rev_command, cwd=directory)
31+
32+ if result['returncode'] == 0:
33+ retval = result['stdout'].strip()
34+ else:
35+ print(result)
36+
37+ return retval
38+
39+class BzrHandler(VCSHandler):
40+ """
41+ bazaar handler.
42+ """
43+
44+ def __init__(self, repo, options="", destination=""):
45+ self.repo = repo
46+ self.options = options
47+ self.destination = destination
48+
49+ self.get_command = "bzr branch {} {} {}".format(
50+ options,
51+ self.repo,
52+ destination,
53+ )
54+
55+ self.rev_command = "bzr revno"
56+
57+class GitHandler(VCSHandler):
58+ """
59+ git handler.
60+ """
61+
62+ def __init__(self, repo, options="", destination=""):
63+ self.repo = repo
64+ self.options = options
65+ self.destination = destination
66+
67+ self.get_command = "git clone {} {} {}".format(
68+ options,
69+ self.repo,
70+ destination,
71+ )
72+
73+ self.rev_command = "git rev-parse HEAD"
74
75=== added file 'utah/client/tests/test_vcs_bzr.py'
76--- utah/client/tests/test_vcs_bzr.py 1970-01-01 00:00:00 +0000
77+++ utah/client/tests/test_vcs_bzr.py 2012-10-09 15:27:21 +0000
78@@ -0,0 +1,53 @@
79+import os
80+import shutil
81+import unittest
82+
83+from utah.client.common import BzrHandler
84+
85+class TestBzrHandler(unittest.TestCase):
86+ """
87+ Test the bazaar VCS handler.
88+ """
89+
90+ def test_init(self):
91+ """
92+ Test the initial setup.
93+ """
94+
95+ repo = "https://code.launchpad.net/~utah/utah/dev/"
96+ bzr = BzrHandler(repo=repo)
97+
98+ self.assertIsNotNone(bzr)
99+ self.assertEqual(bzr.repo, repo)
100+ self.assertEqual(bzr.get_command, "bzr branch {} ".format(repo))
101+ self.assertEqual(bzr.rev_command, "bzr revno")
102+
103+ def test_bzr_get(self):
104+ repo = "https://code.launchpad.net/~utah/utah/dev/"
105+ dest = "utah-dev"
106+ bzr = BzrHandler(repo=repo, destination=dest)
107+ directory = "/tmp"
108+ path = os.path.join(directory, dest)
109+
110+ self.assertFalse(os.path.exists(path))
111+
112+ bzr.get(directory=directory)
113+
114+ self.assertTrue(os.path.exists(path))
115+ shutil.rmtree(path)
116+
117+ def test_bzr_revision(self):
118+ repo = "https://code.launchpad.net/~utah/utah/dev/"
119+ dest = "utah-dev"
120+ bzr = BzrHandler(repo=repo, destination=dest)
121+ directory = "/tmp"
122+ path = os.path.join(directory, dest)
123+
124+ self.assertFalse(os.path.exists(path))
125+ bzr.get(directory=directory)
126+ self.assertTrue(os.path.exists(path))
127+
128+ result = bzr.revision(directory=path)
129+
130+ shutil.rmtree(path)
131+ self.assertEqual(type(int(result)), int)
132
133=== added file 'utah/client/tests/test_vcs_git.py'
134--- utah/client/tests/test_vcs_git.py 1970-01-01 00:00:00 +0000
135+++ utah/client/tests/test_vcs_git.py 2012-10-09 15:27:21 +0000
136@@ -0,0 +1,76 @@
137+import os
138+import shutil
139+import unittest
140+
141+from utah.client.common import GitHandler, run_cmd
142+
143+GIT_TEST_REPO = "/tmp/utahgittest"
144+
145+def setUp():
146+ """
147+ Create a local git repository to test on.
148+ """
149+
150+ # should fail if the repo already exists.
151+ os.mkdir(GIT_TEST_REPO)
152+
153+ run_cmd("git init", cwd=GIT_TEST_REPO)
154+ run_cmd("touch test.py", cwd=GIT_TEST_REPO)
155+ run_cmd("git add test.py", cwd=GIT_TEST_REPO)
156+ run_cmd("git commit -m'Initial import' test.py", cwd=GIT_TEST_REPO)
157+
158+def tearDown():
159+ """
160+ Remove the test repo.
161+ """
162+
163+ # We should only ever get here if the repo was created in setUp().
164+ shutil.rmtree(GIT_TEST_REPO)
165+
166+class TestGitHandler(unittest.TestCase):
167+ """
168+ Test the bazaar VCS handler.
169+ """
170+
171+ def test_init(self):
172+ """
173+ Test the initial setup.
174+ """
175+
176+ repo = GIT_TEST_REPO
177+ git = GitHandler(repo=repo)
178+
179+ self.assertIsNotNone(git)
180+ self.assertEqual(git.repo, repo)
181+ self.assertEqual(git.get_command, "git clone {} ".format(repo))
182+ self.assertEqual(git.rev_command, "git rev-parse HEAD")
183+
184+ def test_git_get(self):
185+ repo = GIT_TEST_REPO
186+ dest = "utah-dev"
187+ git = GitHandler(repo=repo, destination=dest)
188+ directory = "/tmp"
189+ path = os.path.join(directory, dest)
190+
191+ self.assertFalse(os.path.exists(path))
192+
193+ git.get(directory=directory)
194+
195+ self.assertTrue(os.path.exists(path))
196+ shutil.rmtree(path)
197+
198+ def test_git_revision(self):
199+ repo = GIT_TEST_REPO
200+ dest = "utah-dev"
201+ git = GitHandler(repo=repo, destination=dest)
202+ directory = "/tmp"
203+ path = os.path.join(directory, dest)
204+
205+ self.assertFalse(os.path.exists(path))
206+ git.get(directory=directory)
207+ self.assertTrue(os.path.exists(path))
208+
209+ result = git.revision(directory=path)
210+
211+ shutil.rmtree(path)
212+ self.assertEqual(type(result), str)

Subscribers

People subscribed via source and target branches