3 # Copyright (c) 2010, 2011 Intel Inc.
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the Free
7 # Software Foundation; version 2 of the License
9 # This program is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 # You should have received a copy of the GNU General Public License along
15 # with this program; if not, write to the Free Software Foundation, Inc., 59
16 # Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 from __future__ import with_statement
31 from hashlib import md5
36 import sqlite3 as sqlite
41 from xml.etree import cElementTree
44 xmlparse = cElementTree.parse
47 from fs_related import *
48 from rpmmisc import myurlgrab
49 from proxy import get_proxy_for
54 RPM_RE = re.compile("(.*)\.(.*) (.*)-(.*)")
55 RPM_FMT = "%(name)s.%(arch)s %(ver_rel)s"
56 SRPM_RE = re.compile("(.*)-(\d+.*)-(\d+\.\d+).src.rpm")
59 """Detect linux distribution, support "meego"
62 support_dists = ('SuSE',
71 (dist, ver, id) = platform.linux_distribution( \
72 supported_dists = support_dists)
74 (dist, ver, id) = platform.dist( \
75 supported_dists = support_dists)
77 return (dist, ver, id)
80 """Get composited string for current linux distribution
82 (dist, ver, id) = get_distro()
85 return 'Unknown Linux Distro'
87 return ' '.join(map(str.strip, (dist, ver, id)))
89 _LOOP_RULE_PTH = "/etc/udev/rules.d/80-prevent-loop-present.rules"
90 def hide_loopdev_presentation():
92 with open(_LOOP_RULE_PTH, 'w') as wf:
93 wf.write('KERNEL=="loop*", ENV{UDISKS_PRESENTATION_HIDE}="1"')
95 runner.quiet('udevadm trigger')
99 def unhide_loopdev_presentation():
101 os.unlink(_LOOP_RULE_PTH)
102 runner.quiet('udevadm trigger')
106 def extract_rpm(rpmfile, targetdir):
107 rpm2cpio = find_binary_path("rpm2cpio")
108 cpio = find_binary_path("cpio")
113 msger.verbose("Extract rpm file with cpio: %s" % rpmfile)
114 p1 = subprocess.Popen([rpm2cpio, rpmfile], stdout=subprocess.PIPE)
115 p2 = subprocess.Popen([cpio, "-idv"], stdin=p1.stdout,
116 stdout=subprocess.PIPE, stderr=subprocess.PIPE)
117 (sout, serr) = p2.communicate()
118 msger.verbose(sout or serr)
122 def compressing(fpath, method):
127 if method not in comp_map:
128 raise CreatorError("Unsupport compress format: %s, valid values: %s"
129 % (method, ','.join(comp_map.keys())))
130 cmd = find_binary_path(comp_map[method])
131 rc = runner.show([cmd, "-f", fpath])
133 raise CreatorError("Failed to %s file: %s" % (comp_map[method], fpath))
135 def taring(dstfile, target):
137 basen, ext = os.path.splitext(dstfile)
138 comp = {".tar": None,
139 ".gz": "gz", # for .tar.gz
140 ".bz2": "bz2", # for .tar.bz2
144 # specify tarball file path
147 elif basen.endswith(".tar"):
150 tarpath = basen + ".tar"
151 wf = tarfile.open(tarpath, 'w')
153 if os.path.isdir(target):
154 for item in os.listdir(target):
155 wf.add(os.path.join(target, item), item)
157 wf.add(target, os.path.basename(target))
161 compressing(tarpath, comp)
162 # when dstfile ext is ".tgz" and ".tbz", should rename
163 if not basen.endswith(".tar"):
164 shutil.move("%s.%s" % (tarpath, comp), dstfile)
166 def ziping(dstfile, target):
168 wf = zipfile.ZipFile(dstfile, 'w', compression=zipfile.ZIP_DEFLATED)
169 if os.path.isdir(target):
170 for item in os.listdir(target):
171 fpath = os.path.join(target, item)
172 if not os.path.isfile(fpath):
174 wf.write(fpath, item, zipfile.ZIP_DEFLATED)
176 wf.write(target, os.path.basename(target), zipfile.ZIP_DEFLATED)
188 def packing(dstfile, target):
189 (base, ext) = os.path.splitext(dstfile)
190 if ext in (".gz", ".bz2") and base.endswith(".tar"):
192 if ext not in pack_formats:
193 raise CreatorError("Unsupport pack format: %s, valid values: %s"
194 % (ext, ','.join(pack_formats.keys())))
195 func = pack_formats[ext]
196 # func should be callable
197 func(dstfile, target)
199 def human_size(size):
200 """Return human readable string for Bytes size
206 measure = ['B', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']
207 expo = int(math.log(size, 1024))
208 mant = float(size/math.pow(1024, expo))
209 return "{0:.1f}{1:s}".format(mant, measure[expo])
211 def check_space_pre_cp(src, dst):
212 """Check whether disk space is enough before 'cp' like
213 operations, else exception will be raised.
216 srcsize = get_file_size(src) * 1024 * 1024
217 freesize = get_filesystem_avail(dst)
218 if srcsize > freesize:
219 raise CreatorError("space on %s(%s) is not enough for about %s files"
220 % (dst, human_size(freesize), human_size(srcsize)))
222 def get_md5sum(fpath):
223 blksize = 65536 # should be optimized enough
226 with open(fpath, 'rb') as f:
228 data = f.read(blksize)
232 return md5sum.hexdigest()
234 def normalize_ksfile(ksconf, release, arch):
241 if not os.path.exists(ksconf):
246 if not arch or re.match(r'i.86', arch):
249 with open(ksconf) as f:
252 if "@ARCH@" in ksc or "@BUILD_ID@" in ksc:
253 msger.info("Substitute macro variable @BUILD_ID@/@ARCH in ks: %s" % ksconf)
254 ksc = ksc.replace("@ARCH@", arch)
255 ksc = ksc.replace("@BUILD_ID@", release)
256 fd, ksconf = tempfile.mkstemp(prefix=os.path.basename(ksconf), dir="/tmp/")
260 msger.debug('new ks path %s' % ksconf)
263 atexit.register(_clrtempks)
267 def _check_meego_chroot(rootdir):
268 if not os.path.exists(rootdir + "/etc/moblin-release") and \
269 not os.path.exists(rootdir + "/etc/meego-release") and \
270 not os.path.exists(rootdir + "/etc/tizen-release"):
271 raise CreatorError("Directory %s is not a MeeGo/Tizen chroot env"\
274 if not glob.glob(rootdir + "/boot/vmlinuz-*"):
275 raise CreatorError("Failed to find kernel module under %s" % rootdir)
279 def selinux_check(arch, fstypes):
281 getenforce = find_binary_path('getenforce')
285 selinux_status = runner.outs([getenforce])
286 if arch and arch.startswith("arm") and selinux_status == "Enforcing":
287 raise CreatorError("Can't create arm image if selinux is enabled, "
288 "please run 'setenforce 0' to disable selinux")
290 use_btrfs = filter(lambda typ: typ == 'btrfs', fstypes)
291 if use_btrfs and selinux_status == "Enforcing":
292 raise CreatorError("Can't create btrfs image if selinux is enabled,"
293 " please run 'setenforce 0' to disable selinux")
295 def get_image_type(path):
296 def _get_extension_name(path):
297 match = re.search("(?<=\.)\w+$", path)
299 return match.group(0)
303 if os.path.isdir(path):
304 _check_meego_chroot(path)
316 extension = _get_extension_name(path)
317 if extension in maptab:
318 return maptab[extension]
320 fd = open(path, "rb")
321 file_header = fd.read(1024)
323 vdi_flag = "<<< Sun VirtualBox Disk Image >>>"
324 if file_header[0:len(vdi_flag)] == vdi_flag:
327 output = runner.outs(['file', path])
328 isoptn = re.compile(r".*ISO 9660 CD-ROM filesystem.*(bootable).*")
329 usbimgptn = re.compile(r".*x86 boot sector.*active.*")
330 rawptn = re.compile(r".*x86 boot sector.*")
331 vmdkptn = re.compile(r".*VMware. disk image.*")
332 ext3fsimgptn = re.compile(r".*Linux.*ext3 filesystem data.*")
333 ext4fsimgptn = re.compile(r".*Linux.*ext4 filesystem data.*")
334 btrfsimgptn = re.compile(r".*BTRFS.*")
335 if isoptn.match(output):
337 elif usbimgptn.match(output):
338 return maptab["usbimg"]
339 elif rawptn.match(output):
341 elif vmdkptn.match(output):
342 return maptab["vmdk"]
343 elif ext3fsimgptn.match(output):
345 elif ext4fsimgptn.match(output):
347 elif btrfsimgptn.match(output):
350 raise CreatorError("Cannot detect the type of image: %s" % path)
352 def get_file_size(file):
353 """ Return size in MB unit """
354 rc, duOutput = runner.runtool(['du', "-s", "-b", "-B", "1M", file])
356 raise CreatorError("Failed to run %s" % du)
358 size1 = int(duOutput.split()[0])
359 rc, duOutput = runner.runtool(['du', "-s", "-B", "1M", file])
361 raise CreatorError("Failed to run %s" % du)
363 size2 = int(duOutput.split()[0])
369 def get_filesystem_avail(fs):
370 vfstat = os.statvfs(fs)
371 return vfstat.f_bavail * vfstat.f_bsize
373 def convert_image(srcimg, srcfmt, dstimg, dstfmt):
376 raise CreatorError("Invalid destination image format: %s" % dstfmt)
377 msger.debug("converting %s image to %s" % (srcimg, dstimg))
379 path = find_binary_path("qemu-img")
380 argv = [path, "convert", "-f", "vmdk", srcimg, "-O", dstfmt, dstimg]
381 elif srcfmt == "vdi":
382 path = find_binary_path("VBoxManage")
383 argv = [path, "internalcommands", "converttoraw", srcimg, dstimg]
385 raise CreatorError("Invalid soure image format: %s" % srcfmt)
387 rc = runner.show(argv)
389 msger.debug("convert successful")
391 raise CreatorError("Unable to convert disk to %s" % dstfmt)
393 def uncompress_squashfs(squashfsimg, outdir):
394 """Uncompress file system from squshfs image"""
395 unsquashfs = find_binary_path("unsquashfs")
396 args = [ unsquashfs, "-d", outdir, squashfsimg ]
397 rc = runner.show(args)
399 raise SquashfsError("Failed to uncompress %s." % squashfsimg)
401 def mkdtemp(dir = "/var/tmp", prefix = "mic-tmp-"):
402 """ FIXME: use the dir in mic.conf instead """
405 return tempfile.mkdtemp(dir = dir, prefix = prefix)
407 def get_repostrs_from_ks(ks):
408 def _get_temp_reponame(baseurl):
409 md5obj = hashlib.md5(baseurl)
410 tmpreponame = "%s" % md5obj.hexdigest()
415 for repodata in ks.handler.repo.repoList:
420 'includepkgs', # val is list
421 'excludepkgs', # val is list
433 if hasattr(repodata, attr) and getattr(repodata, attr):
434 repo[attr] = getattr(repodata, attr)
436 if 'name' not in repo:
437 repo['name'] = _get_temp_reponame(repodata.baseurl)
439 kickstart_repos.append(repo)
441 return kickstart_repos
443 def _get_uncompressed_data_from_url(url, filename, proxies):
444 filename = myurlgrab(url, filename, proxies)
446 if filename.endswith(".gz"):
448 runner.quiet(['gunzip', "-f", filename])
449 elif filename.endswith(".bz2"):
451 runner.quiet(['bunzip2', "-f", filename])
453 filename = filename.replace(suffix, "")
456 def _get_metadata_from_repo(baseurl, proxies, cachedir, reponame, filename,
457 sumtype=None, checksum=None):
458 url = os.path.join(baseurl, filename)
459 filename_tmp = str("%s/%s/%s" % (cachedir, reponame, os.path.basename(filename)))
460 if os.path.splitext(filename_tmp)[1] in (".gz", ".bz2"):
461 filename = os.path.splitext(filename_tmp)[0]
463 filename = filename_tmp
464 if sumtype and checksum and os.path.exists(filename):
466 sumcmd = find_binary_path("%ssum" % sumtype)
470 file_checksum = runner.outs([sumcmd, filename]).split()[0]
472 if file_checksum and file_checksum == checksum:
475 return _get_uncompressed_data_from_url(url,filename_tmp,proxies)
477 def get_metadata_from_repos(repos, cachedir):
478 my_repo_metadata = []
480 reponame = repo['name']
481 baseurl = repo['baseurl']
485 proxy = repo['proxy']
487 proxy = get_proxy_for(baseurl)
491 proxies = {str(baseurl.split(":")[0]):str(proxy)}
493 makedirs(os.path.join(cachedir, reponame))
494 url = os.path.join(baseurl, "repodata/repomd.xml")
495 filename = os.path.join(cachedir, reponame, 'repomd.xml')
496 repomd = myurlgrab(url, filename, proxies)
498 root = xmlparse(repomd)
500 raise CreatorError("repomd.xml syntax error.")
502 ns = root.getroot().tag
503 ns = ns[0:ns.rindex("}")+1]
509 for elm in root.getiterator("%sdata" % ns):
510 if elm.attrib["type"] == "patterns":
511 filepaths['patterns'] = elm.find("%slocation" % ns).attrib['href']
512 checksums['patterns'] = elm.find("%sopen-checksum" % ns).text
513 sumtypes['patterns'] = elm.find("%sopen-checksum" % ns).attrib['type']
516 for elm in root.getiterator("%sdata" % ns):
517 if elm.attrib["type"] in ("group_gz", "group"):
518 filepaths['comps'] = elm.find("%slocation" % ns).attrib['href']
519 checksums['comps'] = elm.find("%sopen-checksum" % ns).text
520 sumtypes['comps'] = elm.find("%sopen-checksum" % ns).attrib['type']
524 for elm in root.getiterator("%sdata" % ns):
525 if elm.attrib["type"] in ("primary_db", "primary"):
526 primary_type = elm.attrib["type"]
527 filepaths['primary'] = elm.find("%slocation" % ns).attrib['href']
528 checksums['primary'] = elm.find("%sopen-checksum" % ns).text
529 sumtypes['primary'] = elm.find("%sopen-checksum" % ns).attrib['type']
535 for item in ("primary", "patterns", "comps"):
536 if item not in filepaths:
537 filepaths[item] = None
539 if not filepaths[item]:
541 filepaths[item] = _get_metadata_from_repo(baseurl,
551 repokey = _get_metadata_from_repo(baseurl,
555 "repodata/repomd.xml.key")
558 msger.debug("\ncan't get %s/%s" % (baseurl, "repodata/repomd.xml.key"))
560 my_repo_metadata.append({"name":reponame,
563 "primary":filepaths['primary'],
566 "patterns":filepaths['patterns'],
567 "comps":filepaths['comps'],
570 return my_repo_metadata
572 def get_rpmver_in_repo(repometadata):
573 for repo in repometadata:
574 if repo["primary"].endswith(".xml"):
575 root = xmlparse(repo["primary"])
576 ns = root.getroot().tag
577 ns = ns[0:ns.rindex("}")+1]
580 for elm in root.getiterator("%spackage" % ns):
581 if elm.find("%sname" % ns).text == 'rpm':
582 for node in elm.getchildren():
583 if node.tag == "%sversion" % ns:
584 versionlist.append(node.attrib['ver'])
590 key = lambda ver: map(int, ver.split('.')))).next()
592 elif repo["primary"].endswith(".sqlite"):
593 con = sqlite.connect(repo["primary"])
594 for row in con.execute("select version from packages where "
595 "name=\"rpm\" ORDER by version DESC"):
601 def get_arch(repometadata):
603 for repo in repometadata:
604 if repo["primary"].endswith(".xml"):
605 root = xmlparse(repo["primary"])
606 ns = root.getroot().tag
607 ns = ns[0:ns.rindex("}")+1]
608 for elm in root.getiterator("%spackage" % ns):
609 if elm.find("%sarch" % ns).text not in ("noarch", "src"):
610 arch = elm.find("%sarch" % ns).text
611 if arch not in archlist:
612 archlist.append(arch)
613 elif repo["primary"].endswith(".sqlite"):
614 con = sqlite.connect(repo["primary"])
615 for row in con.execute("select arch from packages where arch not in (\"src\", \"noarch\")"):
616 if row[0] not in archlist:
617 archlist.append(row[0])
622 for i in range(len(archlist)):
623 if archlist[i] not in rpmmisc.archPolicies.keys():
627 while j < len(uniq_arch):
628 if archlist[i] in rpmmisc.archPolicies[uniq_arch[j]].split(':'):
631 if uniq_arch[j] in rpmmisc.archPolicies[archlist[i]].split(':'):
633 uniq_arch[j] = archlist[i]
636 uniq_arch.remove(uniq_arch[j])
640 uniq_arch.append(archlist[i])
642 return uniq_arch, archlist
644 def get_package(pkg, repometadata, arch = None):
647 for repo in repometadata:
648 if repo["primary"].endswith(".xml"):
649 root = xmlparse(repo["primary"])
650 ns = root.getroot().tag
651 ns = ns[0:ns.rindex("}")+1]
652 for elm in root.getiterator("%spackage" % ns):
653 if elm.find("%sname" % ns).text == pkg:
654 if elm.find("%sarch" % ns).text != "src":
655 version = elm.find("%sversion" % ns)
656 tmpver = "%s-%s" % (version.attrib['ver'], version.attrib['rel'])
659 location = elm.find("%slocation" % ns)
660 pkgpath = "%s" % location.attrib['href']
663 if repo["primary"].endswith(".sqlite"):
664 con = sqlite.connect(repo["primary"])
666 for row in con.execute("select version, release,location_href from packages where name = \"%s\" and arch != \"src\"" % pkg):
667 tmpver = "%s-%s" % (row[0], row[1])
669 pkgpath = "%s" % row[2]
673 for row in con.execute("select version, release,location_href from packages where name = \"%s\"" % pkg):
674 tmpver = "%s-%s" % (row[0], row[1])
676 pkgpath = "%s" % row[2]
681 makedirs("%s/%s/packages" % (target_repo["cachedir"], target_repo["name"]))
682 url = os.path.join(target_repo["baseurl"], pkgpath)
683 filename = str("%s/%s/packages/%s" % (target_repo["cachedir"], target_repo["name"], os.path.basename(pkgpath)))
684 pkg = myurlgrab(str(url), filename, target_repo["proxies"])
689 def get_source_name(pkg, repometadata):
691 def get_bin_name(pkg):
692 m = RPM_RE.match(pkg)
697 def get_src_name(srpm):
698 m = SRPM_RE.match(srpm)
706 pkg_name = get_bin_name(pkg)
710 for repo in repometadata:
711 if repo["primary"].endswith(".xml"):
712 root = xmlparse(repo["primary"])
713 ns = root.getroot().tag
714 ns = ns[0:ns.rindex("}")+1]
715 for elm in root.getiterator("%spackage" % ns):
716 if elm.find("%sname" % ns).text == pkg_name:
717 if elm.find("%sarch" % ns).text != "src":
718 version = elm.find("%sversion" % ns)
719 tmpver = "%s-%s" % (version.attrib['ver'], version.attrib['rel'])
722 fmt = elm.find("%sformat" % ns)
724 fns = fmt.getchildren()[0].tag
725 fns = fns[0:fns.rindex("}")+1]
726 pkgpath = fmt.find("%ssourcerpm" % fns).text
730 if repo["primary"].endswith(".sqlite"):
731 con = sqlite.connect(repo["primary"])
732 for row in con.execute("select version, release, rpm_sourcerpm from packages where name = \"%s\" and arch != \"src\"" % pkg_name):
733 tmpver = "%s-%s" % (row[0], row[1])
735 pkgpath = "%s" % row[2]
740 return get_src_name(pkgpath)
744 def get_pkglist_in_patterns(group, patterns):
748 root = xmlparse(patterns)
750 raise SyntaxError("%s syntax error." % patterns)
752 for elm in list(root.getroot()):
754 ns = ns[0:ns.rindex("}")+1]
755 name = elm.find("%sname" % ns)
756 summary = elm.find("%ssummary" % ns)
757 if name.text == group or summary.text == group:
765 for requires in list(elm):
766 if requires.tag.endswith("requires"):
773 for pkg in list(requires):
774 pkgname = pkg.attrib["name"]
775 if pkgname not in pkglist:
776 pkglist.append(pkgname)
780 def get_pkglist_in_comps(group, comps):
784 root = xmlparse(comps)
786 raise SyntaxError("%s syntax error." % comps)
788 for elm in root.getiterator("group"):
790 name = elm.find("name")
791 if id.text == group or name.text == group:
792 packagelist = elm.find("packagelist")
799 for require in elm.getiterator("packagereq"):
800 if require.tag.endswith("packagereq"):
801 pkgname = require.text
802 if pkgname not in pkglist:
803 pkglist.append(pkgname)
807 def is_statically_linked(binary):
808 return ", statically linked, " in runner.outs(['file', binary])
810 def setup_qemu_emulator(rootdir, arch):
811 # mount binfmt_misc if it doesn't exist
812 if not os.path.exists("/proc/sys/fs/binfmt_misc"):
813 modprobecmd = find_binary_path("modprobe")
814 runner.show([modprobecmd, "binfmt_misc"])
815 if not os.path.exists("/proc/sys/fs/binfmt_misc/register"):
816 mountcmd = find_binary_path("mount")
817 runner.show([mountcmd, "-t", "binfmt_misc", "none", "/proc/sys/fs/binfmt_misc"])
819 # qemu_emulator is a special case, we can't use find_binary_path
820 # qemu emulator should be a statically-linked executable file
821 qemu_emulator = "/usr/bin/qemu-arm"
822 if not os.path.exists(qemu_emulator) or not is_statically_linked(qemu_emulator):
823 qemu_emulator = "/usr/bin/qemu-arm-static"
824 if not os.path.exists(qemu_emulator):
825 raise CreatorError("Please install a statically-linked qemu-arm")
827 # qemu emulator version check
828 armv7_list = [arch for arch in rpmmisc.archPolicies.keys() if arch.startswith('armv7')]
829 if arch in armv7_list: # need qemu (>=0.13.0)
830 qemuout = runner.outs([qemu_emulator, "-h"])
831 m = re.search("version\s*([.\d]+)", qemuout)
833 qemu_version = m.group(1)
834 if qemu_version < "0.13":
835 raise CreatorError("Requires %s version >=0.13 for %s" % (qemu_emulator, arch))
837 msger.warning("Can't get version info of %s, please make sure it's higher than 0.13.0" % qemu_emulator)
839 if not os.path.exists(rootdir + "/usr/bin"):
840 makedirs(rootdir + "/usr/bin")
841 shutil.copy(qemu_emulator, rootdir + qemu_emulator)
843 # disable selinux, selinux will block qemu emulator to run
844 if os.path.exists("/usr/sbin/setenforce"):
845 msger.info('Try to disable selinux')
846 runner.show(["/usr/sbin/setenforce", "0"])
848 node = "/proc/sys/fs/binfmt_misc/arm"
849 if is_statically_linked(qemu_emulator) and os.path.exists(node):
852 # unregister it if it has been registered and is a dynamically-linked executable
853 if not is_statically_linked(qemu_emulator) and os.path.exists(node):
854 qemu_unregister_string = "-1\n"
855 fd = open("/proc/sys/fs/binfmt_misc/arm", "w")
856 fd.write(qemu_unregister_string)
859 # register qemu emulator for interpreting other arch executable file
860 if not os.path.exists(node):
861 qemu_arm_string = ":arm:M::\\x7fELF\\x01\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\x28\\x00:\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xfa\\xff\\xff\\xff:%s:\n" % qemu_emulator
862 fd = open("/proc/sys/fs/binfmt_misc/register", "w")
863 fd.write(qemu_arm_string)
868 def SrcpkgsDownload(pkgs, repometadata, instroot, cachedir):
869 def get_source_repometadata(repometadata):
871 for repo in repometadata:
872 if repo["name"].endswith("-source"):
873 src_repometadata.append(repo)
875 return src_repometadata
878 def get_src_name(srpm):
879 m = SRPM_RE.match(srpm)
884 src_repometadata = get_source_repometadata(repometadata)
886 if not src_repometadata:
887 msger.warning("No source repo found")
893 for repo in src_repometadata:
894 cachepath = "%s/%s/packages/*.src.rpm" %(cachedir, repo["name"])
895 lpkgs_path += glob.glob(cachepath)
897 for lpkg in lpkgs_path:
898 lpkg_name = get_src_name(os.path.basename(lpkg))
899 lpkgs_dict[lpkg_name] = lpkg
900 localpkgs = lpkgs_dict.keys()
903 destdir = instroot+'/usr/src/SRPMS'
904 if not os.path.exists(destdir):
909 srcpkg_name = get_source_name(_pkg, repometadata)
912 srcpkgset.add(srcpkg_name)
914 for pkg in list(srcpkgset):
917 shutil.copy(lpkgs_dict[pkg], destdir)
918 src_pkgs.append(os.path.basename(lpkgs_dict[pkg]))
920 src_pkg = get_package(pkg, src_repometadata, 'src')
922 shutil.copy(src_pkg, destdir)
923 src_pkgs.append(src_pkg)
924 msger.info("%d source packages gotten from cache" % cached_count)
928 def strip_end(text, suffix):
929 if not text.endswith(suffix):
931 return text[:-len(suffix)]