本文整理汇总了Python中ovd.Platform.System.System.execute方法的典型用法代码示例。如果您正苦于以下问题:Python System.execute方法的具体用法?Python System.execute怎么用?Python System.execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ovd.Platform.System.System
的用法示例。
在下文中一共展示了System.execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
# 需要导入模块: from ovd.Platform.System import System [as 别名]
# 或者: from ovd.Platform.System.System import execute [as 别名]
def create(self, password):
cmd = "useradd -d /dev/null -s /bin/false -G %s,%s %s"%(Config.group, "sambashare", self.login)
p = System.execute(cmd)
if p.returncode == 9:
Logger.warn("FS: unable to create user: already exists")
return False
elif p.returncode != 0:
Logger.error("FS: unable to create user")
Logger.debug("FS: command '%s' return %d: %s"%(cmd, p.returncode, p.stdout.read().decode("UTF-8")))
return False
cmd = 'smbpasswd -s -a %s'%(self.login)
p = System.execute(cmd, wait = False)
p.stdin.write("%s\n%s\n"%(password, password))
p.wait()
if p.returncode != 0:
Logger.error("FS: unable to set samba password")
Logger.debug("FS: command '%s' return %d: %s"%(cmd, p.returncode, p.stdout.read().decode("UTF-8")))
return False
cmd = 'htpasswd -b %s "%s" "%s"'%(Config.dav_passwd_file, self.login, password)
p = System.execute(cmd)
if p.returncode != 0:
Logger.error("FS: unable to update apache auth file")
Logger.debug("FS: command '%s' return %d: %s"%(cmd, p.returncode, p.stdout.read().decode("UTF-8")))
return False
return True
示例2: destroy
# 需要导入模块: from ovd.Platform.System import System [as 别名]
# 或者: from ovd.Platform.System.System import execute [as 别名]
def destroy(self):
ret = True
cmd = 'htpasswd -D %s "%s"'%(Config.dav_passwd_file, self.login)
p = System.execute(cmd)
if p.returncode != 0:
Logger.error("FS: unable to update apache auth file")
Logger.debug("FS: command '%s' return %d: %s"%(cmd, p.returncode, p.stdout.read().decode("UTF-8")))
return False
cmd = 'smbpasswd -x %s'%(self.login)
p = System.execute(cmd)
if p.returncode != 0:
Logger.error("FS: unable to del smb password")
Logger.debug("FS: command '%s' return %d: %s"%(cmd, p.returncode, p.stdout.read().decode("UTF-8")))
ret = False
cmd = "userdel -f %s"%(self.login)
p = System.execute(cmd)
if p.returncode != 0:
Logger.error("FS: unable to del user")
Logger.debug("FS: command '%s' return %d: %s"%(cmd, p.returncode, p.stdout.read().decode("UTF-8")))
ret = False
return ret
示例3: perform
# 需要导入模块: from ovd.Platform.System import System [as 别名]
# 或者: from ovd.Platform.System.System import execute [as 别名]
def perform(self):
os.mkdir(self.directory)
f_stdout = open(os.path.join(self.directory, "stdout"), "w")
f_stderr = open(os.path.join(self.directory, "stderr"), "w")
process_out = {"stdout": f_stdout, "stderr": f_stderr}
p = System.execute(["apt-get", "update"], True, {}, process_out)
if p.returncode != 0:
f_stdout.close()
f_stderr.close()
return False
apt_env = {"DEBIAN_FRONTEND": "noninteractive", "DEBIAN_PRIORITY": "critical", "DEBCONF_NONINTERACTIVE_SEEN": "true"}
command = ["apt-get", "--yes", "--force-yes", "--option", "DPkg::Options::=--force-confold"]
if self.order == "upgrade":
command.append("dist-upgrade")
elif self.order == "install":
command.append("install")
elif self.order == "remove":
command.append("autoremove")
command.append("--purge")
if self.order in ["install", "remove"]:
command.extend(self.packages)
p = System.execute(command, True, apt_env, process_out)
if p.returncode != 0:
f_stdout.close()
f_stderr.close()
return False
f_stdout.close()
f_stderr.close()
return True
示例4: check_remaining_mount_points
# 需要导入模块: from ovd.Platform.System import System [as 别名]
# 或者: from ovd.Platform.System.System import execute [as 别名]
def check_remaining_mount_points(self):
try:
user = pwd.getpwnam(System.local_encode(self.name))
except KeyError:
return False
mount_points = MountPoint.get_list(user.pw_dir)
if mount_points is None:
return False
success = True
for d in mount_points:
path = System.local_encode(d)
Logger.warn("Remaining mount point '%s'"%(path))
cmd = 'umount "%s"'%(path)
p = System.execute(cmd)
if p.returncode == 0:
continue
Logger.warn("Unable to unmount remaining mount point %s: force the unmount"%(path))
Logger.debug('umount command "%s" return: %s'%(cmd, p.stdout.read()))
cmd = 'umount -l "%s"'%(path)
p = System.execute(cmd)
if p.returncode != 0:
Logger.error("Unable to force the unmount remaining mount point %s"%(path))
Logger.debug('umount command "%s" return: %s'%(cmd, p.stdout.read()))
success = False
if success == False:
Logger.error("Unable to unmount remaining mount point, home dir %s won't be purged"%(user.pw_dir))
return success
示例5: do_right_normalization
# 需要导入模块: from ovd.Platform.System import System [as 别名]
# 或者: from ovd.Platform.System.System import execute [as 别名]
def do_right_normalization(self):
cmd = 'chown -R %s:%s "%s"'%(Config.uid, Config.gid, self.directory)
p = System.execute(cmd)
if p.returncode is not 0:
Logger.debug("FS: following command '%s' returned %d => %s"%(cmd, p.returncode, p.stdout.read()))
cmd = 'chmod -R u=rwX,g=rwX,o-rwx "%s"'%(self.directory)
p = System.execute(cmd)
if p.returncode is not 0:
Logger.debug("FS: following command '%s' returned %d => %s"%(cmd, p.returncode, p.stdout.read()))
示例6: cleanup_repository
# 需要导入模块: from ovd.Platform.System import System [as 别名]
# 或者: from ovd.Platform.System.System import execute [as 别名]
def cleanup_repository(self):
cmd = 'chown -R %s:%s "%s"'%(Config.uid, Config.gid, Config.backendSpool)
p = System.execute(cmd)
if p.returncode is not 0:
Logger.debug("FS: following command '%s' returned %d => %s"%(cmd, p.returncode, p.stdout.read()))
return False
cmd = 'chmod -R u=rwX,g=rwX,o-rwx "%s"'%(Config.backendSpool)
p = System.execute(cmd)
if p.returncode is not 0:
Logger.debug("FS: following command '%s' returned %d => %s"%(cmd, p.returncode, p.stdout.read()))
return False
return True
示例7: copySessionStart
# 需要导入模块: from ovd.Platform.System import System [as 别名]
# 或者: from ovd.Platform.System.System import execute [as 别名]
def copySessionStart(self):
profile_tmp_dir = os.path.join(Profile.TEMPORARY_PROFILE_PATH, self.session.user.name)
if os.path.exists(profile_tmp_dir):
System.rchown(profile_tmp_dir, self.session.user.name)
if self.homeDir is None or not os.path.isdir(self.homeDir):
return
d = os.path.join(self.profile_mount_point, "conf.Linux")
if not System.mount_point_exist(d):
return
if self.profile["profile_mode"] == "advanced":
return
# Copy conf files
d = self.transformToLocaleEncoding(d)
cmd = self.getRsyncMethod(d, self.homeDir, Config.profile_filters_filename, True)
Logger.debug("rsync cmd '%s'" % (cmd))
p = System.execute(cmd)
if p.returncode is not 0:
Logger.error("Unable to copy conf from profile")
Logger.debug(
"Unable to copy conf from profile, cmd '%s' return %d: %s" % (cmd, p.returncode, p.stdout.read())
)
示例8: existSomeWhere
# 需要导入模块: from ovd.Platform.System import System [as 别名]
# 或者: from ovd.Platform.System.System import execute [as 别名]
def existSomeWhere(self):
try:
pwd.getpwnam(self.login)
return True
except:
pass
cmd = "smbpasswd -e %s"%(self.login)
p = System.execute(cmd)
if p.returncode == 0:
return True
accessOK = False
try:
f = file(Config.dav_passwd_file, "r")
accessOK = True
except:
pass
if accessOK:
lines = f.readlines()
f.close
for line in lines:
if line.startswith(self.login+":"):
return True
return False
示例9: del_user
# 需要导入模块: from ovd.Platform.System import System [as 别名]
# 或者: from ovd.Platform.System.System import execute [as 别名]
def del_user(self, user):
if user not in self.ro_users and user not in self.rw_users:
return True
ret = True
if user in self.ro_users:
cmd = "deluser %s %s_ro"%(user, self.group)
else:
cmd = "deluser %s %s_rw"%(user, self.group)
p = System.execute(cmd)
if p.returncode is not 0:
ret = False
Logger.error("FS: unable to del user in group")
Logger.debug("FS: command '%s' return %d: %s"%(cmd, p.returncode, p.stdout.read().decode("UTF-8")))
htgroup = HTGroup(Config.dav_group_file)
if user in self.ro_users:
self.ro_users.remove(user)
htgroup.delete(user, self.group+"_ro")
if user in self.rw_users:
self.rw_users.remove(user)
htgroup.delete(user, self.group+"_rw")
if (len(self.ro_users) + len(self.rw_users)) == 0:
return self.disable()
return True
示例10: destroy
# 需要导入模块: from ovd.Platform.System import System [as 别名]
# 或者: from ovd.Platform.System.System import execute [as 别名]
def destroy(self):
lock = FileLock("/tmp/user.lock")
arg_remove = ""
if self.check_remaining_mount_points():
arg_remove = "--remove"
cmd = "userdel --force %s %s"%(arg_remove, System.local_encode(self.name))
retry = 5
while retry !=0:
lock.acquire()
p = System.execute(cmd)
lock.release()
if p.returncode == 0:
return True
if p.returncode == 12:
Logger.debug("mail dir error: '%s' return %d => %s"%(str(cmd), p.returncode, p.stdout.read()))
return True
Logger.debug("User delete of %s: retry %i"%(self.name, 6-retry))
if p.returncode == 1 or p.returncode == 10: # an other process is creating a user
Logger.debug("An other process is creating a user")
retry -=1
time.sleep(0.2)
continue
if p.returncode != 0:
Logger.error("userdel return %d (%s)"%(p.returncode, p.stdout.read()))
return False
return True
示例11: mount_cifs
# 需要导入模块: from ovd.Platform.System import System [as 别名]
# 或者: from ovd.Platform.System.System import execute [as 别名]
def mount_cifs(self, share, uri, dest):
mount_env = {}
if share.has_key("login") and share.has_key("password"):
cmd = "mount -t cifs -o 'uid=%s,gid=0,%s,iocharset=utf8' //%s%s %s" % (
self.session.user.name,
self.DEFAULT_PERMISSION,
uri.netloc,
uri.path,
dest,
)
mount_env["USER"] = share["login"]
mount_env["PASSWD"] = share["password"]
else:
cmd = "mount -t cifs -o 'guest,uid=%s,gid=0,%s,iocharset=utf8' //%s%s %s" % (
self.session.user.name,
self.DEFAULT_PERMISSION,
uri.netloc,
uri.path,
dest,
)
cmd = self.transformToLocaleEncoding(cmd)
Logger.debug("Profile, share mount command: '%s'" % (cmd))
p = System.execute(cmd, env=mount_env)
if p.returncode != 0:
Logger.debug("CIFS mount failed (status: %d) => %s" % (p.returncode, p.stdout.read()))
return False
return True
示例12: getIcon
# 需要导入模块: from ovd.Platform.System import System [as 别名]
# 或者: from ovd.Platform.System.System import execute [as 别名]
def getIcon(self, filename):
Logger.debug("ApplicationsDetection::getIcon %s"%(filename))
try:
entry = xdg.DesktopEntry.DesktopEntry(filename)
except xdg.Exceptions.Error as detail:
Logger.warn("ApplicationsDetection::getIcon %s" % detail)
return None
iconName = entry.getIcon()
if entry.getIcon() == u'':
# icon field is not required for type=Application
return None
iconPath = xdg.IconTheme.getIconPath(iconName, size = 32, theme=Config.linux_icon_theme, extensions = ["png", "xpm"])
if iconPath == None:
return None
bufFile = tempfile.mktemp(".png")
cmd = 'convert -resize 32x32 "%s" "%s"'%(iconPath, bufFile)
p = System.execute(cmd)
if p.returncode != 0:
Logger.debug("getIcon cmd '%s' returned (%d): %s"%(cmd, p.returncode, p.stdout.read()))
Logger.error("getIcon: imagemagick error")
if os.path.exists(bufFile):
os.remove(bufFile)
return None
try:
f = file(bufFile, "r")
except IOError, err:
Logger.error("ApplicationsDetection::getIcon finale icon file '%s' does not exists"%(bufFile))
return None
示例13: create
# 需要导入模块: from ovd.Platform.System import System [as 别名]
# 或者: from ovd.Platform.System.System import execute [as 别名]
def create(self):
lock = FileLock("/tmp/user.lock")
# TODO get the default home in /etc/default/useradd
default_home_dir = os.path.join(u"/home", self.name)
home_dir = default_home_dir
i = 0
while os.path.exists(home_dir) and i < 100:
home_dir = default_home_dir+"_%d"%(i)
i+= 1
if i > 0:
Logger.warn("Unable to create home directory %s, the home is now %s"%(default_home_dir, home_dir))
if os.path.exists(home_dir):
Logger.error("Unable to find a valid home directory")
return False
cmd = u"useradd -m -d '%s' -k '%s'"%(home_dir, Config.linux_skel_directory)
if self.infos.has_key("displayName"):
cmd+= u""" --comment "%s,,," """%(self.infos["displayName"].replace('"', ""))
groups = ["video", "audio", "pulse", "pulse-access", Config.linux_fuse_group]
if self.infos.has_key("groups"):
groups+= self.infos["groups"]
cmd+= u" --groups %s"%(",".join(groups))
cmd+= u" "+self.name
retry = 5
while retry !=0:
if retry < 0:
Logger.error("ERROR: unable to add a new user")
lock.acquire()
p = System.execute(System.local_encode(cmd))
lock.release()
if p.returncode == 0:
break
Logger.debug("Add user :retry %i"%(6-retry))
if p.returncode == 9: # user already exist
Logger.error("User %s already exist"%(self.name))
break;
if p.returncode == 1: # an other process is creating a user
Logger.error("An other process is creating a user")
retry -=1
time.sleep(0.2)
continue
if p.returncode != 0:
Logger.error("UserAdd return %d (%s)"%(p.returncode, p.stdout.read()))
return False
if self.infos.has_key("password"):
if not self.set_password():
return False
return self.post_create()
示例14: clean
# 需要导入模块: from ovd.Platform.System import System [as 别名]
# 或者: from ovd.Platform.System.System import execute [as 别名]
def clean(self):
cmd = 'htpasswd -D %s "%s"'%(Config.dav_passwd_file, self.login)
p = System.execute(cmd)
if p.returncode != 0:
Logger.warn("FS: unable to remove user %s in 'clean' process"%(self.login))
Logger.debug("FS: command '%s' return %d: %s"%(cmd, p.returncode, p.stdout.read().decode("UTF-8")))
cmd = 'smbpasswd -x %s'%(self.login)
p = System.execute(cmd)
if p.returncode != 0:
Logger.warn("FS: unable to remove user %s in 'clean' process"%(self.login))
Logger.debug("FS: command '%s' return %d: %s"%(cmd, p.returncode, p.stdout.read().decode("UTF-8")))
cmd = "userdel -f %s"%(self.login)
p = System.execute(cmd)
if p.returncode != 0:
Logger.warn("FS: unable to remove user %s in 'clean' process"%(self.login))
Logger.debug("FS: command '%s' return %d: %s"%(cmd, p.returncode, p.stdout.read().decode("UTF-8")))
示例15: delete
# 需要导入模块: from ovd.Platform.System import System [as 别名]
# 或者: from ovd.Platform.System.System import execute [as 别名]
def delete(self):
cmd = "rm -rf %s"%(self.directory)
p = System.execute(cmd)
if p.returncode is not 0:
Logger.error("FS: unable to del share")
Logger.debug("FS: command '%s' return %d: %s"%(cmd, p.returncode, p.stdout.read().decode("UTF-8")))
return False
return True