Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 115203 | Differences between
and this patch

Collapse All | Expand All

(-)src/equery/equery.orig (-2 / +163 lines)
Lines 19-24 Link Here
19
import time
19
import time
20
import string
20
import string
21
import types
21
import types
22
import bz2
22
23
23
# portage (output module) and gentoolkit need special path modifications
24
# portage (output module) and gentoolkit need special path modifications
24
sys.path.insert(0, "/usr/lib/portage/pym")
25
sys.path.insert(0, "/usr/lib/portage/pym")
Lines 1478-1483 Link Here
1478
			   "  " + pp.localoption("-p, --portage-tree") + "	  - also search in portage tree (" + gentoolkit.settings["PORTDIR"] + ")\n" + \
1479
			   "  " + pp.localoption("-p, --portage-tree") + "	  - also search in portage tree (" + gentoolkit.settings["PORTDIR"] + ")\n" + \
1479
			   "  " + pp.localoption("-o, --overlay-tree") + "	  - also search in overlay tree (" + gentoolkit.settings["PORTDIR_OVERLAY"] + ")\n"
1480
			   "  " + pp.localoption("-o, --overlay-tree") + "	  - also search in overlay tree (" + gentoolkit.settings["PORTDIR_OVERLAY"] + ")\n"
1480
1481
1482
class CmdDisplayGccVersion(Command):
1483
	"""Display the gcc version used to compile a package."""
1484
	
1485
	def __init__(self):
1486
		self.default_opts = {
1487
			"allInstalledPackages": 0,
1488
			}
1489
1490
	def shortHelp(self):
1491
		return pp.localoption("<local-opts>") + " - display the gcc version used to compile a package"
1492
	
1493
	def longHelp(self):
1494
		return "Display th gcc version used to compile a particular a package\n" + \
1495
			   "\n" + \
1496
			   "Syntax:\n" + \
1497
			   "  " + pp.command("gcc") + pp.localoption(" <local-opts> ") + "\n" + \
1498
			   "  " + pp.command("gcc") + pp.pkgquery(" pkgspec") + "\n" + \
1499
			   pp.localoption("<local-opts>") + " is either of: \n" + \
1500
			   "  " + pp.localoption("-A, --all") + " - scan all installed packages\n"
1501
1502
	def parseArgs(self, args):
1503
1504
		query = ""
1505
		need_help = 0
1506
		opts = self.default_opts
1507
		skip = 0
1508
		
1509
		if len(args)==0:
1510
			need_help=1
1511
		
1512
		for i in xrange(len(args)):
1513
1514
			if skip:
1515
				skip -= 1
1516
				continue
1517
			x = args[i]
1518
			
1519
			if x in ["-h","--help"]:
1520
				need_help = 1
1521
				break
1522
			elif x in ["-A", "--all"]:
1523
				opts["allInstalledPackages"] = 1
1524
			#elif len(args)==0:
1525
				
1526
			else:
1527
				query = x
1528
1529
		if need_help:
1530
			print_info(0, self.longHelp())
1531
			sys.exit(-1)
1532
			
1533
		return (query, opts)
1534
1535
	def perform(self, args):
1536
		(query, opts)=self.parseArgs(args)
1537
		if opts["allInstalledPackages"]:
1538
			print_info(0,"[ Searching for gcc used for "+pp.pkgquery("all packages")+"... ]")
1539
			all=self._scanDb()
1540
			print_info(0,"  Last installed gcc slot:                         "+pp.number(all[0]))
1541
			print_info(0,"  Packages installed:                              "+pp.number(all[1]))
1542
			print_info(0,"  Packages compiled with a gcc of an old slot:     "+portage.output.yellow(all[3]))
1543
			if len(all[4])!=0:
1544
				print_info(0,string.rjust("[SLOT]",13)+string.rjust("[VERSION]",13))
1545
				for p in all[4]:
1546
					print_info(0,string.rjust("["+pp.number((p[0]))+"]",32)+string.rjust("["+pp.number((p[1]))+"]",32)+' '+pp.cpv(p[2]))
1547
			
1548
		else:
1549
			print_info(0,"[ Searching for packages matching "+pp.pkgquery(query+" ")+"... ]")
1550
			v=self._getGccVersion(query)
1551
			print_info(0,pp.section("*")+" gcc version used for "+pp.cpv(v["CPV"]))
1552
			print_info(0,string.rjust("version: ",11)+pp.number(v["COMPILER"]["VERSION"]))
1553
			print_info(0,string.rjust("slot: ",11)+pp.number(v["COMPILER"]["SLOT"]))
1554
1555
	def _gccInstalledSlots(self):
1556
		slots=[]
1557
		expr=re.compile("^gcc-[0-9]")
1558
		for n in os.listdir(portage.root+portage.VDB_PATH+os.sep+"sys-devel"):
1559
			if expr.match(n):
1560
				slots.append(n)
1561
		slots.sort()
1562
		for n in slots:
1563
			slots[slots.index(n)]=open(portage.root+portage.VDB_PATH+os.sep+"sys-devel"+os.sep+n+os.sep+"SLOT", "r").read()[:-1]
1564
		return slots
1565
1566
	def _getGccVersion(self,pkg):
1567
		pkg_split=gentoolkit.split_package_name(pkg)
1568
		if pkg_split[2]!="":     # if a specific version is given
1569
			if pkg_split[0]!="":     # if the category of the package is given
1570
				if pkg_split[0][0]!="=":     # if the category is not preceded by an "="
1571
					found=gentoolkit.find_installed_packages("="+pkg)     # add the "="
1572
				else:
1573
					found=gentoolkit.find_installed_packages(pkg)
1574
			else:     # the category is not given, so we check for the "=" on the package name
1575
				if pkg_split[1][0]!="=":     # if the name is not preceded by an "="
1576
					found=gentoolkit.find_installed_packages("="+pkg)     # add the "="
1577
				else:
1578
					found=gentoolkit.find_installed_packages(pkg)
1579
		else:     # search for all version for the given package
1580
			found=gentoolkit.find_installed_packages(pkg)
1581
		if len(found)==0:
1582
			print_error("Package not found")
1583
			sys.exit(1)
1584
		else:
1585
			for i in gentoolkit.sort_package_list(found):
1586
				compiler={"VERSION":portage.output.red("!!! ")+"unknown", "SLOT":portage.output.red("!!! ")+"unknown"}
1587
				env=bz2.BZ2File(portage.root+portage.VDB_PATH+os.sep+i.get_category()+os.sep+i.get_name()+'-'+i.get_version()+os.sep+"environment.bz2")
1588
				expr=re.compile("^ROOTPATH")
1589
				for l in env.readlines():
1590
					if expr.match(l)!=None:
1591
						break
1592
				l=string.split(string.split(l, "=")[1], ":")
1593
				expr=re.compile(i.get_env_var("CHOST"))
1594
				for v in l:
1595
					m=expr.search(v)
1596
					if m!=None:
1597
						break
1598
				if m==None:
1599
					return {"CPV":i.get_cpv(),"COMPILER":compiler}
1600
				else:
1601
					v=string.split(v, os.sep)
1602
					v=v[len(v)-1]
1603
					if v[-1]=='\n':
1604
						compiler["VERSION"]=v[:-1]
1605
					else:
1606
						compiler["VERSION"]=v
1607
					for s in self._gccInstalledSlots():
1608
						expr=re.compile(s)
1609
						if expr.match(v):
1610
							break
1611
					compiler["SLOT"]=s
1612
				return {"CPV":i.get_cpv(),"COMPILER":compiler}
1613
1614
	def _scanDb(self):
1615
		slots=self._gccInstalledSlots()
1616
		last_slot=slots[-1]
1617
		num_pkg=0
1618
		num_last=0
1619
		old=[]
1620
		l1=os.listdir(portage.root+portage.VDB_PATH)
1621
		l1.sort()
1622
		for i in l1:
1623
			l2=os.listdir(portage.root+portage.VDB_PATH+os.sep+i)
1624
			l2.sort()
1625
			for j in l2:
1626
				pkg=i+os.sep+j
1627
				pkg_gcc=self._getGccVersion(pkg)
1628
				num_pkg+=1
1629
				if pkg_gcc["COMPILER"]["SLOT"]==last_slot:
1630
					num_last+=1
1631
				else:
1632
					old.append(pkg)
1633
		l=[]
1634
		for p in old:
1635
			v=self._getGccVersion(p)
1636
			l.append([v["COMPILER"]["SLOT"],v["COMPILER"]["VERSION"],p])
1637
		return [str(last_slot),str(num_pkg),str(num_last),str(num_pkg-num_last),l]
1638
1639
1481
#
1640
#
1482
# Command line tokens to commands mapping
1641
# Command line tokens to commands mapping
1483
#
1642
#
Lines 1495-1501 Link Here
1495
	"check" : CmdCheckIntegrity(),
1653
	"check" : CmdCheckIntegrity(),
1496
	"stats" : CmdDisplayStatistics(),
1654
	"stats" : CmdDisplayStatistics(),
1497
	"glsa" : CmdListGLSAs(),
1655
	"glsa" : CmdListGLSAs(),
1498
	"which": CmdWhich()
1656
	"which": CmdWhich(),
1657
	"gcc" : CmdDisplayGccVersion()
1499
	}
1658
	}
1500
1659
1501
# Short command line tokens
1660
# Short command line tokens
Lines 1513-1519 Link Here
1513
	"s" : "size",
1672
	"s" : "size",
1514
	"t" : "stats",
1673
	"t" : "stats",
1515
	"u" : "uses",
1674
	"u" : "uses",
1516
	"w" : "which"
1675
	"w" : "which",
1676
	"o" : "gcc"
1517
}
1677
}
1518
1678
1519
from gentoolkit import Config
1679
from gentoolkit import Config

Return to bug 115203