def __init__(self, request): """Box""" resource_provider = ResourceProvider() resource = Resource(resource_provider) self.charts = [] self.chart_type = None self.layout = Layout(request) self.body = '' self.javascript = '' self.chart_name = request.matchdict['box_name'] chart_format = os.path.splitext(request.environ['PATH_INFO'])[1] # Go through the registry, and find the resource for this box # XXX This should be a dictionary for res in RESOURCES_REGISTRY: if res[0] == self.chart_name: self.resources = [res] if chart_format == '.html': self.render_html(request) elif chart_format == '.csv': self.body = resource.get(self.chart_name, CSV, request.matchdict) elif chart_format == '.json': self.body = resource.get(self.chart_name, JSON, request.matchdict) else: print "Format not supported %s" % chart_format raise AttributeError
def get_user_resource_tags(username, collectionid, resourceid): rsrc = Resource() rsrc.create() result = rsrc.get(username, collectionid, resourceid) if not result: return [{'No tags'}] else: return [{'TagText': result[0]['tags']}]
class ResourceTest(object): def __init__(self): self.photostore_resource = Resource(True) self.photostore_resource.create() def test_resource(self): curtime = str(time.time()) self.photostore_resource.put('gopa', 1, '[%s]: test put' % curtime, curtime) data = self.photostore_resource.get('gopa', 1, curtime) for d in data: print 'GET: data cltnid %s, uid %s, description %s\n' % \ (d['g_rsrc_collectionid'], d['g_uid'], \ d['description']) data = self.photostore_resource.get('gopa', 1, None) for d in data: print 'QUERY: data cltnid %s, uid %s, description %s\n' % \ (d['g_rsrc_collectionid'], d['g_uid'], d['description'])
def get_user_resource_details(username, collectionid, resourceid): rsrc = Resource() rsrc.create() result = rsrc.get(username, collectionid, resourceid) if not result: return {'Not found'} else: return { 'FileSource': result[0]['hires_url'], 'Description' : 'Powered by PhotoStore Technology', 'Location': 'Palo Alto' }
def get_resource(data): if not data: return {'NOTFOUND'} rsrc = Resource(True) if 'collectionid' in data: collectionid = data['collectionid'] else: collectionid = None if 'resourceid' in data: resourceid = data['resourceid'] else: resourceid = None return rsrc.get(data['user'], collectionid, resourceid)
class TestResource(object): def setup(self): self.resource = Resource('/tmp/a', dummy_compute_digest) def teardown(self): print ("Resource teardown") def test_get(self): self.resource.compute_digest() result = self.resource.get() assert result[1] == '/tmp/a' assert result[0] == 'digest' def test_to_string(self): self.resource.compute_digest() result = str(self.resource) assert result == '/tmp/a --> digest'
class Restyler(object): """Gets resources and renders them as charts""" def __init__(self, request, cells): resource_provider = ResourceProvider() self.resource = Resource(resource_provider) self.cells = cells self.resources = self.get_resources() self.charts = self.get_charts(request) self.packages = self.get_packages() self.javascript = render_javascript(self.charts, self.packages) def get_charts(self, request): """Return the charts needed for rendering""" url = get_absolute_url(request) charts = [] for chart in self.get_chart_infos(request): chart['chartoptions_rendered'] = "" # Render the chart to JSon if not JSON in chart or chart[JSON] is None: pass elif not 'charttype' in chart: pass else: chart['data'] = chart[JSON] chart['chartoptions']['is3D'] = False rendered = render_chartoptions(chart['chartoptions']) chart['chartoptions_rendered'] = rendered chart['csv_download_url'] = url + "%s.csv" % chart['id'] chart['html_download_url'] = url + "%s.html" % chart['id'] chart['module_id'] = self.get_module_id(chart) if self.cells.get_new_row_for_chart(chart['id']): chart['module_style'] = "clear: both;" else: chart['module_style'] = "" rendered = render_description(request, chart.get('description', ''), chart.get('description_type', '')) chart['description_rendered'] = rendered # Use an id with the postfox '_div' to make collisions unprobable chart['div_id'] = chart['id'] + '_div' charts.append(chart) return charts def get_module_id(self, chart): """Return the HTML id attribute value for the chart.""" return self.cells.get_column_for_chart(chart['id']) def get_packages(self): """Google Chart tools has a lot of packages covered in the corecharts already, and the only chart type that necessitates loading a package is the table. """ packages = set(['corechart']) for chart in self.charts: if chart.get('charttype', None) in ['Table', 'ImageSparkLine']: packages.add(chart['charttype'].lower()) return packages def get_resources(self): """Get a list of all resources""" resources = [] # And keep track of any that were not found unknown = set(self.cells.get_cells()) # Go through the registry, and take only the resources that are # referenced from the cells of the layout for resource in RESOURCES_REGISTRY: if resource[0] in self.cells.get_cells(): if resource[0] in unknown: # This is a known resource, so remove it from the unknown unknown.remove(resource[0]) # Avoid duplicates if not resource in resources: resources.append(resource[:]) if len(unknown) > 0: print "Unknown resources: %s" % unknown raise AttributeError return resources def get_chart_infos(self, request): """Get all augmented charts from the resources in the context.""" charts = [] for name, method, content_types in self.resources: # Fill an empty chart with the statistics resources based on the # wanted content types chart = BOXES[name].copy() if not 'id' in chart: # At least put in a default id chart['id'] = name success = True for ctype in content_types: result = self.resource.get(name, ctype, request.matchdict) if result is None: success = False else: chart[ctype] = result if success: # Call the method on the current context method(self, chart) charts.append(chart) return charts
def get_user_resources(username, collectionid, resourceid): rsrc = Resource() rsrc.create() return rsrc.get(username, collectionid, resourceid)
def get_user_resource_comments(username, collectionid, resourceid): rsrc = Resource() rsrc.create() result = rsrc.get(username, collectionid, resourceid) return [{'CommentText': 'Nice pic!!'}]
events.register(start_level) menu.append(playbutton) display.register(menu[2]) menu.append(Textbox((5, cell_size), text_color, big_font, "Start Level")) display.register(menu[3]) menu.append(Textbox((5, cell_size), text_color, big_font, "Level: " + str(level_number))) # display.register(menu[4]) # 5 ; Wave menu.append(Textbox((5, menu_item_height * 2 + menu_item_v_offset), text_color, font, "Wave: " + str(wave_number))) display.register(menu[5]) # 6 ; Hearts menu.append(Textbox((5, menu_item_height * 3 + menu_item_v_offset), text_color, font, "Hearts: " + str(heart_number) + "/" + str(heart_max))) display.register(menu[6]) # 7 ; Money menu.append(Textbox((5, menu_item_height * 4 + menu_item_v_offset), text_color, font, "Money: " + str(money.get()))) display.register(menu[7]) # 8 ; Kill Count menu.append(Textbox((5, menu_item_height * 5 + menu_item_v_offset), text_color, font, "Kills: " + str(kill_counter))) display.register(menu[8]) # 9 ; Towers ------------------------------------------------------------------------------------------- # ------------------------------------------------------------------------------------------------------ menu.append(Textbox((5, menu_item_height * 6 + menu_item_v_offset), dark(red), font, "Towers")) display.register(menu[9]) box = generic_renderables.Box((2, menu_item_height * 6 + menu_item_v_offset + 22), (menu_width - 4, screen_height - (menu_item_height * 6 + menu_item_v_offset + 24)), dark(red)) menu.append(box) display.register(menu[10]) # - 1 ; POISON ------------------------------------------------------------------------------------------- menu.append(Textbox((5, menu_tower_v_offset - 5), text_color, font, "Poison")) display.register(menu[11]) menu.append(Textbox((5, menu_tower_v_offset + cell_size / 2 - 5), text_color, font,