def process_file(self): #FIXME read from config f = open(self.sourceFile,"r") docs = json.load(f) newdocs = [] f.close() docs = self.handle_docs(docs) #FIXME Two different dump functions one here one in potiron-an-all.py if self.directory is None: json.dump(docs, sys.stdout) else: #FIXME assume that always the same filename filename = None if len(docs) > 0: item = docs[0] if item.has_key("filename"): filename = item["filename"] if filename is None: errormsg("Cannot store file as no filename was found") return fn = get_file_struct(self.directory, filename) t = fn.split("/") t.pop() d = "/".join(t) if os.path.exists(d) == False: os.makedirs(d) if os.path.exists(fn): #FIXME Merge files? errormsg("Do not overwrite file " + fn) return f = open(fn,"w") json.dump(docs,f)
def process_file(self): #FIXME read from config f = open(self.sourceFile, "r") docs = json.load(f) newdocs = [] f.close() docs = self.handle_docs(docs) #FIXME Two different dump functions one here one in potiron-an-all.py if self.directory is None: json.dump(docs, sys.stdout) else: #FIXME assume that always the same filename filename = None if len(docs) > 0: item = docs[0] if item.has_key("filename"): filename = item["filename"] if filename is None: errormsg("Cannot store file as no filename was found") return fn = get_file_struct(self.directory, filename) t = fn.split("/") t.pop() d = "/".join(t) if os.path.exists(d) == False: os.makedirs(d) if os.path.exists(fn): #FIXME Merge files? errormsg("Do not overwrite file " + fn) return f = open(fn, "w") json.dump(docs, f)
def store_packet(rootdir, pcapfilename, obj): if rootdir is not None: jsonfilename = potiron.get_file_struct(rootdir, pcapfilename) f = open(jsonfilename, "w") f.write(obj) f.close() infomsg("Created filename " + jsonfilename) else: sys.stdout.write(obj)
def store_packet(rootdir, pcapfilename, obj): if rootdir is not None: jsonfilename = potiron.get_file_struct(rootdir, pcapfilename) f = open(jsonfilename,"w") f.write(obj) f.close() infomsg("Created filename "+jsonfilename) else: sys.stdout.write(obj)
config.getint("ipasn", "port")) fd = sys.stdout if args.directory is not None: filename = None if args.read is None: if len(docs) > 0: if "filename" not in docs[0]: sys.exit(0) filename = docs[0]["filename"] else: # When no filename can be extracted abort sys.exit(0) else: filename = args.read[0] fn = get_file_struct(args.directory[0], filename) t = fn.split('/') d = "/".join(t[0:-1]) # When processing in parallel the directory could have been created # Between the directory test and makedirs try: if not os.path.exists(d): os.makedirs(d) except OSError as e: if e.errno != 17: # Something else happened propagate exception raise OSError(e) potiron.infomsg("Someone else created the directory") fd = open(fn, "w") newdocs = [] for doc in docs:
def create_dirs(rootdir, pcapfilename): jsonfilename = potiron.get_file_struct(rootdir, pcapfilename) d = os.path.dirname(jsonfilename) if os.path.exists(d) == False: os.makedirs(d)
asn = AnnotateASN(config.get("ipasn", "server"), config.getint("ipasn", "port")) fd = sys.stdout if args.directory is not None: filename = None if args.read is None: if len(docs) > 0: if "filename" not in docs[0]: sys.exit(0) filename = docs[0]["filename"] else: # When no filename can be extracted abort sys.exit(0) else: filename = args.read[0] fn = get_file_struct(args.directory[0], filename) t = fn.split('/') d = "/".join(t[0:-1]) # When processing in parallel the directory could have been created # Between the directory test and makedirs try: if not os.path.exists(d): os.makedirs(d) except OSError as e: if e.errno != 17: # Something else happened propagate exception raise OSError(e) potiron.infomsg("Someone else created the directory") fd = open(fn, "w") newdocs = [] for doc in docs: