From 4337b9dbe66233ff607244bdbb9452bf4cdc0506 Mon Sep 17 00:00:00 2001 From: Bastian Eicher Date: Mon, 7 Jun 2010 21:41:53 +0200 Subject: [PATCH] Replaced x.startswith('/') with os.path.isabs(x) --- tests/testmanifest.py | 2 +- zeroinstall/0launch-gui/properties.py | 3 ++- zeroinstall/gtkui/cache.py | 4 ++-- zeroinstall/injector/fetch.py | 2 +- zeroinstall/injector/iface_cache.py | 4 ++-- zeroinstall/injector/model.py | 2 +- zeroinstall/injector/policy.py | 6 +++--- zeroinstall/injector/reader.py | 4 ++-- zeroinstall/injector/trust.py | 2 +- zeroinstall/zerostore/manifest.py | 2 +- 10 files changed, 16 insertions(+), 15 deletions(-) diff --git a/tests/testmanifest.py b/tests/testmanifest.py index b615b3a..2e3d064 100755 --- a/tests/testmanifest.py +++ b/tests/testmanifest.py @@ -27,7 +27,7 @@ class TestManifest(BaseTest): '\n'.join(manifest.generate_manifest(self.tmpdir))) def write(self, path, contents, time = None): - assert not path.startswith('/') + assert not os.path.isabs(path) myfile = os.path.join(self.tmpdir, path) stream = file(myfile, 'w') stream.write(contents) diff --git a/zeroinstall/0launch-gui/properties.py b/zeroinstall/0launch-gui/properties.py index 828931a..91dc4b3 100644 --- a/zeroinstall/0launch-gui/properties.py +++ b/zeroinstall/0launch-gui/properties.py @@ -2,6 +2,7 @@ # See the README file for details, or visit http://0install.net. import zeroinstall +import os from zeroinstall.support import tasks from zeroinstall.injector.model import Interface, Feed, stable, testing, developer, stability_levels from zeroinstall.injector.iface_cache import iface_cache @@ -138,7 +139,7 @@ class Description: buffer.insert_with_tags(iter, _('Valid signature by "%(name)s"\n- Dated: %(sig_date)s\n- Fingerprint: %(sig_fingerprint)s\n') % {'name': name, 'sig_date': time.strftime('%c', time.localtime(sig.get_timestamp())), 'sig_fingerprint': sig.fingerprint}) if not sig.is_trusted(): - if feed.url.startswith('/'): + if os.path.isabs(feed.url): buffer.insert_with_tags(iter, _('WARNING: This key is not in the trusted list') + '\n') else: buffer.insert_with_tags(iter, _('WARNING: This key is not in the trusted list (either you removed it, or ' diff --git a/zeroinstall/gtkui/cache.py b/zeroinstall/gtkui/cache.py index 22ffd37..06ef477 100644 --- a/zeroinstall/gtkui/cache.py +++ b/zeroinstall/gtkui/cache.py @@ -83,7 +83,7 @@ class CachedInterface(object): self.size = size def delete(self): - if not self.uri.startswith('/'): + if not os.path.isabs(self.uri): cached_iface = basedir.load_first_cache(namespaces.config_site, 'interfaces', model.escape(self.uri)) if cached_iface: @@ -346,7 +346,7 @@ class CacheExplorer: for uri in all: iface_size = 0 try: - if uri.startswith('/'): + if os.path.isabs(uri): cached_iface = uri else: cached_iface = basedir.load_first_cache(namespaces.config_site, diff --git a/zeroinstall/injector/fetch.py b/zeroinstall/injector/fetch.py index 907758f..d5d3d77 100644 --- a/zeroinstall/injector/fetch.py +++ b/zeroinstall/injector/fetch.py @@ -163,7 +163,7 @@ class Fetcher(object): from download import DownloadAborted debug(_("download_and_import_feed %(url)s (force = %(force)d)"), {'url': feed_url, 'force': force}) - assert not feed_url.startswith('/') + assert not os.path.isabs(feed_url) primary = self._download_and_import_feed(feed_url, iface_cache, force, use_mirror = False) diff --git a/zeroinstall/injector/iface_cache.py b/zeroinstall/injector/iface_cache.py index a53e897..b764be3 100644 --- a/zeroinstall/injector/iface_cache.py +++ b/zeroinstall/injector/iface_cache.py @@ -374,7 +374,7 @@ class IfaceCache(object): @rtype: [L{gpg.Signature}] or None @since: 0.25""" import gpg - if uri.startswith('/'): + if os.path.isabs(uri): old_iface = uri else: old_iface = basedir.load_first_cache(config_site, 'interfaces', escape(uri)) @@ -407,7 +407,7 @@ class IfaceCache(object): If url is a local path, nothing happens. This prevents us from repeatedly trying to download a failing feed many times in a short period.""" - if url.startswith('/'): + if os.path.isabs(url): return feeds_dir = basedir.save_cache_path(config_site, config_prog, 'last-check-attempt') timestamp_path = os.path.join(feeds_dir, model._pretty_escape(url)) diff --git a/zeroinstall/injector/model.py b/zeroinstall/injector/model.py index e5dd5aa..7dd4e37 100644 --- a/zeroinstall/injector/model.py +++ b/zeroinstall/injector/model.py @@ -536,7 +536,7 @@ class Interface(object): def __init__(self, uri): assert uri - if uri.startswith('http:') or uri.startswith('https:') or uri.startswith('/'): + if uri.startswith('http:') or uri.startswith('https:') or os.path.isabs(uri): self.uri = uri else: raise SafeException(_("Interface name '%s' doesn't start " diff --git a/zeroinstall/injector/policy.py b/zeroinstall/injector/policy.py index 309d752..511eed5 100644 --- a/zeroinstall/injector/policy.py +++ b/zeroinstall/injector/policy.py @@ -154,7 +154,7 @@ class Policy(object): blockers = [] for f in self.solver.feeds_used: - if f.startswith('/'): continue + if os.path.isabs(f): continue feed = iface_cache.get_feed(f) if feed is None or feed.last_modified is None: self.download_and_import_feed_if_online(f) # Will start a download @@ -191,7 +191,7 @@ class Policy(object): @return: true if feed is stale or missing.""" if feed is None: return True - if feed.url.startswith('/'): + if os.path.isabs(feed.url): return False # Local feeds are never stale if feed.last_modified is None: return True # Don't even have it yet @@ -325,7 +325,7 @@ class Policy(object): for f in self.solver.feeds_used: if f in downloads_finished or f in downloads_in_progress: continue - if f.startswith('/'): + if os.path.isabs(f): continue downloads_in_progress[f] = self.fetcher.download_and_import_feed(f, iface_cache) diff --git a/zeroinstall/injector/reader.py b/zeroinstall/injector/reader.py index 56c4296..3fbd5c1 100644 --- a/zeroinstall/injector/reader.py +++ b/zeroinstall/injector/reader.py @@ -41,7 +41,7 @@ def update_from_cache(interface): def load_feed_from_cache(url): """Load a feed. If the feed is remote, load from the cache. If local, load it directly. @return: the feed, or None if it's remote and not cached.""" - if url.startswith('/'): + if os.path.isabs(url): debug(_("Loading local feed file '%s'"), url) return load_feed(url, local = True) else: @@ -86,7 +86,7 @@ def update_user_overrides(interface, main_feed = None): if item.name == 'implementation': id = item.getAttribute('id') assert id is not None - if not (id.startswith('/') or id.startswith('.') or id.startswith('package:')): + if not (os.path.isabs(id) or id.startswith('.') or id.startswith('package:')): assert '=' in id if main_feed: impl = main_feed.implementations.get(id, None) diff --git a/zeroinstall/injector/trust.py b/zeroinstall/injector/trust.py index c6d361f..e972f1c 100644 --- a/zeroinstall/injector/trust.py +++ b/zeroinstall/injector/trust.py @@ -155,7 +155,7 @@ def domain_from_url(url): @raise SafeException: the URL can't be parsed""" import urlparse from zeroinstall import SafeException - if url.startswith('/'): + if os.path.isabs(url): raise SafeException(_("Can't get domain from a local path: '%s'") % url) domain = urlparse.urlparse(url)[1] if domain and domain != '*': diff --git a/zeroinstall/zerostore/manifest.py b/zeroinstall/zerostore/manifest.py index a0af7d5..ab637f5 100644 --- a/zeroinstall/zerostore/manifest.py +++ b/zeroinstall/zerostore/manifest.py @@ -73,7 +73,7 @@ class OldSHA1(Algorithm): if sub == '/.manifest': return - full = os.path.join(root, sub[1:]) + full = os.path.join(root, str.replace(sub[1:], '/', os.sep)) info = os.lstat(full) m = info.st_mode -- 2.11.4.GIT