All pastes #48569 Raw Edit

kommerck

public python v1 · immutable
#48569 ·published 2006-04-07 21:06 UTC
rendered paste body
#!/usr/bin/python#  packmanrobot.py##  Copyright (C) 2001 Hendrik Muhs <Hendrik.Muhs@web.de>##  This program is free software; you can redistribute it and/or modify#  it under the terms of the GNU General Public License as published by#  the Free Software Foundation; either version 2 of the License, or#  (at your option) any later version.##  This program is distributed in the hope that it will be useful,#  but WITHOUT ANY WARRANTY; without even the implied warranty of#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the#  GNU General Public License for more details.# python modulesimport os, sys, time, getopt, re, getpass, urllib, urllib2, string# global variables#defaults, put your own settings in ~/.packmanrobot (without '"')packmanuser=""packmanpassword=""mantra=""rpmbin="/bin/rpm"rpmtopdir="/usr/src/packages"gpgbin="/usr/bin/gpg"scpbin="/usr/bin/scp"sshbin="/usr/bin/ssh"target="i586"distversion="10.0"#PACKAGER="Leon Freitag <leon\@links2linux.de>"#PACKAGER_NAME="Leon Freitag"#VENDOR="Packman"build=1upload=1sign=1remove=0forceremove=0# packman adminpageadminpage='https://packman.links2linux.de/admin/index.php'def usage():  print '''Options:packmanrobot.py [options]... [spec-file]...  -h, --help            show this helpscreen  -b, --build           only build, no sign, no upload  -s, --sign            only sign, no build, no upload  -u  --upload          only upload  -r  --remove          look for old files and ask for deletion  -f  --forceremove     use together with --remove, delete without asking  -t {arch}, --target={arch}  -d {Distversion} --dist={Distversion}  '''def error(message):  print "Error: " + message  sys.exit(1)def runcommand(command, opt, password):  pid, fd = os.forkpty() # If Child; execute external process  if pid == 0:        os.execv(command, [command]+opt) #if parent, read/write with child through file descriptor  else:        time.sleep(2)        # need authentification?        try:                # Get password prompt; ignore                out = os.read(fd, 1000)                sys.stdout.write (out)                #write password                os.write(fd, password + "\n")                #read response from child process                out = os.read(fd,len(password) )                  # do not show the mantra on the screen                out = os.read(fd,100 )                while out:                        sys.stdout.write (out)                        try:                                out = os.read(fd, 100)                        except :                                out=""        except: pass        # get the exit status        pid, rc =  os.waitpid(pid,0)        os.close(fd)  return rcdef get_pkg_nr():  params = urllib.urlencode({'module':'edit_package'})  f=urllib2.urlopen(adminpage,params)  content=f.read()  regpkg = re.escape(packmanpackagename)  package_regex=re.compile('<option value="(.*)".*>'+regpkg+'\s*<')  match=package_regex.search(content)  if match: return match.group(1)  return Nonedef get_cat_nr():  params= urllib.urlencode({'module': 'new_package'})  f=urllib2.urlopen(adminpage,params)  content=f.read()  category_regex=re.compile('<option value="(.*)">'+packmangroup+'\s*<')  match=category_regex.search(content)  if match: return match.group(1)  return Nonedef releasepackage(srpm, pkg_nr):  params = urllib.urlencode({'source_package': srpm, 'submit_button':'ok','action':'show_add_form','module': 'new_release', 'pkg_nr': pkg_nr})  f=urllib2.urlopen(adminpage,params)  content=f.read()  dist_nr_regex=re.compile('<option value="(.*)".*>SuSE '+distversion+'\s*<')  arch_nr_regex=re.compile('<option value="(.*)".*>'+target+'\s*<')  name_nr_regex=re.compile('<option value="(.*)".*>'+packman+'\s*<')  match=dist_nr_regex.search(content)  if not match : error("New package entry failed: wrong Distribution")  dist_nr = match.group(1)  match=arch_nr_regex.search(content)  if not match : error("New package entry failed: wrong Target")  arch_nr = match.group(1)  match=name_nr_regex.search(content)  if not match : error("New package entry failed: wrong Packman")  name_nr = match.group(1)  # commit the source package  params = urllib.urlencode({'release': packversion, 'distribution_nr': dist_nr, 'arch_nr': arch_nr, 'name_nr': name_nr,                'public': '1', 'submit_button': 'add release','module':'new_release','add_release':'true',                'pkg_nr': pkg_nr, 'src_file': srpm})  f=urllib2.urlopen(adminpage,params)  # binary (Binary package file(s))  # find out version_nr  params = urllib.urlencode({'pkg_nr': pkg_nr, 'submit_button':'ok', 'action': 'choose_version', 'module': 'new_bin_file'})  f=urllib2.urlopen(adminpage,params)  content=f.read()  version_target_dist = packversion + '-' + target + '-' + 'SuSE ' + distversion  version_nr_regex=re.compile('<option value="(.*)".*>'+ version_target_dist + '\s*<')  match=version_nr_regex.search(content)  if not match : error("New package entry failed: wrong Version")  version_nr = match.group(1)  # commit the binarys  for pack in packages:        name=pack[0]        version=pack[1]        release=pack[2]        packmandesc=pack[5]        packmandesc_de=pack[6]        rpm = "suse/" + distversion + "/" + target + "/" + name + "-" + version + "-" + release + "." + target + ".rpm"        params = urllib.urlencode({'file':rpm, 'description': packmandesc, 'description_de': packmandesc_de, 'public': '1',                'submit_button': 'add bin-file', 'module': 'new_bin_file', 'ev': version_target_dist, 'add_bin_file':'true',                'version_nr': version_nr, 'package': packmanpackagename, 'pkg_nr': pkg_nr})        f=urllib2.urlopen(adminpage,params)  returndef makedeps(): # make dependencies  for pack in packages:        name=re.escape(pack[0])        version=pack[1]        release=pack[2]        packmandepends=pack[7]        depend = string.split(packmandepends)        params = urllib.urlencode({'module': 'new_dep'})        f=urllib2.urlopen(adminpage,params)        content=f.read()        newtarget=target        # get bin_file_nr        #bin_file_nr_regex=re.compile('<option value="(.*)".*>suse/' + distversion + "/" + target + "/" + name +        #                        '-[\d.]+-.*[.]' + target + '[.]rpm\s*<')        bin_file_nr_regex=re.compile('<option value="(.*)".*>suse/' + distversion + "/" + target + "/" + name +                "-" + version + "-" + release + "." + target + '[.]rpm\s*<')        match=bin_file_nr_regex.search(content)        if not match : error("Dependency entry failed: wrong Binary")        bin_file_nr = match.group(1)        for dep in depend:                newtarget=target                while newtarget:                        dep_regex=re.compile('<option value="(.*)".*>suse/' + distversion + "/" + newtarget + "/" + dep +                                        '-[a-zA-Z0-9._]+-.*[.]' + newtarget + '[.]rpm\s*<')                        match=dep_regex.search(content)                        # dependency faile                        if not match :                                if newtarget == "i486" :                                        newtarget = "i386"                                else:                                        if newtarget == "i586" :                                                newtarget = "i486"                                        else:                                                if newtarget == "i686" :                                                        newtarget = "i586"                                                else:                                                        if newtarget == "noarch" :                                                                newtarget = ""                                                        else:                                                                newtarget = "noarch"                        else:                                newtarget = ""                if not match : print("Dependency entry failed: wrong Dependency: " + dep)                else:                        dep_nr = match.group(1)                        params = urllib.urlencode({'bin_file_nr_1': bin_file_nr, 'bin_file_nr_2': dep_nr, 'submit': 'create dep',                                 'module': 'new_dep','create_dep': 'true'})                        f=urllib2.urlopen(adminpage,params)  returndef preparsespec(content):  # this function handles %define  defines=[]  content2=[]  define_regex=re.compile('^%define\s*(\S*)\s+(.*)')  for line in content:        for e in defines:                 line=string.replace(line,'%{'+e[0]+'}',e[1])                 line=string.replace(line,'%'+e[0],e[1])        res=define_regex.search(line)        if res:                # new define found                key=res.group(1)                value=res.group(2)                defines.append([key,value])        else: content2.append(line)  return content2def getdescriptions(desc):  description_regex=re.compile('^%description\s*(.*)')  description_l_regex=re.compile('.*-l *(\S*).*')  description=""  description_de=""  i=0  while i<len(desc):        res=description_regex.search(desc[i])        if res:                res=description_l_regex.search(desc[i])                i=i+1                if res:                        if res.group(1)=="de":                                while i<len(desc):                                        if desc[i]=="": break                                        if (desc[i][0]=="%" or desc[i][0] =="#"): break                                        description_de=description_de+desc[i]                                        i=i+1                else:                        while  i<len(desc):                                if desc[i]=="": break                                if (desc[i][0]=="%" or desc[i][0] =="#"): break                                description=description+desc[i]                                i=i+1                i=i-1        i=i+1  return description, description_dedef readconfig():  global packmanuser, packmanpassword, mantra  global rpmbin, rpmtopdir, gpgbin, scpbin  try:        fd=open(os.path.expanduser('~/.packmanrobot'), "r")  except:        print "no configuration file found: use defaults"        return  content=fd.readlines()  fd.close()  packmanuser_regex=re.compile('packmanuser=(.*)',re.IGNORECASE)  packmanpassword_regex=re.compile('packmanpassword=(.*)',re.IGNORECASE)  mantra_regex=re.compile('mantra=(.*)',re.IGNORECASE)  rpmbin_regex=re.compile('rpmbin=(.*)',re.IGNORECASE)  rpmtopdir_regex=re.compile('rpmtopdir=(.*)',re.IGNORECASE)  gpgbin_regex=re.compile('gpgbin=(.*)',re.IGNORECASE)  scpbin_regex=re.compile('scpbin=(.*)',re.IGNORECASE)  sshbin_regex=re.compile('sshbin=(.*)',re.IGNORECASE)  target_regex=re.compile('target=(.*)',re.IGNORECASE)  distversion_regex=re.compile('distversion=(.*)',re.IGNORECASE)  for line in content:        res=packmanuser_regex.search(line)        if res: packmanuser= res.group(1)        res=packmanpassword_regex.search(line)        if res: packmanpassword= res.group(1)        res=mantra_regex.search(line)        if res: mantra= res.group(1)        res=rpmbin_regex.search(line)        if res: rpmbin= res.group(1)        res=rpmtopdir_regex.search(line)        if res: rpmtopdir= res.group(1)        res=gpgbin_regex.search(line)        if res: gpgbin= res.group(1)        res=scpbin_regex.search(line)        if res: scpbin= res.group(1)        res=sshbin_regex.search(line)        if res: sshbin= res.group(1)        res=target_regex.search(line)        if res: target= res.group(1)        res=distversion_regex.search(line)        if res: distversion= res.group(1)  returndef parsespec():  global specfile  global packager, packmangroup, packmanpackagename, url, packman, srpmfile, packversion, packdescription, packdescription_de  global packages, description_format  packages=[]  print "Parsing the specfile"  try:        fd=open(specfile, "r")  except:        error("Could not open Spec-file")  content=fd.readlines()  fd.close()  content=preparsespec(content)  # divide preamble and prep  preamble_regex=re.compile('%prep *$')  i=0  for line in content:        res=preamble_regex.search(line)        if res: break        i=i+1  preamble = content[:i]  content=content[i:]  # look for subpackages  subpackage_regex=re.compile('^%package .*')  subpackage=[]  i=0  for line in preamble:        res=subpackage_regex.search(line)        if res: subpackage.append(i)        i=i+1  # get defaults  name_regex=re.compile('^Name\s*:\s*([^\s]+)', re.IGNORECASE)  version_regex=re.compile('^Version\s*:\s*([^\s]+)', re.IGNORECASE)  release_regex=re.compile('^Release\s*:\s*([^\s]+)', re.IGNORECASE)  packager_regex=re.compile('^Packager\s*:\s*([^\s]+)', re.IGNORECASE)  url_regex=re.compile('^Url\s*:\s*([^\s]+)', re.IGNORECASE)  packmangroup_regex=re.compile('#\s*Packmangroup\s*:\s*([^\n]+)', re.IGNORECASE)  packmanpackagename_regex=re.compile('#\s*Packmanpackagename\s*:\s*([^\s]+)', re.IGNORECASE)  packman_regex=re.compile('#\s*Packman\s*:\s*([^\s]+ [^\s]+)', re.IGNORECASE)  packmandesc_regex=re.compile('#\s*Packmandesc\s*:\s*(.*)', re.IGNORECASE)  packmandesc_de_regex=re.compile('#\s*Packmandesc_de\s*:\s*(.*)', re.IGNORECASE)  packmandepends_regex=re.compile('#\s*Packmandepends\s*:\s*(.*)', re.IGNORECASE)  packmanpackagedesc_de_regex=re.compile('#\s*Packmanpackagedesc_de\s*:\s*(.*)', re.IGNORECASE)  packmanpackagedesc_regex=re.compile('#\s*Packmanpackagedesc\s*:\s*(.*)', re.IGNORECASE)  url=""  packmandesc = ""  packmandesc_de = ""  packmandepends = ""  description = ""  description_de = ""  if len(subpackage):        mainpart=preamble[:subpackage[0]]  else:        mainpart=preamble  i=0  for line in mainpart:        if line[0:12]=="%description": break        res=name_regex.search(line)        if res: name= res.group(1)        res=version_regex.search(line)        if res: version= res.group(1)        res=release_regex.search(line)        if res: release= res.group(1)        res=packmangroup_regex.search(line)        if res: packmangroup= res.group(1)        res=packmanpackagename_regex.search(line)        if res: packmanpackagename= res.group(1)        res=packager_regex.search(line)        if res: packager=res.group(1)        res=url_regex.search(line)        if res: url=res.group(1)        res=packman_regex.search(line)        if res: packman=res.group(1)        res=packmandesc_regex.search(line)        if res: packmandesc=res.group(1)        res=packmandesc_de_regex.search(line)        if res: packmandesc_de=res.group(1)        res=packmandepends_regex.search(line)        if res: packmandepends=res.group(1)        res=packmanpackagedesc_de_regex.search(line)        if res: description_de=res.group(1)        res=packmanpackagedesc_regex.search(line)        if res: description=res.group(1)        i=i+1  # get descriptions  desc = mainpart[i:]  if description == "":  	description,description_de=getdescriptions(desc)	description_format = "text"  else:  	description_format ="html"  # the main package  pack=[name,version,release,description,description_de,packmandesc,packmandesc_de, packmandepends]  packages.append(pack)  # version, description, description_de for the packmandb  packversion = version  packdescription = description  packdescription_de =description_de  # do subpackages  for i in range(0,len(subpackage)):        # defaults (from the mainpackage)        name=packages[0][0]        version=packages[0][1]        release=packages[0][2]        if i == (len(subpackage)-1): k= len(preamble)        else: k=subpackage[i+1]        sub=preamble[subpackage[i]:k]        # get subpackage        # get the name, see if '-n' was specified        name_regex=re.compile('^%package *-n *(.*)')        name2_regex=re.compile('^%package *(.*)')        res=name_regex.search(sub[0])        if res: name=res.group(1)        else:                res=name2_regex.search(sub[0])                if res: name=name + '-' + res.group(1)                else: error("Parse Error: %package not correct")        # TODO        packmandesc = ""        packmandesc_de = ""        packmandepends = ""        k=0        for line in sub[1:]:                if line[0:12]=="%description": break                res=version_regex.search(line)                if res: version= res.group(1)                res=release_regex.search(line)                if res: release= res.group(1)                res=packmandesc_regex.search(line)                if res: packmandesc=res.group(1)                res=packmandesc_de_regex.search(line)                if res: packmandesc_de=res.group(1)                res=packmandepends_regex.search(line)                if res: packmandepends=res.group(1)                k=k+1        desc = sub[k:]        description,description_de=getdescriptions(desc)        pack=[name,version,release,description,description_de,packmandesc,packmandesc_de, packmandepends]        packages.append(pack)  # look for debuginfo package (suse 9.3+ only)  #--------da gehts los---kommentieren wenn ohne debuginfo packages gebaut werden soll-----------  name_regex=re.compile('^%debug_package')  res=name_regex.search(sub[0])  if res:          name=name+"-debuginfo"         res=version_regex.search(line)         if res: version= res.group(1)         res=release_regex.search(line)         if res: release= res.group(1)         res=packmandesc_regex.search(line)         if res: packmandesc=res.group(1)         res=packmandesc_de_regex.search(line)         if res: packmandesc_de=res.group(1)         res=packmandepends_regex.search(line)         if res: packmandepends=res.group(1)         pack=[name,version,release,description,description_de,packmandesc,packmandesc_de, packmandepends]         packages.append(pack)  #--------ende des hacks----------------  returndef buildpackage():  global mantra, specfile  if mantra == "":        mantra= getpass.getpass("\nGPG Passwort eingeben:")  print "building the package with command:"  print rpmbin + " --sign -v --target=" + target + " -ba "+ specfile  # "--nosignature",  rc= runcommand(rpmbin,["--sign", "-v", "--target=" + target,  "-ba", specfile],mantra)  if rc != 0 : error("Packaging failed")  returndef signpackage():  global mantra,gpgbin, rpmfile,srpmfile  if mantra == "":        mantra= getpass.getpass("\nGPG Passwort eingeben:")  print "sign the packages"  # the rpms  for pack in packages:        name=pack[0]        version=pack[1]        release=pack[2]        rpmfile=rpmtopdir + "/RPMS/" + target + "/" + name + "-" + version + "-" + release + "." + target + ".rpm"        rc= runcommand(gpgbin,["--detach-sign", "-a", "--yes", rpmfile],mantra)        if rc != 0 : error("Signing failed")  print "creating requires"  # the rpms  for pack in packages:        name=pack[0]        version=pack[1]        release=pack[2]        rpmfile=rpmtopdir + "/RPMS/" + target + "/" + name + "-" + version + "-" + release + "." + target + ".rpm"        reqfile=name + "." + distversion + ".requires"        print reqfile        rc= runcommand("/bin/sh",["-c", "for lib in `rpm -q --requires -p \""+rpmfile+                                  "\" | grep -e '^lib.*so'`; do rpm -q --whatprovides $lib --queryformat='Requires:\t%{NAME} >= %{VERSION}\n' ;done | sort -u > "+reqfile],                       mantra)        if rc != 0 : error("creating requires failed")  print "printing packmandepends"  # the rpms  for pack in packages:        name=pack[0]        version=pack[1]        release=pack[2]        rpmfile=rpmtopdir + "/RPMS/" + target + "/" + name + "-" + version + "-" + release + "." + target + ".rpm"        print name + "." + distversion + ".packmandepends"        rc= runcommand("/bin/sh",["-c", "for lib in `rpm -q --requires -p \""+rpmfile+                                  "\" | grep -e '^lib.*so'`; do rpm -q --whatprovides $lib --queryformat='%{NAME} >= %{VERSION}-%{RELEASE}\n' ;done | fgrep '.pm.' | cut -d\  -f 1 "],                       mantra)        if rc != 0 : error("creating requires failed")  # the srpm  pack=packages[0]  name=pack[0]  version=pack[1]  release=pack[2]  srpmfile= rpmtopdir + "/SRPMS/" + name + "-" + version + "-" + release + ".src.rpm"  rc= runcommand(gpgbin,["--detach-sign", "-a", "--yes", srpmfile],mantra)  if rc != 0 : error("Signing failed")  returndef upload():  global packmanuser,packmanpassword  print "upload the packages"  if packmanuser == "":        packmanuser= raw_input("Packmanuser:")  if packmanpassword == "":        packmanpassword= getpass.getpass("\nPackman-Passwort eingeben:")  #the rpms  for pack in packages:        name=pack[0]        version=pack[1]        release=pack[2]        rpmfile=rpmtopdir + "/RPMS/" + target + "/" + name + "-" + version + "-" + release + "." + target + ".rpm"        rc = runcommand(scpbin, [rpmfile,packmanuser+"@packman.links2linux.de:/home/ftp/pub/packman/suse/" + distversion + "/" +target + "/"],packmanpassword)        if rc != 0 : error("Upload failed")        rc = runcommand(scpbin, [rpmfile+".asc",packmanuser+"@packman.links2linux.de:/home/ftp/pub/packman/suse/" + distversion + "/" + target + "/"],packmanpassword)        if rc != 0 : error("Upload failed")  # the srpm  pack=packages[0]  name=pack[0]  version=pack[1]  release=pack[2]  srpmfile= rpmtopdir + "/SRPMS/" + name + "-" + version + "-" + release + ".src.rpm"  rc = runcommand(scpbin, [srpmfile,packmanuser+"@packman.links2linux.de:/home/ftp/pub/packman/suse/" + distversion + "/SRPMS/"],packmanpassword)  if rc != 0 : error("Upload failed")  rc = runcommand(scpbin, [srpmfile+".asc",packmanuser+"@packman.links2linux.de:/home/ftp/pub/packman/suse/" + distversion + "/SRPMS/"],packmanpassword)  if rc != 0 : error("Upload failed")  returndef updatedb():  global packmanuser,packmanpassword, description_format  # initialize the handler  authinfo = urllib2.HTTPBasicAuthHandler()  authinfo.add_password('Administration', 'packman.links2linux.de', packmanuser, packmanpassword)  opener = urllib2.build_opener(authinfo)  urllib2.install_opener(opener)  pack=packages[0]  name=pack[0]  version=pack[1]  release=pack[2]  srpm = "suse/" + distversion + "/SRPMS/" + name + "-" + version + "-" + release + ".src.rpm"  # new package or update?  pkg_nr = get_pkg_nr()  if pkg_nr:        # update!        # update package entry        # find out cat-nr        cat_nr = get_cat_nr()        if not cat_nr: error("Update package entry failed: wrong Category: " + packmangroup)        #commit change        params= urllib.urlencode({'package': packmanpackagename, 'cat_nr': cat_nr, 'homepage': url, 'description': packdescription,                'description_de': packdescription_de, 'description_format':description_format, 'public':'1', 'submit': 'save', 			'pkg_nr': pkg_nr, 'update_package': 'true',                'module': 'edit_package', })        f=urllib2.urlopen(adminpage,params)        # update source package        # find out version_nr        params= urllib.urlencode({'pkg_nr': pkg_nr, 'submit_button':'ok', 'action':'choose_release', 'module':'edit_release'})        f=urllib2.urlopen(adminpage,params)        content=f.read()        version_target_dist = packversion + '-' + target + '-' + 'SuSE ' + distversion        version_nr_regex=re.compile('<option value="(.*)".*>.*-' + target + '-' + 'SuSE ' + distversion+ '\s*<')        match=version_nr_regex.search(content)        if match :                # update release                version_nr = match.group(1)                # delete release                params= urllib.urlencode({ 'version_nr': version_nr, 'submit_button': '  delete  ',                        'delete_release': 'true', 'pkg_nr': pkg_nr, 'module': 'del_release'})                f=urllib2.urlopen(adminpage,params)        # release        releasepackage(srpm, pkg_nr)        print "Update package entry finished"  else:        # new Packman-package!        # find out category        cat_nr = get_cat_nr()        if not cat_nr : error("New package entry failed: wrong Category: " + packmangroup)        # create package        params = urllib.urlencode({'package': packmanpackagename, 'cat_nr': cat_nr, 'homepage': url, 'description': packdescription,                        'description_de': packdescription_de, 'description_format':description_format, 'submit': 'add_new_package', 			'add_new_package': 'true', 'module': 'new_package'})        f=urllib2.urlopen(adminpage,params)        # source package (Release)        # get pkg_nr        pkg_nr = get_pkg_nr()        if not pkg_nr: error("New package entry failed: Package could not be created")        # package created        # go on with release        releasepackage(srpm, pkg_nr)        # find out dist_nr, arch_nr, name_nr        print "New package entry finished"  makedeps()  returndef removeoldpackages():  global packmanuser,packmanpassword  print "Looking for old files"  if packmanuser == "":        packmanuser= raw_input("Packmanuser:")  if packmanpassword == "":        packmanpassword= getpass.getpass("\nPackman Passwort eingeben:")  for pack in packages:        name=pack[0]        version=pack[1]        release=pack[2]        print ("\nOld files from package " + name+":\n")        files=[]        pid, fd = os.forkpty()        # If Child; execute external process        if pid == 0:                os.execv(sshbin, [sshbin, packmanuser+'@links2linux.de',                        'ls /home/ftp/pub/packman/suse/' + distversion + '/' + target + '/' + name + '-*.' + target + '.rpm*'])        #if parent, read/write with child through file descriptor        else:                time.sleep(2)                out = os.read(fd,8)                if out == "password:":                        os.write(fd, packmanpassword + "\n")                        #read response from child process                        out = os.read(fd,len(packmanpassword) )                  # do not show the mantra on the screen                        out=os.read(fd,10)                content = out                while out :                        try:                                out = os.read(fd, 10)                        except :                                out=""                        content=content+out                pid, rc =  os.waitpid(pid,0)                os.close(fd)		regname=re.escape(name)                oldfiles_regex=re.compile('/home/ftp/pub/packman/suse/' + distversion + '/' + target + '/' + regname +'-(\d+.*-.*).'+                        target + '[.]rpm[.]*')                for line in string.split(content,'\n'):                        match=oldfiles_regex.search(line)                        if match:                                if not match.group(1) == version + '-' + release: files.append(line.strip())                if not files == []:                        for file in files:                                print file                        if forceremove == 0:                                if ( string.lower(raw_input("remove (y/n)?")) == "y"):                                        for file in files:                                                rc= runcommand(sshbin,[packmanuser+'@links2linux.de','rm_pm ' + file],packmanpassword)                        else:                                for file in files:                                        rc= runcommand(sshbin,[packmanuser+'@links2linux.de','rm_pm ' + file],packmanpassword)        # the srpm  pack=packages[0]  name=pack[0]  version=pack[1]  release=pack[2]  print ("\nOld files from source-package " + name+":\n")  files=[]  pid, fd = os.forkpty()  # If Child; execute external process  if pid == 0:        os.execv(sshbin, [sshbin, packmanuser+'@links2linux.de',                'ls /home/ftp/pub/packman/suse/' + distversion + '/SRPMS/' + name + '-*-*.src.rpm*'])        #if parent, read/write with child through file descriptor  else:        time.sleep(2)        out = os.read(fd,8)        if out == "password:":                os.write(fd, packmanpassword + "\n")                #read response from child process                out = os.read(fd,len(packmanpassword) )                  # do not show the mantra on the screen                out=os.read(fd,10)        content = out        while out :                try:                        out = os.read(fd, 10)                except :                        out=""                content=content+out        pid, rc =  os.waitpid(pid,0)        os.close(fd)        oldfiles_regex=re.compile('/home/ftp/pub/packman/suse/' + distversion + '/SRPMS/' + name +'-(\d+.*-.*)[.]src[.]rpm.*')        for line in string.split(content,'\n'):                match=oldfiles_regex.search(line)                if match:                        if not match.group(1) == version + '-' + release: files.append(line.strip())        if not files == []:                for file in files:                        print file                if forceremove == 0:                        if ( string.lower(raw_input("remove (y/n)?")) == "y"):                                for file in files:                                        rc= runcommand(sshbin,[packmanuser+'@links2linux.de','rm_pm ' + file],packmanpassword)                else:                        for file in files:                                rc= runcommand(sshbin,[packmanuser+'@links2linux.de','rm_pm ' + file],packmanpassword)  return# the main programif __name__ == '__main__':        print "Packman-Robot Version 0.4.3"        try:                optlist, args = getopt.getopt(sys.argv[1:], "hbsurt:d:",                                              ['help', 'build', 'sign', 'upload', 'remove', 'forceremove', 'target=', 'distversion='])        except getopt.error, message:                sys.stderr.write(message+'\n')                sys.exit(2)        for option,param in optlist:                if option in ('-h', '--help'):                        usage()                        sys.exit(0)                if option in ('-b', '--build'): upload=0;sign=0                if option in ('-s', '--sign'): upload=0;build=0                if option in ('-u', '--upload'): build=0;sign=0                if option in ('-r', '--remove'): remove=1                if option in ('-f', '--forceremove'): forceremove=1                if option in ('-t', '--target'): target = param                if option in ('-d', '--distversion'): distversion = param        if len(args) != 1:                usage()                sys.exit(2)        specfile = args[0]        # get config        readconfig()        # parse specfile        parsespec()        if build:                buildpackage()        if sign:                signpackage ()        if upload:                upload()                updatedb()        if remove:                removeoldpackages()        print "Succesfully finished."        sys.exit(0)