Merge lp:~marcoceppi/charm-tools/better-getall into lp:charm-tools/1.6

Proposed by Marco Ceppi
Status: Needs review
Proposed branch: lp:~marcoceppi/charm-tools/better-getall
Merge into: lp:charm-tools/1.6
Diff against target: 94 lines (+18/-6)
4 files modified
charmtools/get.py (+2/-2)
charmtools/getall.py (+2/-0)
charmtools/search.py (+11/-1)
tests/test_charm_get.py (+3/-3)
To merge this branch: bzr merge lp:~marcoceppi/charm-tools/better-getall
Reviewer Review Type Date Requested Status
Charm Toolers Pending
Review via email: mp+253765@code.launchpad.net

Description of the change

Have search use the API

To post a comment you must log in.
Revision history for this message
Adam Israel (aisrael) wrote :

Hey Marco,

Some brief comments on this merge. I did a quick run through, testing getall. It look like it's working fine here. I particularly like the flag to fetch by series.

I have run into an intermittent "Connection Timeout: disconnecting client after 300.0 seconds" with the previous revision and this one, and I wonder if that could also be fixed here. It's confusing when that warning pops up. I don't know if it's skipped a charm due to timeout, or if it retried. I've also had it happen at the end of a getall, which at first left me thinking that the timeout aborted the fetch (which is not the case, afaict).

Unmerged revisions

354. By Marco Ceppi

Search against the API

353. By Marco Ceppi

Make Charm imports simpler

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmtools/get.py'
2--- charmtools/get.py 2014-01-12 18:38:35 +0000
3+++ charmtools/get.py 2015-03-21 21:21:48 +0000
4@@ -19,7 +19,7 @@
5 import argparse
6
7 from mr import Mr
8-from charmworldlib import charm as cwc
9+from charmworldlib.charm import Charm
10
11
12 def setup_parser():
13@@ -39,7 +39,7 @@
14 charm_id = charm_id.replace('cs:', '')
15
16 try:
17- charm = cwc.Charm(charm_id)
18+ charm = Charm(charm_id)
19 except:
20 return None
21
22
23=== modified file 'charmtools/getall.py'
24--- charmtools/getall.py 2014-02-18 15:39:48 +0000
25+++ charmtools/getall.py 2015-03-21 21:21:48 +0000
26@@ -29,6 +29,8 @@
27 'Launchpad')
28 parser.add_argument('charms_directory', nargs='?',
29 help='Path to where all charms should be downloaded')
30+ parser.add_argument('--series', '-s', action='append',
31+ help='Series of the charms to be downloaded')
32
33 return parser
34
35
36=== modified file 'charmtools/search.py'
37--- charmtools/search.py 2013-12-02 20:25:28 +0000
38+++ charmtools/search.py 2015-03-21 21:21:48 +0000
39@@ -17,6 +17,7 @@
40 import argparse
41
42 from . import charms
43+from charmworldlib.charm import Charms
44
45
46 def setup_parser():
47@@ -24,12 +25,21 @@
48 description='Match name against all '
49 'charms (official and personal) in store')
50 parser.add_argument('name', nargs=1, help='Name which to search by')
51+ parser.add_argument('--recommended', '-r', action='store_true',
52+ help='Only show recommended charms')
53
54 return parser
55
56
57+def search(query=None, recommended=False):
58+ criteria = {'text': query}
59+ if recommended:
60+ criteria['type'] = 'approved'
61+ return Charms().search(criteria)
62+
63+
64 def main():
65 parser = setup_parser()
66 args = parser.parse_args()
67- matches = [c for c in charms.remote() if args.name[0] in c]
68+ matches = ["cs:%s" % c.id for c in search(args.name[0], args.recommended)]
69 print '\n'.join(matches)
70
71=== modified file 'tests/test_charm_get.py'
72--- tests/test_charm_get.py 2014-01-10 16:20:16 +0000
73+++ tests/test_charm_get.py 2015-03-21 21:21:48 +0000
74@@ -17,17 +17,17 @@
75
76
77 class JujuCharmGetTest(unittest.TestCase):
78- @patch('charmworldlib.charm.Charm')
79+ @patch('charmtools.get.Charm')
80 def test_parse_charm_id(self, mCharm):
81 self.assertEqual(mCharm(), parse_charm_id('precise/dummy-0'))
82 mCharm.assert_called_with('precise/dummy-0')
83
84- @patch('charmworldlib.charm.Charm')
85+ @patch('charmtools.get.Charm')
86 def test_parse_charm_id_cs(self, mCharm):
87 self.assertEqual(mCharm(), parse_charm_id('cs:precise/dummy-0'))
88 mCharm.assert_called_with('precise/dummy-0')
89
90- @patch('charmworldlib.charm.Charm')
91+ @patch('charmtools.get.Charm')
92 def test_parse_charm_id_notfound(self, mCharm):
93 mCharm.side_effect = Exception('Charm not found')
94 self.assertEqual(None, parse_charm_id('precise/dummy-0'))

Subscribers

People subscribed via source and target branches