Mercurial > hg > PaInt
annotate paint/info.py @ 54:a8236b97abd3
separate methods for gathering package information
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Wed, 23 Jan 2013 15:12:37 -0800 |
parents | |
children | 042a1b2a3e8a |
rev | line source |
---|---|
54
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
1 """ |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
2 interfaces to get information from a package |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
3 """ |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
4 |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
5 import os |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
6 import sys |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
7 |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
8 class PackageInfo(object): |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
9 """abstract base class of package info""" |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
10 def __init__(self, path): |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
11 """ |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
12 - path : path to setup.py or its directory |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
13 """ |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
14 if os.path.isdir(path): |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
15 path = os.path.join(path, 'setup.py') |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
16 assert os.path.exists(path), "'%s' not found" % path |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
17 self.setup_py = os.path.abspath(path) |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
18 |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
19 def __call__(self): |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
20 """returns dictionary of package info""" |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
21 raise NotImplementedError("abstract base class") |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
22 |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
23 class SetupOverridePackageInfo(PackageInfo): |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
24 """ |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
25 gather setup.py information by overriding the function |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
26 """ |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
27 |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
28 def __call__(self): |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
29 setuptools = sys.modules.get('setuptools') |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
30 sys.modules['setuptools'] = sys.modules[__name__] |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
31 globals()['setup'] = self._setup |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
32 try: |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
33 |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
34 return self.__dict__.pop('_info') |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
35 |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
36 def _setup(self, **kwargs): |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
37 self._info = kwargs |