1
2 '''
3 # DESCRIPTION:
4 # Entropy Object Oriented Interface
5
6 Copyright (C) 2007-2009 Fabio Erculiani
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 '''
22 import os
23 import sys
24 import shutil
25 from entropy.const import etpConst, etpUi
26 from entropy.exceptions import *
27 from entropy.output import darkred, darkgreen, brown, darkblue, purple, red, bold
28 from entropy.i18n import _
29 from entropy.core import SystemSettings
32
34
35 if not hasattr(OutputInterface,'updateProgress'):
36 mytxt = _("OutputInterface does not have an updateProgress method")
37 raise IncorrectParameter("IncorrectParameter: %s, (! %s !)" % (OutputInterface,mytxt,))
38 elif not callable(OutputInterface.updateProgress):
39 mytxt = _("OutputInterface does not have an updateProgress method")
40 raise IncorrectParameter("IncorrectParameter: %s, (! %s !)" % (OutputInterface,mytxt,))
41
42 self.spm_backend = etpConst['spm']['backend']
43 self.valid_backends = etpConst['spm']['available_backends']
44 if self.spm_backend not in self.valid_backends:
45 mytxt = "%s: %s" % (_("Invalid backend"),self.spm_backend,)
46 raise IncorrectParameter("IncorrectParameter: %s" % (mytxt,))
47
48 if self.spm_backend == "portage":
49 self.intf = PortagePlugin(OutputInterface)
50
51 @staticmethod
56
58
59 import entropy.tools as entropyTools
60
62 """Take a dependency structure as returned by paren_reduce or use_reduce
63 and generate an equivalent structure that has no redundant lists."""
65 list.__init__(self)
66 self._zap_parens(src, self)
67
69 if not src:
70 return dest
71 i = iter(src)
72 for x in i:
73 if isinstance(x, basestring):
74 if x == '||':
75 x = self._zap_parens(i.next(), [], disjunction=True)
76 if len(x) == 1:
77 dest.append(x[0])
78 else:
79 dest.append("||")
80 dest.append(x)
81 elif x.endswith("?"):
82 dest.append(x)
83 dest.append(self._zap_parens(i.next(), []))
84 else:
85 dest.append(x)
86 else:
87 if disjunction:
88 x = self._zap_parens(x, [])
89 if len(x) == 1:
90 dest.append(x[0])
91 else:
92 dest.append(x)
93 else:
94 self._zap_parens(x, dest)
95 return dest
96
98
99 if not hasattr(OutputInterface,'updateProgress'):
100 mytxt = _("OutputInterface does not have an updateProgress method")
101 raise IncorrectParameter("IncorrectParameter: %s, (! %s !)" % (OutputInterface,mytxt,))
102 elif not callable(OutputInterface.updateProgress):
103 mytxt = _("OutputInterface does not have an updateProgress method")
104 raise IncorrectParameter("IncorrectParameter: %s, (! %s !)" % (OutputInterface,mytxt,))
105
106
107 self.updateProgress = OutputInterface.updateProgress
108 self.askQuestion = OutputInterface.askQuestion
109 sys.path.append("/usr/lib/gentoolkit/pym")
110
111 from entropy.misc import LogFile
112 self.LogFile = LogFile
113
114
115 import portage
116 self.portage = portage
117 self.EAPI = 1
118 try:
119 import portage.const as portage_const
120 except ImportError:
121 import portage_const
122 if hasattr(portage_const,"EAPI"):
123 self.EAPI = portage_const.EAPI
124 self.portage_const = portage_const
125
126 from portage.versions import best
127 self.portage_best = best
128
129 try:
130 import portage.util as portage_util
131 except ImportError:
132 import portage_util
133 self.portage_util = portage_util
134
135 try:
136 import portage.sets as portage_sets
137 self.portage_sets = portage_sets
138 except ImportError:
139 self.portage_sets = None
140
141 try:
142 import glsa
143 self.glsa = glsa
144 except ImportError:
145 self.glsa = None
146
147 if hasattr(self.portage,'exception'):
148 self.portage_exception = self.portage.exception
149 else:
150 self.portage_exception = Exception
151
152 self.builtin_pkg_sets = [
153 "system","world","installed","module-rebuild",
154 "security","preserved-rebuild","live-rebuild",
155 "downgrade","unavailable"
156 ]
157
159 spmLog = self.LogFile(
160 level = etpConst['spmloglevel'],
161 filename = etpConst['spmlogfile'],
162 header = "[spm]"
163 )
164 spmLog.write(message)
165 spmLog.flush()
166 spmLog.close()
167
177
179
180 if not self.glsa: return
181 if command not in ['new','all','affected']: return
182
183 glsaconfig = self.glsa.checkconfig(self.portage.config(clone=self.portage.settings))
184 completelist = self.glsa.get_glsa_list(glsaconfig["GLSA_DIR"], glsaconfig)
185
186 glsalist = []
187 if command == "new":
188 checklist = []
189 if os.access(glsaconfig["CHECKFILE"], os.R_OK):
190 checklist = [line.strip() for line in open(glsaconfig["CHECKFILE"], "r").readlines()]
191 glsalist = [e for e in completelist if e not in checklist]
192 elif command == "all":
193 glsalist = completelist
194 elif command == "affected":
195
196 for x in completelist:
197 try:
198 myglsa = self.glsa.Glsa(x, glsaconfig)
199 except (self.glsa.GlsaTypeException, self.glsa.GlsaFormatException), e:
200 continue
201 if not myglsa.isVulnerable():
202 continue
203 glsalist.append(x)
204
205 return glsalist
206
247
249 if myroot == None:
250 myroot = etpConst['systemroot']+"/"
251 mydb = {}
252 mydb[myroot] = {}
253 mydb[myroot]['vartree'] = self._get_portage_vartree(myroot)
254 mydb[myroot]['porttree'] = self._get_portage_portagetree(myroot)
255 mydb[myroot]['bintree'] = self._get_portage_binarytree(myroot)
256 mydb[myroot]['virtuals'] = self.portage.settings.getvirtuals(myroot)
257 if etpUi['mute']:
258 pid = os.fork()
259 if pid > 0:
260 os.waitpid(pid, 0)
261 else:
262 f = open("/dev/null","w")
263 old_stdout = sys.stdout
264 old_stderr = sys.stderr
265 sys.stdout = f
266 sys.stderr = f
267 self.portage._global_updates(mydb, {})
268 sys.stdout = old_stdout
269 sys.stderr = old_stderr
270 f.close()
271 os._exit(0)
272 else:
273 self.portage._global_updates(mydb, {})
274
276 return os.path.join(etpConst['systemroot'],"/",self.portage_const.WORLD_FILE)
277
279 x = []
280 if self.portage.thirdpartymirrors.has_key(mirrorname):
281 x = self.portage.thirdpartymirrors[mirrorname]
282 return x
283
285 return self.portage.settings[var]
286
288 config_protect = self.portage.settings['CONFIG_PROTECT']
289 config_protect = config_protect.split()
290 config_protect_mask = self.portage.settings['CONFIG_PROTECT_MASK']
291 config_protect_mask = config_protect_mask.split()
292
293 protect = []
294 for x in config_protect:
295 x = os.path.expandvars(x)
296 protect.append(x)
297 mask = []
298 for x in config_protect_mask:
299 x = os.path.expandvars(x)
300 mask.append(x)
301 return ' '.join(protect),' '.join(mask)
302
304
305 if not etpConst['spm']['cache'].has_key('portage'):
306 etpConst['spm']['cache']['portage'] = {}
307 if not etpConst['spm']['cache']['portage'].has_key('vartree'):
308 etpConst['spm']['cache']['portage']['vartree'] = {}
309
310 cached = etpConst['spm']['cache']['portage']['vartree'].get(root)
311 if cached != None:
312 return cached
313
314 try:
315 mytree = self.portage.vartree(root=root)
316 except Exception, e:
317 raise SPMError("SPMError: %s: %s" % (Exception,e,))
318 etpConst['spm']['cache']['portage']['vartree'][root] = mytree
319 return mytree
320
322
323 if not etpConst['spm']['cache'].has_key('portage'):
324 etpConst['spm']['cache']['portage'] = {}
325 if not etpConst['spm']['cache']['portage'].has_key('portagetree'):
326 etpConst['spm']['cache']['portage']['portagetree'] = {}
327
328 cached = etpConst['spm']['cache']['portage']['portagetree'].get(root)
329 if cached != None:
330 return cached
331
332 try:
333 mytree = self.portage.portagetree(root=root)
334 except Exception, e:
335 raise SPMError("SPMError: %s: %s" % (Exception,e,))
336 etpConst['spm']['cache']['portage']['portagetree'][root] = mytree
337 return mytree
338
340
341 if not etpConst['spm']['cache'].has_key('portage'):
342 etpConst['spm']['cache']['portage'] = {}
343 if not etpConst['spm']['cache']['portage'].has_key('binarytree'):
344 etpConst['spm']['cache']['portage']['binarytree'] = {}
345
346 cached = etpConst['spm']['cache']['portage']['binarytree'].get(root)
347 if cached != None:
348 return cached
349
350 pkgdir = root+self.portage.settings['PKGDIR']
351 try:
352 mytree = self.portage.binarytree(root,pkgdir)
353 except Exception, e:
354 raise SPMError("SPMError: %s: %s" % (Exception,e,))
355 etpConst['spm']['cache']['portage']['binarytree'][root] = mytree
356 return mytree
357
359
360 if use_cache:
361 if not etpConst['spm']['cache'].has_key('portage'):
362 etpConst['spm']['cache']['portage'] = {}
363 if not etpConst['spm']['cache']['portage'].has_key('config'):
364 etpConst['spm']['cache']['portage']['config'] = {}
365
366 cached = etpConst['spm']['cache']['portage']['config'].get((config_root,root))
367 if cached != None:
368 return cached
369
370 try:
371 mysettings = self.portage.config(config_root = config_root, target_root = root, config_incrementals = self.portage_const.INCREMENTALS)
372 except Exception, e:
373 raise SPMError("SPMError: %s: %s" % (Exception,e,))
374 if use_cache:
375 etpConst['spm']['cache']['portage']['config'][(config_root,root)] = mysettings
376 return mysettings
377
378
379
381 try:
382 return self.portage.portdb.xmatch(match,str(atom))
383 except ValueError:
384 return None
385
386
388 atoms = self.portage.portdb.xmatch("match-all",str(atom))
389 return self.portage_best(atoms)
390
392 from xml.dom import minidom
393 data = {}
394 portdir = self.portage.settings['PORTDIR']
395 myfile = os.path.join(portdir,category,"metadata.xml")
396 if os.access(myfile,os.R_OK) and os.path.isfile(myfile):
397 doc = minidom.parse(myfile)
398 longdescs = doc.getElementsByTagName("longdescription")
399 for longdesc in longdescs:
400 data[longdesc.getAttribute("lang").strip()] = ' '.join([x.strip() for x in longdesc.firstChild.data.strip().split("\n")])
401 return data
402
404 try:
405 return self.portage.portdb.xmatch("match-all",str(atom))[0].split("/")[0]
406 except:
407 return None
408
409
411 system = self.portage.settings.packages
412 sysoutput = []
413 for x in system:
414 y = self.get_installed_atoms(x)
415 if (y != None):
416 for z in y:
417 sysoutput.append(z)
418 sysoutput.extend(etpConst['spm']['system_packages'])
419 return sysoutput
420
422 mypath = etpConst['systemroot']+"/"
423 mytree = self._get_portage_vartree(mypath)
424 rc = mytree.dep_match(str(atom))
425 if rc: return rc[-1]
426
428 if atom.startswith("="): atom = atom[1:]
429 return self.portage.portdb.aux_get(atom,['DESCRIPTION'])[0]
430
432 if atom.startswith("="): atom = atom[1:]
433 return self.portage.portdb.findname(atom)
434
436 if atom.startswith("="): atom = atom[1:]
437 ebuild_path = self.get_package_ebuild_path(atom)
438 if isinstance(ebuild_path,basestring):
439 cp = os.path.join(os.path.dirname(ebuild_path),"ChangeLog")
440 if os.path.isfile(cp) and os.access(cp,os.R_OK):
441 f = open(cp,"r")
442 txt = f.read()
443 f.close()
444 return txt
445
447 mypath = etpConst['systemroot']+"/"
448 mytree = self._get_portage_vartree(mypath)
449 if atom.startswith("="): atom = atom[1:]
450 rc = mytree.dbapi.aux_get(atom, ["DESCRIPTION"])[0]
451 if rc: return rc
452
454 if atom.startswith("="): atom = atom[1:]
455 return self.portage.portdb.aux_get(atom,['SLOT'])[0]
456
458 mypath = etpConst['systemroot']+"/"
459 mytree = self._get_portage_vartree(mypath)
460 if atom.startswith("="): atom = atom[1:]
461 rc = mytree.getslot(atom)
462 if rc: return rc
463
465 mypath = etpConst['systemroot']+"/"
466 mytree = self._get_portage_vartree(mypath)
467 rc = mytree.dep_match(str(atom))
468 if rc: return rc
469
471 key_split = key.split("/")
472 cat = key_split[0]
473 name = key_split[1]
474 cat_dir = os.path.join(self.get_vdb_path(),cat)
475 if not os.path.isdir(cat_dir):
476 return []
477 return [os.path.join(cat,x) for x in os.listdir(cat_dir) if \
478 x.startswith(name)]
479
480
482
483
484 pkgname = atom.split("/")[1]
485 pkgcat = atom.split("/")[0]
486
487 if not os.path.isdir(dirpath):
488 os.makedirs(dirpath)
489 dirpath += "/"+pkgname+etpConst['packagesext']
490 dbdir = self.get_vdb_path()+"/"+pkgcat+"/"+pkgname+"/"
491
492 import tarfile
493 import stat
494 trees = self.portage.db["/"]
495 vartree = trees["vartree"]
496 dblnk = self.portage.dblink(pkgcat, pkgname, "/", vartree.settings, treetype="vartree", vartree=vartree)
497 dblnk.lockdb()
498 tar = tarfile.open(dirpath,"w:bz2")
499
500 contents = dblnk.getcontents()
501 paths = sorted(contents.keys())
502
503 for path in paths:
504 try:
505 exist = os.lstat(path)
506 except OSError:
507 continue
508 ftype = contents[path][0]
509 lpath = path
510 arcname = path[1:]
511 if 'dir' == ftype and \
512 not stat.S_ISDIR(exist.st_mode) and \
513 os.path.isdir(lpath):
514 lpath = os.path.realpath(lpath)
515 tarinfo = tar.gettarinfo(lpath, arcname)
516
517 if stat.S_ISREG(exist.st_mode):
518 tarinfo.type = tarfile.REGTYPE
519 f = open(path)
520 try:
521 tar.addfile(tarinfo, f)
522 finally:
523 f.close()
524 else:
525 tar.addfile(tarinfo)
526
527 tar.close()
528
529
530 import entropy.xpak as xpak
531 tbz2 = xpak.tbz2(dirpath)
532 tbz2.recompose(dbdir)
533
534 dblnk.unlockdb()
535
536 if os.path.isfile(dirpath):
537 return dirpath
538 else:
539 raise FileNotFound("FileNotFound: Spm:quickpkg %s: %s %s" % (
540 _("error"),
541 dirpath,
542 _("not found"),
543 )
544 )
545
547 return os.path.join(self.portage_const.USER_CONFIG_PATH,'package.use')
548
550 result = self.unset_package_useflags(atom, useflags)
551 if not result: return False
552 return self._handle_new_useflags(atom, useflags, "")
553
555 result = self.unset_package_useflags(atom, useflags)
556 if not result: return False
557 return self._handle_new_useflags(atom, useflags, "-")
558
560 matched_atom = self.get_best_atom(atom)
561 if not matched_atom:
562 return False
563 use_file = self.get_package_use_file()
564
565 if not (os.path.isfile(use_file) and os.access(use_file,os.W_OK)):
566 return False
567 f = open(use_file,"r")
568 content = [x.strip() for x in f.readlines()]
569 f.close()
570
571 def handle_line(line, useflags):
572
573 data = line.split()
574 if len(data) < 2:
575 return False, line
576
577 myatom = data[0]
578 if matched_atom != self.get_best_atom(myatom):
579 return False, line
580
581 flags = data[1:]
582 base_flags = []
583 added_flags = []
584 for flag in flags:
585 myflag = flag
586 if myflag.startswith("+"):
587 myflag = myflag[1:]
588 elif myflag.startswith("-"):
589 myflag = myflag[1:]
590 if not myflag:
591 continue
592 base_flags.append(myflag)
593
594 for useflag in useflags:
595 if mark+useflag in base_flags:
596 continue
597 added_flags.append(mark+useflag)
598
599 new_line = "%s %s" % (myatom, ' '.join(flags+added_flags))
600 return True, new_line
601
602
603 atom_found = False
604 new_content = []
605 for line in content:
606
607 changed, elaborated_line = handle_line(line, useflags)
608 if changed: atom_found = True
609 new_content.append(elaborated_line)
610
611 if not atom_found:
612 myline = "%s %s" % (atom, ' '.join([mark+x for x in useflags]))
613 new_content.append(myline)
614
615
616 f = open(use_file+".tmp","w")
617 for line in new_content:
618 f.write(line+"\n")
619 f.flush()
620 f.close()
621 shutil.move(use_file+".tmp",use_file)
622 return True
623
625 matched_atom = self.get_best_atom(atom)
626 if not matched_atom:
627 return False
628
629 use_file = self.get_package_use_file()
630 if not (os.path.isfile(use_file) and os.access(use_file,os.W_OK)):
631 return False
632
633 f = open(use_file,"r")
634 content = [x.strip() for x in f.readlines()]
635 f.close()
636
637 new_content = []
638 for line in content:
639
640 data = line.split()
641 if len(data) < 2:
642 new_content.append(line)
643 continue
644
645 myatom = data[0]
646 if matched_atom != self.get_best_atom(myatom):
647 new_content.append(line)
648 continue
649
650 flags = data[1:]
651 new_flags = []
652 for flag in flags:
653 myflag = flag
654
655 if myflag.startswith("+"):
656 myflag = myflag[1:]
657 elif myflag.startswith("-"):
658 myflag = myflag[1:]
659
660 if myflag in useflags:
661 continue
662 elif not flag:
663 continue
664
665 new_flags.append(flag)
666
667 if new_flags:
668 new_line = "%s %s" % (myatom, ' '.join(new_flags))
669 new_content.append(new_line)
670
671 f = open(use_file+".tmp","w")
672 for line in new_content:
673 f.write(line+"\n")
674 f.flush()
675 f.close()
676 shutil.move(use_file+".tmp",use_file)
677 return True
678
680 matched_atom = self.get_best_atom(atom)
681 if not matched_atom:
682 return {}
683 global_useflags = self.get_useflags()
684 use_force = self.get_useflags_force()
685 use_mask = self.get_useflags_mask()
686 package_use_useflags = self.get_package_use_useflags(atom)
687
688 data = {}
689 data['use_force'] = use_force.copy()
690 data['use_mask'] = use_mask.copy()
691 data['global_use'] = global_useflags.split()
692
693 iuse = self.get_package_setting(atom, "IUSE")
694 if not isinstance(iuse,basestring):
695 iuse = ''
696 data['iuse'] = iuse.split()[:]
697 iuse = set()
698 for myiuse in data['iuse']:
699 if myiuse.startswith("+"):
700 myiuse = myiuse[1:]
701 iuse.add(myiuse)
702
703 use = [f for f in data['global_use']+list(package_use_useflags['enabled']) if (f in iuse) and (f not in use_mask) and (f not in package_use_useflags['disabled'])]
704 use_disabled = [f for f in iuse if (f not in data['global_use']) and (f not in use_mask) and (f not in package_use_useflags['enabled'])]
705 data['use'] = use[:]
706 data['use_disabled'] = use_disabled[:]
707
708 matched_slot = self.get_package_slot(matched_atom)
709 try:
710 installed_atom = self.get_installed_atom("%s:%s" % (self.entropyTools.dep_getkey(atom),matched_slot,))
711 except self.portage_exception:
712 installed_atom = None
713
714 if installed_atom:
715
716
717 previous_iuse = self.get_installed_package_setting(installed_atom, "IUSE").split()
718 previous_use = self.get_installed_package_setting(installed_atom, "USE").split()
719
720 new_previous_iuse = set()
721 for myuse in previous_iuse:
722 if myuse.startswith("+"):
723 myuse = myuse[1:]
724 new_previous_iuse.add(myuse)
725 previous_iuse = list(new_previous_iuse)
726
727 inst_use = [f for f in previous_iuse if (f in previous_use) and (f not in use_mask)]
728
729
730
731 use_removed = []
732 for myuse in inst_use:
733 if myuse not in use:
734 use_removed.append(myuse)
735
736
737 use_not_avail = []
738 for myuse in previous_iuse:
739 if (myuse not in iuse) and (myuse not in use_removed):
740 use_not_avail.append(myuse)
741
742
743 t_use = []
744 for myuse in use:
745 if myuse not in inst_use:
746 myuse = "+%s*" % (myuse,)
747 t_use.append(myuse)
748 use = t_use
749
750
751 t_use_disabled = []
752 for myuse in use_disabled:
753 if myuse in inst_use:
754 if myuse in use_removed+use_not_avail:
755 continue
756 myuse = "-%s*" % (myuse,)
757 else:
758 myuse = "-%s" % (myuse,)
759 t_use_disabled.append(myuse)
760 use_disabled = t_use_disabled
761
762 for myuse in use_removed:
763 use_disabled.append("(-%s*)" % (myuse,))
764 for myuse in use_not_avail:
765 use_disabled.append("(-%s)" % (myuse,))
766 else:
767 use_disabled = ["-"+x for x in use_disabled]
768
769 data['use_string'] = ' '.join(sorted(use)+sorted([x for x in use_disabled]))
770 data['use_string_colored'] = ' '.join(
771 sorted([darkred(x) for x in use if not x.startswith("+")] + \
772 [darkgreen(x) for x in use if x.startswith("+")]) + \
773 sorted([darkblue(x) for x in use_disabled if x.startswith("-")] + \
774 [brown(x) for x in use_disabled if x.startswith("(") and (x.find("*") == -1)] + \
775 [purple(x) for x in use_disabled if x.startswith("(") and (x.find("*") != -1)]
776 )
777 )
778 return data
779
781
782 matched_atom = self.get_installed_atom(atom)
783 if not matched_atom:
784 return {}
785
786 global_use = self.get_installed_package_setting(matched_atom, "USE")
787 use_mask = self.get_useflags_mask()
788
789 data = {}
790 data['use_mask'] = use_mask.copy()
791 data['global_use'] = global_use.split()
792
793 iuse = self.get_installed_package_setting(matched_atom, "IUSE")
794 if not isinstance(iuse,basestring): iuse = ''
795 data['iuse'] = iuse.split()[:]
796 iuse = set()
797 for myiuse in data['iuse']:
798 if myiuse.startswith("+"):
799 myiuse = myiuse[1:]
800 iuse.add(myiuse)
801
802 use = [f for f in data['global_use'] if (f in iuse) and (f not in use_mask)]
803 use_disabled = [f for f in iuse if (f not in data['global_use']) and (f not in use_mask)]
804 data['use'] = use[:]
805 data['use_disabled'] = use_disabled[:]
806
807 data['use_string'] = ' '.join(sorted(use)+sorted([x for x in use_disabled]))
808 data['use_string_colored'] = ' '.join(
809 sorted([darkred(x) for x in use if not x.startswith("+")] + \
810 [darkgreen(x) for x in use if x.startswith("+")]) + \
811 sorted([darkblue(x) for x in use_disabled if x.startswith("-")] + \
812 [brown(x) for x in use_disabled if x.startswith("(") and (x.find("*") == -1)] + \
813 [purple(x) for x in use_disabled if x.startswith("(") and (x.find("*") != -1)]
814 )
815 )
816 return data
817
818
820
821 data = {
822 'enabled': set(),
823 'disabled': set(),
824 }
825
826 matched_atom = self.get_best_atom(atom)
827 if not matched_atom:
828 return data
829
830 use_file = self.get_package_use_file()
831 if not (os.path.isfile(use_file) and os.access(use_file,os.W_OK)):
832 return data
833
834 use_data = self.portage_util.grabdict(use_file)
835 for myatom in use_data:
836 mymatch = self.get_best_atom(myatom)
837 if mymatch != matched_atom:
838 continue
839 for flag in use_data[myatom]:
840 if flag.startswith("-"):
841 myflag = flag[1:]
842 data['enabled'].discard(myflag)
843 data['disabled'].add(myflag)
844 else:
845 myflag = flag
846 if myflag.startswith("+"):
847 myflag = myflag[1:]
848 data['disabled'].discard(myflag)
849 data['enabled'].add(myflag)
850
851 return data
852
854 return self.portage.settings['USE']
855
857 return self.portage.settings.useforce
858
860 return self.portage.settings.usemask
861
863 mypath = etpConst['systemroot']+"/"
864 mytree = self._get_portage_vartree(mypath)
865 if atom.startswith("="): atom = atom[1:]
866 return mytree.dbapi.aux_get(atom, [setting])[0]
867
869 if atom.startswith("="): atom = atom[1:]
870 return self.portage.portdb.aux_get(atom,[setting])[0]
871
873 mypath = etpConst['systemroot']+"/"
874 mysplit = atom.split("/")
875 content = self.portage.dblink(mysplit[0], mysplit[1], mypath, self.portage.settings).getcontents()
876 return content.keys()
877
879 mypath = etpConst['systemroot']+"/"
880 mytree = self._get_portage_vartree(mypath)
881 packages = mytree.dbapi.cpv_all()
882 matches = set()
883 for package in packages:
884 mysplit = package.split("/")
885 content = self.portage.dblink(mysplit[0], mysplit[1], mypath, self.portage.settings).getcontents()
886 if not like:
887 if filename in content:
888 matches.add(package)
889 else:
890 for myfile in content:
891 if myfile.find(filename) != -1:
892 matches.add(package)
893 return matches
894
896 mypath = etpConst['systemroot']+"/"
897 mytree = self._get_portage_vartree(mypath)
898 packages = mytree.dbapi.cpv_all()
899 matches = {}
900 filenames = filenames.copy()
901 for package in packages:
902 cat, pkgv = package.split("/")
903 content = self.portage.dblink(cat, pkgv, mypath, self.portage.settings).getcontents()
904 if not like:
905 for filename in filenames:
906 if filename in content:
907 myslot = self.get_installed_package_slot(package)
908 if not matches.has_key((package,myslot)):
909 matches[(package,myslot)] = set()
910 matches[(package,myslot)].add(filename)
911 else:
912 for filename in filenames:
913 for myfile in content:
914 if myfile.find(filename) != -1:
915 myslot = self.get_installed_package_slot(package)
916 if not matches.has_key((package,myslot)):
917 matches[(package,myslot)] = set()
918 matches[(package,myslot)].add(filename)
919 return matches
920
921 - def calculate_dependencies(self, my_iuse, my_use, my_license, my_depend, my_rdepend, my_pdepend, my_provide, my_src_uri):
922 metadata = {}
923 metadata['USE'] = my_use
924 metadata['IUSE'] = my_iuse
925 metadata['LICENSE'] = my_license
926 metadata['DEPEND'] = my_depend
927 metadata['PDEPEND'] = my_pdepend
928 metadata['RDEPEND'] = my_rdepend
929 metadata['PROVIDE'] = my_provide
930 metadata['SRC_URI'] = my_src_uri
931 use = metadata['USE'].split()
932 raw_use = use
933 metadata['USE_MASK'] = self.get_useflags_mask()
934 iuse = set()
935 for myiuse in metadata['IUSE'].split():
936 if myiuse.startswith("+"):
937 myiuse = myiuse[1:]
938 if (myiuse not in use) and ("-"+myiuse not in use):
939 use.append(myiuse)
940 elif myiuse.startswith("-"):
941 myiuse = myiuse[1:]
942 iuse.add(myiuse)
943 use = sorted([f for f in use if f in iuse])
944 metadata['USE'] = " ".join(use)
945 for k in "LICENSE", "RDEPEND", "DEPEND", "PDEPEND", "PROVIDE", "SRC_URI":
946 try:
947 deps = self.paren_reduce(metadata[k])
948 deps = self.use_reduce(deps, uselist=raw_use)
949 deps = self.paren_normalize(deps)
950 if k == "LICENSE":
951 deps = self.paren_license_choose(deps)
952 else:
953 deps = self.paren_choose(deps)
954 if k.endswith("DEPEND"):
955 deps = self.usedeps_reduce(deps)
956 deps = ' '.join(deps)
957 except Exception, e:
958 self.entropyTools.print_traceback()
959 self.updateProgress(
960 darkred("%s: %s: %s :: %s") % (
961 _("Error calculating dependencies"),
962 str(Exception),
963 k,
964 e,
965 ),
966 importance = 1,
967 type = "error",
968 header = red(" !!! ")
969 )
970 deps = ''
971 continue
972 metadata[k] = deps
973 return metadata
974
976 newlist = []
977 for dependency in dependencies:
978 use_deps = self.entropyTools.dep_getusedeps(dependency)
979 if use_deps:
980 use_deps = [x for x in use_deps if (x[0] not in ("!",)) and (x[-1] not in ("=","?",))]
981 if use_deps:
982 dependency = "%s[%s]" % (self.entropyTools.remove_usedeps(dependency),','.join(use_deps),)
983 else:
984 dependency = self.entropyTools.remove_usedeps(dependency)
985 newlist.append(dependency)
986 return newlist
987
989 """
990
991 # deps.py -- Portage dependency resolution functions
992 # Copyright 2003-2004 Gentoo Foundation
993 # Distributed under the terms of the GNU General Public License v2
994 # $Id: portage_dep.py 9174 2008-01-11 05:49:02Z zmedico $
995
996 Take a string and convert all paren enclosed entities into sublists, optionally
997 futher splitting the list elements by spaces.
998
999 Example usage:
1000 >>> paren_reduce('foobar foo ( bar baz )',1)
1001 ['foobar', 'foo', ['bar', 'baz']]
1002 >>> paren_reduce('foobar foo ( bar baz )',0)
1003 ['foobar foo ', [' bar baz ']]
1004
1005 @param mystr: The string to reduce
1006 @type mystr: String
1007 @rtype: Array
1008 @return: The reduced string in an array
1009 """
1010 mylist = []
1011 while mystr:
1012 left_paren = mystr.find("(")
1013 has_left_paren = left_paren != -1
1014 right_paren = mystr.find(")")
1015 has_right_paren = right_paren != -1
1016 if not has_left_paren and not has_right_paren:
1017 freesec = mystr
1018 subsec = None
1019 tail = ""
1020 elif mystr[0] == ")":
1021 return [mylist,mystr[1:]]
1022 elif has_left_paren and not has_right_paren:
1023 raise InvalidDependString(
1024 "InvalidDependString: %s: '%s'" % (_("missing right parenthesis"),mystr,))
1025 elif has_left_paren and left_paren < right_paren:
1026 freesec,subsec = mystr.split("(",1)
1027 subsec,tail = self.paren_reduce(subsec)
1028 else:
1029 subsec,tail = mystr.split(")",1)
1030 subsec = self.strip_empty(subsec.split(" "))
1031 return [mylist+subsec,tail]
1032 mystr = tail
1033 if freesec:
1034 mylist = mylist + self.strip_empty(freesec.split(" "))
1035 if subsec is not None:
1036 mylist = mylist + [subsec]
1037 return mylist
1038
1040 """
1041
1042 # deps.py -- Portage dependency resolution functions
1043 # Copyright 2003-2004 Gentoo Foundation
1044 # Distributed under the terms of the GNU General Public License v2
1045 # $Id: portage_dep.py 9174 2008-01-11 05:49:02Z zmedico $
1046
1047 Strip all empty elements from an array
1048
1049 @param myarr: The list of elements
1050 @type myarr: List
1051 @rtype: Array
1052 @return: The array with empty elements removed
1053 """
1054 for x in range(len(myarr)-1, -1, -1):
1055 if not myarr[x]:
1056 del myarr[x]
1057 return myarr
1058
1059 - def use_reduce(self, deparray, uselist=[], masklist=[], matchall=0, excludeall=[]):
1060 """
1061
1062 # deps.py -- Portage dependency resolution functions
1063 # Copyright 2003-2004 Gentoo Foundation
1064 # Distributed under the terms of the GNU General Public License v2
1065 # $Id: portage_dep.py 9174 2008-01-11 05:49:02Z zmedico $
1066
1067 Takes a paren_reduce'd array and reduces the use? conditionals out
1068 leaving an array with subarrays
1069
1070 @param deparray: paren_reduce'd list of deps
1071 @type deparray: List
1072 @param uselist: List of use flags
1073 @type uselist: List
1074 @param masklist: List of masked flags
1075 @type masklist: List
1076 @param matchall: Resolve all conditional deps unconditionally. Used by repoman
1077 @type matchall: Integer
1078 @rtype: List
1079 @return: The use reduced depend array
1080 """
1081
1082 for x in range(len(deparray)):
1083 if deparray[x] in ["||","&&"]:
1084 if len(deparray) - 1 == x or not isinstance(deparray[x+1], list):
1085 mytxt = _("missing atom list in")
1086 raise InvalidDependString(deparray[x]+" "+mytxt+" \""+str(deparray)+"\"")
1087 if deparray and deparray[-1] and deparray[-1][-1] == "?":
1088 mytxt = _("Conditional without target in")
1089 raise InvalidDependString("InvalidDependString: "+mytxt+" \""+str(deparray)+"\"")
1090
1091
1092
1093
1094
1095 _dep_check_strict = False
1096
1097 mydeparray = deparray[:]
1098 rlist = []
1099 while mydeparray:
1100 head = mydeparray.pop(0)
1101
1102 if isinstance(head,list):
1103 additions = self.use_reduce(head, uselist, masklist, matchall, excludeall)
1104 if additions:
1105 rlist.append(additions)
1106 elif rlist and rlist[-1] == "||":
1107
1108
1109 rlist.append([])
1110 else:
1111 if head[-1] == "?":
1112
1113 newdeparray = [head]
1114 while isinstance(newdeparray[-1], basestring) and newdeparray[-1][-1] == "?":
1115 if mydeparray:
1116 newdeparray.append(mydeparray.pop(0))
1117 else:
1118 raise ValueError, _("Conditional with no target")
1119
1120
1121 warned = 0
1122 if len(newdeparray[-1]) == 0:
1123 mytxt = "%s. (%s)" % (_("Empty target in string"),_("Deprecated"),)
1124 self.updateProgress(
1125 darkred("PortagePlugin.use_reduce(): %s" % (mytxt,)),
1126 importance = 0,
1127 type = "error",
1128 header = bold(" !!! ")
1129 )
1130 warned = 1
1131 if len(newdeparray) != 2:
1132 mytxt = "%s. (%s)" % (_("Nested use flags without parenthesis"),_("Deprecated"),)
1133 self.updateProgress(
1134 darkred("PortagePlugin.use_reduce(): %s" % (mytxt,)),
1135 importance = 0,
1136 type = "error",
1137 header = bold(" !!! ")
1138 )
1139 warned = 1
1140 if warned:
1141 self.updateProgress(
1142 darkred("PortagePlugin.use_reduce(): "+" ".join(map(str,[head]+newdeparray))),
1143 importance = 0,
1144 type = "error",
1145 header = bold(" !!! ")
1146 )
1147
1148
1149 ismatch = True
1150 missing_flag = False
1151 for head in newdeparray[:-1]:
1152 head = head[:-1]
1153 if not head:
1154 missing_flag = True
1155 break
1156 if head.startswith("!"):
1157 head_key = head[1:]
1158 if not head_key:
1159 missing_flag = True
1160 break
1161 if not matchall and head_key in uselist or \
1162 head_key in excludeall:
1163 ismatch = False
1164 break
1165 elif head not in masklist:
1166 if not matchall and head not in uselist:
1167 ismatch = False
1168 break
1169 else:
1170 ismatch = False
1171 if missing_flag:
1172 mytxt = _("Conditional without flag")
1173 raise InvalidDependString(
1174 "InvalidDependString: "+mytxt+": \"" + \
1175 str([head+"?", newdeparray[-1]])+"\"")
1176
1177
1178 if ismatch:
1179 target = newdeparray[-1]
1180 if isinstance(target, list):
1181 additions = self.use_reduce(target, uselist, masklist, matchall, excludeall)
1182 if additions:
1183 rlist.append(additions)
1184 elif not _dep_check_strict:
1185
1186 rlist.append(target)
1187 else:
1188 mytxt = _("Conditional without parenthesis")
1189 raise InvalidDependString(
1190 "InvalidDependString: "+mytxt+": '%s?'" % head)
1191
1192 else:
1193 rlist += [head]
1194 return rlist
1195
1197 newlist = []
1198 do_skip = False
1199 for idx in range(len(dep_list)):
1200
1201 if do_skip:
1202 do_skip = False
1203 continue
1204
1205 item = dep_list[idx]
1206 if item == "||":
1207 next_item = dep_list[idx+1]
1208 if not next_item:
1209 do_skip = True
1210 continue
1211 item = self.dep_or_select(next_item)
1212 if not item:
1213
1214 newlist.append(str(next_item))
1215 else:
1216 newlist += item
1217 do_skip = True
1218 elif isinstance(item, list):
1219 item = self.dep_and_select(item)
1220 newlist += item
1221 else:
1222 newlist.append(item)
1223
1224 return newlist
1225
1227 do_skip = False
1228 newlist = []
1229 for idx in range(len(and_list)):
1230
1231 if do_skip:
1232 do_skip = False
1233 continue
1234
1235 x = and_list[idx]
1236 if x == "||":
1237 x = self.dep_or_select(and_list[idx+1])
1238 do_skip = True
1239 if not x:
1240 x = str(and_list[idx+1])
1241 else:
1242 newlist += x
1243 elif isinstance(x, list):
1244 x = self.dep_and_select(x)
1245 newlist += x
1246 else:
1247 newlist.append(x)
1248
1249
1250 for x in newlist:
1251 match = self.get_installed_atom(x)
1252 if match == None:
1253 return []
1254
1255 return newlist
1256
1258 do_skip = False
1259 for idx in range(len(or_list)):
1260 if do_skip:
1261 do_skip = False
1262 continue
1263 x = or_list[idx]
1264 if x == "||":
1265 x = self.dep_or_select(or_list[idx+1])
1266 do_skip = True
1267 elif isinstance(x, list):
1268 x = self.dep_and_select(x)
1269 if not x:
1270 continue
1271
1272 return x
1273 else:
1274 x = [x]
1275
1276 for y in x:
1277 match = self.get_installed_atom(y)
1278 if match != None:
1279 return [y]
1280
1281 return []
1282
1284
1285 newlist = set()
1286 for item in dep_list:
1287
1288 if isinstance(item, list):
1289
1290 data = set(self.paren_license_choose(item))
1291 newlist.update(data)
1292 else:
1293 if item not in ["||"]:
1294 newlist.add(item)
1295
1296 return list(newlist)
1297
1299 rc = etpConst['systemroot']+"/"+self.portage_const.VDB_PATH
1300 if (not rc.endswith("/")):
1301 return rc+"/"
1302 return rc
1303
1305 mypath = etpConst['systemroot']+"/"
1306 mysettings = self._get_portage_config("/",mypath)
1307 portdb = self.portage.portdbapi(mysettings["PORTDIR"], mysettings = mysettings)
1308 cps = portdb.cp_all()
1309 visibles = set()
1310 for cp in cps:
1311 if categories and cp.split("/")[0] not in categories:
1312 continue
1313
1314 slots = set()
1315 atoms = self.get_best_atom(cp, "match-visible")
1316 if atoms:
1317 for atom in atoms:
1318 slots.add(portdb.aux_get(atom, ["SLOT"])[0])
1319 for slot in slots:
1320 visibles.add(cp+":"+slot)
1321 del cps
1322
1323
1324 available = set()
1325 for visible in visibles:
1326 match = self.get_best_atom(visible)
1327 if match == None:
1328 continue
1329 if filter_reinstalls:
1330 installed = self.get_installed_atom(visible)
1331
1332 if installed != match:
1333 available.add(match)
1334 else:
1335 available.add(match)
1336 del visibles
1337
1338 return available
1339
1340
1342 if not dbdir:
1343 appDbDir = self.get_vdb_path()
1344 else:
1345 appDbDir = dbdir
1346 dbDirs = os.listdir(appDbDir)
1347 installedAtoms = set()
1348 for pkgsdir in dbDirs:
1349 if os.path.isdir(appDbDir+pkgsdir):
1350 pkgdir = os.listdir(appDbDir+pkgsdir)
1351 for pdir in pkgdir:
1352 pkgcat = pkgsdir.split("/")[-1]
1353 if categories and (pkgcat not in categories):
1354 continue
1355 pkgatom = pkgcat+"/"+pdir
1356 if pkgatom.find("-MERGING-") == -1:
1357 installedAtoms.add(pkgatom)
1358 return sorted(list(installedAtoms)), len(installedAtoms)
1359
1361 if not dbdir:
1362 appDbDir = self.get_vdb_path()
1363 else:
1364 appDbDir = dbdir
1365 installedAtoms = set()
1366
1367 for current_dirpath, subdirs, files in os.walk(appDbDir):
1368 pvs = os.listdir(current_dirpath)
1369 for mypv in pvs:
1370 if mypv.startswith("-MERGING-"):
1371 continue
1372 mypvpath = current_dirpath+"/"+mypv
1373 if not os.path.isdir(mypvpath):
1374 continue
1375 mycounter_file = mypvpath+"/"+etpConst['spm']['xpak_entries']['counter']
1376 if not os.access(mycounter_file,os.R_OK):
1377 continue
1378 f = open(mycounter_file)
1379 try:
1380 counter = int(f.readline().strip())
1381 except (IOError, ValueError):
1382 f.close()
1383 continue
1384 installedAtoms.add((os.path.basename(current_dirpath)+"/"+mypv,counter))
1385 return installedAtoms
1386
1388
1389
1390 setconfigpaths = [os.path.join(self.portage_const.GLOBAL_CONFIG_PATH, etpConst['setsconffilename'])]
1391 setconfigpaths.append(os.path.join(settings["PORTDIR"], etpConst['setsconffilename']))
1392 setconfigpaths += [os.path.join(x, etpConst['setsconffilename']) for x in settings["PORTDIR_OVERLAY"].split()]
1393 setconfigpaths.append(os.path.join(settings["PORTAGE_CONFIGROOT"],
1394 self.portage_const.USER_CONFIG_PATH.lstrip(os.path.sep), etpConst['setsconffilename']))
1395 return self.portage_sets.SetConfig(setconfigpaths, settings, trees)
1396
1398
1399 if self.portage_sets == None: return
1400 myroot = etpConst['systemroot']+"/"
1401 return self._load_sets_config(
1402 self.portage.settings,
1403 self.portage.db[myroot]
1404 )
1405
1407 config = self.get_set_config()
1408 if config == None: return {}
1409 mysets = config.getSets()
1410 if not builtin_sets:
1411 builtin_pkg_sets = [x for x in self.builtin_pkg_sets if x in mysets]
1412 for pkg_set in builtin_pkg_sets: mysets.pop(pkg_set)
1413 return mysets
1414
1416 config = self.get_set_config()
1417 if config == None: return []
1418 return config.getSetAtoms(pkgset_obj).copy()
1419
1421 config = self.get_set_config()
1422 if config == None: return {}
1423 mysets = {}
1424 sets = config.getSets()
1425 if not builtin_sets:
1426 builtin_pkg_sets = [x for x in self.builtin_pkg_sets if x in sets]
1427 for pkg_set in builtin_pkg_sets: sets.pop(pkg_set)
1428 for myset in sorted(sets):
1429 try: atoms = config.getSetAtoms(myset).copy()
1430 except: continue
1431 mysets[myset] = atoms
1432 return mysets
1433
1435 if not dbdir:
1436 appDbDir = self.get_vdb_path()
1437 else:
1438 appDbDir = dbdir
1439 counters = set()
1440 for catdir in os.listdir(appDbDir):
1441 catdir = appDbDir+catdir
1442 if not os.path.isdir(catdir):
1443 continue
1444 for pkgdir in os.listdir(catdir):
1445 pkgdir = catdir+"/"+pkgdir
1446 if not os.path.isdir(pkgdir):
1447 continue
1448 counterfile = pkgdir+"/"+etpConst['spm']['xpak_entries']['counter']
1449 if not os.path.isfile(pkgdir+"/"+etpConst['spm']['xpak_entries']['counter']):
1450 continue
1451 try:
1452 f = open(counterfile,"r")
1453 counter = int(f.readline().strip())
1454 counters.add(counter)
1455 f.close()
1456 except:
1457 continue
1458 if counters:
1459 newcounter = max(counters)
1460 else:
1461 newcounter = 0
1462 if not os.path.isdir(os.path.dirname(etpConst['edbcounter'])):
1463 os.makedirs(os.path.dirname(etpConst['edbcounter']))
1464 try:
1465 f = open(etpConst['edbcounter'],"w")
1466 except IOError, e:
1467 if e[0] == 21:
1468 shutil.rmtree(etpConst['edbcounter'],True)
1469 try:
1470 os.rmdir(etpConst['edbcounter'])
1471 except:
1472 pass
1473 f = open(etpConst['edbcounter'],"w")
1474 f.write(str(newcounter))
1475 f.flush()
1476 f.close()
1477 del counters
1478 return newcounter
1479
1480
1481 - def spm_doebuild(self, myebuild, mydo, tree, cpv, portage_tmpdir = None, licenses = [], fork = False):
1482 if fork:
1483
1484 return self.entropyTools.spawn_function(
1485 self._portage_doebuild, myebuild,
1486 mydo, tree, cpv,
1487 portage_tmpdir, licenses
1488 )
1489 return self._portage_doebuild(myebuild, mydo, tree, cpv, portage_tmpdir, licenses)
1490
1491 - def _portage_doebuild(self, myebuild, mydo, tree, cpv, portage_tmpdir = None, licenses = []):
1492
1493
1494
1495
1496
1497
1498 oldsystderr = sys.stderr
1499 f = open("/dev/null","w")
1500 if not etpUi['debug']:
1501 sys.stderr = f
1502
1503
1504
1505 domute = False
1506 if etpUi['mute']:
1507 domute = True
1508 oldsysstdout = sys.stdout
1509 sys.stdout = f
1510
1511 mypath = etpConst['systemroot']+"/"
1512 os.environ["SKIP_EQUO_SYNC"] = "1"
1513 os.environ["CD_ROOT"] = "/tmp"
1514 os.environ["ROOT"] = mypath
1515
1516 if licenses:
1517 os.environ["ACCEPT_LICENSE"] = str(' '.join(licenses))
1518
1519
1520 myebuilddir = os.path.dirname(myebuild)
1521 keys = self.portage.auxdbkeys
1522 metadata = {}
1523
1524 for key in keys:
1525 mykeypath = os.path.join(myebuilddir,key)
1526 if os.path.isfile(mykeypath) and os.access(mykeypath,os.R_OK):
1527 f = open(mykeypath,"r")
1528 metadata[key] = f.readline().strip()
1529 f.close()
1530
1531
1532
1533
1534 mysettings = self._get_portage_config("/",mypath)
1535 mysettings['EBUILD_PHASE'] = mydo
1536 mysettings['EAPI'] = "0"
1537 if metadata.has_key('EAPI'):
1538 mysettings['EAPI'] = metadata['EAPI']
1539 mysettings.backup_changes("EAPI")
1540
1541 try:
1542 mysettings._environ_whitelist = set(mysettings._environ_whitelist)
1543
1544 mysettings._environ_whitelist.add("SKIP_EQUO_SYNC")
1545 mysettings._environ_whitelist.add("ACCEPT_LICENSE")
1546 mysettings._environ_whitelist.add("CD_ROOT")
1547 mysettings._environ_whitelist.add("ROOT")
1548 mysettings._environ_whitelist = frozenset(mysettings._environ_whitelist)
1549 except:
1550 self.write_traceback_to_log()
1551
1552 cpv = str(cpv)
1553 mysettings.setcpv(cpv)
1554 portage_tmpdir_created = False
1555 if portage_tmpdir:
1556 if not os.path.isdir(portage_tmpdir):
1557 os.makedirs(portage_tmpdir)
1558 portage_tmpdir_created = True
1559 mysettings['PORTAGE_TMPDIR'] = str(portage_tmpdir)
1560 mysettings.backup_changes("PORTAGE_TMPDIR")
1561
1562 mydbapi = self.portage.fakedbapi(settings=mysettings)
1563 mydbapi.cpv_inject(cpv, metadata = metadata)
1564
1565
1566 vartree = self._get_portage_vartree(mypath)
1567
1568 try:
1569 rc = self.portage.doebuild(
1570 myebuild = str(myebuild),
1571 mydo = str(mydo),
1572 myroot = mypath,
1573 tree = tree,
1574 mysettings = mysettings,
1575 mydbapi = mydbapi,
1576 vartree = vartree,
1577 use_cache = 0
1578 )
1579 except:
1580 self.write_traceback_to_log()
1581 raise
1582
1583
1584 if domute:
1585 sys.stdout = oldsysstdout
1586
1587 sys.stderr = oldsystderr
1588 f.close()
1589
1590 if portage_tmpdir_created:
1591 shutil.rmtree(portage_tmpdir,True)
1592
1593 del mydbapi
1594 del metadata
1595 del keys
1596 return rc
1597
1678
1680
1681 pkg_content = {}
1682
1683 if os.path.isfile(content_file):
1684
1685 f = open(content_file,"r")
1686 content = [x.decode('raw_unicode_escape') for x in f.readlines()]
1687 f.close()
1688 outcontent = set()
1689 for line in content:
1690 line = line.strip().split()
1691 try:
1692 datatype = line[0]
1693 datafile = line[1:]
1694 if datatype == 'obj':
1695 datafile = datafile[:-2]
1696 datafile = ' '.join(datafile)
1697 elif datatype == 'dir':
1698 datafile = ' '.join(datafile)
1699 elif datatype == 'sym':
1700 datafile = datafile[:-3]
1701 datafile = ' '.join(datafile)
1702 else:
1703 myexc = "InvalidData: %s %s. %s." % (
1704 datafile,
1705 _("not supported"),
1706 _("Probably Portage API has changed"),
1707 )
1708 raise InvalidData(myexc)
1709 outcontent.add((datafile,datatype))
1710 except:
1711 pass
1712
1713 outcontent = sorted(outcontent)
1714 for datafile, datatype in outcontent:
1715 pkg_content[datafile] = datatype
1716
1717 else:
1718
1719
1720
1721 mytempdir = etpConst['packagestmpdir']+"/"+os.path.basename(package_path)+".inject"
1722 if os.path.isdir(mytempdir):
1723 shutil.rmtree(mytempdir)
1724 if not os.path.isdir(mytempdir):
1725 os.makedirs(mytempdir)
1726
1727 self.entropyTools.uncompress_tar_bz2(package_path, extractPath = mytempdir, catchEmpty = True)
1728 tmpdir_len = len(mytempdir)
1729 for currentdir, subdirs, files in os.walk(mytempdir):
1730 pkg_content[currentdir[tmpdir_len:]] = u"dir"
1731 for item in files:
1732 item = currentdir+"/"+item
1733 if os.path.islink(item):
1734 pkg_content[item[tmpdir_len:]] = u"sym"
1735 else:
1736 pkg_content[item[tmpdir_len:]] = u"obj"
1737
1738
1739 shutil.rmtree(mytempdir,True)
1740 try:
1741 os.rmdir(mytempdir)
1742 except (OSError,):
1743 pass
1744
1745 return pkg_content
1746
1771
1789
1823
1849
1863
1874
1875
2119