parameters: (source, target, env)
return_statement: return 0
docstring: Filter the targets for the needed files and use the variables in env
      to create the specfile.
docstring_summary: Filter the targets for the needed files and use the variables in env
      to create the specfile.
docstring_tokens: Filter the targets for the needed files and use the variables in env to create the specfile .
function: def build_specfiles(source, target, env):
      """ Filter the targets for the needed files and use the variables in env
      to create the specfile.
      """
      #
      # At first we care for the CONTROL/control file, which is the main file for ipk.
      #
      # For this we need to open multiple files in random order, so we store into
      # a dict so they can be easily accessed.
      #
      #
      opened_files={}
      def open_file(needle, haystack=None):
          try:
              return opened_files[needle]
          except KeyError:
              files = filter(lambda x: x.get_path().rfind(needle) != -1, haystack)
              # Py3: filter returns an iterable, not a list
              file = list(files)[0]
              opened_files[needle] = open(file.get_abspath(), 'w')
              return opened_files[needle]
  
      control_file = open_file('control', target)
  
      if 'X_IPK_DESCRIPTION' not in env:
          env['X_IPK_DESCRIPTION']="%s\n %s"%(env['SUMMARY'],
                                              env['DESCRIPTION'].replace('\n', '\n '))
  
  
      content = """
  Package: $NAME
  Version: $VERSION
  Priority: $X_IPK_PRIORITY
  Section: $X_IPK_SECTION
  Source: $SOURCE_URL
  Architecture: $ARCHITECTURE
  Maintainer: $X_IPK_MAINTAINER
  Depends: $X_IPK_DEPENDS
  Description: $X_IPK_DESCRIPTION
  """
  
      control_file.write(env.subst(content))
  
      #
      # now handle the various other files, which purpose it is to set post-,
      # pre-scripts and mark files as config files.
      #
      # We do so by filtering the source files for files which are marked with
      # the "config" tag and afterwards we do the same for x_ipk_postrm,
      # x_ipk_prerm, x_ipk_postinst and x_ipk_preinst tags.
      #
      # The first one will write the name of the file into the file
      # CONTROL/configfiles, the latter add the content of the x_ipk_* variable
      # into the same named file.
      #
      for f in [x for x in source if 'PACKAGING_CONFIG' in dir(x)]:
          config = open_file('conffiles')
          config.write(f.PACKAGING_INSTALL_LOCATION)
          config.write('\n')
  
      for str in 'POSTRM PRERM POSTINST PREINST'.split():
          name="PACKAGING_X_IPK_%s"%str
          for f in [x for x in source if name in dir(x)]:
              file = open_file(name)
              file.write(env[str])
  
      #
      # close all opened files
      for f in opened_files.values():
          f.close()
  
      # call a user specified function
      if 'CHANGE_SPECFILE' in env:
          content += env['CHANGE_SPECFILE'](target)
  
      return 0
function_tokens: def build_specfiles ( source , target , env ) : # # At first we care for the CONTROL/control file, which is the main file for ipk. # # For this we need to open multiple files in random order, so we store into # a dict so they can be easily accessed. # # opened_files = { } def open_file ( needle , haystack = None ) : try : return opened_files [ needle ] except KeyError : files = filter ( lambda x : x . get_path ( ) . rfind ( needle ) != - 1 , haystack ) # Py3: filter returns an iterable, not a list file = list ( files ) [ 0 ] opened_files [ needle ] = open ( file . get_abspath ( ) , 'w' ) return opened_files [ needle ] control_file = open_file ( 'control' , target ) if 'X_IPK_DESCRIPTION' not in env : env [ 'X_IPK_DESCRIPTION' ] = "%s\n %s" % ( env [ 'SUMMARY' ] , env [ 'DESCRIPTION' ] . replace ( '\n' , '\n ' ) ) content = """
  Package: $NAME
  Version: $VERSION
  Priority: $X_IPK_PRIORITY
  Section: $X_IPK_SECTION
  Source: $SOURCE_URL
  Architecture: $ARCHITECTURE
  Maintainer: $X_IPK_MAINTAINER
  Depends: $X_IPK_DEPENDS
  Description: $X_IPK_DESCRIPTION
  """ control_file . write ( env . subst ( content ) ) # # now handle the various other files, which purpose it is to set post-, # pre-scripts and mark files as config files. # # We do so by filtering the source files for files which are marked with # the "config" tag and afterwards we do the same for x_ipk_postrm, # x_ipk_prerm, x_ipk_postinst and x_ipk_preinst tags. # # The first one will write the name of the file into the file # CONTROL/configfiles, the latter add the content of the x_ipk_* variable # into the same named file. # for f in [ x for x in source if 'PACKAGING_CONFIG' in dir ( x ) ] : config = open_file ( 'conffiles' ) config . write ( f . PACKAGING_INSTALL_LOCATION ) config . write ( '\n' ) for str in 'POSTRM PRERM POSTINST PREINST' . split ( ) : name = "PACKAGING_X_IPK_%s" % str for f in [ x for x in source if name in dir ( x ) ] : file = open_file ( name ) file . write ( env [ str ] ) # # close all opened files for f in opened_files . values ( ) : f . close ( ) # call a user specified function if 'CHANGE_SPECFILE' in env : content += env [ 'CHANGE_SPECFILE' ] ( target ) return 0