original_docstring: Do the real work. The main goal of this function is to be able to
      call p4a_setup from another tool (p4a_coffee.py) that has already
      parsed the arguments and options of the command.
      
docstring: Do the real work. The main goal of this function is to be able to
  call p4a_setup from another tool (p4a_coffee.py) that has already
  parsed the arguments and options of the command.
docstring_tokens: Do the real work . The main goal of this function is to be able to call p4a_setup from another tool ( p4a_coffee . py ) that has already parsed the arguments and options of the command .
code: def work(options, args = []):
      '''Do the real work. The main goal of this function is to be able to
      call p4a_setup from another tool (p4a_coffee.py) that has already
      parsed the arguments and options of the command.
      '''
  
      # Determine architecture for binary packages (and special arch name for debs).
      deb_arch = arch = options.arch
      if not arch:
          arch = platform.machine()
      if arch == "x86_64":
          deb_arch = "amd64"
      elif re.match("i\d86", arch):
          deb_arch = "i386"
      p4a_util.debug("arch=" + arch)
      p4a_util.debug("deb_arch=" + deb_arch)
  
      # Determine current running distro unless provided.
      distro = options.distro
      if not distro:
          distro = p4a_util.get_distro()
      if options.deb:
          if distro not in [ "ubuntu", "debian" ]:
              p4a_util.die("Invalid target distro for building .debs: " + distro)
      p4a_util.debug("distro=" + distro)
  
      pack_dir = options.pack_dir
      if pack_dir:
          pack_dir = os.path.realpath(os.path.abspath(pack_dir))
          p4a_util.warn("Par4All installation is to be found in " + pack_dir + " (--pack-dir)")
      else:
          pack_dir = default_pack_dir
          p4a_util.warn("Assuming Par4All is currently installed in " + pack_dir + " (default; use --pack-dir to override)")
      if not os.path.isdir(pack_dir):
          p4a_util.die("Directory does not exist: " + pack_dir)
  
      # By default use the version computed by p4a_version.VERSION:
      version = None
      if options.version:
          version = options.version
          p4a_util.info("Version: " + version + " (--package-version)")
      else:
          version = p4a_version.VERSION(pack_dir)
          p4a_util.info("Version: " + version + " (override with --package-version)")
  
      if options.append_date:
          dt = p4a_util.utc_datetime()
          version += "~" + dt
  
      gitrev = p4a_version.GITREV(pack_dir)
      p4a_util.info("Git revision: " + gitrev)
  
      if len(args):
          if not options.publish:
              p4a_util.die("You specified files on command line but did not specify --publish")
          publish_files(args, distro, distro, arch, deb_arch,
                        version, options.development)
          return
  
      if options.development and not options.append_date:
          options.append_date = True
  
      if len(options.publish_only):
          (full_version, version) = p4a_version.make_full_revision(custom_version = version)
          publish_files(options.publish_only, distro, distro, arch, deb_arch,
                        version, options.development)
          return
  
      if (not options.deb #and not options.sdeb
          and not options.tgz and not options.stgz):
          p4a_util.warn("--deb and/or --tgz and/or --stgz not specified, assuming --deb --tgz --stgz")
          options.deb = True
          options.tgz = True
          options.stgz = True
  
  	if options.retry_publish:
  		file_to_publish=[]
  		if options.deb:
  			if options.pack_output_dir:
  				file_to_publish+=glob.glob(options.pack_output_dir+"/*.deb")
  			else:
  				file_to_publish+=glob.glob("*.deb")
  		if options.tgz or options.stgz:
  			if options.pack_output_dir:
  				file_to_publish+=glob.glob(options.pack_output_dir+"/*.gz")
  			else:
  				file_to_publish+=glob.glob("*.gz")
  		publish_files(file_to_publish, distro, distro, arch, deb_arch,
                        version, options.development)
  		return
  
      prefix = options.install_prefix
      if prefix:
          # Make the script working with relative path too:
          prefix = os.path.abspath(prefix)
          p4a_util.warn("Installation prefix: " + prefix + " (--install-prefix)")
      else:
          prefix = default_install_prefix
          p4a_util.warn("Installation prefix: " + prefix + " (default; override with --install-prefix)")
  
      # Strip forward slash:
      if prefix[0] == "/" and len(prefix):
          prefix = prefix[1:]
  
      output_dir = options.pack_output_dir
      if output_dir:
          # Make the script working with relative path too:
          output_dir = os.path.abspath(output_dir)
          p4a_util.warn("Packages will be put in " + output_dir + " (--pack-output-dir)")
          if output_dir == os.getcwd():
              output_dir = None
      else:
          p4a_util.warn("Packages will be put in " + os.getcwd() + " (default; override with --pack-output-dir)")
  
      # Check that fakeroot is available.
      if not p4a_util.which("fakeroot"):
          p4a_util.die("fakeroot not found, please install it (sudo aptitude install fakeroot)")
  
  
      global temp_dirs
      output_files = []
      try:
          if options.deb:
  			#remove previous *.deb
  			p4a_util.run(["rm -fv *.deb"])
  			output_files.append(create_deb(pack_dir = pack_dir, install_prefix = prefix,
  				version = version, gitrev = gitrev, distro = distro, arch = deb_arch,
                  keep_temp = options.keep_temp))
  
          if options.tgz:
  			#remove previous *.gz
  			p4a_util.run(["rm -fv *.gz"])
  			output_files.append(create_tgz(pack_dir = pack_dir, install_prefix = prefix,
                  version = version, gitrev = gitrev, distro = distro, arch = arch,
                  keep_temp = options.keep_temp))
  
          if options.stgz:
  			#remove previous *.gz
  			p4a_util.run(["rm -fv *src.tar.gz"])
  			output_files.append(create_stgz(pack_dir = pack_dir, install_prefix = prefix,
                  version = version, gitrev = gitrev,
                  keep_temp = options.keep_temp))
  
          if options.publish:
              publish_files(output_files, distro, distro, arch, deb_arch,
                            version, options.development)
  
          if output_dir:
              for file in output_files:
                  dest_file = os.path.join(output_dir, os.path.split(file)[1])
                  if dest_file == file:
                      continue
                  if os.path.exists(dest_file):
                      p4a_util.warn("Removing existing " + dest_file)
                      os.remove(dest_file)
                  p4a_util.run([ "mv", "-v", file, dest_file ])
      except:
          for dir in temp_dirs:
              if os.path.isdir(dir):
                  p4a_util.warn("NOT Removing " + dir)
          raise
  
      for dir in temp_dirs:
          if os.path.isdir(dir):
              if options.keep_temp:
                  p4a_util.warn("NOT Removing " + dir + " (--keep-temp)")
              else:
                  p4a_util.rmtree(dir, can_fail = True)
code_tokens: def work ( options , args = [ ] ) : deb_arch = arch = options . arch if not arch : arch = platform . machine ( ) if arch == "x86_64" : deb_arch = "amd64" elif re . match ( "i\d86" , arch ) : deb_arch = "i386" p4a_util . debug ( "arch=" + arch ) p4a_util . debug ( "deb_arch=" + deb_arch ) distro = options . distro if not distro : distro = p4a_util . get_distro ( ) if options . deb : if distro not in [ "ubuntu" , "debian" ] : p4a_util . die ( "Invalid target distro for building .debs: " + distro ) p4a_util . debug ( "distro=" + distro ) pack_dir = options . pack_dir if pack_dir : pack_dir = os . path . realpath ( os . path . abspath ( pack_dir ) ) p4a_util . warn ( "Par4All installation is to be found in " + pack_dir + " (--pack-dir)" ) else : pack_dir = default_pack_dir p4a_util . warn ( "Assuming Par4All is currently installed in " + pack_dir + " (default; use --pack-dir to override)" ) if not os . path . isdir ( pack_dir ) : p4a_util . die ( "Directory does not exist: " + pack_dir ) version = None if options . version : version = options . version p4a_util . info ( "Version: " + version + " (--package-version)" ) else : version = p4a_version . VERSION ( pack_dir ) p4a_util . info ( "Version: " + version + " (override with --package-version)" ) if options . append_date : dt = p4a_util . utc_datetime ( ) version += "~" + dt gitrev = p4a_version . GITREV ( pack_dir ) p4a_util . info ( "Git revision: " + gitrev ) if len ( args ) : if not options . publish : p4a_util . die ( "You specified files on command line but did not specify --publish" ) publish_files ( args , distro , distro , arch , deb_arch , version , options . development ) return if options . development and not options . append_date : options . append_date = True if len ( options . publish_only ) : ( full_version , version ) = p4a_version . make_full_revision ( custom_version = version ) publish_files ( options . publish_only , distro , distro , arch , deb_arch , version , options . development ) return if ( not options . deb and not options . tgz and not options . stgz ) : p4a_util . warn ( "--deb and/or --tgz and/or --stgz not specified, assuming --deb --tgz --stgz" ) options . deb = True options . tgz = True options . stgz = True if options . retry_publish : file_to_publish = [ ] if options . deb : if options . pack_output_dir : file_to_publish += glob . glob ( options . pack_output_dir + "/*.deb" ) else : file_to_publish += glob . glob ( "*.deb" ) if options . tgz or options . stgz : if options . pack_output_dir : file_to_publish += glob . glob ( options . pack_output_dir + "/*.gz" ) else : file_to_publish += glob . glob ( "*.gz" ) publish_files ( file_to_publish , distro , distro , arch , deb_arch , version , options . development ) return prefix = options . install_prefix if prefix : prefix = os . path . abspath ( prefix ) p4a_util . warn ( "Installation prefix: " + prefix + " (--install-prefix)" ) else : prefix = default_install_prefix p4a_util . warn ( "Installation prefix: " + prefix + " (default; override with --install-prefix)" ) if prefix [ 0 ] == "/" and len ( prefix ) : prefix = prefix [ 1 : ] output_dir = options . pack_output_dir if output_dir : output_dir = os . path . abspath ( output_dir ) p4a_util . warn ( "Packages will be put in " + output_dir + " (--pack-output-dir)" ) if output_dir == os . getcwd ( ) : output_dir = None else : p4a_util . warn ( "Packages will be put in " + os . getcwd ( ) + " (default; override with --pack-output-dir)" ) if not p4a_util . which ( "fakeroot" ) : p4a_util . die ( "fakeroot not found, please install it (sudo aptitude install fakeroot)" ) global temp_dirs output_files = [ ] try : if options . deb : p4a_util . run ( [ "rm -fv *.deb" ] ) output_files . append ( create_deb ( pack_dir = pack_dir , install_prefix = prefix , version = version , gitrev = gitrev , distro = distro , arch = deb_arch , keep_temp = options . keep_temp ) ) if options . tgz : p4a_util . run ( [ "rm -fv *.gz" ] ) output_files . append ( create_tgz ( pack_dir = pack_dir , install_prefix = prefix , version = version , gitrev = gitrev , distro = distro , arch = arch , keep_temp = options . keep_temp ) ) if options . stgz : p4a_util . run ( [ "rm -fv *src.tar.gz" ] ) output_files . append ( create_stgz ( pack_dir = pack_dir , install_prefix = prefix , version = version , gitrev = gitrev , keep_temp = options . keep_temp ) ) if options . publish : publish_files ( output_files , distro , distro , arch , deb_arch , version , options . development ) if output_dir : for file in output_files : dest_file = os . path . join ( output_dir , os . path . split ( file ) [ 1 ] ) if dest_file == file : continue if os . path . exists ( dest_file ) : p4a_util . warn ( "Removing existing " + dest_file ) os . remove ( dest_file ) p4a_util . run ( [ "mv" , "-v" , file , dest_file ] ) except : for dir in temp_dirs : if os . path . isdir ( dir ) : p4a_util . warn ( "NOT Removing " + dir ) raise for dir in temp_dirs : if os . path . isdir ( dir ) : if options . keep_temp : p4a_util . warn ( "NOT Removing " + dir + " (--keep-temp)" ) else : p4a_util . rmtree ( dir , can_fail = True )
short_docstring: Do the real work.
short_docstring_tokens: Do the real work .
comment: '''Do the real work. The main goal of this function is to be able to
      call p4a_setup from another tool (p4a_coffee.py) that has already
      parsed the arguments and options of the command.
      '''$SEP$# Determine architecture for binary packages (and special arch name for debs).$SEP$# Determine current running distro unless provided.$SEP$# By default use the version computed by p4a_version.VERSION:$SEP$#and not options.sdeb$SEP$# Make the script working with relative path too:$SEP$# Strip forward slash:$SEP$# Make the script working with relative path too:$SEP$# Check that fakeroot is available.$SEP$#remove previous *.deb$SEP$#remove previous *.gz$SEP$#remove previous *.gz