def create_files(self): self.create_docs() if os.path.exists(self.dest): shutil.rmtree(self.dest) os.mkdir(self.dest) json_files = FilesForCouch(self.docs, self.dest) json_files.create() if not self.settings.only_files: couch_up = CouchdbUploader( path=self.dest, couchdb_uri=self.settings.couchdb_uri, couchdb_db=self.settings.couchdb_db ) for fname in os.listdir(self.dest): couch_up.put(data="@{}".format(fname), doc_id=fname[:-5])
def create_files(self, dest=None, src=None): auth = auth_from_uri(self.settings.couchdb_uri) if hasattr(self.settings, 'src_client_ldif') and ( self.settings.src_client_ldif): client_ldif = IspmanClientLDIF( open(self.settings.src_client_ldif, 'r'), sys.stdout, editor=auth[0] ) client_ldif.parse() data = [(k, v) for k, v in client_ldif.clients.iteritems()] json_files = FilesForCouch(data, dest) json_files.create() dns_ldif = IspmanDnsLDIF( open(src, 'r'), sys.stdout, self.settings, clients_ldif=client_ldif, editor=auth[0] ) else: dns_ldif = IspmanDnsLDIF( open(src, 'r'), sys.stdout, self.settings, editor=auth[0] ) dns_ldif.parse() if self.settings.show_ips: for ip in dns_ldif.a_record_ips: try: hostname = gethostbyaddr(ip)[0] except: hostname = None print("ip:{} ({}), \ndomains:{}\n".format( ip, hostname, dns_ldif.a_record_hosts[ip])) data = [[k, v] for k, v in dns_ldif.domains.iteritems()] docs_processor = DnsDocsProcessor(self.settings, data) docs_processor.process() json_files = FilesForCouch(data, dest, use_id_in_data=True) json_files.create()