Browse Source

replace shutil.chown with os.chown

bugfixes
harshadyeola 10 years ago
parent
commit
7994f0738e
  1. 108
      .travis.yml
  2. 5
      ee/cli/plugins/site_functions.py
  3. 29
      ee/cli/plugins/stack.py
  4. 5
      ee/core/addswap.py
  5. 18
      ee/core/fileutils.py

108
.travis.yml

@ -24,15 +24,12 @@ script:
- sudo ee stack install
- sudo ee stack install --web
- sudo ee stack install --admin
# - sudo ee site create html.com
- sudo ee site create html.net --html
- sudo ee site create php.com --php
- sudo ee site create mysql.com --mysql
- sudo ee site create site1.com --wp
- sudo ee site create site1.net --basic
- sudo ee site create site1.org --wp --basic
- sudo ee site create site1.in --basic --wp
- sudo ee site create subdomain.site1.in --basic --wp
- sudo ee site create site2.com --wpsc
- sudo ee site create site2.net --wp --wpsc
- sudo ee site create site2.org --wpsc --wp
@ -43,63 +40,44 @@ script:
- sudo ee site create site4.net --wp --wpfc
- sudo ee site create site4.org --wpfc --wp
- sudo ee site create site5.com --wpsubdir
# - sudo ee site create site5.net --wpsubdir
# - sudo ee site create site5.org --basic --wpsubdir
# - sudo ee site create site5.in --wpsubdirectory
# - sudo ee site create site5.co --wpsubdirectory --basic
# - sudo ee site create site5.co.in --basic --wpsubdirector
# - sudo ee site create site6.com --wpsubdir --wpsc
# - sudo ee site create site6.net --wpsc --wpsubdir
# - sudo ee site create site6.org --wpsubdirectory --wpsc
# - sudo ee site create site6.in --wpsc --wpsubdirectory
# - sudo ee site create site7.com --wpsubdir --w3tc
# - sudo ee site create site7.net --w3tc --wpsubdir
# - sudo ee site create site7.org --wpsubdirectory --w3tc
# - sudo ee site create site7.in --w3tc --wpsubdirectory
# - sudo ee site create site8.com --wpsubdir --wpfc
# - sudo ee site create site8.net --wpfc --wpsubdir
# - sudo ee site create site8.org --wpsubdirectory --wpfc
# - sudo ee site create site8.in --wpfc --wpsubdirectory
# - sudo ee site create site9.com --wpsubdom
# - sudo ee site create site9.net --wpsubdom --basic
# - sudo ee site create site9.org --basic --wpsubdom
# - sudo ee site create site9.in --wpsubdomain
# - sudo ee site create site9.co --wpsubdomain --basic
# - sudo ee site create site9.co.in --basic --wpsubdomain
# - sudo ee site create site10.com --wpsubdom --wpsc
# - sudo ee site create site10.net --wpsc --wpsubdom
# - sudo ee site create site10.org --wpsubdomain --wpsc
# - sudo ee site create site10.in --wpsc --wpsubdomain
# - sudo ee site create site11.com --wpsubdom --w3tc
# - sudo ee site create site11.net --w3tc --wpsubdom
# - sudo ee site create site11.org --wpsubdomain --w3tc
# - sudo ee site create site11.in --w3tc --wpsubdomain
# - sudo ee site create site12.com --wpsubdom --wpfc
# - sudo ee site create site12.net --wpfc --wpsubdom
# - sudo ee site create site12.org --wpsubdomain --wpfc
# - sudo ee site create site12.in --wpfc --wpsubdomain
#
# - sudo ee debug
# - sudo ee debug --stop
# - sudo ee site create 1.com --html
# - sudo ee site create 2.com --php
# - sudo ee site create 3.com --mysql
# - sudo ee site update 1.com --wp
# - sudo ee site update 2.com --wpsubdir
# - sudo ee site update 3.com --wpsubdomain
# - sudo ee site update site1.com --wp --wpfc
# - sudo ee site update site1.com --wp --w3tc
# - sudo ee site update site1.com --wp --wpsc
# - sudo ee site update site5.com --wpsubdir --wpfc
# - sudo ee site update site5.com --wpsubdir --w3tc
# - sudo ee site update site5.com --wpsubdir --wpsc
# - sudo ee site update site9.com --wpsubdom --wpfc
# - sudo ee site update site9.com --wpsubdom --w3tc
# - sudo ee site update site9.com --wpsubdom --wpsc
# - sudo ee site delete site12.com --no-prompt
# - sudo ee site delete site12.net --no-prompt
# - sudo ee site delete site12.org --no-prompt
#
# - sudo ee stack install --mail
# - sudo ls /var/www/
# - sudo wp --allow-root --info
- sudo ee site create site5.net --wpsubdir
- sudo ee site create site6.com --wpsubdir --wpsc
- sudo ee site create site6.net --wpsc --wpsubdir
- sudo ee site create site7.com --wpsubdir --w3tc
- sudo ee site create site7.net --w3tc --wpsubdir
- sudo ee site create site8.com --wpsubdir --wpfc
- sudo ee site create site8.net --wpfc --wpsubdir
- sudo ee site create site9.in --wpsubdomain
- sudo ee site create site10.org --wpsubdomain --wpsc
- sudo ee site create site10.in --wpsc --wpsubdomain
- sudo ee site create site11.org --wpsubdomain --w3tc
- sudo ee site create site11.in --w3tc --wpsubdomain
- sudo ee site create site12.org --wpsubdomain --wpfc
- sudo ee site create site12.in --wpfc --wpsubdomain
- sudo ee debug
- sudo ee debug --stop
- sudo ee site create 1.com --html
- sudo ee site create 2.com --php
- sudo ee site create 3.com --mysql
- sudo ee site update 1.com --wp
- sudo ee site update 2.com --wpsubdir
- sudo ee site update 3.com --wpsubdomain
- sudo ee site update site1.com --wp --wpfc
- sudo ee site update site1.com --wp --w3tc
- sudo ee site update site1.com --wp --wpsc
- sudo ee site update site5.com --wpsubdir --wpfc
- sudo ee site update site5.com --wpsubdir --w3tc
- sudo ee site update site5.com --wpsubdir --wpsc
- sudo ee site update site9.com --wpsubdom --wpfc
- sudo ee site update site9.com --wpsubdom --w3tc
- sudo ee site update site9.com --wpsubdom --wpsc
- sudo ee site delete site12.com --no-prompt
- sudo ee site delete site12.net --no-prompt
- sudo ee site delete site12.org --no-prompt
- sudo ee stack install --mail
- sudo ls /var/www/
- sudo wp --allow-root --info

5
ee/cli/plugins/site_functions.py

@ -11,6 +11,7 @@ import string
import sys
import getpass
import glob
import pwd
def setupdomain(self, data):
@ -308,8 +309,8 @@ def uninstallwp_plugin(self, plugin_name, data):
def setwebrootpermissions(self, webroot):
Log.debug(self, "Setting up permissions")
EEFileUtils.chown(self, webroot, EEVariables.ee_php_user,
EEVariables.ee_php_user, recursive=True)
EEFileUtils.chown(self, webroot, pwd.getpwnam(EEVariables.ee_php_user)[2],
pwd.getpwnam(EEVariables.ee_php_user)[3], recursive=True)
def sitebackup(self, data):

29
ee/cli/plugins/stack.py

@ -531,7 +531,9 @@ class EEStackController(CementBaseController):
Log.debug(self, "Setting Privileges to dovecot ")
# EEShellExec.cmd_exec(self, "chown -R vmail:vmail /var/lib"
# "/dovecot")
EEFileUtils.chown(self, "/var/lig/dovecot", "vmail", "vmail",
EEFileUtils.chown(self, "/var/lig/dovecot",
pwd.getpwnam('vmail')[2],
pwd.getpwnam('vmail')[3],
recursive=True)
EEShellExec.cmd_exec(self, "sievec /var/lib/dovecot/sieve/"
"default.sieve")
@ -598,8 +600,9 @@ class EEStackController(CementBaseController):
# EEShellExec.cmd_exec(self, 'chown -R www-data:www-data '
# '/var/www/22222/htdocs/db/pma')
EEFileUtils.chown(self, '/var/www/22222',
EEVariables.ee_php_user,
EEVariables.ee_php_user, recursive=True)
pwd.getpwnam(EEVariables.ee_php_user)[2],
pwd.getpwnam(EEVariables.ee_php_user)[3],
recursive=True)
if any('/tmp/memcache.tar.gz' == x[1]
for x in packages):
Log.debug(self, "Extracting memcache.tar.gz to location"
@ -611,8 +614,9 @@ class EEStackController(CementBaseController):
# EEShellExec.cmd_exec(self, 'chown -R www-data:www-data '
# '/var/www/22222/htdocs/cache/memcache')
EEFileUtils.chown(self, '/var/www/22222',
EEVariables.ee_php_user,
EEVariables.ee_php_user, recursive=True)
pwd.getpwnam(EEVariables.ee_php_user)[2],
pwd.getpwnam(EEVariables.ee_php_user)[3],
recursive=True)
if any('/tmp/webgrind.tar.gz' == x[1]
for x in packages):
@ -630,8 +634,9 @@ class EEStackController(CementBaseController):
# EEShellExec.cmd_exec(self, 'chown -R www-data:www-data '
# '/var/www/22222/htdocs/php/webgrind/')
EEFileUtils.chown(self, '/var/www/22222',
EEVariables.ee_php_user,
EEVariables.ee_php_user, recursive=True)
pwd.getpwnam(EEVariables.ee_php_user)[2],
pwd.getpwnam(EEVariables.ee_php_user)[3],
recursive=True)
if any('/tmp/anemometer.tar.gz' == x[1]
for x in packages):
@ -759,8 +764,9 @@ class EEStackController(CementBaseController):
"create")
EEFileUtils.chown(self, '/var/www/22222',
EEVariables.ee_php_user,
EEVariables.ee_php_user, recursive=True)
pwd.getpwnam(EEVariables.ee_php_user)[2],
pwd.getpwnam(EEVariables.ee_php_user)[3],
recursive=True)
# Copy Dovecot and Postfix templates which are depednet on
# Vimbadmin
@ -907,8 +913,9 @@ class EEStackController(CementBaseController):
EEFileUtils.remove(self, ["/var/www/roundcubemail"
"/htdocs/installer"])
EEFileUtils.chown(self, '/var/www/roundcubemail',
EEVariables.ee_php_user,
EEVariables.ee_php_user, recursive=True)
pwd.getpwnam(EEVariables.ee_php_user)[2],
pwd.getpwnam(EEVariables.ee_php_user)[3],
recursive=True)
@expose(help="Install packages")
def install(self, packages=[], apt_packages=[], disp_msg=True):

5
ee/core/addswap.py

@ -3,6 +3,7 @@ from ee.core.variables import EEVariables
from ee.core.shellexec import EEShellExec
from ee.core.fileutils import EEFileUtils
from ee.core.logging import Log
import pwd
class EESwap():
@ -19,7 +20,9 @@ class EESwap():
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.chown(self, "/ee-swapfile",
pwd.getpwnam("root")[2],
pwd.getpwnam("root")[3])
EEFileUtils.chmod(self, "/ee-swapfile", 0o600)
EEShellExec.cmd_exec(self, "swapon /ee-swapfile")
with open("/etc/fstab", "a") as swap_file:

18
ee/core/fileutils.py

@ -18,13 +18,15 @@ class EEFileUtils():
if os.path.isfile(file):
Log.info(self, "Removing {0:65}".format(file), end=' ')
os.remove(file)
Log.info(self, "{0}".format("[" + Log.ENDC + "Done" + Log.OKBLUE + "]"))
Log.info(self, "{0}".format("[" + Log.ENDC + "Done" +
Log.OKBLUE + "]"))
Log.debug(self, 'file Removed')
if os.path.isdir(file):
try:
Log.info(self, "Removing {0:65}".format(file), end=' ')
shutil.rmtree(file)
Log.info(self, "{0}".format("[" + Log.ENDC + "Done" + Log.OKBLUE + "]"))
Log.info(self, "{0}".format("[" + Log.ENDC + "Done" +
Log.OKBLUE + "]"))
except shutil.Error as e:
Log.debug(self, "{err}".format(err=str(e.reason)))
Log.error(self, 'Unable to Remove file ')
@ -85,18 +87,18 @@ class EEFileUtils():
Log.debug(self, "{err}".format(err=e.strerror))
Log.error(self, 'Unable to Change Directory {0}'.format(path))
def chown(self, path, user, group, recursive=False):
def chown(self, path, userid, groupid, recursive=False):
try:
if recursive:
for root, dirs, files in os.walk(path):
for d in dirs:
shutil.chown(os.path.join(root, d), user=user,
group=group)
os.chown(os.path.join(root, d), userid,
groupid)
for f in files:
shutil.chown(os.path.join(root, f), user=user,
group=group)
os.chown(os.path.join(root, f), userid,
groupid)
else:
shutil.chown(path, user=user, group=group)
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))

Loading…
Cancel
Save