def do_list(self, args): try: org_name = None if args: do_parser = self.arg_list() try: do_args = do_parser.parse_args(shlex.split(args)) except SystemExit as e: return org_name = do_args.org # call UForge API printer.out("Getting all the roles for the organization...") org = org_utils.org_get(self.api, org_name) all_roles = self.api.Orgs(org.dbId).Roles().Getall(None) table = Texttable(200) table.set_cols_align(["c", "c"]) table.header(["Name", "Description"]) for role in all_roles.roles.role: table.add_row([role.name, role.description]) print table.draw() + "\n" return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: " + str(e), printer.ERROR) self.help_list() except Exception as e: return marketplace_utils.handle_uforge_exception(e)
def do_remove(self, args): try: # add arguments do_parser = self.arg_remove() try: do_args = do_parser.parse_args(shlex.split(args)) except SystemExit as e: return printer.out("Getting subscription profile with name [" + do_args.name + "]...") org = org_utils.org_get(self.api, do_args.org) subscriptions = self.api.Orgs(org.dbId).Subscriptions().Getall(Search=do_args.name) subscription = subscriptions.subscriptionProfiles.subscriptionProfile[0] # Create the list of administrators all_roles = roles() all_roles.roles = pyxb.BIND() # Copy the list of current roles - Remove the roles selected in args for r in subscription.roles.role: if r.name not in do_args.roles: already_role = role() already_role.name = r.name all_roles.roles.append(already_role) # call UForge API self.api.Orgs(org.dbId).Subscriptions(subscription.dbId).Roles.Update(all_roles) printer.out("Somes roles removed from subscription profile [" + do_args.name + "]...") return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: " + str(e), printer.ERROR) self.help_remove() except Exception as e: return marketplace_utils.handle_uforge_exception(e)
def do_delete(self, args): try: # add arguments do_parser = self.arg_delete() try: do_args = do_parser.parse_args(shlex.split(args)) except SystemExit as e: return printer.out("Deleting subscription profile [" + do_args.name + "] ...") org = org_utils.org_get(self.api, do_args.org) # call UForge API subscriptions = self.api.Orgs( org.dbId).Subscriptions().Getall(Search=do_args.name) if len(subscriptions.subscriptionProfiles.subscriptionProfile ) == 1: subscription = subscriptions.subscriptionProfiles.subscriptionProfile[ 0] self.api.Orgs(org.dbId).Subscriptions( subscription.dbId).Remove(None) printer.out("Subscription profile [" + do_args.name + "] deleted") else: printer.out("Unable to delete subscription profile [" + do_args.name + "]") return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: " + str(e), printer.ERROR) self.help_delete() except Exception as e: return marketplace_utils.handle_uforge_exception(e)
def do_list(self, args): try: org_name = None if args: do_parser = self.arg_list() try: do_args = do_parser.parse_args(shlex.split(args)) except SystemExit as e: return org_name = do_args.org # call UForge API printer.out( "Getting all the subscription profiles for organization ...") org = org_utils.org_get(self.api, org_name) print org subscriptions = self.api.Orgs( org.dbId).Subscriptions().Getall(None) table = Texttable(200) table.set_cols_align(["c", "c", "c", "c"]) table.header(["Name", "Code", "Active", "description"]) for subscription in subscriptions.subscriptionProfiles.subscriptionProfile: table.add_row([ subscription.name, subscription.code, "X" if subscription.active else "", subscription.description ]) print table.draw() + "\n" return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: " + str(e), printer.ERROR) self.help_list() except Exception as e: return marketplace_utils.handle_uforge_exception(e)
def do_list(self, args): try: # add arguments do_parser = self.arg_list() do_args = do_parser.parse_args(shlex.split(args)) # call UForge API printer.out("Getting vendors ...") org = org_utils.org_get(self.api, do_args.org) vendors = self.api.Orgs(org.dbId).Vendors().Getall() table = Texttable(200) table.set_cols_align(["c", "c", "c"]) table.header(["Active", "Name", "Email"]) sorted_vendor_list = generics_utils.order_list_object_by( vendors.vendors.vendor, "name") for vendor in sorted_vendor_list: table.add_row([ "" if vendor.inactive else "X", vendor.name, vendor.email ]) print table.draw() + "\n" return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: " + str(e), printer.ERROR) self.help_list() except Exception as e: return marketplace_utils.handle_uforge_exception(e)
def do_list(self, args): try: org_name = None if args: do_parser = self.arg_list() try: do_args = do_parser.parse_args(shlex.split(args)) except SystemExit as e: return org_name = do_args.org # call UForge API printer.out("Getting all the subscription profiles for organization ...") org = org_utils.org_get(self.api, org_name) print org subscriptions = self.api.Orgs(org.dbId).Subscriptions().Getall(None) table = Texttable(200) table.set_cols_align(["c", "c", "c", "c"]) table.header(["Name", "Code", "Active", "description"]) for subscription in subscriptions.subscriptionProfiles.subscriptionProfile: table.add_row([subscription.name, subscription.code, "X" if subscription.active else "", subscription.description]) print table.draw() + "\n" return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: " + str(e), printer.ERROR) self.help_list() except Exception as e: return marketplace_utils.handle_uforge_exception(e)
def do_update(self, args): try: # add arguments do_parser = self.arg_update() try: do_args = do_parser.parse_args(shlex.split(args)) except SystemExit as e: return printer.out("Getting subscription profile with name [" + do_args.name + "]...") org = org_utils.org_get(self.api, do_args.org) # call UForge API subscriptions = self.api.Orgs(org.dbId).Subscriptions().Getall(Search=do_args.name) if subscriptions.total == 1: subscription = subscriptions.subscriptionProfiles.subscriptionProfile[0] updated_subscription = subscriptionProfile() updated_subscription.name = subscription.name updated_subscription.code = subscription.code if do_args.description: updated_subscription.description = do_args.description if do_args.active: updated_subscription.active = True else: updated_subscription.active = False printer.out("Updating subscription profile with name [" + do_args.name + "] ...") # call UForge API self.api.Orgs(org.dbId).Subscriptions(subscription.dbId).Update(updated_subscription) return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: " + str(e), printer.ERROR) self.help_update() except Exception as e: return marketplace_utils.handle_uforge_exception(e)
def do_delete(self, args): try: # add arguments do_parser = self.arg_delete() try: do_args = do_parser.parse_args(shlex.split(args)) except SystemExit as e: return printer.out("Deleting subscription profile [" + do_args.name + "] ...") org = org_utils.org_get(self.api, do_args.org) # call UForge API subscriptions = self.api.Orgs(org.dbId).Subscriptions().Getall(Search=do_args.name) if len(subscriptions.subscriptionProfiles.subscriptionProfile) == 1: subscription = subscriptions.subscriptionProfiles.subscriptionProfile[0] self.api.Orgs(org.dbId).Subscriptions(subscription.dbId).Remove(None) printer.out("Subscription profile [" + do_args.name + "] deleted") else: printer.out("Unable to delete subscription profile [" + do_args.name + "]") return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: " + str(e), printer.ERROR) self.help_delete() except Exception as e: return marketplace_utils.handle_uforge_exception(e)
def do_promote(self, args): try: doParser = self.arg_promote() doArgs = doParser.parse_args(shlex.split(args)) orgSpecified = org_utils.org_get(api=self.api, name=doArgs.org) adminUser = self.api.Users(doArgs.account).Get() if adminUser == None: printer.out("User [" + doArgs.account + "] doesn't exist.", printer.ERROR) else: self.api.Orgs(orgSpecified.dbId).Members(adminUser.loginName).Change(Admin=True, body=adminUser) printer.out("User [" + doArgs.account + "] has been promoted in [" + orgSpecified.name + "] :", printer.OK) if adminUser.active == True: active = "X" else: active = "" printer.out("Informations about [" + adminUser.loginName + "] :") table = Texttable(200) table.set_cols_align(["c", "l", "c", "c", "c", "c", "c", "c"]) table.header( ["Login", "Email", "Lastname", "Firstname", "Created", "Active", "Promo Code", "Creation Code"]) table.add_row([adminUser.loginName, adminUser.email, adminUser.surname, adminUser.firstName, adminUser.created.strftime("%Y-%m-%d %H:%M:%S"), active, adminUser.promoCode, adminUser.creationCode]) print table.draw() + "\n" return 0 except ArgumentParserError as e: printer.out("In Arguments: " + str(e), printer.ERROR) self.help_promote() except Exception as e: return marketplace_utils.handle_uforge_exception(e)
def do_add(self, args): try: do_parser = self.arg_add() try: do_args = do_parser.parse_args(shlex.split(args)) except SystemExit as e: return # call UForge API printer.out("Getting user [" + do_args.account + "] ...") user = self.api.Users(do_args.account).Get() if user is None: printer.err("user " + self.login + "does not exist", printer.ERROR) return 1 org = org_utils.org_get(self.api, do_args.org) all_roles = self.api.Orgs(org.dbId).Roles().Getall(None) # Check if the given roles really exist in the organization found = False for r in do_args.roles: found = False for existing_role in all_roles.roles.role: if existing_role.name == r: found = True break if not found: printer.err("unable to find role with name [" + r + "] in org [" + org.name + "]") return 1 # Create a new roles structures new_roles = roles() new_roles.roles = pyxb.BIND() # Add the new roles for new_role in do_args.roles: r = role() r.name = new_role new_roles.roles.append(r) # Add the user existing roles for existing_user_role in user.roles.role: new_roles.roles.append(existing_user_role) self.api.Users(do_args.account).Roles.Update(new_roles) printer.out("User [" + do_args.account + "] updated with new roles.") return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: " + str(e), printer.ERROR) self.help_add() except Exception as e: return marketplace_utils.handle_uforge_exception(e)
def do_create(self, args): try: # add arguments do_parser = self.arg_create() try: do_args = do_parser.parse_args(shlex.split(args)) except SystemExit as e: return # call UForge API printer.out("Creating subscription profile [" + do_args.name + "] ...") org = org_utils.org_get(self.api, do_args.org) # create a user manually new_subscription_profile = subscriptionProfile() new_subscription_profile.name = do_args.name new_subscription_profile.code = do_args.code if do_args.description: new_subscription_profile.description = do_args.description if do_args.active: new_subscription_profile.active = do_args.active new_subscription_profile.admins = pyxb.BIND() if do_args.admins: for a in do_args.admins: new_admin = user() new_admin.loginName = a new_subscription_profile.admins.append(new_admin) new_subscription_profile.roles = pyxb.BIND() if do_args.roles: for a in do_args.roles: new_role = role() new_role.name = a new_subscription_profile.roles.append(new_role) # Send the create user request to the server new_subscription_profile = self.api.Orgs(org.dbId).Subscriptions().Add(new_subscription_profile) if new_subscription_profile is None: printer.out("No information about the new subscription profile available", printer.ERROR) else: table = Texttable(200) table.set_cols_align(["c", "c", "c"]) table.header( ["Name", "Code", "Active"]) table.add_row([new_subscription_profile.name, new_subscription_profile.code, "X" if new_subscription_profile.active else ""]) print table.draw() + "\n" return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: " + str(e), printer.ERROR) self.help_create() except Exception as e: return marketplace_utils.handle_uforge_exception(e)
def do_add(self, args): try: do_parser = self.arg_add() try: do_args = do_parser.parse_args(shlex.split(args)) except SystemExit as e: return # call UForge API printer.out("Getting user [" + do_args.account + "] ...") user = self.api.Users(do_args.account).Get() if user is None: printer.err("user " + self.login + "does not exist", printer.ERROR) return 1 org = org_utils.org_get(self.api, do_args.org) all_roles = self.api.Orgs(org.dbId).Roles().Getall(None) # Check if the given roles really exist in the organization found = False for r in do_args.roles: found = False for existing_role in all_roles.roles.role: if existing_role.name == r: found = True break; if not found: printer.err("unable to find role with name [" + r + "] in org [" + org.name + "]") return 1 # Create a new roles structures new_roles = roles() new_roles.roles = pyxb.BIND() # Add the new roles for new_role in do_args.roles: r = role() r.name = new_role new_roles.roles.append(r) # Add the user existing roles for existing_user_role in user.roles.role: new_roles.roles.append(existing_user_role) self.api.Users(do_args.account).Roles.Update(new_roles) printer.out("User [" + do_args.account + "] updated with new roles.") return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: " + str(e), printer.ERROR) self.help_add() except Exception as e: return marketplace_utils.handle_uforge_exception(e)
def do_remove(self, args): try: # add arguments do_parser = self.arg_remove() try: do_args = do_parser.parse_args(shlex.split(args)) except SystemExit as e: return printer.out("Getting role [" + do_args.name + "]...") org = org_utils.org_get(self.api, do_args.org) all_roles = self.api.Orgs(org.dbId).Roles().Getall(None) old_role = None for r in all_roles.roles.role: if r.name == do_args.name: old_role = r break if old_role is None: printer.out("No role [" + do_args.name + "]...") return 1 new_role = role() new_role.name = old_role.name new_role.description = old_role.description new_role.entitlements = pyxb.BIND() delete_roles = compare(r.entitlements.entitlement, do_args.entitlements, "name") for entitlementItem in r.entitlements.entitlement: exist = False for deleterole in delete_roles: if entitlementItem.name == deleterole.name: exist = True if not exist: already_entitlement = entitlement() already_entitlement.name = entitlementItem.name new_role.entitlements.append(already_entitlement) else: printer.out("Removed " + entitlementItem.name + " from role.") self.api.Orgs(org.dbId).Roles().Update(new_role) printer.out("Role [" + do_args.name + "] updated with new entitlements.") return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: " + str(e), printer.ERROR) self.help_remove() except Exception as e: return marketplace_utils.handle_uforge_exception(e)
def do_add(self, args): try: # add arguments do_parser = self.arg_add() try: do_args = do_parser.parse_args(shlex.split(args)) except SystemExit as e: return printer.out("Getting subscription profile with name [" + do_args.name + "]...") org = org_utils.org_get(self.api, do_args.org) subscriptions = self.api.Orgs( org.dbId).Subscriptions().Getall(Search=do_args.name) if subscriptions is None: printer.out("No subscription with name [" + do_args.name + "]") else: subscription = subscriptions.subscriptionProfiles.subscriptionProfile[ 0] # Create the list of administrators admins = users() admins.users = pyxb.BIND() # Copy the list of current administrators for admin in subscription.admins.admin: already_admin = user() already_admin.loginName = admin.loginName admins.users.append(already_admin) for e in do_args.admins: new_admin = user() new_admin.loginName = e admins.users.append(new_admin) # call UForge API self.api.Orgs(org.dbId).Subscriptions( subscription.dbId).Admins.Update(admins) printer.out( "Some users added as administrators of subscription profile [" + do_args.name + "]...") return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: " + str(e), printer.ERROR) self.help_add() except Exception as e: return marketplace_utils.handle_uforge_exception(e)
def do_add(self, args): try: # add arguments do_parser = self.arg_add() try: do_args = do_parser.parse_args(shlex.split(args)) except SystemExit as e: return printer.out("Getting subscription profile with name [" + do_args.name + "]...") org = org_utils.org_get(self.api, do_args.org) subscriptions = self.api.Orgs( org.dbId).Subscriptions().Getall(Search=do_args.name) subscription = subscriptions.subscriptionProfiles.subscriptionProfile[ 0] # Create the list of roles all_roles = roles() all_roles.roles = pyxb.BIND() # Copy the list of current administrators for r in subscription.roles.role: already_role = role() already_role.name = r.name all_roles.roles.append(already_role) # Add the new administrators given as input for nr in do_args.roles: new_role = role() new_role.name = nr all_roles.roles.append(new_role) # call UForge API self.api.Orgs(org.dbId).Subscriptions( subscription.dbId).Roles.Update(all_roles) printer.out("Some roles added for subscription profile [" + do_args.name + "]...") return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: " + str(e), printer.ERROR) self.help_add() except Exception as e: return marketplace_utils.handle_uforge_exception(e)
def do_info(self, args): try: # add arguments do_parser = self.arg_info() try: do_args = do_parser.parse_args(shlex.split(args)) except SystemExit as e: return # call UForge API printer.out("Getting subscription profile with name [" + do_args.name + "]...") org = org_utils.org_get(self.api, do_args.org) subscriptions = self.api.Orgs( org.dbId).Subscriptions().Getall(Search=do_args.name) table = Texttable(200) table.set_cols_align(["l", "l"]) table.header(["Info", "Value"]) subscription = subscriptions.subscriptionProfiles.subscriptionProfile[ 0] table.add_row(["Name", subscription.name]) table.add_row(["Code", subscription.code]) table.add_row(["Active", "Yes" if subscription.active else "No"]) if subscription.roles.role: table.add_row(["Roles", ""]) for role in subscription.roles.role: table.add_row(["", role.name]) else: table.add_row(["Roles", "None"]) if subscription.admins.admin: table.add_row(["Administrators", ""]) for admin in subscription.admins.admin: table.add_row(["", admin.loginName]) else: table.add_row(["Administrators", "None"]) print table.draw() + "\n" return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: " + str(e), printer.ERROR) self.help_info() except Exception as e: return marketplace_utils.handle_uforge_exception(e)
def do_delete(self, args): try: # add arguments do_parser = self.arg_delete() try: do_args = do_parser.parse_args(shlex.split(args)) except SystemExit as e: return printer.out("Deleting role [" + do_args.name + "] ...") org = org_utils.org_get(self.api, do_args.org) self.api.Orgs(org.dbId).Roles(do_args.name).Delete() printer.out("Role [" + do_args.name + "] deleted") return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: " + str(e), printer.ERROR) self.help_delete() except Exception as e: return marketplace_utils.handle_uforge_exception(e)
def do_add(self, args): try: # add arguments do_parser = self.arg_add() try: do_args = do_parser.parse_args(shlex.split(args)) except SystemExit as e: return printer.out("Getting subscription profile with name [" + do_args.name + "]...") org = org_utils.org_get(self.api, do_args.org) subscriptions = self.api.Orgs(org.dbId).Subscriptions().Getall(Search=do_args.name) if subscriptions is None: printer.out("No subscription with name [" + do_args.name + "]") else: subscription = subscriptions.subscriptionProfiles.subscriptionProfile[0] # Create the list of administrators admins = users() admins.users = pyxb.BIND() # Copy the list of current administrators for admin in subscription.admins.admin: already_admin = user() already_admin.loginName = admin.loginName admins.users.append(already_admin) for e in do_args.admins: new_admin = user() new_admin.loginName = e admins.users.append(new_admin) # call UForge API self.api.Orgs(org.dbId).Subscriptions(subscription.dbId).Admins.Update(admins) printer.out("Some users added as administrators of subscription profile [" + do_args.name + "]...") return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: " + str(e), printer.ERROR) self.help_add() except Exception as e: return marketplace_utils.handle_uforge_exception(e)
def do_info(self, args): try: # add arguments do_parser = self.arg_info() try: do_args = do_parser.parse_args(shlex.split(args)) except SystemExit as e: return # call UForge API printer.out("Getting subscription profile with name [" + do_args.name + "]...") org = org_utils.org_get(self.api, do_args.org) subscriptions = self.api.Orgs(org.dbId).Subscriptions().Getall(Search=do_args.name) table = Texttable(200) table.set_cols_align(["l", "l"]) table.header(["Info", "Value"]) subscription = subscriptions.subscriptionProfiles.subscriptionProfile[0] table.add_row(["Name", subscription.name]) table.add_row(["Code", subscription.code]) table.add_row(["Active", "Yes" if subscription.active else "No"]) if subscription.roles.role: table.add_row(["Roles", ""]) for role in subscription.roles.role: table.add_row(["", role.name]) else: table.add_row(["Roles", "None"]) if subscription.admins.admin: table.add_row(["Administrators", ""]) for admin in subscription.admins.admin: table.add_row(["", admin.loginName]) else: table.add_row(["Administrators", "None"]) print table.draw() + "\n" return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: " + str(e), printer.ERROR) self.help_info() except Exception as e: return marketplace_utils.handle_uforge_exception(e)
def do_update(self, args): try: # add arguments do_parser = self.arg_update() try: do_args = do_parser.parse_args(shlex.split(args)) except SystemExit as e: return printer.out("Getting subscription profile with name [" + do_args.name + "]...") org = org_utils.org_get(self.api, do_args.org) # call UForge API subscriptions = self.api.Orgs( org.dbId).Subscriptions().Getall(Search=do_args.name) if subscriptions.total == 1: subscription = subscriptions.subscriptionProfiles.subscriptionProfile[ 0] updated_subscription = subscriptionProfile() updated_subscription.name = subscription.name updated_subscription.code = subscription.code if do_args.description: updated_subscription.description = do_args.description if do_args.active: updated_subscription.active = True else: updated_subscription.active = False printer.out("Updating subscription profile with name [" + do_args.name + "] ...") # call UForge API self.api.Orgs(org.dbId).Subscriptions( subscription.dbId).Update(updated_subscription) return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: " + str(e), printer.ERROR) self.help_update() except Exception as e: return marketplace_utils.handle_uforge_exception(e)
def do_info(self, args): try: # add arguments do_parser = self.arg_info() try: do_args = do_parser.parse_args(shlex.split(args)) except SystemExit as e: return # call UForge API printer.out("Getting role [" + do_args.name + "]...") org = org_utils.org_get(self.api, do_args.org) all_roles = self.api.Orgs(org.dbId).Roles().Getall(None) selected_role = None for role in all_roles.roles.role: if role.name == do_args.name: selected_role = role break if selected_role is None: printer.out("No role [" + do_args.name + "]...") return 1 printer.out("Name: " + selected_role.name) printer.out("Description: " + selected_role.description) table = Texttable(200) table.set_cols_align(["l", "l"]) table.header(["Entitlement", "Description"]) for entitlement in selected_role.entitlements.entitlement: table.add_row([entitlement.name, entitlement.description]) print table.draw() + "\n" return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: " + str(e), printer.ERROR) self.help_info() except Exception as e: return marketplace_utils.handle_uforge_exception(e)
def do_create(self, args): try: # add arguments do_parser = self.arg_create() try: do_args = do_parser.parse_args(shlex.split(args)) except SystemExit as e: return printer.out("Creating role [" + do_args.name + "] ...") org = org_utils.org_get(self.api, do_args.org) new_role = role() new_role.name = do_args.name if do_args.description: new_role.description = do_args.description if do_args.entitlements: if do_args.entitlements is not None: new_role.entitlements = pyxb.BIND() entList = self.api.Entitlements.Getall() entList = entList.entitlements.entitlement entList = compare(entList, do_args.entitlements, "name") for ent in entList: add_entitlement = entitlement() add_entitlement.name = ent.name add_entitlement.description = ent.description new_role.entitlements.append(add_entitlement) printer.out("Entitlement " + ent.name + " added to the role") self.api.Orgs(org.dbId).Roles().Create(new_role) printer.out("Role [" + new_role.name + "] was correctly created", printer.OK) return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: " + str(e), printer.ERROR) self.help_create() except Exception as e: return marketplace_utils.handle_uforge_exception(e)
def do_list(self, args): try: # add arguments do_parser = self.arg_list() do_args = do_parser.parse_args(shlex.split(args)) # call UForge API printer.out("Getting vendors ...") org = org_utils.org_get(self.api, do_args.org) vendors = self.api.Orgs(org.dbId).Vendors().Getall() table = Texttable(200) table.set_cols_align(["c", "c", "c"]) table.header(["Active", "Name", "Email"]) sorted_vendor_list = generics_utils.order_list_object_by(vendors.vendors.vendor, "name") for vendor in sorted_vendor_list: table.add_row(["" if vendor.inactive else "X", vendor.name, vendor.email]) print table.draw() + "\n" return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: " + str(e), printer.ERROR) self.help_list() except Exception as e: return marketplace_utils.handle_uforge_exception(e)
def do_create(self, args): try: # add arguments do_parser = self.arg_create() try: do_args = do_parser.parse_args(shlex.split(args)) except SystemExit as e: return # call UForge API printer.out("Creating subscription profile [" + do_args.name + "] ...") org = org_utils.org_get(self.api, do_args.org) # create a user manually new_subscription_profile = subscriptionProfile() new_subscription_profile.name = do_args.name new_subscription_profile.code = do_args.code if do_args.description: new_subscription_profile.description = do_args.description if do_args.active: new_subscription_profile.active = do_args.active new_subscription_profile.admins = pyxb.BIND() if do_args.admins: for a in do_args.admins: new_admin = user() new_admin.loginName = a new_subscription_profile.admins.append(new_admin) new_subscription_profile.roles = pyxb.BIND() if do_args.roles: for a in do_args.roles: new_role = role() new_role.name = a new_subscription_profile.roles.append(new_role) # Send the create user request to the server new_subscription_profile = self.api.Orgs( org.dbId).Subscriptions().Add(new_subscription_profile) if new_subscription_profile is None: printer.out( "No information about the new subscription profile available", printer.ERROR) else: table = Texttable(200) table.set_cols_align(["c", "c", "c"]) table.header(["Name", "Code", "Active"]) table.add_row([ new_subscription_profile.name, new_subscription_profile.code, "X" if new_subscription_profile.active else "" ]) print table.draw() + "\n" return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: " + str(e), printer.ERROR) self.help_create() except Exception as e: return marketplace_utils.handle_uforge_exception(e)