def do_volume_create(self, args): '''Create volume.''' body = self.client.volume_create( size=args.size, image=args.image, desc=args.desc) utils.pretty(head='VOLUME|STATUS', body=body)
def do_image_create(self, args): '''Create image.''' body = self.client.image_create( url=args.url, platform=args.platform, shared=str(args.shared).lower(), desc=args.desc) utils.pretty(head='IMAGE|STATUS', body=body)
def do_image_show(self, args): '''Show image.''' body = self.client.image_show(image=args.image) body = dict(json.loads(body)) # TODO remove below workaround once image show is ready. head = '|'.join(body.keys()).upper() body = '|'.join([v.strip() for v in body.values()]).replace(',', '') body = '["%s"]' % body utils.pretty(head=head, body=body)
def init_devices(): servers = novac.servers.list(detailed=True) for srv in servers: image_id = srv.image['id'] if (str(glancec.images.get(image_id)['name']) == pod_images['vnf']['image_name']): profile = { 'name': srv.name, 'uuid': srv.id, 'interfaces': srv.addresses } utils.pretty(profile) update_network_device.add_device(profile) update_alarm.add_alarm(srv.name)
def display_summary_tax(summary_taxdata, CGTCalc, taxyear, report): """ taxdata contains a list of tuples ## Each tuplue (gbp_disposal_proceeds, gbp_allowable_costs, gbp_gains, gbp_losses, number_disposals, commissions, taxes, gbp_gross_profit, gbp_net_profit) """ ## Unpack tuple (gbp_disposal_proceeds, gbp_allowable_costs, gbp_gains, gbp_losses, number_disposals, gbp_commissions, gbp_taxes, gbp_gross_profit, abs_quantity, gbp_net_profit) = summary_taxdata report.write(star_line()) report.write("\n\n Summary for tax year ending 5th April %d \n" % taxyear) report.write("\n Figures in GBP\n\n") if CGTCalc: report.write("Disposal Proceeds = %s, Allowable Costs = %s, Disposals = %d \n Year Gains = %s Year Losses = %s PROFIT = %s\n" % \ (pretty(gbp_disposal_proceeds), pretty(gbp_allowable_costs), number_disposals, pretty(gbp_gains), pretty(gbp_losses), pretty(gbp_net_profit))) else: report.write("Gross trading profit %s, Commission paid %s, Taxes paid %s, Net profit %s\n" % \ (pretty(gbp_gross_profit), pretty(gbp_commissions), pretty(gbp_taxes), pretty(gbp_net_profit))) report.write("\nNot included: interest paid, interest received, data and other fees, internet connection,...\n hardware, software, books, subscriptions, office space, Dividend income (report seperately)\n\n") report.write("\n\n")
def do_vlan_create(self, args): '''Create VLAN.''' body = self.client.vlan_create( vlan=args.vlan, network=args.network, netmask=args.netmask, gateway=args.gateway, start_ip=args.begin, end_ip=args.end, shared=str(args.shared).lower(), use_dhcp=str(args.use_dhcp).lower() ) utils.pretty(head='VLAN|STATUS', body=body)
def do_vm_create(self, args): """Create virtual machine.""" metadata = {} if args.user_data: metadata["user_data"] = utils.read_file(args.user_data) body = self.client.vm_create( image=args.image, vlan=args.vlan, name=args.name, cpu=args.cpu, memory=args.memory, increase=args.increase, metadata=metadata) utils.pretty(head="VM|STATUS", body=body)
def handle_create(instance_id): print ">> Handling Instance_Create Message" #Wait for novac to update# time.sleep(3) servers = novac.servers.list(detailed=True) for srv in servers: if (instance_id == srv.id): image_id = srv.image['id'] if (glancec.images.get(image_id)['name'] == pod_images['vnf']['image_name']): print "\t > Detect vSRX creation. Adding Network Devie and Alarm to AppFormix..." profile = { 'name': srv.name, 'uuid': srv.id, 'interfaces': srv.addresses } utils.pretty(profile) update_network_device.add_device(profile) update_alarm.add_alarm(srv.name)
def test_pretty_list_of_lists(self): import utils AAstr = '''a,b,c d,e,f g,h,i''' AA = [['a', 'b', 'c'], ['d', 'e', 'f'], ['g','h', 'i']] self.assertEqual(AAstr, utils.pretty(AA))
def reader(port): while port.isOpen(): data = '' length = 0 data = port.read(1) #blocks here if not data: continue if data == '\x04': #event pkt data = data + port.read(1) #event opcode, un-needed length = port.read(1) #read byte length data = data + length #append it to stream length = ord(length) #get int for i in range(length): data = data + port.read(1) #the rest port.last_rx = data port.has_data.set() if port.socket: port.socket.sendall(data) if port.debug: print "Got: %s\n" % pretty(port.last_rx) else: pass #types 1,2,3 not applicable
def goal_function(self, **args): """ This is the function that the class exports, and that can be plugged into the generic SPSA minimizer. Mainly we launch the engine match, take the opposite of the score (because we want to *maximize* the score but SPSA is a minimizer). Note that we add a regulization term, which helps the convexity of the problem. """ # Create the parameter vector theta = {} for (name, value) in self.THETA_0.items(): v = args[name] theta[name] = v # Calculate the regularization term regularization = utils.regulizer(utils.difference(theta, self.THETA_0), 0.01, 0.5) # Calculate the score of the minimatch score = self.launch_engine(theta) result = -score + regularization print("**args = " + utils.pretty(args)) print("goal = " + str(-result)) return result
def set_parameters_from_string(self, s): """ This is the function to transform the list of parameters, given as a string, into a vector for internal usage by the class. Example: "QueenValue 10.0 RookValue 6.0 " would be transformed into the following python vector: {'QueenValue': 10.0, 'RookValue': 6.0} this vector will be used as the starting point for the optimizer """ # Parse the string s = ' '.join(s.split()) list = s.split(' ') n = len(list) # Create the initial vector, and store it in THETA_0 self.THETA_0 = {} for k in range(0 , n // 2): name = list[ 2*k ] value = float(list[ 2*k + 1]) self.THETA_0[name] = value # The function also prints and returns THETA_0 print("read_parameters : THETA_0 = " + utils.pretty(self.THETA_0)) return self.THETA_0
def test_pretty_dict(self): import utils Dstr = '''color: blue shape: square texture: groovy''' D = {'shape': 'square', 'texture': 'groovy', 'color': 'blue'} self.assertEqual(Dstr, utils.pretty(D))
def test_pretty_list(self): import utils Astr = '''ennie meanie mightie''' A = ['ennie', 'meanie', 'mightie'] self.assertEqual(Astr, utils.pretty(A))
def update(self, flow): url = "{0}/flow".format(self.host) _label = flow.get('label') if _label: for realflow in self: if realflow.get('label') == _label: _realid = realflow.get('id') # First delete response = requests.delete( url=url + "/{0}".format(_realid), headers={"content-type": "application/json"}) # Then add response = requests.post( url=url, json=naked(flow), headers={"content-type": "application/json"}) welldone = response.status_code == 200 return welldone else: exceptionmsg = "label not in {0}".format(pretty(flow)) raise KeyError(exceptionmsg)
def gen_depend_map(self, test_funcs, drop_env=None, start_node=None): dep_graph = {} if not start_node: start_node = Env() dep_graph.setdefault(start_node, {}) nodes = [start_node] widgets = ['Processed: ', Counter(), ' nodes (', Timer(), ')'] LOGGER.info("Start gen depend map...") pbar = ProgressBar(widgets=widgets, max_value=100000) pbar.start() while nodes: node = nodes.pop() for func in test_funcs: new_node = node.gen_transfer_env(func) if new_node is None: continue if drop_env and len(new_node) > drop_env: continue if new_node not in dep_graph.keys(): dep_graph.setdefault(new_node, {}) nodes.append(new_node) data = dep_graph[node] data.setdefault(new_node, set()) data[new_node].add(func) pbar.update(len(dep_graph)) LOGGER.debug(pretty(dep_graph)) LOGGER.info('Depend map is %d x %d size', len(dep_graph), len(dep_graph)) self.dep_graph = dep_graph if self._use_map: self.build_graph_map()
def update(self, flow): url = "{0}/flow".format(self.host) _label = flow.get('label') if _label: for realflow in self: if realflow.get('label') == _label: _realid = realflow.get('id') # First delete response = requests.delete( url=url+"/{0}".format(_realid), headers={"content-type": "application/json"}) # Then add response = requests.post( url=url, json=naked(flow), headers={"content-type": "application/json"}) welldone = response.status_code == 200 return welldone else: exceptionmsg = "label not in {0}".format(pretty(flow)) raise KeyError(exceptionmsg)
def __str__(self): response = "" for flow in self.flows: response += "\"{0}\" ({1}) -> {2}\n\n".\ format(blue(flow.get('label')),\ orange(flow.get('id')), pretty(flow.get('nodes')) ) return response
def run(program, gas): program.gas = gas iterations = 0 os.system("clear") while True: print("ITER %i\n" % iterations) iterations += 1 pretty(program) program = step(program) input() os.system("clear") if program["gas"] == 0: break pretty(program) print("Exiting main (OutOfGas).") return program
def run(self): ''' Return a point which is (hopefully) a minimizer of the goal function f, starting from point theta0 Returns: the point (as a dict) which is (hopefully) a minimize of 'f'. ''' k = 0 theta = self.theta0 while True: if self.constraints is not None: theta = self.constraints(theta) print("theta = " + utils.pretty(theta)) c_k = self.c / ((k + 1)**self.gamma) a_k = self.a / ((k + 1 + self.A)**self.alpha) gradient = self.approximate_gradient(theta, c_k) #For steepest descent we update via a constant small step in the gradient direction mu = -0.01 / max(1.0, utils.norm2(gradient)) theta = utils.linear_combinaison(1.0, theta, mu, gradient) ## For RPROP, we update with information about the sign of the gradients theta = utils.linear_combinaison(1.0, theta, -0.01, self.rprop(theta, gradient)) #We then move to the point which gives the best average of goal (avg_goal, avg_theta) = self.average_best_evals(30) theta = utils.linear_combinaison(0.8, theta, 0.2, avg_theta) k = k + 1 if k >= self.max_iter: break if (k % 100 == 0) or (k <= 1000): (avg_goal, avg_theta) = self.average_evaluations(30) print("iter = " + str(k)) print("mean goal (all) = " + str(avg_goal)) print("mean theta (all) = " + utils.pretty(avg_theta)) (avg_goal, avg_theta) = self.average_best_evals(30) print('mean goal (best) = ' + str(avg_goal)) print('mean theta (best) = ' + utils.pretty(avg_theta)) print( '-----------------------------------------------------------') return theta
def writer(port): while True: rx_data = port.socket.recv(1024) if not rx_data: break port.write(rx_data) port.last_tx = rx_data if port.debug: print "Sent: %s" % pretty(port.last_tx) port.socket.close()
def run(program, gas, mem=0): program.gas = gas program.mem = mem iterations = 0 os.system("clear") while True: print("ITER %i\n" % iterations) iterations += 1 pretty(program) program = step(program) #input() sleep(0.1) os.system("clear") if program["status"] > 0: #program["gas"] == 0 or break pretty(program) print("Exiting main (%s)." % STATUS[program.status]) return program
def rprop(self, theta, gradient): #get the previous g of the RPROP algorithm if self.rprop_previous_g != {}: previous_g = self.rprop_previous_g else: previous_g = gradient #get the previous delta of the RPROP algorithm if self.rprop_previous_delta != {}: delta = self.rprop_previous_delta else: delta = gradient delta = utils.copy_and_fill(delta, 0.5) p = utils.hadamard_product(previous_g, gradient) print('gradient = ' + utils.pretty(gradient)) print('old_g = ' + utils.pretty(previous_g)) print('p = ' + utils.pretty(p)) g = {} eta = {} for (name, value) in p.items(): if p[name] > 0: eta[name] = 1.1 #building speed if p[name] < 0: eta[name] = 0.5 #we have passed a local minima :slow down if p[name] == 0: eta[name] = 1.0 delta[name] = eta[name] * delta[name] delta[name] = min(50.0, delta[name]) g[name] = gradient[name] print('g = ' + utils.pretty(g)) print('eta =' + utils.pretty(eta)) print('delta = ' + utils.pretty(delta)) #store the current g and delta for the next call of the RPROP algorithm self.rprop_previous_g = g self.rprop_previous_delta = delta #calculate the update for the current RPROP s = utils.hadamard_product(delta, utils.sign(g)) print('sign(g) = ' + utils.pretty(utils.sign(g))) print(' s = ' + utils.pretty(s)) return s
def do_volume_detach(self, args): '''Detach volume.''' body = self.client.volume_detach(args.volume) utils.pretty(head='VM|VOLUME|STATUS', body=body)
def do_volume_delete(self, args): '''Delete volume.''' body = self.client.volume_delete(args.volume) utils.pretty(head='VOLUME|STATUS', body=body)
def _print_tax_details(self, report, reportinglevel, CGTCalc, net_profit, open_value, close_value, groupid, gbp_net_profit, open_comm, close_comm, open_tax, close_tax, allowable_costs, disposal_proceeds, commissions, taxes): code=self.closingtrade.Code currency=self.closingtrade.Currency assetclass=(getattr(self.closingtrade, "AssetClass","")) datelabel=self.closingtrade.Date.strftime('%d/%m/%Y') ## quantity will be negative for a closing sale / opening buy sign_quantity=self.closingtrade.SignQuantity abs_quantity=abs(sign_quantity) average_open_value= abs(open_value) / abs_quantity average_close_value= abs(close_value) / abs_quantity ## Labelling if sign_quantity<0: labels=("BUY", "SELL") signs=("-", "") else: labels=("OPEN SHORT", "CLOSE SHORT") signs=("+","-") if net_profit<0: pandl="LOSS" else: pandl="PROFIT" inreport=reporting_detail(reportinglevel) if inreport.extraline(): report.write(star_line()) report.write("\n") if CGTCalc: """ Example of CGT output 1. SELL: 40867 XYZ (Stock) on 17/12/2013 at EUR0.911 gives LOSS of XYZ 8,275.00 equals GBP 5,000 (or CLOSE SHORT: . Matches with OPEN SHORT: ) Matches with: BUY: SAME DAY TRADES. TRADES WITHIN 30 days SECTION 104 HOLDING. 40867 shares of XYZ bought at average price of EUR1.11333 """ if inreport.showbrieftrade(): report.write("%d: %s %d %s %s on %s at %s %s each gives %s of %s %s equals GBP %s\n" % \ (groupid, labels[1], int(abs_quantity), code, assetclass, datelabel, currency, pretty(average_close_value), pandl, currency, pretty(round(net_profit)), pretty(gbp_net_profit))) if inreport.showextra(): report.write(" Commission %s %s and taxes %s %s on %s\n"% (currency, pretty(close_comm), currency, pretty(close_tax),labels[1])) if inreport.listtrades(): report.write("Trade details:"+self.closingtrade.__repr__()+"\n") if inreport.showextra(): report.write("Total allowable cost %s %s Total disposal proceeds %s %s\n" % \ (currency, pretty(allowable_costs), currency, pretty(disposal_proceeds))) report.write("\nMatches with:\n") ## Calculation strings, build up to show how we calculated our profit or loss calc_string="%s(%d*%s) - %s - %s " % \ (signs[1], int(abs_quantity), pretty(average_close_value, commas=False), pretty(close_comm), pretty(close_tax)) if len(self.sameday)>0: sameday_quantity=int(round(abs(self.sameday.final_position()))) sameday_avg_value=self.sameday.average_value() sameday_tax=sum([trade.Tax for trade in self.sameday]) sameday_comm=sum([trade.Commission for trade in self.sameday]) sameday_calc_string="%s(%d*%s) - %s - %s " % \ (signs[0], sameday_quantity, pretty(sameday_avg_value, commas=False), pretty(sameday_comm), pretty(sameday_tax)) calc_string=calc_string+sameday_calc_string if inreport.showextra(): report.write("SAME DAY TRADE(S) Matches with %s of %d %s at average of %s %s each \n Commissions %s %s Taxes %s %s \n" % \ (labels[0], sameday_quantity, code, currency, pretty(sameday_avg_value), currency, pretty(sameday_comm), currency, pretty(sameday_tax))) if inreport.listtrades(): report.write("\nTrades:\n") self.sameday.print_trades_and_parents(report) if len(self.withinmonth)>0: withinmonth_quantity=int(abs(round((self.withinmonth.final_position())))) withinmonth_avg_value=self.withinmonth.average_value() withinmonth_tax=sum([trade.Tax for trade in self.withinmonth]) withinmonth_comm=sum([trade.Commission for trade in self.withinmonth]) tradecount=len(self.withinmonth) (startdate,enddate)=self.withinmonth.range_of_dates() withinmonth_calc_string="%s(%d*%s) - %s - %s " % \ (signs[0], withinmonth_quantity, pretty(withinmonth_avg_value, commas=False), pretty(withinmonth_comm), pretty(withinmonth_tax)) calc_string=calc_string+withinmonth_calc_string if inreport.showextra(): report.write("SUBSEQUENT %d TRADE(S) Within 30 days between %s and %s: Matches with %s of %d %s at of %s %s each \n Commissions %s %s Taxes %s %s \n" % \ (tradecount, str(startdate.date()), str(enddate.date()), labels[0], withinmonth_quantity, code, currency, pretty(withinmonth_avg_value), currency, pretty(withinmonth_comm), currency, pretty(withinmonth_tax))) if inreport.listtrades(): report.write("\nTrades:\n") self.withinmonth.print_trades_and_parents(report) if len(self.s104)>0: s104_quantity=int(round(abs(self.s104.final_position()))) s104_avg_value=self.s104.average_value() s104_tax=sum([trade.Tax for trade in self.s104]) s104_comm=sum([trade.Commission for trade in self.s104]) tradecount=len(self.s104) (startdate,enddate)=self.s104.range_of_dates() parent_quantity=self.s104.total_including_parents() s104_calc_string="%s(%d*%s) - %s - %s " % \ (signs[0], s104_quantity, pretty(s104_avg_value, commas=False), pretty(s104_comm), pretty(s104_tax)) calc_string=calc_string+s104_calc_string if inreport.showextra(): report.write("PRO-RATA SECTION 104: Quantity %f %s allocated from total holding of %s, made up of %d trades between %s and %s\n At average value of %s %s Commissions %s %s Taxes %s %s \n" % \ ( s104_quantity, code, pretty(parent_quantity), len(self.s104), str(startdate.date()), str(enddate.date()), currency, pretty(s104_avg_value), currency, pretty(s104_comm), currency, pretty(s104_tax))) if inreport.listtrades(): report.write("\nTrades:\n") self.s104.print_trades_and_parents(report) if inreport.showcalcs(): ## Show full calculations report.write("\nCALCULATION: "+calc_string+" = %s \n" % pretty(round(net_profit))) else: """ Example of non CGT output SELL 40867 RSA (Stock) on 17/12/2013 at EUR0.911 gives net LOSS of EUR 8,275 equals GBP5,000.0 AVERAGE price EUR . Total commission: EUR Total tax: EUR """ if inreport.showbrieftrade(): report.write("%d: %s of %d %s %s on %s at %s %s each Net %s of %s %s equals GBP %s\n" % \ (groupid, labels[1], int(abs_quantity), code, assetclass, datelabel, currency, pretty(average_close_value), pandl, currency, pretty(round(net_profit)), pretty(gbp_net_profit))) if inreport.listtrades(): report.write("Trade details:"+self.closingtrade.__repr__()+"\n") tradecount=len(self.s104) (startdate,enddate)=self.s104.range_of_dates() parent_quantity=self.s104.total_including_parents() ## Calculation strings, build up to show how we calculated our profit or loss calc_string="%s(%d*%s) - %s - %s " % \ (signs[1], int(abs_quantity), pretty(average_close_value, commas=False), pretty(close_comm), pretty(close_tax)) closing_calc_string="%s(%d*%s) - %s - %s " % \ (signs[0], int(abs_quantity), pretty(average_open_value, commas=False), pretty(open_comm), pretty(open_tax)) calc_string=calc_string+closing_calc_string if inreport.showextra(): report.write("\n%s at average value %s each between %s and %s. Total round-trip commission %s %s, and taxes %s %s" % \ (labels[0], pretty(average_open_value), str(startdate.date()), str(enddate.date()), currency, pretty(commissions), currency, pretty(taxes))) if inreport.listtrades(): ## Trade by trade breakdown report.write("\nTrades:\n") self.s104.print_trades_and_parents(report) if inreport.showcalcs(): ## calculations report.write("\nCALCULATION: "+calc_string+" = %s \n" % pretty(round(net_profit))) if inreport.extraline(): report.write("\n")
def __repr__(self): return str(utils.pretty(self))
def do_snapshot_create(self, args): '''Create a SNAPSHOT''' body = self.client.snapshot_create(vm=args.vm, desc=args.desc) utils.pretty(head='SNAPSHOT|STATUS', body=body)
def do_snapshot_list(self, args): '''List snapshots.''' body = self.client.snapshot_list() utils.pretty(head='SNAPSHOT|STATUS|DESC|OWNER', body=body)
def do_vlan_delete(self, args): '''Delete VLAN.''' body = self.client.vlan_delete(vlan=args.vlan) utils.pretty(head='VLAN|STATUS', body=body)
def do_image_delete(self, args): '''Delete image.''' body = self.client.image_delete(image=args.image) utils.pretty(head='IMAGE|STATUS', body=body)
def do_image_list(self, args): '''List images.''' body = self.client.image_list() utils.pretty(head='IMAGE|SIZE|OS|DESC|OWNER', body=body)
def do_vm_delete(self, args): '''Delete virtual machine.''' body = self.client.vm_delete(vm=args.vm) utils.pretty(head='VM|STATUS', body=body)
def do_vm_list(self, args): """List virtual machines.""" body = self.client.vm_list() head = 'VM|IMAGE|IP|NAME|VXLAN|STATUS|VNC' utils.pretty(head=head, body=body)
def brief(self): return "ID %s Quantity %s" % (getattr(self, "TradeID",""), pretty(self.SignQuantity))
def __str__(self): return pretty(self)
def do_volume_attach(self, args): '''Attach volume to VM.''' body = self.client.volume_attach( volume=args.volume, vm=args.vm) utils.pretty(head='VM|VOLUME|STATUS', body=body)
def __repr__(self): return "ID %s Code %s Date %s Quantity %s Price %s Value per block %s" % \ (getattr(self, "TradeID",""), self.Code, str(self.Date), pretty(self.SignQuantity), pretty(self.Price), pretty(abs(self.Value/self.SignQuantity)))
def do_vlan_attach(self, args): '''Attach VLAN to VM.''' body = self.client.vlan_attach( vlan=args.vlan, vm=args.vm) utils.pretty(head='VM|VLAN|STATUS', body=body)
def run(self): """ Return a point which is (hopefully) a minimizer of the goal function f, starting from point theta0. Returns: The point (as a dict) which is (hopefully) a minimizer of "f". """ k = 0 theta = self.theta0 while True: k = k + 1 self.iter = k if self.constraints is not None: theta = self.constraints(theta) #print("theta = " + utils.pretty(theta)) c_k = self.c / (k**self.gamma) a_k = self.a / ((k + self.A)**self.alpha) gradient = self.approximate_gradient(theta, c_k) #print(str(k) + " gradient = " + utils.pretty(gradient)) # if k % 1000 == 0: # print(k + utils.pretty(theta) + "norm2(g) = " + str(utils.norm2(gradient))) # print(k + " theta = " + utils.pretty(theta)) ## For SPSA we update with a small step (theta = theta - a_k * gradient) ## theta = utils.linear_combinaison(1.0, theta, -a_k, gradient) ## For steepest descent we update via a constant small step in the gradient direction mu = -0.01 / max(1.0, utils.norm2(gradient)) theta = utils.linear_combinaison(1.0, theta, mu, gradient) ## For RPROP, we update with information about the sign of the gradients theta = utils.linear_combinaison(1.0, theta, -0.01, self.rprop(theta, gradient)) ## We then move to the point which gives the best average of goal (avg_goal, avg_theta) = self.average_best_evals(30) theta = utils.linear_combinaison(0.98, theta, 0.02, avg_theta) if (k % 10 == 0): (avg_goal, avg_theta) = self.average_evaluations(30) print("iter = " + str(k)) print("mean goal (all) = " + str(avg_goal)) print("mean theta (all) = " + utils.pretty(avg_theta)) (avg_goal, avg_theta) = self.average_best_evals(30) print("mean goal (best) = " + str(avg_goal)) print("mean theta (best) = " + utils.pretty(avg_theta)) print( "-----------------------------------------------------------------" ) if k >= self.max_iter: break return theta
def do_snapshot_delete(self, args): '''Delete a SNAPSHOT''' body = self.client.snapshot_delete(snapshot=args.snapshot) utils.pretty(head='SNAPSHOT|STATUS', body=body)
def do_vlan_list(self, args): '''List vlan.''' body = self.client.vlan_list() # NETWORK|NETMASK|GATEWAY|START_IP|END_IP utils.pretty(head='VLAN|DESC|OWNER', body=body)
raise NotImplementedError("Not handled type: %r" % (ast,)) if __name__ == "__main__": p = argparse.ArgumentParser() p.add_argument("source") args = p.parse_args() with open(args.source) as f: source = f.read() ast = parsing.parse(source) lowerer = Lowerer() lowerer.add_code_block(lowerer.top_level.root_block, ast) print utils.pretty(lowerer.top_level) print "=" * 20, "Doing inference." # Define a global typing context with an entry for nil. import prelude root_gamma = prelude.make_gamma() # Do inference. inf = inference.Inference() inf.infer_code_block(root_gamma, lowerer.top_level.root_block) print "=" * 20, "Inference complete." print utils.pretty(lowerer.top_level)
def vector_to_file(vector, file_name, action): string = ','.join(pretty(_) for _ in vector) with open(file_name, action) as file: return file.write(string + '\n')
def do_volume_list(self, args): '''List volume.''' body = self.client.volume_list() utils.pretty( head='VOLUME|SIZE|DESC|VM|DEVICE|BOOTABLE|STATUS', body=body)
results = ga.get(dimensions, metrics, filters, start_date, end_date) return results def syntax(emsg=None): prog = os.path.basename(sys.argv[0]) ws = ' ' * len(prog) if emsg: print emsg print print ' %s <dimensions> <metrics> <filters> <start_date> <end_date>' \ % prog print print ' Eq.:' print print ' %s ga:date ga:visits,ga:bounces ga:channelGrouping==Direct 2daysAgo 1daysAgo' % prog print print " %s ga:date ga:transactions,ga:transactionRevenue '' 2016-11-01 2016-11-07" % prog print print " %s ga:country,ga:region,ga:city ga:transactions,ga:transactionRevenue 'ga:channelGrouping==Directga:channelGrouping==Paid Search,ga:channelGrouping==Organic Search' 2daysAgo 1daysAgo" % prog print sys.exit(1) if __name__ == '__main__': print pretty(GoogleAnalytics().process())
def test_pretty_str(self): import utils str = 'This is a string' self.assertEqual(str, utils.pretty(str))