def take_action(self, args): import os import requests import tempfile import fabulous.image result = api.search( args.package, rows_per_page=1, start_row=0, ) if not result['rows']: raise IndexError("No such package found.") package = result['rows'][0] tmpl = "https://apps.fedoraproject.org/packages/images/icons/%s.png" url = tmpl % package['icon'] response = requests.get(url) fd, filename = tempfile.mkstemp(suffix='.png') with open(filename, 'w') as f: if not response.raw.data: # Newer python-requests f.write(response.content) else: # Older python-requests f.write(response.raw.data) fab = fabulous.image.Image(filename) os.remove(filename) print(fab)
def take_action(self, args): import os import requests import tempfile import fabulous.image result = api.search(args.package, rows_per_page=1, start_row=0) if not result["rows"]: raise IndexError("No such package found.") package = result["rows"][0] tmpl = "https://apps.fedoraproject.org/packages/images/icons/%s.png" url = tmpl % package["icon"] response = requests.get(url) fd, filename = tempfile.mkstemp(suffix=".png") with open(filename, "w") as f: f.write(response.raw.data) fab = fabulous.image.Image(filename) os.remove(filename) print(fab)
def test_search(self): """ Test the search function of the API. """ guake_search = search(PKG) self.assertEqual(guake_search['rows'][0]['upstream_url'], 'http://www.guake.org/') self.assertEqual(guake_search['rows'][0]['devel_owner'], 'pingou') self.assertEqual(guake_search['rows'][0]['link'], PKG)
def take_action(self, args): columns = ['name', 'summary'] result = api.search( args.package, rows_per_page=args.rows_per_page, start_row=args.start_row, ) rows = result['rows'] return ( columns, [[row[col] for col in columns] for row in rows], )
def take_action(self, args): result = api.search(args.package, rows_per_page=1, start_row=0) if not result["rows"]: raise IndexError("No such package found.") package = result["rows"][0] package["link"] = "https://apps.fedoraproject.org/packages/%s" % package["link"] del package["sub_pkgs"] # TODO -- handle sub packages correctly. del package["icon"] # TODO -- use python-fabulous package["name"] = args.package return (package.keys(), package.values())
def take_action(self, args): columns = ['name', 'summary'] result = api.search( args.package, rows_per_page=args.rows_per_page, start_row=args.start_row, ) final_rows = [] for row in result['rows']: final_rows.append(row) for sub_package in row['sub_pkgs']: sub_package['name'] = " " + sub_package['name'] final_rows.append(sub_package) return ( columns, [[row[col] for col in columns] for row in final_rows], )
def take_action(self, args): result = api.search( args.package, rows_per_page=1, start_row=0, ) if not result['rows']: raise IndexError("No such package found.") package = result['rows'][0] package['link'] = "https://apps.fedoraproject.org/packages/%s" % \ package['link'] del package['sub_pkgs'] # TODO -- handle sub packages correctly. del package['icon'] # TODO -- use python-fabulous package['name'] = args.package return (package.keys(), package.values())
def take_action(self, args): result = api.search( args.package, rows_per_page=1, start_row=0, ) if not result['rows']: raise IndexError("No such package found.") package = result['rows'][0] match = False for pkg in result['rows']: if pkg['name'] == args.package: match = True for sub_pkg in pkg['sub_pkgs']: if sub_pkg['name'] == args.package: package['name'] = sub_pkg['name'] package['description'] = sub_pkg['description'] package['summary'] = sub_pkg['summary'] package['name'] = sub_pkg['name'] package['link'] = sub_pkg['link'] match = True break if match is False: raise IndexError("No such package found.") package['link'] = "https://apps.fedoraproject.org/packages/%s" % \ package['link'] del package['sub_pkgs'] # TODO -- handle sub packages correctly. del package['icon'] # TODO -- use python-fabulous package['name'] = args.package return (package.keys(), package.values())
def take_action(self, args): columns = ["name", "summary"] result = api.search(args.package, rows_per_page=args.rows_per_page, start_row=args.start_row) rows = result["rows"] return (columns, [[row[col] for col in columns] for row in rows])