本文整理汇总了Python中WebappConfig.debug.OUT.info方法的典型用法代码示例。如果您正苦于以下问题:Python OUT.info方法的具体用法?Python OUT.info怎么用?Python OUT.info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WebappConfig.debug.OUT
的用法示例。
在下文中一共展示了OUT.info方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_module
# 需要导入模块: from WebappConfig.debug import OUT [as 别名]
# 或者: from WebappConfig.debug.OUT import info [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)
示例2: write
# 需要导入模块: from WebappConfig.debug import OUT [as 别名]
# 或者: from WebappConfig.debug.OUT import info [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 + '!')
示例3: remove
# 需要导入模块: from WebappConfig.debug import OUT [as 别名]
# 或者: from WebappConfig.debug.OUT import info [as 别名]
def remove(self, entry):
'''
Decide whether to delete something - and then go ahead and do so
Just like portage, we only remove files that have not changed
from when we installed them. If the timestamp or checksum is
different, we leave the file in place.
Inputs
entry - file/dir/sym to remove
'''
OUT.debug('Trying to remove file', 6)
# okay, deal with the file | directory | symlink
removeable = self.__content.get_canremove(entry)
if not removeable:
# Remove directory or file.
# Report if we are only pretending
if self.__p:
OUT.info(' pretending to remove: ' + entry)
# try to remove the entry
try:
entry_type = self.__content.etype(entry)
if self.__content.etype(entry) == 'dir':
# its a directory -> rmdir
if not self.__p:
os.rmdir(entry)
else:
# its a file -> unlink
if not self.__p:
os.unlink(entry)
except:
# Report if there is a problem
OUT.notice('!!! '
+ self.__content.epath(entry))
return
if self.__v and not self.__p:
# Report successful deletion
OUT.notice('<<< ' + entry_type + ' '
* (5 - len(entry_type))
+ self.__content.epath(entry))
self.__content.delete(entry)
return True
else:
OUT.notice(removeable)
return False
示例4: listinstalls
# 需要导入模块: from WebappConfig.debug import OUT [as 别名]
# 或者: from WebappConfig.debug.OUT import info [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: clean
# 需要导入模块: from WebappConfig.debug import OUT [as 别名]
# 或者: from WebappConfig.debug.OUT import info [as 别名]
def clean(self):
self.file_behind_flag = False
OUT.debug('Basic server clean', 7)
self.file_behind_flag |= self.__del.remove_files()
self.file_behind_flag |= self.__del.remove_dirs()
OUT.info('Any files or directories listed above must be removed b'
'y hand')
# okay, let's finish off
#
# we don't need the contents file anymore
self.file_behind_flag |= not self.__content.kill()
# right - we need to run the hook scripts now
# if they fail, we don't actually care
# run the hooks
self.__ebuild.run_hooks('clean', self)
# do we need the dotconfig file?
#
# if the .webapp file is the only one in the dir, we believe
# that we can remove it
self.__dotconfig.kill()
# is the installation directory empty?
if not os.listdir(self.__destd) and os.path.isdir(self.__destd):
if not self.__p:
os.rmdir(self.__destd)
else:
OUT.notice('--- ' + self.__destd)
# update the list of installs
self.__db.remove(self.__destd)
# Remove the selinux module
if self.__selinux is not None:
self.__selinux.remove_module()
# did we leave anything behind?
if self.file_behind_flag:
OUT.warn('Remove whatever is listed above by hand')
示例6: kill
# 需要导入模块: from WebappConfig.debug import OUT [as 别名]
# 或者: from WebappConfig.debug.OUT import info [as 别名]
def kill(self):
''' Remove the contents file.'''
if not self.__p:
try:
dbpath = self.appdb()
self.check_installdir()
os.unlink(dbpath)
self.__content = {}
return True
except:
OUT.warn('Failed to remove ' + self.appdb() + '!')
return False
else:
OUT.info('Would have removed ' + self.appdb())
return True
示例7: write
# 需要导入模块: from WebappConfig.debug import OUT [as 别名]
# 或者: from WebappConfig.debug.OUT import info [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))
示例8: add
# 需要导入模块: from WebappConfig.debug import OUT [as 别名]
# 或者: from WebappConfig.debug.OUT import info [as 别名]
def add(self, installdir, user, group):
'''
Add a record to the list of virtual installs.
installdir - the installation directory
'''
if not installdir:
OUT.die('The installation directory must be specified!')
if not str(user):
OUT.die('Please specify a valid user!')
if not str(group):
OUT.die('Please specify a valid group!')
OUT.debug('Adding install record', 6)
dbpath = self.appdb()
if not dbpath:
OUT.die('No package specified!')
if not self.__p and not os.path.isdir(os.path.dirname(dbpath)):
os.makedirs(os.path.dirname(dbpath), self.__dir_perm(0o755))
fd = None
if not self.__p:
fd = os.open(dbpath,
os.O_WRONLY | os.O_APPEND | os.O_CREAT,
self.__file_perm(0o600))
entry = str(int(time.time())) + ' ' + str(user) + ' ' + str(group)\
+ ' ' + installdir + '\n'
OUT.debug('New record', 7)
if not self.__p:
os.write(fd, (entry).encode('utf-8'))
os.close(fd)
else:
OUT.info('Pretended to append installation ' + installdir)
OUT.info('Entry:\n' + entry)
示例9: mkdirs
# 需要导入模块: from WebappConfig.debug import OUT [as 别名]
# 或者: from WebappConfig.debug.OUT import info [as 别名]
def mkdirs(self, directory = '', current_type = ''):
'''
Create a set of directories
Inputs
directory - the directory within the source hierarchy
'''
sd = self.__sourced + '/' + directory
real_dir = re.compile('/+').sub('/',
self.__ws.appdir()
+ '/' + self.__sourced
+ '/' + directory)
OUT.debug('Creating directories', 6)
if not self.__ws.source_exists(sd):
OUT.warn(self.__ws.package_name()
+ ' does not install any files from '
+ real_dir + '; skipping')
return
OUT.info(' Installing from ' + real_dir)
for i in self.__ws.get_source_directories(sd):
OUT.debug('Handling directory', 7)
# create directory first
next_type = self.mkdir(directory + '/' + i, current_type)
# then recurse into the directory
self.mkdirs(directory + '/' + i, next_type)
for i in self.__ws.get_source_files(sd):
OUT.debug('Handling file', 7)
# handle the file
self.mkfile(directory + '/' + i, current_type)
示例10: reportpackageavail
# 需要导入模块: from WebappConfig.debug import OUT [as 别名]
# 或者: from WebappConfig.debug.OUT import info [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)
示例11: kill
# 需要导入模块: from WebappConfig.debug import OUT [as 别名]
# 或者: from WebappConfig.debug.OUT import info [as 别名]
def kill(self):
''' Remove the dot config file.'''
empty = self.is_empty()
OUT.debug('Trying to removing .webapp file', 7)
if not empty:
if not self.__p:
try:
os.unlink(self.__dot_config())
except:
OUT.warn('Failed to remove '
+ self.__dot_config() + '!')
return False
else:
OUT.info('Would have removed ' + self.__dot_config())
return True
else:
OUT.notice('--- ' + empty)
return False
示例12: write
# 需要导入模块: from WebappConfig.debug import OUT [as 别名]
# 或者: from WebappConfig.debug.OUT import info [as 别名]
def write(self):
'''
Write the contents file.
A short test:
>>> import os.path
>>> here = os.path.dirname(os.path.realpath(__file__))
>>> a = Contents(here + '/tests/testfiles/contents/',
... package = 'test', version = '1.0',
... pretend = True)
>>> a.read()
>>> OUT.color_off()
>>> a.write() #doctest: +ELLIPSIS
* Would have written content file .../tests/testfiles/contents//.webapp-test-1.0!
'''
dbpath = self.appdb()
if not dbpath:
OUT.die('No package specified!')
self.check_installdir()
values = [' '.join(i) for i in 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 + '!')
示例13: upgrade
# 需要导入模块: from WebappConfig.debug import OUT [as 别名]
# 或者: from WebappConfig.debug.OUT import info [as 别名]
def upgrade(self, new_category, new_package, new_version):
# I have switched the order of upgrades
# we are now removing the olde app and then installing the new one
# I am not sure why it was the other way around before
# and this way seems more intuitive and also has the benefit
# of working -- rl03
# first remove the older app
OUT.info('Removing old version ' + self.__dotconfig.packagename())
self.clean()
# now install the new one
self.__content.set_category(new_category)
self.__content.set_version(new_version)
self.__content.set_package(new_package)
self.__db.set_category(new_category)
self.__db.set_version(new_version)
self.__db.set_package(new_package)
self.install(True)
示例14: install
# 需要导入模块: from WebappConfig.debug import OUT [as 别名]
# 或者: from WebappConfig.debug.OUT import info [as 别名]
def install(self, upgrade = False):
self.config_protected_dirs = []
OUT.debug('Basic server install', 7)
# The root of the virtual install location needs to exist
if not os.path.isdir(self.__destd) and not self.__p:
OUT.debug('Directory missing', 7)
dir = self.__destd
dirs = []
while dir != '/':
dirs.insert(0, dir)
dir = os.path.dirname(dir)
a = self.__perm['dir']['install-owned'][2]('0755')
OUT.debug('Strange')
# Create the directories
for i in dirs:
if not os.path.isdir(i):
os.mkdir(i)
os.chmod(i,
self.__perm['dir']['install-owned'][2]('0755'))
os.chown(i,
self.__perm['dir']['install-owned'][0],
self.__perm['dir']['install-owned'][1])
if self.__v:
OUT.info(' Creating installation directory: '
+ i)
# Create the handler for installing
self.__flags['relative'] = True
wa = WebappAdd(self.__sourced,
self.__destd,
self.__perm,
self.__handler,
self.__flags)
self.__add = wa
OUT.info('Installing ' + self.__ws.package_name() + '...')
# we need to create the directories to place our files in
# and we need to copy in the files
OUT.info(' Creating required directories', 1)
OUT.info(' Linking in required files', 1)
OUT.info(' This can take several minutes for larger apps', 1)
self.__add.mkdirs()
self.config_protected_dirs += self.__add.config_protected_dirs
# Create the second handler for installing the root files
self.__flags['relative'] = False
wa = WebappAdd(self.__hostroot,
self.__vhostroot,
self.__perm,
self.__handler,
self.__flags)
self.__add = wa
self.__add.mkdirs()
self.config_protected_dirs += self.__add.config_protected_dirs
OUT.info(' Files and directories installed', 1)
self.__dotconfig.write(self.__ws.category,
self.__ws.pn,
self.__ws.pvr,
self.__flags['host'],
self.__flags['orig'],
str(self.__perm['file']['config-owned'][0])
+ ':' + str(self.__perm['file']['config-owned'][1]),)
self.__db.add(self.__destd,
self.__perm['file']['config-owned'][0],
self.__perm['file']['config-owned'][1])
# run the hooks
self.__ebuild.run_hooks('install', self)
# show the post-installation instructions
if not upgrade:
self.__ebuild.show_postinst(self)
else:
#.........这里部分代码省略.........
示例15: add
# 需要导入模块: from WebappConfig.debug import OUT [as 别名]
# 或者: from WebappConfig.debug.OUT import info [as 别名]
#.........这里部分代码省略.........
<optional> is additional data that depends upon <what>
NOTE:
Filenames used to be on the end of the line. This made
the old bash version more complicated, and
prone to failure. So I have moved the filename into the
middle of the line. -- Stuart
Portage uses absolute names for its files, dirs, and symlinks.
We do not.
In theory, you can move a directory containing a web-based app,
and
a) the app itself will not break, and
b) webapp-config will still work on that directory
for upgrades and cleans.
Position-independence *is* a design constraint that all future
changes to this script need to honour.
Inputs:
dsttype - type to add (one of dir|sym|file|hardlink)
ctype - internal webapp-config type
- (server-owned | config-owned | virtual)
destination - install dir (normally $G_INSTALLDIR)
path - filename inside 'destination'
real_path - for config-protected files realpath =! path
(and this is important for md5)
relative - 1 for storing a relative filename, 0 otherwise
'''
OUT.debug('Adding entry to content dictionary', 6)
# Build the full path that we use as index in the contents list
while path[0] == '/':
path = path[1:]
while destination[-1] == '/':
destination = destination[:-1]
entry = destination + '/' + path
# special case - we don't add entries for '.'
if os.path.basename(entry) == '.':
return
if (not self.__p
and not os.path.islink(entry)
and (not os.path.exists(entry)
or not os.access(entry, os.R_OK))):
OUT.warn('Cannot access file ' + entry + ' to add it as'
' installation content. This should not happen!')
return
allowed_types = {
'file' : [ 'file', self.file_md5, self.file_null ],
'hardlink': [ 'file', self.file_md5, self.file_null ],
'dir' : [ 'dir', self.file_zero, self.file_null ],
'sym' : [ 'sym', self.file_zero, self.file_link ],
}
if not dsttype in list(allowed_types.keys()):
OUT.die('Oops, webapp-config bug. "dsttype" is ' + dsttype)
# Generate handler for file attributes
a = allowed_types[dsttype]
# For absolute entries the path must match the entry
if not relative:
path = entry
OUT.debug('Adding entry', 7)
# report if pretending
if self.__p:
OUT.info(' pretending to add: ' +
' '.join([dsttype,
str(int(relative)),
ctype,
'"' + path + '"']))
else:
# Only the path is enclosed in quotes, NOT the link targets
self.__content[entry] = [ a[0],
str(int(relative)),
ctype,
'"' + path + '"',
self.file_time(entry),
a[1](real_path),
a[2](entry)]
if self.__v:
msg = path
if msg[0] == "/":
msg = self.__root + msg
msg = self.__re.sub('/', msg)
OUT.notice('>>> ' + a[0] + ' ' * (4 - len(a[0])) + ' (' \
+ ctype + ') ' + msg)