connected_group.add_argument( "--show-active", help="Flag to show only the active stations (default)", dest="active", action="store_true" ) connected_group.add_argument("--show-all", help="Flag to show all stations", dest="active", action="store_false") label_group = parser.add_mutually_exclusive_group() label_group.add_argument( "--label", help="Flag to label stations in graph (default).", dest="label", action="store_true" ) label_group.add_argument( "--no-label", help="Flag to not label stations in graph.", dest="label", action="store_false" ) parser.add_argument( "--label_type", help="Use 'station_name' or 'station_number' [station_number]", default="station_number" ) parser.set_defaults(label=True, active=True) args = parser.parse_args() args.xgraph = args.xgraph.upper() args.ygraph = args.ygraph.upper() args.verbosity = args.verbosity.lower() located = None if args.update: data = geo_location.parse_update_request(args.update) geo_location.update(args, data) if args.show: args.locate = args.show args.graph = True if args.locate: located = geo_location.locate_station(args, show_geo=True) if args.graph: geo_location.plot_arrays(args, located, label_station=args.label)
def get_part(self, args, hpn_query=None, rev_query=None, exact_match=False, return_dictionary=True, show_part=False): """ Return information on a part. It will return all matching first characters unless exact_match==True. Returns part_dict, a dictionary keyed on hera part number with part data as found in hera_mc tables Parameters ----------- args: arguments as per mc and parts argument parser hpn_query: the input hera part number (whole or first part thereof) exact_match: boolean to enforce full part number match show_part: boolean to call show_part or not """ if hpn_query is None: hpn_query = args.hpn exact_match = args.exact_match if rev_query is None: rev_query = args.revision_number if not exact_match and hpn_query[-1]!='%': hpn_query = hpn_query+'%' local_parts_keys = [] part_dict = {} db = mc.connect_to_mc_db(args) with db.sessionmaker() as session: ### Get parts to check and fill in last_revisions and connections_dictionary as able for match_part in session.query(part_connect.Parts).filter(part_connect.Parts.hpn.like(hpn_query)): if match_part.hpn not in local_parts_keys: local_parts_keys.append(match_part.hpn) if match_part.hpn not in self.last_revisions.keys(): self.last_revisions[match_part.hpn] = part_connect.get_last_revision_number(args,match_part.hpn,False) if match_part.hpn not in self.connections_dictionary.keys(): self.get_connection(args, hpn_query=match_part.hpn, rev_query = rev_query, port_query='all', exact_match=True, return_dictionary=False, show_connection=False) ### Now get unique part/rev and put into dictionary for match_key in local_parts_keys: revq = rev_query.upper() if revq == 'LAST': revq = self.last_revisions[match_key] part_query = session.query(part_connect.Parts).filter( (part_connect.Parts.hpn==match_key) & (part_connect.Parts.hpn_rev==revq) ) part_and_rev = part_query.all() part_cnt = part_query.count() if not part_cnt: ### None found. continue elif part_cnt == 1: part = part_and_rev[0] ### Found only one. is_connected = self.is_in_connections_db(args,part.hpn,part.hpn_rev) psd_for_dict = part.stop_date if not part.stop_date: psd_for_dict = 'N/A' part_dict[part.hpn] = {'rev':part.hpn_rev, 'is_connected':is_connected, 'hptype': part.hptype, 'manufacturer_number': part.manufacturer_number, 'start_date': part.start_date, 'stop_date': psd_for_dict, 'a_ports': [], 'b_ports': [], 'short_description':'', 'geo':None} part_dict[part.hpn]['repr'] = part.__repr__() # Keep for now for part_info in session.query(part_connect.PartInfo).filter( (part_connect.PartInfo.hpn == part.hpn) & (part_connect.PartInfo.hpn_rev == part.hpn_rev) ): part_dict[part.hpn]['short_description'] = part_info.short_description part_dict[part.hpn]['a_ports'] = self.connections_dictionary[part.hpn]['a_ports'] part_dict[part.hpn]['b_ports'] = self.connections_dictionary[part.hpn]['b_ports'] if part.hptype == 'station': args.locate = part.hpn part_dict[part.hpn]['geo'] = geo_location.locate_station(args, show_geo=False) if part.hpn not in self.parts_dictionary.keys(): self.parts_dictionary[part.hpn] = part_dict[part.hpn] ### This only handles the most recent revs. else: ### Found more than one, which shouldn't happen. print("Warning part_handling:175: Well, being here is a surprise -- should only be one part.", part.hpn) if show_part: if len(part_dict.keys()) == 0: print(hpn_query,' not found.') else: self.show_part(args, part_dict) if return_dictionary: return part_dict