Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use os.path for portable path manipulation

  • Loading branch information...
commit 8fb3ba2a38e453729f64658c38a64e211dc80c5d 1 parent 3827020
Thomas Leonard talex5 authored
2  bugs.py
View
@@ -10,7 +10,7 @@ def do_report_bug(args):
"""report-bug"""
buildenv = BuildEnv()
- log_name = 'build/build-failure.log'
+ log_name = join('build', 'build-failure.log')
build_log = codecs.open(log_name, 'r', 'utf-8')
log_text = build_log.read()
build_log.close()
15 build.py
View
@@ -68,9 +68,10 @@ def do_pkg_config_binding(binding, impl):
for i, line in enumerate(lines):
if '=' not in line: continue
name, value = [x.strip() for x in line.split('=', 1)]
- if name == 'prefix' and value.startswith('/'):
+ if name == 'prefix' and os.path.isabs(value):
print "Absolute prefix=%s in %s; overriding..." % (value, feed_name)
- lines[i] = 'prefix=%s/%s\n' % (path, value[1:])
+ lines[i] = 'prefix=' + os.path.join(
+ path, os.path.splitdrive(value)[1][1:]) +'\n'
write_pc(pc, lines)
break
do_env_binding(binding, path)
@@ -107,10 +108,11 @@ def fixup_generated_pkgconfig_file(pc_file):
for i, line in enumerate(lines):
if '=' not in line: continue
name, value = [x.strip() for x in line.split('=', 1)]
- if name == 'prefix' and value.startswith('/'):
+ if name == 'prefix' and os.path.isabs(value):
print "Absolute prefix=%s in %s; fixing..." % (value, pc_file)
rel_path = os.path.relpath(value, os.path.dirname(pc_file))
- lines[i] = 'prefix=${pcfiledir}/%s\n' % rel_path
+ lines[i] = 'prefix=' + os.path.join(
+ '${pcfiledir}', rel_path) + '\n'
write_pc(pc_file, lines)
break
@@ -290,7 +292,8 @@ def do_build_internal(options, args):
print >>log, "\nBuilt using 0compile-%s" % __main__.version
print >>log, "\nBuild system: " + ', '.join(uname)
print >>log, "\n%s:\n" % ENV_FILE
- shutil.copyfileobj(file("../" + ENV_FILE), log)
+ with open(os.path.join(os.pardir, ENV_FILE)) as properties_file:
+ shutil.copyfileobj(properties_file, log)
log.write('\n')
@@ -590,7 +593,7 @@ def find_library(name, wanted):
os.symlink(target, os.path.join(mappings_dir, 'lib' + name + soext))
def dup_src(fn):
- srcdir = os.environ['SRCDIR'] + '/'
+ srcdir = os.path.join(os.environ['SRCDIR'], '')
builddir = os.environ['BUILDDIR']
build_in_src = srcdir + 'build' == builddir
2  gui_support.py
View
@@ -115,7 +115,7 @@ def done_notify():
self.add_msg("Registering as a feed for %s" % real_iface.uri)
break
else:
- if iface.uri.startswith('/'):
+ if os.path.isabs(iface.uri):
self.add_msg("Warning: no <feed-for> in local feed %s!" % iface.uri)
feed = buildenv.local_iface_file
6 setup.py
View
@@ -26,8 +26,8 @@ def do_setup(args, get_dir_callback = None):
create_dir = os.path.basename(interface)
if create_dir.endswith('.xml'):
create_dir = create_dir[:-4]
- assert '/' not in create_dir
- assert create_dir is not '.'
+ assert os.path.dirname(create_dir) == ''
+ assert create_dir != os.path.curdir
if get_dir_callback:
create_dir = get_dir_callback(create_dir)
elif len(args) == 2:
@@ -38,7 +38,7 @@ def do_setup(args, get_dir_callback = None):
raise __main__.UsageError()
iface_uri = model.canonical_iface_uri(args[0])
- if iface_uri.startswith('/'):
+ if os.path.isabs(iface_uri):
root = qdom.parse(file(iface_uri))
if root.uri == namespaces.XMLNS_IFACE and root.name == 'selections':
# Looks like this is a selections file, not an interface.
10 support.py
View
@@ -113,7 +113,7 @@ def exec_maybe_sandboxed(readable, writable, tmpdir, prog, args):
USE_PLASH = 'USE_PLASH_0COMPILE'
- assert prog.startswith('/')
+ assert os.path.isabs(prog)
_pola_run = find_in_path('pola-run')
if _pola_run is None:
@@ -203,7 +203,7 @@ def distdir(self):
arch = self.target_arch.replace('*', 'any')
distdir_name = self.iface_name.lower()
distdir_name += '-' + arch.lower()
- assert '/' not in distdir_name
+ assert os.path.dirname(distdir_name) == ''
return os.path.realpath(distdir_name)
def get_binary_template(self):
@@ -222,7 +222,7 @@ def get_binary_template(self):
@property
def metadir(self):
metadir = self.config.get('compile', 'metadir')
- assert not metadir.startswith('/')
+ assert not os.path.isabs(metadir)
return join(self.distdir, metadir)
@property
@@ -339,8 +339,8 @@ def get_selections(self, prompt = False):
if os.path.isdir('src'):
self.user_srcdir = os.path.realpath('src')
if self.user_srcdir == self.orig_srcdir or \
- self.user_srcdir.startswith(self.orig_srcdir + '/') or \
- self.orig_srcdir.startswith(self.user_srcdir + '/'):
+ self.user_srcdir.startswith(os.path.join(self.orig_srcdir, '')) or \
+ self.orig_srcdir.startswith(os.path.join(self.user_srcdir, '')):
info("Ignoring 'src' directory because it coincides with %s",
self.orig_srcdir)
self.user_srcdir = None
20 tests/testcompile.py
View
@@ -104,14 +104,14 @@ def testCompile(self):
compile('setup', hello_uri, self.hello_dir, expect = 'Created directory')
os.chdir(self.hello_dir)
- compile('build', expect = 'Executing: "$SRCDIR/configure"')
+ compile('build', expect = 'Executing: "%s"' % os.path.join('$SRCDIR','configure'))
target_dir = 'gnu-hello-%s' % support.get_arch_name().lower()
archive_stem = 'gnu-hello-%s-1.3' % support.get_arch_name().lower()
assert os.path.isdir(target_dir), '%s not a directory' % target_dir
- run('%s/bin/hello' % target_dir, expect = 'Hello, world!')
- run(launch_command, '%s/0install/GNU-Hello.xml' % target_dir, expect = 'Hello, world!')
+ run(os.path.join(target_dir,'bin','hello'), expect = 'Hello, world!')
+ run(launch_command, os.path.join(target_dir,'0install','GNU-Hello.xml'), expect = 'Hello, world!')
compile('publish', 'http://localhost/downloads', expect = "Now upload '%s.tar.bz2'" % archive_stem)
def testAutocompile(self):
@@ -125,7 +125,7 @@ def testLocal(self):
target_dir = 'hello2-any-any'
assert os.path.isdir(target_dir), '%s not a directory' % target_dir
- run(launch_command, '%s/0install/hello2.xml' % target_dir, expect = 'ROX-Lib')
+ run(launch_command, os.path.join(target_dir, '0install', 'hello2.xml'), expect = 'ROX-Lib')
def testBadVersion(self):
compile('setup', local_bad_version, self.hello_dir, expect = 'Created directory')
@@ -160,13 +160,13 @@ def testCopySrc(self):
compile('diff')
compile('--verbose', 'build', expect = 'Hello from C')
target_dir = 'cprog-%s' % support.get_arch_name().lower()
- patch_file = os.path.join(target_dir, '0install/from-0.1.patch')
+ patch_file = os.path.join(target_dir, '0install', 'from-0.1.patch')
assert not os.path.exists(patch_file)
# 'src' contains a change
- prog = file('src/main.c').read()
+ prog = file(os.path.join('src','main.c')).read()
prog = prog.replace('Hello', 'Goodbye')
- stream = file('src/main.c', 'w')
+ stream = file(os.path.join('src','main.c'), 'w')
stream.write(prog)
stream.close()
compile('diff', expect = 'diff')
@@ -178,12 +178,12 @@ def testCopySrc(self):
compile('build', expect = 'Goodbye from C')
# 'src' contains an error
- stream = file('src/main.c', 'w')
+ stream = file(os.path.join('src','main.c'), 'w')
stream.write('this is not valid C!')
stream.close()
shutil.rmtree('build')
compile('build', expect = 'Build failed', expect_status = 1)
- assert os.path.exists('build/build-failure.log')
+ assert os.path.exists(os.path.join('build', 'build-failure.log'))
# 'src' does not exist
shutil.rmtree('src')
@@ -193,7 +193,7 @@ def testCopySrc(self):
# Check we fixed the .pc files...
pc_data = open(os.path.join(target_dir, 'pkgconfig', 'cprog.pc')).read()
- assert pc_data == "prefix=${pcfiledir}/..\n", `pc_data`
+ assert pc_data == "prefix=" + os.path.join("${pcfiledir}",os.path.pardir) + "\n", `pc_data`
# Check we removed the bad .la files...
assert not os.path.exists(os.path.join(target_dir, 'lib', 'bad.la')) # libtool - bad
Please sign in to comment.
Something went wrong with that request. Please try again.