Mercurial > hg > PaInt
annotate paint/info.py @ 56:042a1b2a3e8a
start flushing out tests
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Wed, 23 Jan 2013 16:01:29 -0800 |
parents | a8236b97abd3 |
children | d5e5c7496784 |
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: |
56 | 33 module = imp.load_source('setup', setup_py) |
34 finally: | |
35 sys.modules.pop('setuptools') | |
36 if setuptools: | |
37 sys.modules['setuptools'] = setuptools | |
38 globals().pop('setup') | |
54
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
39 return self.__dict__.pop('_info') |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
40 |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
41 def _setup(self, **kwargs): |
a8236b97abd3
separate methods for gathering package information
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
42 self._info = kwargs |