Trees | Indices | Help |
---|
|
1 # 2 # Copyright (c) 2008--2016 Red Hat, Inc. 3 # 4 # This software is licensed to you under the GNU General Public License, 5 # version 2 (GPLv2). There is NO WARRANTY for this software, express or 6 # implied, including the implied warranties of MERCHANTABILITY or FITNESS 7 # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 8 # along with this software; if not, see 9 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 10 # 11 # Red Hat trademarks are not licensed under GPLv2. No permission is 12 # granted to use or replicate Red Hat trademarks that are incorporated 13 # in this software or its documentation. 14 # 15 16 import os 17 import stat 18 import sys 19 import time 20 import traceback 2123 debug_level = 1 24 logfile = None 2595 98 101 104 107 110 113 11727 if debug_level <= self.debug_level: 28 outstr = "%s %s: %s\n" % ( 29 time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())), 30 self.get_caller(), 31 " ".join([str(it) for it in args])) 32 sys.stdout.write(outstr) 33 34 if not self.logfile is None: 35 self.write_to_logfile(outstr)3638 if debug_level <= self.debug_level: 39 outstr = "%s %s: %s\n" % ( 40 time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())), 41 self.get_caller(), 42 " ".join([str(it) for it in args])) 43 if not self.logfile is None: 44 self.write_to_logfile(outstr)45 4648 if os.access(self.logfile, os.F_OK|os.R_OK|os.W_OK): 49 logname = open(self.logfile, "a") 50 logname.write(logstr) 51 logname.close() 52 else: 53 #pkilambi: bug#179367: check permissions before writing. 54 #non-root users will not have permissions to create the file 55 56 # Set to root-RW-only if we have to create the file 57 mode = stat.S_IRUSR | stat.S_IWUSR # octal 0o600 58 try: 59 # Need to use os.open to insure initial permissions 60 fd = os.open(self.logfile, os.O_WRONLY | os.O_CREAT, mode) 61 logname = os.fdopen(fd, 'w') 62 logname.write(logstr) 63 logname.close() 64 except: 65 print("does not have permissions to create file %s" % (self.logfile)) 66 sys.exit(1)67 70 73 7678 tbStack = traceback.extract_stack() 79 callid = len(tbStack) - caller_offset 80 module = tbStack[callid] 81 module_file = os.path.basename(module[0]) 82 module_file = module_file.split('.', 1)[0] 83 return "%s.%s" % (module_file, module[2])8486 outstr = " ".join([str(it) for it in args]) 87 sys.stderr.write(outstr) 88 sys.stderr.write("\n") 89 if not self.logfile is None: 90 self.write_to_logfile(outstr)91
Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Wed Mar 4 07:37:50 2020 | http://epydoc.sourceforge.net |