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
=== modified file 'utah/client/common.py'
--- utah/client/common.py 2012-10-03 09:09:49 +0000
+++ utah/client/common.py 2012-10-09 15:27:21 +0000
@@ -355,3 +355,69 @@
355 match = pattern.match(host_info['media-info'])355 match = pattern.match(host_info['media-info'])
356356
357 return match.group(1) if match else '?'357 return match.group(1) if match else '?'
358
359# VCS Support
360# XXX: This maybe ought to be moved to another file
361REPO_DEFAULT_DIR = "."
362
363class VCSHandler(object):
364 """
365 Base class for Version Ccontrol System support.
366 """
367 repo = ""
368
369 def get(self, directory=REPO_DEFAULT_DIR):
370 """
371 Method to retrieve a copy of the repository
372 """
373 run_cmd(self.get_command, cwd=directory)
374
375 def revision(self, directory=REPO_DEFAULT_DIR):
376 """
377 get the revision number
378 """
379 retval = None
380 result = run_cmd(self.rev_command, cwd=directory)
381
382 if result['returncode'] == 0:
383 retval = result['stdout'].strip()
384 else:
385 print(result)
386
387 return retval
388
389class BzrHandler(VCSHandler):
390 """
391 bazaar handler.
392 """
393
394 def __init__(self, repo, options="", destination=""):
395 self.repo = repo
396 self.options = options
397 self.destination = destination
398
399 self.get_command = "bzr branch {} {} {}".format(
400 options,
401 self.repo,
402 destination,
403 )
404
405 self.rev_command = "bzr revno"
406
407class GitHandler(VCSHandler):
408 """
409 git handler.
410 """
411
412 def __init__(self, repo, options="", destination=""):
413 self.repo = repo
414 self.options = options
415 self.destination = destination
416
417 self.get_command = "git clone {} {} {}".format(
418 options,
419 self.repo,
420 destination,
421 )
422
423 self.rev_command = "git rev-parse HEAD"
358424
=== added file 'utah/client/tests/test_vcs_bzr.py'
--- utah/client/tests/test_vcs_bzr.py 1970-01-01 00:00:00 +0000
+++ utah/client/tests/test_vcs_bzr.py 2012-10-09 15:27:21 +0000
@@ -0,0 +1,53 @@
1import os
2import shutil
3import unittest
4
5from utah.client.common import BzrHandler
6
7class TestBzrHandler(unittest.TestCase):
8 """
9 Test the bazaar VCS handler.
10 """
11
12 def test_init(self):
13 """
14 Test the initial setup.
15 """
16
17 repo = "https://code.launchpad.net/~utah/utah/dev/"
18 bzr = BzrHandler(repo=repo)
19
20 self.assertIsNotNone(bzr)
21 self.assertEqual(bzr.repo, repo)
22 self.assertEqual(bzr.get_command, "bzr branch {} ".format(repo))
23 self.assertEqual(bzr.rev_command, "bzr revno")
24
25 def test_bzr_get(self):
26 repo = "https://code.launchpad.net/~utah/utah/dev/"
27 dest = "utah-dev"
28 bzr = BzrHandler(repo=repo, destination=dest)
29 directory = "/tmp"
30 path = os.path.join(directory, dest)
31
32 self.assertFalse(os.path.exists(path))
33
34 bzr.get(directory=directory)
35
36 self.assertTrue(os.path.exists(path))
37 shutil.rmtree(path)
38
39 def test_bzr_revision(self):
40 repo = "https://code.launchpad.net/~utah/utah/dev/"
41 dest = "utah-dev"
42 bzr = BzrHandler(repo=repo, destination=dest)
43 directory = "/tmp"
44 path = os.path.join(directory, dest)
45
46 self.assertFalse(os.path.exists(path))
47 bzr.get(directory=directory)
48 self.assertTrue(os.path.exists(path))
49
50 result = bzr.revision(directory=path)
51
52 shutil.rmtree(path)
53 self.assertEqual(type(int(result)), int)
054
=== added file 'utah/client/tests/test_vcs_git.py'
--- utah/client/tests/test_vcs_git.py 1970-01-01 00:00:00 +0000
+++ utah/client/tests/test_vcs_git.py 2012-10-09 15:27:21 +0000
@@ -0,0 +1,76 @@
1import os
2import shutil
3import unittest
4
5from utah.client.common import GitHandler, run_cmd
6
7GIT_TEST_REPO = "/tmp/utahgittest"
8
9def setUp():
10 """
11 Create a local git repository to test on.
12 """
13
14 # should fail if the repo already exists.
15 os.mkdir(GIT_TEST_REPO)
16
17 run_cmd("git init", cwd=GIT_TEST_REPO)
18 run_cmd("touch test.py", cwd=GIT_TEST_REPO)
19 run_cmd("git add test.py", cwd=GIT_TEST_REPO)
20 run_cmd("git commit -m'Initial import' test.py", cwd=GIT_TEST_REPO)
21
22def tearDown():
23 """
24 Remove the test repo.
25 """
26
27 # We should only ever get here if the repo was created in setUp().
28 shutil.rmtree(GIT_TEST_REPO)
29
30class TestGitHandler(unittest.TestCase):
31 """
32 Test the bazaar VCS handler.
33 """
34
35 def test_init(self):
36 """
37 Test the initial setup.
38 """
39
40 repo = GIT_TEST_REPO
41 git = GitHandler(repo=repo)
42
43 self.assertIsNotNone(git)
44 self.assertEqual(git.repo, repo)
45 self.assertEqual(git.get_command, "git clone {} ".format(repo))
46 self.assertEqual(git.rev_command, "git rev-parse HEAD")
47
48 def test_git_get(self):
49 repo = GIT_TEST_REPO
50 dest = "utah-dev"
51 git = GitHandler(repo=repo, destination=dest)
52 directory = "/tmp"
53 path = os.path.join(directory, dest)
54
55 self.assertFalse(os.path.exists(path))
56
57 git.get(directory=directory)
58
59 self.assertTrue(os.path.exists(path))
60 shutil.rmtree(path)
61
62 def test_git_revision(self):
63 repo = GIT_TEST_REPO
64 dest = "utah-dev"
65 git = GitHandler(repo=repo, destination=dest)
66 directory = "/tmp"
67 path = os.path.join(directory, dest)
68
69 self.assertFalse(os.path.exists(path))
70 git.get(directory=directory)
71 self.assertTrue(os.path.exists(path))
72
73 result = git.revision(directory=path)
74
75 shutil.rmtree(path)
76 self.assertEqual(type(result), str)

Subscribers

People subscribed via source and target branches