if not os.path.isfile(fulltestcase):
raise bb.build.FuncFailed("Testcase %s not found" % fulltestcase)
list.append((item, casefile, fulltestcase))
+ f.close()
final_list = check_list(list)
return final_list
return
tmpdir = d.getVar('TMPDIR', True)
- file_content = open(path).read()
- if tmpdir in file_content:
- messages.append("File %s in package contained reference to tmpdir" % package_qa_clean_path(path,d))
+ with open(path) as f:
+ file_content = f.read()
+ if tmpdir in file_content:
+ messages.append("File %s in package contained reference to tmpdir" % package_qa_clean_path(path,d))
QAPATHTEST[xorg-driver-abi] = "package_qa_check_xorg_driver_abi"
for file in files:
path = os.path.join(root,file)
if file.endswith(".la"):
- file_content = open(path).read()
- if workdir in file_content:
- error_msg = "%s failed sanity test (workdir) in path %s" % (file,root)
- sane = package_qa_handle_error("la", error_msg, d)
+ with open(path) as f:
+ file_content = f.read()
+ if workdir in file_content:
+ error_msg = "%s failed sanity test (workdir) in path %s" % (file,root)
+ sane = package_qa_handle_error("la", error_msg, d)
elif file.endswith(".pc"):
- file_content = open(path).read()
- if pkgconfigcheck in file_content:
- error_msg = "%s failed sanity test (tmpdir) in path %s" % (file,root)
- sane = package_qa_handle_error("pkgconfig", error_msg, d)
+ with open(path) as f:
+ file_content = f.read()
+ if pkgconfigcheck in file_content:
+ error_msg = "%s failed sanity test (tmpdir) in path %s" % (file,root)
+ sane = package_qa_handle_error("pkgconfig", error_msg, d)
return sane
def calc_gconv_deps(fn, pkg, file_regex, output_pattern, group):
deps = []
- f = open(fn, "r")
+ f = open(fn, "rb")
c_re = re.compile('^copy "(.*)"')
i_re = re.compile('^include "(\w+)".*')
for l in f.readlines():
def calc_charmap_deps(fn, pkg, file_regex, output_pattern, group):
deps = []
- f = open(fn, "r")
+ f = open(fn, "rb")
c_re = re.compile('^copy "(.*)"')
i_re = re.compile('^include "(\w+)".*')
for l in f.readlines():
def calc_locale_deps(fn, pkg, file_regex, output_pattern, group):
deps = []
- f = open(fn, "r")
+ f = open(fn, "rb")
c_re = re.compile('^copy "(.*)"')
i_re = re.compile('^include "(\w+)".*')
for l in f.readlines():
def base_get_metadata_monotone_branch(path, d):
monotone_branch = "<unknown>"
try:
- monotone_branch = file( "%s/_MTN/options" % path ).read().strip()
- if monotone_branch.startswith( "database" ):
- monotone_branch_words = monotone_branch.split()
- monotone_branch = monotone_branch_words[ monotone_branch_words.index( "branch" )+1][1:-1]
+ with open("%s/_MTN/options" % path) as f:
+ monotone_branch = f.read().strip()
+ if monotone_branch.startswith( "database" ):
+ monotone_branch_words = monotone_branch.split()
+ monotone_branch = monotone_branch_words[ monotone_branch_words.index( "branch" )+1][1:-1]
except:
pass
return monotone_branch
def base_get_metadata_monotone_revision(path, d):
monotone_revision = "<unknown>"
try:
- monotone_revision = file( "%s/_MTN/revision" % path ).read().strip()
- if monotone_revision.startswith( "format_version" ):
- monotone_revision_words = monotone_revision.split()
- monotone_revision = monotone_revision_words[ monotone_revision_words.index( "old_revision" )+1][1:-1]
+ with open("%s/_MTN/revision" % path) as f:
+ monotone_revision = f.read().strip()
+ if monotone_revision.startswith( "format_version" ):
+ monotone_revision_words = monotone_revision.split()
+ monotone_revision = monotone_revision_words[ monotone_revision_words.index( "old_revision" )+1][1:-1]
except IOError:
pass
return monotone_revision
def base_get_metadata_svn_revision(path, d):
revision = "<unknown>"
try:
- revision = file( "%s/.svn/entries" % path ).readlines()[3].strip()
+ with open("%s/.svn/entries" % path) as f:
+ revision = f.readlines()[3].strip()
except IOError:
pass
return revision
def get_directory_size(dir):
if os.listdir(dir):
- size = int(os.popen('du -sk %s' % dir).readlines()[0].split('\t')[0])
+ with os.popen('du -sk %s' % dir) as f:
+ size = int(f.readlines()[0].split('\t')[0])
else:
size = 0
return size
g = glob('*')
if g or allow_empty == "1":
packagedfile = pkgdatadir + '/runtime/%s.packaged' % pkg
- file(packagedfile, 'w').close()
+ open(packagedfile, 'w').close()
if bb.data.inherits_class('kernel', d) or bb.data.inherits_class('module-base', d):
write_extra_runtime_pkgs(variants, packages, pkgdatadir)
for extension in ".shlibdeps", ".pcdeps", ".clilibdeps":
depsfile = d.expand("${PKGDEST}/" + pkg + extension)
if os.access(depsfile, os.R_OK):
- fd = file(depsfile)
+ fd = open(depsfile)
lines = fd.readlines()
fd.close()
for l in lines:
bb.mkdirhier(controldir)
os.chmod(controldir, 0755)
try:
- ctrlfile = file(os.path.join(controldir, 'control'), 'wb')
+ ctrlfile = open(os.path.join(controldir, 'control'), 'w')
# import codecs
# ctrlfile = codecs.open("someFile", "w", "utf-8")
except OSError:
if not scriptvar:
continue
try:
- scriptfile = file(os.path.join(controldir, script), 'w')
+ scriptfile = open(os.path.join(controldir, script), 'w')
except OSError:
bb.utils.unlockfile(lf)
raise bb.build.FuncFailed("unable to open %s script file for writing." % script)
conffiles_str = localdata.getVar("CONFFILES", True)
if conffiles_str:
try:
- conffiles = file(os.path.join(controldir, 'conffiles'), 'w')
+ conffiles = open(os.path.join(controldir, 'conffiles'), 'w')
except OSError:
bb.utils.unlockfile(lf)
raise bb.build.FuncFailed("unable to open conffiles for writing.")
controldir = os.path.join(root, 'CONTROL')
bb.mkdirhier(controldir)
try:
- ctrlfile = file(os.path.join(controldir, 'control'), 'w')
+ ctrlfile = open(os.path.join(controldir, 'control'), 'w')
except OSError:
bb.utils.unlockfile(lf)
raise bb.build.FuncFailed("unable to open control file for writing.")
if not scriptvar:
continue
try:
- scriptfile = file(os.path.join(controldir, script), 'w')
+ scriptfile = open(os.path.join(controldir, script), 'w')
except OSError:
bb.utils.unlockfile(lf)
raise bb.build.FuncFailed("unable to open %s script file for writing." % script)
conffiles_str = localdata.getVar("CONFFILES", True)
if conffiles_str:
try:
- conffiles = file(os.path.join(controldir, 'conffiles'), 'w')
+ conffiles = open(os.path.join(controldir, 'conffiles'), 'w')
except OSError:
bb.utils.unlockfile(lf)
raise bb.build.FuncFailed("unable to open conffiles for writing.")
outdepends = workdir + "/" + srcname + ".requires"
try:
- from __builtin__ import file
- dependsfile = file(outdepends, 'w')
+ dependsfile = open(outdepends, 'w')
except OSError:
raise bb.build.FuncFailed("unable to open spec file for writing.")
outprovides = workdir + "/" + srcname + ".provides"
try:
- from __builtin__ import file
- providesfile = file(outprovides, 'w')
+ providesfile = open(outprovides, 'w')
except OSError:
raise bb.build.FuncFailed("unable to open spec file for writing.")
# Write the SPEC file
try:
- from __builtin__ import file
- specfile = file(outspecfile, 'w')
+ specfile = open(outspecfile, 'w')
except OSError:
raise bb.build.FuncFailed("unable to open spec file for writing.")
last_sstate_dir = ""
sanityverfile = 'conf/sanity_info'
if os.path.exists(sanityverfile):
- f = open(sanityverfile, 'r')
- for line in f:
- if line.startswith('SANITY_VERSION'):
- last_sanity_version = int(line.split()[1])
- if line.startswith('TMPDIR'):
- last_tmpdir = line.split()[1]
- if line.startswith('SSTATE_DIR'):
- last_sstate_dir = line.split()[1]
+ with open(sanityverfile, 'r') as f:
+ for line in f:
+ if line.startswith('SANITY_VERSION'):
+ last_sanity_version = int(line.split()[1])
+ if line.startswith('TMPDIR'):
+ last_tmpdir = line.split()[1]
+ if line.startswith('SSTATE_DIR'):
+ last_sstate_dir = line.split()[1]
sanity_version = int(sanity_data.getVar('SANITY_VERSION', True) or 1)
network_error = False
if last_sstate_dir != sstate_dir:
messages = messages + check_sanity_sstate_dir_change(sstate_dir, sanity_data)
if os.path.exists("conf") and not messages:
- f = open(sanityverfile, 'w')
- f.write("SANITY_VERSION %s\n" % sanity_version)
- f.write("TMPDIR %s\n" % tmpdir)
- f.write("SSTATE_DIR %s\n" % sstate_dir)
+ with open(sanityverfile, 'w') as f:
+ f.write("SANITY_VERSION %s\n" % sanity_version)
+ f.write("TMPDIR %s\n" % tmpdir)
+ f.write("SSTATE_DIR %s\n" % sstate_dir)
#
# Check that TMPDIR hasn't changed location since the last time we were run
#
checkfile = os.path.join(tmpdir, "saved_tmpdir")
if os.path.exists(checkfile):
- f = open(checkfile, "r")
- saved_tmpdir = f.read().strip()
- if (saved_tmpdir != tmpdir):
- messages = messages + "Error, TMPDIR has changed location. You need to either move it back to %s or rebuild\n" % saved_tmpdir
+ with open(checkfile, "r") as f:
+ saved_tmpdir = f.read().strip()
+ if (saved_tmpdir != tmpdir):
+ messages = messages + "Error, TMPDIR has changed location. You need to either move it back to %s or rebuild\n" % saved_tmpdir
else:
bb.utils.mkdirhier(tmpdir)
- f = open(checkfile, "w")
- f.write(tmpdir)
- f.close()
+ with open(checkfile, "w") as f:
+ f.write(tmpdir)
#
# Check the 'ABI' of TMPDIR
current_abi = sanity_data.getVar('OELAYOUT_ABI', True)
abifile = sanity_data.getVar('SANITY_ABIFILE', True)
if os.path.exists(abifile):
- f = open(abifile, "r")
- abi = f.read().strip()
+ with open(abifile, "r") as f:
+ abi = f.read().strip()
if not abi.isdigit():
- f = open(abifile, "w")
- f.write(current_abi)
+ with open(abifile, "w") as f:
+ f.write(current_abi)
elif abi == "2" and current_abi == "3":
bb.note("Converting staging from layout version 2 to layout version 3")
subprocess.call(sanity_data.expand("mv ${TMPDIR}/staging ${TMPDIR}/sysroots"), shell=True)
subprocess.call(sanity_data.expand("ln -s sysroots ${TMPDIR}/staging"), shell=True)
subprocess.call(sanity_data.expand("cd ${TMPDIR}/stamps; for i in */*do_populate_staging; do new=`echo $i | sed -e 's/do_populate_staging/do_populate_sysroot/'`; mv $i $new; done"), shell=True)
- f = open(abifile, "w")
- f.write(current_abi)
+ with open(abifile, "w") as f:
+ f.write(current_abi)
elif abi == "3" and current_abi == "4":
bb.note("Converting staging layout from version 3 to layout version 4")
if os.path.exists(sanity_data.expand("${STAGING_DIR_NATIVE}${bindir_native}/${MULTIMACH_HOST_SYS}")):
subprocess.call(sanity_data.expand("mv ${STAGING_DIR_NATIVE}${bindir_native}/${MULTIMACH_HOST_SYS} ${STAGING_BINDIR_CROSS}"), shell=True)
subprocess.call(sanity_data.expand("ln -s ${STAGING_BINDIR_CROSS} ${STAGING_DIR_NATIVE}${bindir_native}/${MULTIMACH_HOST_SYS}"), shell=True)
-
- f = open(abifile, "w")
- f.write(current_abi)
+ with open(abifile, "w") as f:
+ f.write(current_abi)
elif abi == "4":
messages = messages + "Staging layout has changed. The cross directory has been deprecated and cross packages are now built under the native sysroot.\nThis requires a rebuild.\n"
elif abi == "5" and current_abi == "6":
bb.note("Converting staging layout from version 5 to layout version 6")
subprocess.call(sanity_data.expand("mv ${TMPDIR}/pstagelogs ${SSTATE_MANIFESTS}"), shell=True)
- f = open(abifile, "w")
- f.write(current_abi)
+ with open(abifile, "w") as f:
+ f.write(current_abi)
elif abi == "7" and current_abi == "8":
messages = messages + "Your configuration is using stamp files including the sstate hash but your build directory was built with stamp files that do not include this.\nTo continue, either rebuild or switch back to the OEBasic signature handler with BB_SIGNATURE_HANDLER = 'OEBasic'.\n"
elif (abi != current_abi and current_abi == "9"):
# Code to convert from one ABI to another could go here if possible.
messages = messages + "Error, TMPDIR has changed its layout version number (%s to %s) and you need to either rebuild, revert or adjust it at your own risk.\n" % (abi, current_abi)
else:
- f = open(abifile, "w")
- f.write(current_abi)
- f.close()
+ with open(abifile, "w") as f:
+ f.write(current_abi)
oeroot = sanity_data.getVar('COREBASE')
if oeroot.find ('+') != -1:
if os.access(fn, os.R_OK):
import re
- f = file(fn, 'r')
+ f = open(fn, 'r')
lines = f.readlines()
f.close()
r = re.compile("([^:]+):\s*(.*)")
def read_file(filename):
try:
- f = file( filename, "r" )
+ f = open( filename, "r" )
except IOError as reason:
return "" # WARNING: can't raise an error now because of the new RDEPENDS handling. This is a bit ugly. :M:
else:
- return f.read().strip()
+ data = f.read().strip()
+ f.close()
+ return data
return None
def ifelse(condition, iftrue = True, iffalse = False):
d.appendVar('ALTERNATIVE_%s' % (pn), ' ' + alt_name)
d.setVarFlag('ALTERNATIVE_LINK_NAME', alt_name, alt_link_name)
+ f.close()
}
pkg_postinst_${PN} () {