def create(name, url, type, title, active, owner_org, frequency, config): """Create new harvest source. """ try: result = utils.create_harvest_source(name, url, type, title, active, owner_org, frequency, config) except tk.ValidationError as e: tk.error_shout(u"Validation error:") for field, err in e.error_summary.items(): tk.error_shout("\t{}: {}".format(field, err)) raise click.Abort() click.echo(result)
def create_harvest_source(self): if len(self.args) >= 2: name = six.text_type(self.args[1]) else: print("Please provide a source name") sys.exit(1) if len(self.args) >= 3: url = six.text_type(self.args[2]) else: print("Please provide a source URL") sys.exit(1) if len(self.args) >= 4: type = six.text_type(self.args[3]) else: print("Please provide a source type") sys.exit(1) if len(self.args) >= 5: title = six.text_type(self.args[4]) else: title = None if len(self.args) >= 6: active = not ( self.args[5].lower() == "false" or self.args[5] == "0" ) else: active = True if len(self.args) >= 7: owner_org = six.text_type(self.args[6]) else: owner_org = None if len(self.args) >= 8: frequency = six.text_type(self.args[7]) if not frequency: frequency = "MANUAL" else: frequency = "MANUAL" if len(self.args) >= 9: source_config = six.text_type(self.args[8]) else: source_config = None try: result = utils.create_harvest_source( name, url, type, title, active, owner_org, frequency, source_config ) except ValidationError as e: print("An error occurred:") print(str(e.error_dict)) raise e print(result)