def _run(self): try: self.log = quasseltool.Logutil(self.opts.db) except sqlite3.OperationalError: if self.opts.db == "": dbname = "(defaults)" else: dbname = self.opts.db print "FATAL: Unable to open db file %s" % os.path.expanduser( dbname) print "if it is somewhere else, use the -d FILE option" sys.exit(1) if self.opts.user == "": print "No user specified. Available options are:" for user in self.log.get_users(): print user print "\nUse -u USER to choose one" sys.exit(0) if not self.log.is_user(self.opts.user): print "FATAL: User %s does not exist in DB" % self.opts.user sys.exit(1) if self.opts.network == "": print "No network specified. Available options are:" for network in self.log.get_networks(self.opts.user): print network print "\nUse -n NETWORK to choose one" sys.exit(0) if not self.log.is_network(self.opts.user, self.opts.network): print "FATAL: Network %s does not exist for user %s" % ( self.opts.network, self.opts.user) sys.exit(1) if self.opts.channel == "": print "No channel specified. Available options are:" for channel in self.log.get_buffers(self.opts.user, self.opts.network): print channel print "\nUse -c CHANNEL to choose one" sys.exit(0) if not self.log.is_buffer(self.opts.user, self.opts.network, self.opts.channel): print "FATAL: Channel %s does not exist on network %s for user %s" % ( self.opts.channel, self.opts.network, self.opts.user) sys.exit(1) if self.opts.out == "": print "No outfile specified. use -o filename to do so.\nFile will be overwritten if it exists" sys.exit(0) filename = os.path.expanduser(self.opts.out) outfile = codecs.open(filename, "wb", "iso8859_15", errors="replace") #outfile = codecs.open(filename, "wb", "utf-8") sys.stdout.write( "Writing Logfile %s of channel %s on network %s for user %s... " % (filename, self.opts.channel, self.opts.network, self.opts.user)) sys.stdout.flush() counter = Consolecounter("", "\nDone\n") self.log.getlog(self.opts.user, self.opts.network, self.opts.channel, outfile, counter=counter) outfile.close()
def _run(self): self.log = quasseltool.Logutil() #try: # # if self.opts.db == "": # dbname = "(defaults)" # else: # dbname = self.opts.db # print "FATAL: Unable to open db file %s"%os.path.expanduser(dbname) # print "if it is somewhere else, use the -d FILE option" # sys.exit(1) if self.opts.user == "": print "No user specified. Available options are:" for user in self.log.get_users(): print user print "\nUse -u USER to choose one" sys.exit(0) if not self.log.is_user(self.opts.user): print "FATAL: User %s does not exist in DB" % self.opts.user sys.exit(1) if self.opts.out == "": print "No outfile specified. use -o filepath to do so.\nFiles will be overwritten if it exists" sys.exit(0) for network in self.log.get_networks(self.opts.user): self.opts.network = network for channel in self.log.get_buffers(self.opts.user, self.opts.network): self.opts.channel = channel if channel == "": channel = "Buffer" try: os.stat(self.opts.out + network) except: os.mkdir(self.opts.out + network) channel = re.sub(">", "", channel) filename = os.path.expanduser(self.opts.out + network + '/' + channel + ".log") if os.path.isfile(filename): exists = True else: exists = False outfile = codecs.open(filename, "a+", "iso8859_15", errors="replace") if exists: #read time and date on last line of file so that the entire buffer wont have to be dumped again and can instead just be appended. lastline = unicode(last_line(outfile)) time = re.search( "\A\[\d{2}-\w{3}-\d{4} \d{2}:\d{2}:\d{2}\]", lastline) if time: time = time.group(0)[1:-1] + u".999" #outfile = codecs.open(filename, "wb", "utf-8") sys.stdout.write( "Writing Logfile %s of channel %s on network %s for user %s... " % (filename, self.opts.channel, self.opts.network, self.opts.user)) sys.stdout.flush() counter = Consolecounter("", "\nDone\n") self.log.getlog( self.opts.user, self.opts.network, self.opts.channel, outfile, counter=counter, log=self.log, time=time, ) outfile.close()
def _run(self): try: self.log = quasseltool.Logutil() except: print "FATAL: Unable to connect to db" print "you need to edit the connection infos in quasseltool.py" sys.exit(1) if self.opts.user == "": print "No user specified. Available options are:" for user in self.log.get_users(): print user print "\nUse -u USER to choose one" sys.exit(0) if not self.log.is_user(self.opts.user): print "FATAL: User %s does not exist in DB" % self.opts.user sys.exit(1) if self.opts.network == "": print "No network specified. Available options are:" for network in self.log.get_networks(self.opts.user): print network print "\nUse -n NETWORK to choose one" sys.exit(0) if not self.log.is_network(self.opts.user, self.opts.network): print "FATAL: Network %s does not exist for user %s" % ( self.opts.network, self.opts.user) sys.exit(1) if self.opts.channel == "": print "No channel specified. Available options are:" for channel in self.log.get_buffers(self.opts.user, self.opts.network): print channel print "\nUse -c CHANNEL to choose one" sys.exit(0) if not self.log.is_buffer(self.opts.user, self.opts.network, self.opts.channel): print "FATAL: Channel %s does not exist on network %s for user %s" % ( self.opts.channel, self.opts.network, self.opts.user) sys.exit(1) if self.opts.out == "": print "No outfile specified. use -o filename to do so.\nFile will be overwritten if it exists" sys.exit(0) filename = os.path.expanduser(self.opts.out) if os.path.isfile(filename): exists = True else: exists = False outfile = codecs.open(filename, "a+", "iso8859_15", errors="replace") time = False limit = "all" if exists: #read time and date on last line of file so that the entire buffer wont have to be dumped again and can instead just be appended. lastline = unicode(last_line(outfile)) time = re.search("\A\[\d{2}-\w{3}-\d{4} \d{2}:\d{2}:\d{2}\]", lastline) if time: time = time.group(0)[1:-1] + u".999" #outfile = codecs.open(filename, "wb", "utf-8") sys.stdout.write( "Writing Logfile %s of channel %s on network %s for user %s... " % (filename, self.opts.channel, self.opts.network, self.opts.user)) sys.stdout.flush() counter = Consolecounter("", "\nDone\n") self.log.getlog(self.opts.user, self.opts.network, self.opts.channel, outfile, counter=counter, log=self.log, time=time) outfile.close()