本文整理汇总了Python中ee.core.fileutils.EEFileUtils类的典型用法代码示例。如果您正苦于以下问题:Python EEFileUtils类的具体用法?Python EEFileUtils怎么用?Python EEFileUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EEFileUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setwebrootpermissions
def setwebrootpermissions(self, webroot):
Log.debug(self, "Setting up permissions")
try:
EEFileUtils.chown(self, webroot, EEVariables.ee_php_user, EEVariables.ee_php_user, recursive=True)
except Exception as e:
Log.debug(self, str(e))
raise SiteError("problem occured while settingup webroot permissions")
示例2: enable
def enable(self):
if not self.app.pargs.site_name:
try:
while not self.app.pargs.site_name:
self.app.pargs.site_name = (input('Enter site name : ')
.strip())
except IOError as e:
Log.error(self, 'could not input site name')
self.app.pargs.site_name = self.app.pargs.site_name.strip()
# validate domain name
(ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name)
# check if site exists
if not check_domain_exists(self, ee_domain):
Log.error(self, "site {0} does not exist".format(ee_domain))
if os.path.isfile('/etc/nginx/sites-available/{0}'
.format(ee_domain)):
Log.info(self, "Enable domain {0:10} \t".format(ee_domain), end='')
EEFileUtils.create_symlink(self,
['/etc/nginx/sites-available/{0}'
.format(ee_domain),
'/etc/nginx/sites-enabled/{0}'
.format(ee_domain)])
EEGit.add(self, ["/etc/nginx"],
msg="Enabled {0} "
.format(ee_domain))
updateSiteInfo(self, ee_domain, enabled=True)
Log.info(self, "[" + Log.ENDC + "OK" + Log.OKBLUE + "]")
EEService.reload_service(self, 'nginx')
else:
Log.error(self, "nginx configuration file does not exist"
.format(ee_domain))
示例3: operateOnPagespeed
def operateOnPagespeed(self, data):
ee_domain_name = data['site_name']
ee_site_webroot = data['webroot']
if data['pagespeed'] is True:
if not os.path.isfile("{0}/conf/nginx/pagespeed.conf.disabled"
.format(ee_site_webroot)):
Log.debug(self, 'Writting the Pagespeed common '
'configuration to file {0}/conf/nginx/pagespeed.conf'
'pagespeed.conf'.format(ee_site_webroot))
ee_nginx = open('{0}/conf/nginx/pagespeed.conf'
.format(ee_site_webroot), encoding='utf-8',
mode='w')
self.app.render((data), 'pagespeed-common.mustache',
out=ee_nginx)
ee_nginx.close()
else:
EEFileUtils.mvfile(self, "{0}/conf/nginx/pagespeed.conf.disabled"
.format(ee_site_webroot),
'{0}/conf/nginx/pagespeed.conf'
.format(ee_site_webroot))
elif data['pagespeed'] is False:
if os.path.isfile("{0}/conf/nginx/pagespeed.conf"
.format(ee_site_webroot)):
EEFileUtils.mvfile(self, "{0}/conf/nginx/pagespeed.conf"
.format(ee_site_webroot),
'{0}/conf/nginx/pagespeed.conf.disabled'
.format(ee_site_webroot))
# Add nginx conf folder into GIT
EEGit.add(self, ["{0}/conf/nginx".format(ee_site_webroot)],
msg="Adding Pagespeed config of site: {0}"
.format(ee_domain_name))
示例4: removeNginxConf
def removeNginxConf(self, domain):
if os.path.isfile("/etc/nginx/sites-available/{0}".format(domain)):
Log.debug(self, "Removing Nginx configuration")
EEFileUtils.rm(self, "/etc/nginx/sites-enabled/{0}".format(domain))
EEFileUtils.rm(self, "/etc/nginx/sites-available/{0}".format(domain))
EEService.reload_service(self, "nginx")
EEGit.add(self, ["/etc/nginx"], msg="Deleted {0} ".format(domain))
示例5: hashbucket
def hashbucket(self):
# Check Nginx Hashbucket error
sub = subprocess.Popen('nginx -t', stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True)
output, error_output = sub.communicate()
if 'server_names_hash_bucket_size' not in str(error_output):
return True
count = 0
# Get the list of sites-availble
sites_list = os.listdir("/etc/nginx/sites-enabled/")
# Count the number of characters in site names
for site in sites_list:
count = sum([count, len(site)])
# Calculate Nginx hash bucket size
ngx_calc = math.trunc(sum([math.log(count, 2), 2]))
ngx_hash = math.trunc(math.pow(2, ngx_calc))
# Replace hashbucket in Nginx.conf file
if EEFileUtils.grep(self, "/etc/nginx/nginx.conf",
"server_names_hash_bucket_size"):
for line in fileinput.FileInput("/etc/nginx/nginx.conf", inplace=1):
if "server_names_hash_bucket_size" in line:
print("\tserver_names_hash_bucket_size {0};".format(ngx_hash))
else:
print(line, end='')
else:
EEFileUtils.searchreplace(self, '/etc/nginx/nginx.conf',
"gzip_disable \"msie6\";",
"gzip_disable \"msie6\";\n"
"\tserver_names_hash_bucket_size {0};\n"
.format(ngx_hash))
示例6: updatewpuserpassword
def updatewpuserpassword(self, ee_domain, ee_site_webroot):
ee_wp_user = ""
ee_wp_pass = ""
EEFileUtils.chdir(self, "{0}/htdocs/".format(ee_site_webroot))
# Check if ee_domain is wordpress install
try:
is_wp = EEShellExec.cmd_exec(self, "wp --allow-root core" " version")
except CommandExecutionError as e:
raise SiteError("is wordpress site? check command failed ")
# Exit if ee_domain is not wordpress install
if not is_wp:
Log.error(self, "{0} does not seem to be a WordPress site".format(ee_domain))
try:
ee_wp_user = input("Provide WordPress user name [admin]: ")
except Exception as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "\nCould not update password")
if ee_wp_user == "?":
Log.info(self, "Fetching WordPress user list")
try:
EEShellExec.cmd_exec(self, "wp --allow-root user list " "--fields=user_login | grep -v user_login")
except CommandExecutionError as e:
raise SiteError("fetch wp userlist command failed")
if not ee_wp_user:
ee_wp_user = "admin"
try:
is_user_exist = EEShellExec.cmd_exec(
self, "wp --allow-root user list " "--fields=user_login | grep {0}$ ".format(ee_wp_user)
)
except CommandExecutionError as e:
raise SiteError("if wp user exists check command failed")
if is_user_exist:
try:
ee_wp_pass = getpass.getpass(prompt="Provide password for " "{0} user: ".format(ee_wp_user))
while not ee_wp_pass:
ee_wp_pass = getpass.getpass(prompt="Provide password for " "{0} user: ".format(ee_wp_user))
except Exception as e:
Log.debug(self, "{0}".format(e))
raise SiteError("failed to read password input ")
try:
EEShellExec.cmd_exec(
self, "wp --allow-root user update {0}" " --user_pass={1}".format(ee_wp_user, ee_wp_pass)
)
except CommandExecutionError as e:
raise SiteError("wp user password update command failed")
Log.info(self, "Password updated successfully")
else:
Log.error(self, "Invalid WordPress user {0} for {1}.".format(ee_wp_user, ee_domain))
示例7: uninstallwp_plugin
def uninstallwp_plugin(self, plugin_name, data):
ee_site_webroot = data['webroot']
Log.debug(self, "Uninstalling plugin {0}".format(plugin_name))
EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
EEShellExec.cmd_exec(self, "php /usr/bin/wp plugin --allow-root uninstall "
"{0}".format(plugin_name),
errormsg="Unable to UnInstall plugin {0}"
.format(plugin_name))
示例8: setupwordpressnetwork
def setupwordpressnetwork(self, data):
ee_site_webroot = data['webroot']
EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
Log.info(self, "Setting up WordPress Network \t", end='')
EEShellExec.cmd_exec(self, 'wp --allow-root core multisite-convert'
' --title=\'{0}\' {subdomains}'
.format(data['www_domain'], subdomains='--subdomains'
if not data['wpsubdir'] else ''))
Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")
示例9: updatewpuserpassword
def updatewpuserpassword(self, ee_domain, ee_site_webroot):
ee_wp_user = ''
ee_wp_pass = ''
EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
# Check if ee_domain is wordpress install
is_wp = EEShellExec.cmd_exec(self, "wp --allow-root core"
" version",
errormsg="{0} : Unable to check if wp install"
.format(ee_domain))
# Exit if ee_domain is not wordpress install
if not is_wp:
Log.error(self, "{0} does not seem to be a WordPress site"
.format(ee_domain))
try:
ee_wp_user = input("Provide WordPress user name [admin]: ")
except Exception as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "\nCould not update password")
if ee_wp_user == "?":
Log.info(self, "Fetching WordPress user list")
EEShellExec.cmd_exec(self, "wp --allow-root user list "
"--fields=user_login | grep -v user_login",
errormsg="Unable to Fetch users list")
if not ee_wp_user:
ee_wp_user = 'admin'
is_user_exist = EEShellExec.cmd_exec(self, "wp --allow-root user list "
"--fields=user_login | grep {0}$ "
.format(ee_wp_user))
if is_user_exist:
try:
ee_wp_pass = getpass.getpass(prompt="Provide password for "
"{0} user: "
.format(ee_wp_user))
except Exception as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Could not update password")
if len(ee_wp_pass) > 8:
EEShellExec.cmd_exec(self, "wp --allow-root user update {0}"
" --user_pass={1}"
.format(ee_wp_user, ee_wp_pass))
Log.info(self, "Password updated successfully")
else:
Log.error(self, "Password Unchanged. Hint : Your password must be "
"8 characters long")
else:
Log.error(self, "Invalid WordPress user {0} for {1}."
.format(ee_wp_user, ee_domain))
示例10: uninstallwp_plugin
def uninstallwp_plugin(self, plugin_name, data):
ee_site_webroot = data['webroot']
Log.debug(self, "Uninstalling plugin {0}, please wait..."
.format(plugin_name))
EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
try:
EEShellExec.cmd_exec(self, "php /usr/bin/wp plugin "
"--allow-root uninstall "
"{0}".format(plugin_name))
except CommandExecutionError as e:
raise SiteError("plugin uninstall failed")
示例11: add
def add(self):
"""Swap addition with EasyEngine"""
if EEVariables.ee_ram < 512:
if EEVariables.ee_swap < 1000:
Log.info(self, "Adding SWAP")
EEShellExec.cmd_exec(self, "dd if=/dev/zero of=/ee-swapfile " "bs=1024 count=1048k")
EEShellExec.cmd_exec(self, "mkswap /ee-swapfile")
EEFileUtils.chown(self, "/ee-swapfile", "root", "root")
EEFileUtils.chmod(self, "/ee-swapfile", 0o600)
EEShellExec.cmd_exec(self, "swapon /ee-swapfile")
with open("/etc/fstab", encoding="utf-8", mode="a") as swap_file:
swap_file.write("/ee-swapfile\tnone\tswap\tsw\t0 0")
示例12: debug_php
def debug_php(self):
"""Start/Stop PHP debug"""
# PHP global debug start
if (self.app.pargs.php == 'on' and not self.app.pargs.site_name):
if not (EEShellExec.cmd_exec(self, "sed -n \"/upstream php"
"{/,/}/p \" /etc/nginx/"
"conf.d/upstream.conf "
"| grep 9001")):
Log.info(self, "Enabling PHP debug")
data = dict(php="9001", debug="9001", hhvm="9001")
Log.debug(self, 'Writting the Nginx debug configration to file'
' /etc/nginx/conf.d/upstream.conf ')
ee_nginx = open('/etc/nginx/conf.d/upstream.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'upstream.mustache', out=ee_nginx)
ee_nginx.close()
# Enable xdebug
EEFileUtils.searchreplace(self, "/etc/php5/mods-available/"
"xdebug.ini",
";zend_extension",
"zend_extension")
self.trigger_php = True
self.trigger_nginx = True
else:
Log.info(self, "PHP debug is already enabled")
self.msg = self.msg + ['/var/log/php5/slow.log']
# PHP global debug stop
elif (self.app.pargs.php == 'off' and not self.app.pargs.site_name):
if EEShellExec.cmd_exec(self, " sed -n \"/upstream php {/,/}/p\" "
"/etc/nginx/conf.d/upstream.conf "
"| grep 9001"):
Log.info(self, "Disabling PHP debug")
data = dict(php="9000", debug="9001", hhvm="8000")
Log.debug(self, 'Writting the Nginx debug configration to file'
' /etc/nginx/conf.d/upstream.conf ')
ee_nginx = open('/etc/nginx/conf.d/upstream.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'upstream.mustache', out=ee_nginx)
ee_nginx.close()
# Disable xdebug
EEFileUtils.searchreplace(self, "/etc/php5/mods-available/"
"xdebug.ini",
"zend_extension",
";zend_extension")
self.trigger_php = True
self.trigger_nginx = True
else:
Log.info(self, "PHP debug is already disabled")
示例13: sync
def sync(self):
"""
1. reads database information from wp/ee-config.php
2. updates records into ee database accordingly.
"""
Log.info(self, "Synchronizing ee database, please wait...")
sites = getAllsites(self)
if not sites:
pass
for site in sites:
if site.site_type in ['mysql', 'wp', 'wpsubdir', 'wpsubdomain']:
ee_site_webroot = site.site_path
# Read config files
configfiles = glob.glob(ee_site_webroot + '/*-config.php')
if configfiles:
if EEFileUtils.isexist(self, configfiles[0]):
ee_db_name = (EEFileUtils.grep(self, configfiles[0],
'DB_NAME').split(',')[1]
.split(')')[0].strip().replace('\'', ''))
ee_db_user = (EEFileUtils.grep(self, configfiles[0],
'DB_USER').split(',')[1]
.split(')')[0].strip().replace('\'', ''))
ee_db_pass = (EEFileUtils.grep(self, configfiles[0],
'DB_PASSWORD').split(',')[1]
.split(')')[0].strip().replace('\'', ''))
ee_db_host = (EEFileUtils.grep(self, configfiles[0],
'DB_HOST').split(',')[1]
.split(')')[0].strip().replace('\'', ''))
# Check if database really exist
try:
if not EEMysql.check_db_exists(self, ee_db_name):
# Mark it as deleted if not exist
ee_db_name = 'deleted'
ee_db_user = 'deleted'
ee_db_pass = 'deleted'
except StatementExcecutionError as e:
Log.debug(self, str(e))
except Exception as e:
Log.debug(self, str(e))
if site.db_name != ee_db_name:
# update records if any mismatch found
Log.debug(self, "Updating ee db record for {0}"
.format(site.sitename))
updateSiteInfo(self, site.sitename,
db_name=ee_db_name,
db_user=ee_db_user,
db_password=ee_db_pass,
db_host=ee_db_host)
示例14: setupwordpressnetwork
def setupwordpressnetwork(self, data):
ee_site_webroot = data['webroot']
EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
Log.info(self, "Setting up WordPress Network \t", end='')
try:
EEShellExec.cmd_exec(self, 'wp --allow-root core multisite-convert'
' --title=\'{0}\' {subdomains}'
.format(data['www_domain'],
subdomains='--subdomains'
if not data['wpsubdir'] else ''))
except CommandExecutionError as e:
Log.info(self, "[" + Log.ENDC + Log.FAIL + "Fail" + Log.OKBLUE + "]")
raise SiteError("setup wordpress network failed")
Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")
示例15: deleteWebRoot
def deleteWebRoot(self, webroot):
# do some preprocessing before proceeding
webroot = webroot.strip()
if webroot == "/var/www/" or webroot == "/var/www" or webroot == "/var/www/.." or webroot == "/var/www/.":
Log.debug(self, "Tried to remove {0}, but didn't remove it".format(webroot))
return False
if os.path.isdir(webroot):
Log.debug(self, "Removing {0}".format(webroot))
EEFileUtils.rm(self, webroot)
return True
else:
Log.debug(self, "{0} does not exist".format(webroot))
return False