Beispiel #1
0
 def select1(self, arg):
   if has_protocol(arg,'tangler'):
     self.select_tangler(arg)
   elif has_protocol(arg, 'weaver'):
     self.set_weaver(arg)
   elif arg is None:
     self.select_tangler(None)
   else:
     pass #permissive
Beispiel #2
0
 def select1(self, arg):
     if has_protocol(arg, 'tangler'):
         self.select_tangler(arg)
     elif has_protocol(arg, 'weaver'):
         self.set_weaver(arg)
     elif arg is None:
         self.select_tangler(None)
     else:
         pass  #permissive
Beispiel #3
0
    def tangler(self, device, language=deduce, *args, **kwds):
        "Create a tangle object from a dvice specification (either a filename or sink object"
        if has_protocol(device, 'filename'):
            filename = self.master.tangler_directory + str(device)
            sink = named_file_sink(self.pass_frame, filename,
                                   self.master.tangler_prefix)
        elif has_protocol(device, 'sink'):
            sink = device
        else:
            raise TypeError('tangler device argument must be string or sink')

        if language is None: language = 'data'
        if language is deduce:
            try:
                splitup = sink.name.split('.')
                if len(splitup) > 1:
                    extension = splitup[-1]
                    #language = extension_table [extension]
                    language = extension
                else:
                    language = 'data'
            except KeyError:
                language = 'data'
            except IndexError:
                language = 'data'
        language = language.lower()
        language = language.replace('++', 'pp')  # C++ hack
        language = language.replace('-', '_')  # obj-C etc

        try:
            import imp
            import interscript.tanglers
            try:
                file, pathname, description = imp.find_module(
                    language, interscript.tanglers.__path__)
            except:
                #print "imp.find_module failed for '"+language+'"'
                raise exceptions.UserWarning("Can't load tangler")
            try:
                tmod = imp.load_module(language, file, pathname, description)
            except:
                print("imp.load_module failed for '" + pathname + "'")
                raise exceptions.UserWarning("Can't load tangler")
            try:
                class_name = language + "_tangler"
                tglr = getattr(tmod, class_name)
            except:
                print("tangler class '" + class_name +
                      "' not found in module ")
                raise exceptions.UserWarning("Can't load tangler")
            t = tglr(sink, self.current_weaver, self.inhibit_sref)
        except:
            print('Unable to load', language,
                  'tangler for "' + device + '": using data')
            t = data_tangler(sink, self.current_weaver)
        return t
Beispiel #4
0
  def tangler(self,device, language=deduce, *args, **kwds):
    "Create a tangle object from a dvice specification (either a filename or sink object"
    if has_protocol(device, 'filename'):
      filename = self.master.tangler_directory+str(device)
      sink = named_file_sink(
        self.pass_frame,
        filename,
        self.master.tangler_prefix)
    elif has_protocol(device, 'sink'):
      sink = device
    else: raise TypeError('tangler device argument must be string or sink')

    if language is None: language = 'data'
    if language is deduce:
      try:
        splitup = sink.name.split('.')
        if len(splitup)>1:
          extension = splitup[-1]
          #language = extension_table [extension]
          language = extension
        else: language = 'data'
      except KeyError: language = 'data'
      except IndexError: language = 'data'
    language = language.lower()
    language = language.replace('++','pp') # C++ hack
    language = language.replace('-','_') # obj-C etc

    try:
      import imp
      import interscript.tanglers
      try:
        file,pathname,description = imp.find_module(language,interscript.tanglers.__path__)
      except:
        #print "imp.find_module failed for '"+language+'"'
        raise exceptions.UserWarning("Can't load tangler")
      try:
        tmod = imp.load_module(language,file,pathname,description)
      except:
        print("imp.load_module failed for '"+pathname+"'")
        raise exceptions.UserWarning("Can't load tangler")
      try:
        class_name = language + "_tangler"
        tglr = getattr(tmod,class_name)
      except:
        print("tangler class '"+class_name+"' not found in module ")
        raise exceptions.UserWarning("Can't load tangler")
      t = tglr(sink,self.current_weaver,self.inhibit_sref)
    except:
      print('Unable to load',language,'tangler for "'+device+'": using data')
      t=data_tangler(sink,self.current_weaver)
    return t