本文整理汇总了Python中sss.core.logging.Log类的典型用法代码示例。如果您正苦于以下问题:Python Log类的具体用法?Python Log怎么用?Python Log使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Log类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setwebrootpermissions
def setwebrootpermissions(self, webroot):
Log.debug(self, "Setting up permissions")
try:
SSSFileUtils.chown(self, webroot, SSSVariables.sss_php_user, SSSVariables.sss_php_user, recursive=True)
except Exception as e:
Log.debug(self, str(e))
raise SiteError("problem occured while setting up webroot permissions")
示例2: removeApacheConf
def removeApacheConf(self, domain):
if os.path.isfile("/etc/apache2/sites-available/{0}.conf".format(domain)):
Log.debug(self, "Removing Apache configuration")
SSSFileUtils.rm(self, "/etc/apache2/sites-enabled/{0}.conf".format(domain))
SSSFileUtils.rm(self, "/etc/apache2/sites-available/{0}.conf".format(domain))
SSSService.reload_service(self, "apache2")
SSSGit.add(self, ["/etc/apache2"], msg="Deleted {0} ".format(domain))
示例3: secure_auth
def secure_auth(self):
"""This function Secures authentication"""
passwd = ''.join([random.choice
(string.ascii_letters + string.digits)
for n in range(6)])
if not self.app.pargs.user_input:
username = input("Provide HTTP authentication user "
"name [{0}] :".format(SSSVariables.sss_user))
self.app.pargs.user_input = username
if username == "":
self.app.pargs.user_input = SSSVariables.sss_user
if not self.app.pargs.user_pass:
password = getpass.getpass("Provide HTTP authentication "
"password [{0}] :".format(passwd))
self.app.pargs.user_pass = password
if password == "":
self.app.pargs.user_pass = passwd
Log.debug(self, "printf username:"
"$(openssl passwd -crypt "
"password 2> /dev/null)\n\""
"> /etc/apache2/htpasswd-sss 2>/dev/null")
SSSShellExec.cmd_exec(self, "printf \"{username}:"
"$(openssl passwd -crypt "
"{password} 2> /dev/null)\n\""
"> /etc/apache2/htpasswd-sss 2>/dev/null"
.format(username=self.app.pargs.user_input,
password=self.app.pargs.user_pass),
log=False)
SSSGit.add(self, ["/etc/apache2"],
msg="Adding changed secure auth into Git")
示例4: chown
def chown(self, path, user, group, recursive=False):
"""
Change Owner for files
change owner for file with path specified
user: username of owner
group: group of owner
recursive: if recursive is True change owner for all
files in directory
"""
userid = pwd.getpwnam(user)[2]
groupid = pwd.getpwnam(user)[3]
try:
Log.debug(self, "Changing ownership of {0}, Userid:{1},Groupid:{2}"
.format(path, userid, groupid))
# Change inside files/directory permissions only if recursive flag
# is set
if recursive:
for root, dirs, files in os.walk(path):
for d in dirs:
os.chown(os.path.join(root, d), userid,
groupid)
for f in files:
os.chown(os.path.join(root, f), userid,
groupid)
os.chown(path, userid, groupid)
except shutil.Error as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to change owner : {0}".format(path))
except Exception as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to change owner : {0} ".format(path))
示例5: add
def add(self):
"""Swap addition with SimpleSetupServer"""
if SSSVariables.sss_ram < 512:
if SSSVariables.sss_swap < 1000:
Log.info(self, "Adding SWAP file, please wait...")
# Install dphys-swapfile
SSSAptGet.update(self)
SSSAptGet.install(self, ["dphys-swapfile"])
# Stop service
SSSShellExec.cmd_exec(self, "service dphys-swapfile stop")
# Remove Default swap created
SSSShellExec.cmd_exec(self, "/sbin/dphys-swapfile uninstall")
# Modify Swap configuration
if os.path.isfile("/etc/dphys-swapfile"):
SSSFileUtils.searchreplace(self, "/etc/dphys-swapfile",
"#CONF_SWAPFILE=/var/swap",
"CONF_SWAPFILE=/sss-swapfile")
SSSFileUtils.searchreplace(self, "/etc/dphys-swapfile",
"#CONF_MAXSWAP=2048",
"CONF_MAXSWAP=1024")
SSSFileUtils.searchreplace(self, "/etc/dphys-swapfile",
"#CONF_SWAPSIZE=",
"CONF_SWAPSIZE=1024")
else:
with open("/etc/dphys-swapfile", 'w') as conffile:
conffile.write("CONF_SWAPFILE=/sss-swapfile\n"
"CONF_SWAPSIZE=1024\n"
"CONF_MAXSWAP=1024\n")
# Create swap file
SSSShellExec.cmd_exec(self, "service dphys-swapfile start")
示例6: invoke_editor
def invoke_editor(self, filepath, errormsg=''):
"""
Open files using sensible editor
"""
try:
subprocess.call(['sensible-editor', filepath])
except OSError as e:
Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
raise CommandExecutionError
示例7: purge
def purge(self):
"""Start purging of packages"""
apt_packages = []
packages = []
# Default action for stack remove
if ((not self.app.pargs.web) and (not self.app.pargs.apache2) and
(not self.app.pargs.php) and (not self.app.pargs.mysql)):
self.app.pargs.web = True
self.app.pargs.apache2 = True
self.app.pargs.php = True
self.app.pargs.mysql = True
if self.app.pargs.all:
self.app.pargs.web = True
self.app.pargs.apache2 = True
self.app.pargs.php = True
self.app.pargs.mysql = True
if self.app.pargs.web:
self.app.pargs.apache2 = True
self.app.pargs.php = True
self.app.pargs.mysql = True
#self.app.pargs.wpcli = True
#self.app.pargs.postfix = True
if self.app.pargs.apache2:
Log.debug(self, "Purge apt_packages variable of Apache")
apt_packages = apt_packages + SSSVariables.sss_apache
if self.app.pargs.php:
Log.debug(self, "Purge apt_packages variable PHP")
apt_packages = apt_packages + SSSVariables.sss_php
if self.app.pargs.mysql:
Log.debug(self,"Removing apt_packages variable of PHP")
apt_packages = apt_packages + SSSVariables.sss_mysql
packages = packages + ['/usr/bin/tuning-primer']
if len(packages) or len(apt_packages):
sss_prompt = input('Are you sure you to want to purge '
'from server '
'along with their configuration'
' packages,\nAny answer other than '
'"yes" will be stop this '
'operation :')
if sss_prompt == 'YES' or sss_prompt == 'yes':
if len(apt_packages):
Log.info(self, "Purging packages, please wait...")
SSSAptGet.remove(self, apt_packages, purge=True)
SSSAptGet.auto_remove(self)
if len(packages):
SSSFileUtils.remove(self, packages)
SSSAptGet.auto_remove(self)
Log.info(self, "Successfully purged packages")
示例8: getAllsites
def getAllsites(self):
"""
1. returns all records from sss database
"""
try:
q = SiteDB.query.all()
return q
except Exception as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to query database")
示例9: callback
def callback(filename, lines):
for line in lines:
if line.find(":::") == -1:
print(line)
else:
data = line.split(":::")
try:
print(data[0], data[1], zlib.decompress(base64.decodestring(data[2])))
except Exception as e:
Log.info(time.time(), "caught exception rendering a new log line in %s" % filename)
示例10: getSiteInfo
def getSiteInfo(self, site):
"""
Retrieves site record from sss databse
"""
try:
q = SiteDB.query.filter(SiteDB.sitename == site).first()
return q
except Exception as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to query database for site info")
示例11: check_db_exists
def check_db_exists(self, db_name):
try:
if SSSMysql.dbConnection(self, db_name):
return True
except DatabaseNotExistsError as e:
Log.debug(self, str(e))
return False
except MySQLConnectionError as e:
Log.debug(self, str(e))
raise MySQLConnectionError
示例12: updateSiteInfo
def updateSiteInfo(self, site, stype='', cache='', webroot='',
enabled=True, ssl=False, fs='', db='', db_name=None,
db_user=None, db_password=None, db_host=None, hhvm=None,
pagespeed=None):
"""updates site record in database"""
try:
q = SiteDB.query.filter(SiteDB.sitename == site).first()
except Exception as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to query database for site info")
if not q:
Log.error(self, "{0} does not exist in database".format(site))
# Check if new record matches old if not then only update database
if stype and q.site_type != stype:
q.site_type = stype
if cache and q.cache_type != cache:
q.cache_type = cache
if q.is_enabled != enabled:
q.is_enabled = enabled
if ssl and q.is_ssl != ssl:
q.is_ssl = ssl
if db_name and q.db_name != db_name:
q.db_name = db_name
if db_user and q.db_user != db_user:
q.db_user = db_user
if db_user and q.db_password != db_password:
q.db_password = db_password
if db_host and q.db_host != db_host:
q.db_host = db_host
if webroot and q.site_path != webroot:
q.site_path = webroot
if (hhvm is not None) and (q.is_hhvm is not hhvm):
q.is_hhvm = hhvm
if (pagespeed is not None) and (q.is_pagespeed is not pagespeed):
q.is_pagespeed = pagespeed
try:
q.created_on = func.now()
db_session.commit()
except Exception as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to update site info in application database.")
示例13: extract
def extract(self, file, path):
"""Function to extract tar.gz file"""
try:
tar = tarfile.open(file)
tar.extractall(path=path)
tar.close()
os.remove(file)
return True
except tarfile.TarError as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to extract file \{0}".format(file))
return False
示例14: isexist
def isexist(self, path):
"""
Check if file exist on given path
"""
try:
if os.path.exists(path):
return (True)
else:
return (False)
except OSError as e:
Log.debug(self, "{0}".format(e.strerror))
Log.error(self, "Unable to check path {0}".format(path))
示例15: auto_clean
def auto_clean(self):
"""
Similar to `apt-get autoclean`
"""
try:
orig_out = sys.stdout
sys.stdout = open(self.app.config.get("log.logging", "file"), encoding="utf-8", mode="a")
apt_get.autoclean("-y")
sys.stdout = orig_out
except ErrorReturnCode as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to apt-get autoclean")