Commits

catseye  committed 011ff4d

Apply hints at Source-creation time.

  • Participants
  • Parent commits f5ea4b1

Comments (0)

Files changed (1)

File toolshelf.py

 
 class Source(object):
     def __init__(self, url=None, host=None, user=None, project=None,
-                 type=None, hints=''):
-        # TODO: look up specifier in database, to obtain "cookies"
+                 type=None):
         self.url = url
         if not host:
             raise ValueError('no host supplied')
         self.user = user or 'distfile'
         self.project = project
         self.type = type
-        self.hints = hints
+        COOKIES.apply_hints(self)
 
     def __repr__(self):
         return ("Source(url=%r, host=%r, user=%r, "
         if name.startswith('@'):
             return klass.from_catalog(name[1:], problems)
 
-        hints = None
-
         # resolve name shorthands
         # TODO: make these configurable
         match = re.match(r'^gh:(.*?)\/(.*?)$', name)
             project = match.group(3)
             return [
                 Source(url=name, host=host, user=user, project=project,
-                       type='git', hints=hints)
+                       type='git')
             ]
 
         match = re.match(r'^https?:\/\/(.*?)/(.*?)/(.*?)\.git$', name)
             project = match.group(3)
             return [
                 Source(url=name, host=host, user=user, project=project,
-                       type='git', hints=hints)
+                       type='git')
             ]
 
         match = re.match(r'^https?:\/\/(.*?)/.*?\/?([^/]*?)'
             project = match.group(2)
             ext = match.group(3)
             return [
-                Source(url=name, host=host, project=project, type=ext,
-                       hints=hints)
+                Source(url=name, host=host, project=project, type=ext)
             ]
 
         match = re.match(r'^https?:\/\/(.*?)/(.*?)/(.*?)\/?$', name)
             project = match.group(3)
             return [
                 Source(url=name, host=host, user=user, project=project,
-                       type='hg', hints=hints)
+                       type='hg')
             ]
 
         # local
                 # TODO divine type
                 s = Source(host=host, user=user, project=project,
                            type='unknown')
-                s.load_hints()
                 return [s]
             problems.append("Source '%s' not docked" % name)
             return []
         else:
             raise NotImplementedError(self.type)
 
-        self.save_hints()
-
     def build(self):
         if not OPTIONS.build:
             note("* SKIPPING build of %s" % self.name)
         else:
             raise NotImplementedError
 
+    def may_use_path(self, dirname):
+        # TODO: rewrite this to use new hints
+        use_it = True
+        for hint in self.hints.split(':'):
+            # TODO: better hint parsing
+            try:
+                (name, value) = hint.split('=')
+            except ValueError:
+                continue
+            if name == 'x':
+                verboten = os.path.join(self.dir, value)
+                if dirname.startswith(verboten):
+                    use_it = False
+                    break
+        return use_it
+
     def find_path_components(self):
         index = {}
         find_executables(self.dir, index)
         components = []
         for dirname in sorted(index):
-            # TODO: rewrite this more elegantly
-            add_it = True
-            for hint in self.hints.split(':'):
-                # TODO: better hint parsing
-                try:
-                    (name, value) = hint.split('=')
-                except ValueError:
-                    continue
-                if name == 'x':
-                    verboten = os.path.join(self.dir, value)
-                    if dirname.startswith(verboten):
-                        add_it = False
-                        break
-            if not add_it:
+            if not self.may_use_path(dirname):
                 note("(SKIPPING %s)" % dirname)
                 continue
             note("  %s:" % dirname)
     # TODO: improve this
     if problems:
         raise SourceSpecSyntaxError(repr(problems))
-    COOKIES.apply_hints(sources)
     for source in sources:
         # XXX for now, skip if already docked
         if not source.docked:
     # TODO: improve this
     if problems:
         raise SourceSpecSyntaxError(repr(problems))
-    COOKIES.apply_hints(sources)
     for source in sources:
         source.build()
     path_cmd(result, ['rebuild'] + [s.name for s in sources])
     # TODO: improve this
     if problems:
         raise SourceSpecSyntaxError(repr(problems))
-    COOKIES.apply_hints(sources)
     for source in sources:
         source.update()
         source.build()