本文整理汇总了Python中WebappConfig.debug.OUT.die方法的典型用法代码示例。如果您正苦于以下问题:Python OUT.die方法的具体用法?Python OUT.die怎么用?Python OUT.die使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WebappConfig.debug.OUT
的用法示例。
在下文中一共展示了OUT.die方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dirisconfigprotected
# 需要导入模块: from WebappConfig.debug import OUT [as 别名]
# 或者: from WebappConfig.debug.OUT import die [as 别名]
def dirisconfigprotected(self, installdir):
'''
Traverses the path of parent directories for the
given install dir and checks if any matches the list
of config protected files.
>>> a = Protection('','horde','3.0.5','portage')
Add a virtual config protected directory:
>>> a.config_protect += ' /my/strange/htdocs/'
>>> a.dirisconfigprotected('/my/strange/htdocs/where/i/installed/x')
True
>>> a.dirisconfigprotected('/my/strange/htdocs/where/i/installed/x/')
True
>>> a.config_protect += ' /my/strange/htdocs'
>>> a.dirisconfigprotected('/my/strange/htdocs/where/i/installed/x')
True
>>> a.dirisconfigprotected('/my/strange/htdocs/where/i/installed/x/')
True
>>> a.config_protect += ' bad_user /my/strange/htdocs'
>>> a.dirisconfigprotected('/my/bad_user/htdocs/where/i/installed/x')
False
>>> a.dirisconfigprotected('/my/strange/htdocs/where/i/installed/x/')
True
>>> a.dirisconfigprotected('/')
False
'''
my_master = []
for i in self.config_protect.split(' '):
if i[0] == '/':
if i[-1] == '/':
my_master.append(i[:-1])
else:
my_master.append(i)
if installdir[0] != '/':
OUT.die('BUG! Don\'t call this with a relative path.')
if installdir[-1] == '/':
my_dir = installdir[:-1]
else:
my_dir = installdir
while my_dir:
if my_dir == '.' or my_dir == '/':
return False
for x in my_master:
if my_dir == x:
return True
my_dir = os.path.dirname(my_dir)
# nope, the directory isn't config-protected at this time
return False
示例2: get_root
# 需要导入模块: from WebappConfig.debug import OUT [as 别名]
# 或者: from WebappConfig.debug.OUT import die [as 别名]
def get_root(config):
'''Returns the $ROOT variable'''
if config.config.get('USER', 'package_manager') == "portage":
try:
import portage
except ImportError as e:
OUT.die("Portage libraries not found, quitting:\n%s" % e)
return portage.settings['ROOT']
elif config.config.get('USER', 'package_manager') == "paludis":
cat = config.maybe_get('cat')
pn = config.maybe_get('pn')
if cat and pn:
cmd="cave print-id-environment-variable -b --format '%%v\n' --variable-name ROOT %s/%s" % (cat,pn)
fi, fo, fe = os.popen3(cmd)
fi.close()
result_lines = fo.readlines()
fo.close()
fe.close()
if result_lines[0].strip():
return result_lines[0].strip()
else:
return '/'
else:
return '/'
else:
OUT.die("Unknown package manager: " + pm)
示例3: write
# 需要导入模块: from WebappConfig.debug import OUT [as 别名]
# 或者: from WebappConfig.debug.OUT import die [as 别名]
def write(self):
'''
Write the contents file.
'''
dbpath = self.appdb()
if not dbpath:
OUT.die('No package specified!')
self.check_installdir()
values = [' '.join(i) for i in list(self.__content.values())]
if not self.__p:
try:
fd = os.open(self.appdb(), os.O_WRONLY | os.O_CREAT,
self.__perm(0o600))
os.write(fd, ('\n'.join(values)).encode('utf-8'))
os.close(fd)
except Exception as e:
OUT.warn('Failed to write content file ' + dbpath + '!\n'
+ 'Error was: ' + str(e))
else:
OUT.info('Would have written content file ' + dbpath + '!')
示例4: listinstalls
# 需要导入模块: from WebappConfig.debug import OUT [as 别名]
# 或者: from WebappConfig.debug.OUT import die [as 别名]
def listinstalls(self):
'''
Outputs a list of what has been installed so far.
'''
loc = self.read_db()
if not loc and self.__v:
OUT.die('No virtual installs found!')
keys = sorted(loc)
for j in keys:
# The verbose output is meant to be readable for the user
if self.__v:
OUT.info('Installs for ' + '-'.join(j.split('/')), 4)
for i in loc[j]:
if self.__v:
# The verbose output is meant to be readable for
# the user
OUT.info(' ' + i[3].strip(), 1)
else:
# This is a simplified form for the webapp.eclass
print(i[3].strip())
示例5: listunused
# 需要导入模块: from WebappConfig.debug import OUT [as 别名]
# 或者: from WebappConfig.debug.OUT import die [as 别名]
def listunused(self, db):
'''
Outputs a list of what has not been installed so far
'''
packages = self.list_locations()
if not packages:
OUT.die('No packages found!')
keys = sorted(packages)
OUT.debug('Check for unused web applications', 7)
for i in keys:
db.set_category(packages[i][0])
db.set_package (packages[i][1])
db.set_version (packages[i][2])
if not db.has_installs():
if packages[i][0]:
OUT.notice(packages[i][0] + '/' + packages[i][1] + '-' + packages[i][2])
else:
OUT.notice(packages[i][1] + '-' + packages[i][2])
示例6: create_module
# 需要导入模块: from WebappConfig.debug import OUT [as 别名]
# 或者: from WebappConfig.debug.OUT import die [as 别名]
def create_module(self, package_version, vhost_root, server_files, server_dirs):
temp_dir = tempfile.mkdtemp()
OUT.info('Creating SELinux modules')
cleaned_version = re.match(r'(?P<version>[0-9]*\.[0-9]*(?:\.[0-9]*)?)', package_version).group('version')
for policy in self.policy_types:
base_dir = os.path.join(temp_dir, policy)
os.mkdir(base_dir)
with open(os.path.join(base_dir, '{}.te'.format(self.policy_name)), 'w') as te_file:
te_file.write('policy_module({},{})\n'.format(self.policy_name, cleaned_version))
te_file.write('require {\n')
te_file.write(' type httpd_sys_rw_content_t;\n')
te_file.write('}')
with open(os.path.join(base_dir, '{}.fc'.format(self.policy_name)), 'w') as fc_file:
for files in server_files:
fc_file.write('{} gen_context(system_u:object_r:httpd_sys_rw_content_t,s0)\n'.format(SELinux.filename_re_escape(os.path.join(vhost_root, files.rstrip('\n')))))
for dirs in server_dirs:
fc_file.write('{}(/.*)? gen_context(system_u:object_r:httpd_sys_rw_content_t,s0)\n'.format(SELinux.filename_re_escape(os.path.join(vhost_root, dirs.rstrip('\n')))))
if subprocess.call(['make', '-s', '-C', base_dir, '-f', os.path.join('/usr/share/selinux', policy, 'include/Makefile'), '{}.pp'.format(self.policy_name)]):
if not os.path.isfile(os.path.join('/usr/share/selinux', policy, 'include/Makefile')):
OUT.die('Policy {} is not supported, please fix your configuration'.format(policy))
OUT.die('Unable to create {} SELinux module for {} @ {}'.format(policy, self.package_name, self.vhost_hostname))
OUT.info('Installing SELinux modules')
try:
for policy in self.policy_types:
if subprocess.call(['semodule', '-s', policy, '-i', os.path.join(temp_dir, policy, '{}.pp'.format(self.policy_name))]):
OUT.die('Unable to install {} SELinux module for {} @ {}'.format(policy, self.package_name, self.vhost_hostname))
except IOError:
OUT.die('"semodule" was not found, please check you SELinux installation')
shutil.rmtree(temp_dir)
示例7: want_category
# 需要导入模块: from WebappConfig.debug import OUT [as 别名]
# 或者: from WebappConfig.debug.OUT import die [as 别名]
def want_category(config):
'''Check if the package manager requires category info
Portage: optional
Paludis: mandatory
'''
if config.config.get('USER', 'package_manager') == "portage":
return
elif config.config.get('USER', 'package_manager') == "paludis":
if not config.config.has_option('USER', 'cat'):
OUT.die("Package name must be in the form CAT/PN")
else:
OUT.die("Unknown package manager: " + pm)
示例8: __init__
# 需要导入模块: from WebappConfig.debug import OUT [as 别名]
# 或者: from WebappConfig.debug.OUT import die [as 别名]
def __init__(self,
config_owned,
server_owned,
server_owned_r,
virtual_files = 'virtual',
default_dirs = 'default-owned'):
'''
Populates the cache with the file types as provided by the
ebuild.
'''
self.__cache = {}
# Validity of entries are checked by the command line parser
self.__virtual_files = virtual_files
self.__default_dirs = default_dirs
# populate cache
for i in config_owned:
OUT.debug('Adding config-owned file', 8)
self.__cache[self.__fix(i)] = 'config-owned'
for i in server_owned:
if self.__fix(i) in self.__cache.keys():
OUT.debug('Adding config-server-owned file', 8)
self.__cache[self.__fix(i)] = 'config-server-owned'
else:
OUT.debug('Adding server-owned file', 8)
self.__cache[self.__fix(i)] = 'server-owned'
for i in server_owned_r:
if self.__fix(i) in self.__cache.keys():
OUT.die('{} is a the same time recursively server-owned and {}: This case is not supported.'.format(self.__fix(i), self.__cache[self.__fix(i)]))
else :
OUT.debug('Adding recursively server-owned file', 8)
self.__cache[self.__fix(i).strip()] = 'server-owned-dir'
示例9: write
# 需要导入模块: from WebappConfig.debug import OUT [as 别名]
# 或者: from WebappConfig.debug.OUT import die [as 别名]
def write(self,
category,
package,
version,
host,
original_installdir,
user_group):
'''
Output the .webapp file, that tells us in future what has been installed
into this directory.
'''
self.__data['WEB_CATEGORY'] = category
self.__data['WEB_PN'] = package
self.__data['WEB_PVR'] = version
self.__data['WEB_INSTALLEDBY'] = pwd.getpwuid(os.getuid())[0]
self.__data['WEB_INSTALLEDDATE'] = strftime('%Y-%m-%d %H:%M:%S')
self.__data['WEB_INSTALLEDFOR'] = user_group
self.__data['WEB_HOSTNAME'] = host
self.__data['WEB_INSTALLDIR'] = original_installdir
info = ['# ' + self.__file,
'# config file for this copy of '
+ package + '-' + version,
'#',
'# automatically created by Gentoo\'s webapp-config',
'# do NOT edit this file by hand',
'',]
for i in self.__tokens:
info.append(i + '="' + self.__data[i] + '"')
if not self.__p:
try:
fd = os.open(self.__dot_config(),
os.O_WRONLY | os.O_CREAT,
self.__perm(0o600))
os.write(fd, ('\n'.join(info)).encode('utf-8'))
os.close(fd)
except Exception as e:
OUT.die('Unable to write to ' + self.__dot_config()
+ '\nError was: ' + str(e))
else:
OUT.info('Would have written the following information into '
+ self.__dot_config() + ':\n' + '\n'.join(info))
示例10: show_installed
# 需要导入模块: from WebappConfig.debug import OUT [as 别名]
# 或者: from WebappConfig.debug.OUT import die [as 别名]
def show_installed(self):
''' Show which application has been installed in the install
location.'''
if not self.has_dotconfig():
OUT.die('No ' + self.__file + ' file in ' + self.__instdir
+ '; unable to continue')
self.read()
if 'WEB_CATEGORY' in self.__data:
OUT.notice(self.__data['WEB_CATEGORY'] + ' ' +
self.__data['WEB_PN'] + ' ' +
self.__data['WEB_PVR'])
else:
OUT.notice(
self.__data['WEB_PN'] + ' ' +
self.__data['WEB_PVR'])
示例11: dirtype
# 需要导入模块: from WebappConfig.debug import OUT [as 别名]
# 或者: from WebappConfig.debug.OUT import die [as 别名]
def dirtype(self, directory, parent_type = ''):
'''
Inputs:
directory - the directory that we need a decision about
parent_type - the type of the parent directory
returns one of these:
server-owned - dir needs to be owned by the webserver user
config-owned - dir needs to be owned by the config user
config-server-owned - Both the previous cases at the same time
server-owned-dir - Directory that contains file/dirs to be owned
by the webserver user
default-owned - we need a local copy, owned by root
NOTE:
Use get_filetype(filename) for files
NOTE:
the user can use --default-dirs on the command-line to change
what type default directories are really reported as
'''
# remove any whitespace and trailing /
directory = self.__fix(directory)
# check the cache
if directory in self.__cache.keys():
# Check if parent type is recursive
if parent_type == 'server-owned-dir':
new_type = self.__cache[directory]
if new_type == 'config-owned':
OUT.die('This version does not support config dirs')
if new_type == server-owned:
OUT.warn('Configuration error: {} is marked server-owned two times'.format(filename))
return 'server-owned-dir'
return self.__cache[directory]
# Check if parent type is recursive
if parent_type == 'server-owned-dir':
return 'server-owned-dir'
# unspecified directories are default-owned
return self.__default_dirs
示例12: package_installed
# 需要导入模块: from WebappConfig.debug import OUT [as 别名]
# 或者: from WebappConfig.debug.OUT import die [as 别名]
def package_installed(full_name, pm):
'''
This function identifies installed packages.
The Portage part is stolen from gentoolkit.
We are not using gentoolkit directly as it doesn't seem to support ${ROOT}
'''
if pm == "portage":
try:
import portage
except ImportError as e:
OUT.die("Portage libraries not found, quitting:\n%s" % e)
try:
t = portage.db[portage.root]["vartree"].dbapi.match(full_name)
# catch the "ambiguous package" Exception
except ValueError as e:
if isinstance(e[0], list):
t = []
for cp in e[0]:
t += portage.db[portage.root]["vartree"].dbapi.match(cp)
else:
raise ValueError(e)
return t
elif pm == "paludis":
cmd="cave print-best-version '%s'" % (full_name)
fi, fo, fe = os.popen3(cmd)
fi.close()
result_lines = fo.readlines()
error_lines = fe.readlines()
fo.close()
fe.close()
if error_lines:
for i in error_lines:
OUT.warn(i)
return ' '.join(result_lines)
else:
OUT.die("Unknown package manager: " + pm)
示例13: __init__
# 需要导入模块: from WebappConfig.debug import OUT [as 别名]
# 或者: from WebappConfig.debug.OUT import die [as 别名]
def __init__(self, package_name, vhost_hostname, policy_types = ()):
self.package_name = package_name
self.vhost_hostname = vhost_hostname
self.policy_name = '{}_{}'.format(package_name, vhost_hostname)
self.policy_types = policy_types
if self.policy_types is ():
for filename in MAKE_CONF_FILE:
try:
with open(filename) as file:
for line in file.readlines():
if line.startswith('POLICY_TYPES='):
self.policy_types = line[len('POLICY_TYPES='):-1].strip(' "').split()
break
if self.policy_types is not None:
break
except IOError:
pass
if self.policy_types is ():
OUT.die('No SELinux policy was found, abording')
示例14: reportpackageavail
# 需要导入模块: from WebappConfig.debug import OUT [as 别名]
# 或者: from WebappConfig.debug.OUT import die [as 别名]
def reportpackageavail(self):
'''
This is a simple wrapper around packageavail() that outputs
user-friendly error messages if an error occurs
Cannot test the rest, do not want to die.
'''
OUT.info('Do we have ' + self.package_name() + ' available?')
available = self.packageavail()
if available == 0:
OUT.info(' Yes, we do')
if available == 1:
OUT.die(' Please emerge ' + self.package_name() + ' first.')
if available == 3:
OUT.die(' ' + self.package_name() + ' is not compatible with '
'webapp-config.\nIf it should be, report this at '
+ wrapper.bugs_link)
示例15: __init__
# 需要导入模块: from WebappConfig.debug import OUT [as 别名]
# 或者: from WebappConfig.debug.OUT import die [as 别名]
def __init__(self,
fs_root,
root,
category = '',
package = '',
version = '',
dbfile = 'installs'):
self.__r = fs_root
self.root = self.__r + root
self.root = re.compile('/+').sub('/', self.root)
if not os.path.isdir(self.root):
OUT.die('"' + self.root + '" specifies no directory! webapp'
'-config needs a valid directory to store/retrieve in'
'formation. Please correct your settings.')
self.category = category
self.pn = package
self.pvr = version
self.dbfile = dbfile