本文整理汇总了Python中waflib.Utils.readf方法的典型用法代码示例。如果您正苦于以下问题:Python Utils.readf方法的具体用法?Python Utils.readf怎么用?Python Utils.readf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类waflib.Utils
的用法示例。
在下文中一共展示了Utils.readf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_module
# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import readf [as 别名]
def load_module(path):
"""
Load a source file as a python module.
:param path: file path
:type path: string
:return: Loaded Python module
:rtype: module
"""
try:
return cache_modules[path]
except KeyError:
pass
module = imp.new_module(WSCRIPT_FILE)
try:
code = Utils.readf(path, m='rU')
except (IOError, OSError):
raise Errors.WafError('Could not read the file %r' % path)
module_dir = os.path.dirname(path)
sys.path.insert(0, module_dir)
# Inject a dummy symbol to allow executing wscripts using Path
code = 'def Path(path):\n pass\n' + 'def Settings(path):\n pass\n' + code
exec(compile(code, path, 'exec'), module.__dict__)
sys.path.remove(module_dir)
cache_modules[path] = module
return module
示例2: scan
# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import readf [as 别名]
def scan(task):
try:
incn = task.generator.includes_nodes
except AttributeError:
raise WafError('%r is missing a feature such as "go" or "includes": ' % task.generator)
# filter out nodes that are not in the project directory, we don't care
# about these
nodepaths = [x for x in incn if x.is_child_of(x.ctx.bldnode) or x.is_child_of(x.ctx.srcnode)]
bldnode = task.generator.bld.bldnode
deps = []
for input in task.inputs:
file = Utils.readf(input.abspath())
try:
gp = GoParser(file)
gp.parse()
except ParserError:
pass
for s in gp.statements:
if not isinstance(s, ImportSpec):
continue
# TODO: global paths should be treated as local too, but
# no one uses them?
if s.path.startswith("./") or s.path.startswith("../"):
node = find_local(s.path, bldnode)
else:
node = find_global(s.path, nodepaths)
if node:
deps.append(node)
return (deps, None)
示例3: configure
# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import readf [as 别名]
def configure(self):
kdeconfig = self.find_program("kde4-config")
prefix = self.cmd_and_log(kdeconfig + ["--prefix"]).strip()
fname = "%s/share/apps/cmake/modules/KDELibsDependencies.cmake" % prefix
try:
os.stat(fname)
except OSError:
fname = "%s/share/kde4/apps/cmake/modules/KDELibsDependencies.cmake" % prefix
try:
os.stat(fname)
except OSError:
self.fatal("could not open %s" % fname)
try:
txt = Utils.readf(fname)
except EnvironmentError:
self.fatal("could not read %s" % fname)
txt = txt.replace("\\\n", "\n")
fu = re.compile("#(.*)\n")
txt = fu.sub("", txt)
setregexp = re.compile('([sS][eE][tT]\s*\()\s*([^\s]+)\s+"([^"]+)"\)')
found = setregexp.findall(txt)
for (_, key, val) in found:
self.env[key] = val
self.env["LIB_KDECORE"] = ["kdecore"]
self.env["LIB_KDEUI"] = ["kdeui"]
self.env["LIB_KIO"] = ["kio"]
self.env["LIB_KHTML"] = ["khtml"]
self.env["LIB_KPARTS"] = ["kparts"]
self.env["LIBPATH_KDECORE"] = [
os.path.join(self.env.KDE4_LIB_INSTALL_DIR, "kde4", "devel"),
self.env.KDE4_LIB_INSTALL_DIR,
]
self.env["INCLUDES_KDECORE"] = [self.env["KDE4_INCLUDE_INSTALL_DIR"]]
self.env.append_value("INCLUDES_KDECORE", [self.env["KDE4_INCLUDE_INSTALL_DIR"] + os.sep + "KDE"])
self.find_program("msgfmt", var="MSGFMT")
示例4: load_module
# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import readf [as 别名]
def load_module(file_path) :
""" Add global pushing to WSCRIPT when it loads """
try:
return Context.cache_modules[file_path]
except KeyError:
pass
module = imp.new_module(Context.WSCRIPT_FILE)
try:
code = Utils.readf(file_path, m='rU')
except (IOError, OSError) :
raise Errors.WafError('Could not read the file %r' % file_path)
module_dir = os.path.dirname(file_path)
sys.path.insert(0, module_dir)
for k, v in Context.wscript_vars.items() : setattr(module, k, v)
if not hasattr(module, 'src') :
def src(x) :
import os.path
return os.path.abspath(x)
module.src = src
Context.g_module = module
exec(compile(code, file_path, 'exec'), module.__dict__)
sys.path.remove(module_dir)
if not hasattr(module, 'root_path') : module.root_path = file_path
Context.cache_modules[file_path] = module
return module
示例5: _parse_group_doc
# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import readf [as 别名]
def _parse_group_doc(self, group_node):
'''
parse the doc of a package group and return (name, description) to be
used in the .pc file
'''
name = group_node.name
doc_node = group_node.make_node(['doc', name + '.txt'])
try:
doc = Utils.readf(doc_node.abspath())
purpose = None
mnemonic = None
for line in doc.split('\n'):
if line.startswith('@PURPOSE'):
purpose = line.split(':')[1].strip()
elif line.startswith('@MNEMONIC'):
mnemonic = line.split(':')[1].strip()
if purpose and mnemonic:
return (mnemonic, purpose)
except:
pass
return (name, 'N/A')
示例6: execute
# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import readf [as 别名]
def execute(self):
if not Configure.autoconfig:
return execute_method(self)
env=ConfigSet.ConfigSet()
do_config=False
try:
env.load(os.path.join(Context.top_dir,Options.lockfile))
except Exception:
Logs.warn('Configuring the project')
do_config=True
else:
if env.run_dir!=Context.run_dir:
do_config=True
else:
h=0
for f in env['files']:
h=Utils.h_list((h,Utils.readf(f,'rb')))
do_config=h!=env.hash
if do_config:
cmd=env['config_cmd']or'configure'
if Configure.autoconfig=='clobber':
tmp=Options.options.__dict__
Options.options.__dict__=env.options
try:
run_command(cmd)
finally:
Options.options.__dict__=tmp
else:
run_command(cmd)
run_command(self.cmd)
else:
return execute_method(self)
示例7: load_module
# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import readf [as 别名]
def load_module(path):
"""
Load a source file as a python module.
:param path: file path
:type path: string
:return: Loaded Python module
:rtype: module
"""
try:
return cache_modules[path]
except KeyError:
pass
module = imp.new_module(
# Script files may have periods. Python gets confused by module names with periods.
WSCRIPT_FILES.intersection(os.listdir('.')).pop().split('.')[0]
)
try:
code = Utils.readf(path, m='rU')
except (IOError, OSError):
raise Errors.WafError('Could not read the file %r' % path)
module_dir = os.path.dirname(path)
sys.path.insert(0, module_dir)
exec(compile(code, path, 'exec'), module.__dict__)
sys.path.remove(module_dir)
cache_modules[path] = module
return module
示例8: load_module
# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import readf [as 别名]
def load_module(path, encoding=None):
"""
Loads a wscript file as a python module. This method caches results in :py:attr:`waflib.Context.cache_modules`
:param path: file path
:type path: string
:return: Loaded Python module
:rtype: module
"""
try:
return cache_modules[path]
except KeyError:
pass
module = imp.new_module(WSCRIPT_FILE)
try:
code = Utils.readf(path, m="rU", encoding=encoding)
except EnvironmentError:
raise Errors.WafError("Could not read the file %r" % path)
module_dir = os.path.dirname(path)
sys.path.insert(0, module_dir)
try:
exec(compile(code, path, "exec"), module.__dict__)
finally:
sys.path.remove(module_dir)
cache_modules[path] = module
return module
示例9: restore
# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import readf [as 别名]
def restore(self):
try:
env=ConfigSet.ConfigSet(os.path.join(self.cache_dir,'build.config.py'))
except EnvironmentError:
pass
else:
if env.version<Context.HEXVERSION:
raise Errors.WafError('Version mismatch! reconfigure the project')
for t in env.tools:
self.setup(**t)
dbfn=os.path.join(self.variant_dir,Context.DBFILE)
try:
data=Utils.readf(dbfn,'rb')
except(EnvironmentError,EOFError):
Logs.debug('build: Could not load the build cache %s (missing)',dbfn)
else:
try:
Node.pickle_lock.acquire()
Node.Nod3=self.node_class
try:
data=cPickle.loads(data)
except Exception as e:
Logs.debug('build: Could not pickle the build cache %s: %r',dbfn,e)
else:
for x in SAVED_ATTRS:
setattr(self,x,data[x])
finally:
Node.pickle_lock.release()
self.init_dirs()
示例10: setup_private_ssh_key
# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import readf [as 别名]
def setup_private_ssh_key(self):
"""
When WAF_SSH_KEY points to a private key, a .ssh directory will be created in the build directory
Make sure that the ssh key does not prompt for a password
"""
key = os.environ.get('WAF_SSH_KEY', '')
if not key:
return
if not os.path.isfile(key):
self.fatal('Key in WAF_SSH_KEY must point to a valid file')
self.ssh_dir = os.path.join(self.path.abspath(), 'build', '.ssh')
self.ssh_hosts = os.path.join(self.ssh_dir, 'known_hosts')
self.ssh_key = os.path.join(self.ssh_dir, os.path.basename(key))
self.ssh_config = os.path.join(self.ssh_dir, 'config')
for x in self.ssh_hosts, self.ssh_key, self.ssh_config:
if not os.path.isfile(x):
if not os.path.isdir(self.ssh_dir):
os.makedirs(self.ssh_dir)
Utils.writef(self.ssh_key, Utils.readf(key), 'wb')
os.chmod(self.ssh_key, 448)
Utils.writef(self.ssh_hosts, '\n'.join(self.get_ssh_hosts()))
os.chmod(self.ssh_key, 448)
Utils.writef(self.ssh_config, 'UserKnownHostsFile %s' % self.ssh_hosts, 'wb')
os.chmod(self.ssh_config, 448)
self.env.SSH_OPTS = ['-F', self.ssh_config, '-i', self.ssh_key]
self.env.append_value('RSYNC_SEND_OPTS', '--exclude=build/.ssh')
示例11: execute
# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import readf [as 别名]
def execute(self):
if not Configure.autoconfig:
return execute_method(self)
env = ConfigSet.ConfigSet()
do_config = False
try:
env.load(os.path.join(Context.top_dir, Options.lockfile))
except Exception:
Logs.warn('Configuring the project')
do_config = True
else:
if env.run_dir != Context.run_dir:
do_config = True
else:
h = 0
for f in env['files']:
h = Utils.h_list((h, Utils.readf(f, 'rb')))
do_config = h != env.hash
if do_config:
Options.commands.insert(0, self.cmd)
Options.commands.insert(0, 'configure')
if Configure.autoconfig == 'clobber':
Options.options.__dict__ = env.options
return
return execute_method(self)
示例12: load
# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import readf [as 别名]
def load(self,filename):
tbl=self.table
code=Utils.readf(filename,m='rU')
for m in re_imp.finditer(code):
g=m.group
tbl[g(2)]=eval(g(3))
Logs.debug('env: %s'%str(self.table))
示例13: filter_comments
# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import readf [as 别名]
def filter_comments(filename):
code=Utils.readf(filename)
if use_trigraphs:
for(a,b)in trig_def:code=code.split(a).join(b)
code=re_nl.sub('',code)
code=re_cpp.sub(repl,code)
return[(m.group(2),m.group(3))for m in re.finditer(re_lines,code)]
示例14: load_module
# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import readf [as 别名]
def load_module(path, encoding=None):
"""
Load a source file as a python module.
:param path: file path
:type path: string
:return: Loaded Python module
:rtype: module
"""
try:
return cache_modules[path]
except KeyError:
pass
module = imp.new_module(WSCRIPT_FILE)
try:
code = Utils.readf(path, m='rU', encoding=encoding)
except EnvironmentError:
raise Errors.WafError('Could not read the file %r' % path)
module_dir = os.path.dirname(path)
sys.path.insert(0, module_dir)
try : exec(compile(code, path, 'exec'), module.__dict__)
finally: sys.path.remove(module_dir)
cache_modules[path] = module
return module
示例15: bibunitscan
# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import readf [as 别名]
def bibunitscan(self):
"""
Parse the inputs and try to find the *bibunit* dependencies
:return: list of bibunit files
:rtype: list of :py:class:`waflib.Node.Node`
"""
node = self.inputs[0]
env = self.env
nodes = []
if not node: return nodes
code = Utils.readf(node.abspath())
for match in re_bibunit.finditer(code):
path = match.group('file')
if path:
for k in ['', '.bib']:
# add another loop for the tex include paths?
debug('tex: trying %s%s' % (path, k))
fi = node.parent.find_resource(path + k)
if fi:
nodes.append(fi)
# no break, people are crazy
else:
debug('tex: could not find %s' % path)
debug("tex: found the following bibunit files: %s" % nodes)
return nodes