def _dataloadtool_export(self, *args, **kwargs): """ Call `dataloadtool_export()` with the supplied additional arguments. :return: Validated Consumers `objectify` tree. """ sio = BytesIO() sio2 = BytesIO() dataloadtool_export(sio, sio2, *args, **kwargs) xml = sio.getvalue() sio.close() self.assertValidates(xml) consumers = objectify.fromstring(xml, self.parser) return consumers
def handle(self, credentials_filepath, filepath=None, pretty_print=False, all=False, password_callback=None, **options): for p in (credentials_filepath, filepath): if p: if not path.isabs(p): p = path.join(os.getenv('PWD'), p) if not path.isdir(path.dirname(p)): raise Exception("Output directory %s does not exist." % p) elif not os.access(path.dirname(p), os.W_OK): raise Exception("Output directory %s does not have write access." % p) members = self.get_members(include_all=all) callback = None if password_callback is None else self.load_callback(password_callback) with open(filepath, 'w') if filepath else self.stdout as output: with open(credentials_filepath, 'w') as credentials_output: dataloadtool_export(output, credentials_output, members, password_callback=callback, pretty_print=pretty_print)