Gentoo Archives: gentoo-commits

From: "André Erdmann" <dywi@×××××××.de>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/R_overlay:master commit in: roverlay/overlay/
Date: Thu, 05 Jul 2012 16:00:44
Message-Id: 1341503980.9d2a243a6e6eadc71e3962726b29c84d1251d732.dywi@gentoo
1 commit: 9d2a243a6e6eadc71e3962726b29c84d1251d732
2 Author: André Erdmann <dywi <AT> mailerd <DOT> de>
3 AuthorDate: Thu Jul 5 15:59:40 2012 +0000
4 Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
5 CommitDate: Thu Jul 5 15:59:40 2012 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=9d2a243a
7
8 overlay: calculate inherit statement for ebuilds
9
10 modified: roverlay/overlay/__init__.py
11
12 ---
13 roverlay/overlay/__init__.py | 83 +++++++++++++++++++++++++++++++++---------
14 1 files changed, 66 insertions(+), 17 deletions(-)
15
16 diff --git a/roverlay/overlay/__init__.py b/roverlay/overlay/__init__.py
17 index 13b6615..b6a65a1 100644
18 --- a/roverlay/overlay/__init__.py
19 +++ b/roverlay/overlay/__init__.py
20 @@ -60,6 +60,7 @@ class Overlay ( object ):
21 else:
22 self.eclass_files = eclass_files
23
24 + self.eclass_names = None
25
26 #
27 self._profiles_dir = os.path.join ( self.physical_location, 'profiles' )
28 @@ -115,7 +116,7 @@ class Overlay ( object ):
29 returns: None (implicit)
30 """
31 for cat in self._categories.values():
32 - cat.show ( default_header=self._default_header )
33 + cat.show ( default_header=self._get_header() )
34 # --- end of show (...) ---
35
36 def write ( self, **write_kw ):
37 @@ -138,7 +139,7 @@ class Overlay ( object ):
38 for cat in self._categories.values():
39 if cat.physical_location and not cat.empty():
40 util.dodir ( cat.physical_location )
41 - cat.write ( default_header=self._default_header )
42 + cat.write ( default_header=self._get_header() )
43
44 self._write_categories ( only_active=True )
45 # --- end of write (...) ---
46 @@ -253,29 +254,58 @@ class Overlay ( object ):
47 self._write_profiles_file ( 'use.desc', use_desc + '\n' )
48 # --- end of _write_usedesc (...) ---
49
50 + def _get_eclass_import_info ( self, only_eclass_names=False ):
51 + """Yields eclass import information (eclass names and files).
52 +
53 + arguments:
54 + * only_eclass_names -- if True: yield eclass dest names only,
55 + else : yield (eclass name, eclass src file)
56 + Defaults to False.
57 +
58 + raises: AssertionError if a file does not end with '.eclass'.
59 + """
60 + if self.eclass_files:
61 +
62 + for eclass in self.eclass_files:
63 + dest = os.path.splitext ( os.path.basename ( eclass ) )
64 +
65 + if dest[1] == '.eclass' or ( not dest[1] and not '.' in dest[0] ):
66 + if only_eclass_names:
67 + yield dest[0]
68 + else:
69 + yield ( dest[0], eclass )
70 + else:
71 + raise AssertionError (
72 + "{!r} does not end with '.eclass'!".format ( eclass )
73 + )
74 + # --- end of _get_eclass_import_info (...) ---
75 +
76 def _import_eclass ( self, reimport_eclass ):
77 + """Imports eclass files to the overlay. Also sets ebuild_names.
78 +
79 + arguments:
80 + * reimport_eclass -- whether to import existing eclass files (again)
81 +
82 + raises:
83 + * AssertionError, passed from _get_eclass_import_info()
84 + * Exception if copying fails
85 + """
86
87 if self.eclass_files:
88 # import eclass files
89 eclass_dir = os.path.join ( self.physical_location, 'eclass' )
90 try:
91 + eclass_names = list()
92 util.dodir ( eclass_dir )
93
94 - for eclass in self.eclass_files:
95 - src = eclass
96 - dest = None
97 - if isinstance ( eclass, str ):
98 - dest = os.path.basename ( eclass )
99 - else:
100 - # list-like specification ( src, destname )
101 - src = eclass [0]
102 - dest = eclass [1]
103 -
104 - dest = os.path.join ( eclass_dir, dest )
105 -
106 + for destname, eclass in self._get_eclass_import_info ( False ):
107 + dest = os.path.join ( eclass_dir, destname + '.eclass' )
108 if reimport_eclass or not os.path.isfile ( dest ):
109 - shutil.copyfile ( src, dest )
110 + shutil.copyfile ( eclass, dest )
111
112 + eclass_names.append ( destname )
113 +
114 + self.eclass_names = frozenset ( eclass_names )
115
116 except Exception as e:
117 self.logger.critical ( "Cannot import eclass files!" )
118 @@ -311,10 +341,29 @@ class Overlay ( object ):
119 self.logger.exception ( e )
120 self.logger.critical ( "^failed to init overlay" )
121 raise
122 + # --- end of _init_overlay (...) ---
123 +
124 + def _get_header ( self ):
125 + """Returns the ebuild header (including inherit <eclasses>)."""
126 + if self.eclass_names is None:
127 + # writing is possibly disabled since eclass files have not been
128 + # imported (or show() used before write())
129 + inherit = ' '.join ( self._get_eclass_import_info ( True ) )
130 + else:
131 + inherit = ' '.join ( self.eclass_names )
132
133 + inherit = "inherit " + inherit if inherit else None
134
135 + # header and inherit is expected and therefore the first condition here
136 + if inherit and self._default_header:
137 + return '\n'.join (( self._default_header, '', inherit ))
138
139 + elif inherit:
140 + return inherit
141
142 + elif self._default_header:
143 + return self._default_header
144
145 -
146 -
147 + else:
148 + return None
149 + # --- end of _get_header (...) ---