| 1 |
#!/usr/bin/env python |
|---|
| 2 |
""" |
|---|
| 3 |
definition of a trac project |
|---|
| 4 |
""" |
|---|
| 5 |
|
|---|
| 6 |
import os |
|---|
| 7 |
import pkg_resources |
|---|
| 8 |
import subprocess |
|---|
| 9 |
from paste.script import templates |
|---|
| 10 |
|
|---|
| 11 |
class TracProject(templates.Template): |
|---|
| 12 |
"""a trac project""" |
|---|
| 13 |
# eventually this class should do most if not all of what TracLegos |
|---|
| 14 |
# does and its functionality should be factored to that end |
|---|
| 15 |
# methodologies for doing so: |
|---|
| 16 |
|
|---|
| 17 |
# * container: self.project_creator = TracLegos(...): this method favors |
|---|
| 18 |
# keeping TracLegos as the canonical project factory which is called via |
|---|
| 19 |
# the command line and via `paster create` or TTW |
|---|
| 20 |
|
|---|
| 21 |
# * deprecator: the functionalities of TracLegos are mostly (if not |
|---|
| 22 |
# entirely) moved into this class and TracLegos becomes a front-end for |
|---|
| 23 |
# the TracProject PasteScript template (assuming it needs to exist) |
|---|
| 24 |
|
|---|
| 25 |
# practicalities going forward should determine which of these |
|---|
| 26 |
# methodologies is favored |
|---|
| 27 |
|
|---|
| 28 |
# PoachEggs requirements files for the template |
|---|
| 29 |
requirements = [] |
|---|
| 30 |
|
|---|
| 31 |
### attrs for PasteScript Template |
|---|
| 32 |
|
|---|
| 33 |
def pre(self, command, output_dir, vars): |
|---|
| 34 |
|
|---|
| 35 |
# install the requirements |
|---|
| 36 |
for requirement in getattr(self, 'requirements', ()): |
|---|
| 37 |
|
|---|
| 38 |
# if the path is relative to the template, give the full path |
|---|
| 39 |
path = os.path.join(self.module_dir(), requirement) |
|---|
| 40 |
if os.path.exists(path): |
|---|
| 41 |
requirement = path |
|---|
| 42 |
|
|---|
| 43 |
subprocess.call(['poacheggs', '-r', requirement]) |
|---|
| 44 |
|
|---|
| 45 |
def post(self, command, output_dir, vars): |
|---|
| 46 |
pass |
|---|
| 47 |
|
|---|
| 48 |
### internal methods |
|---|
| 49 |
|
|---|
| 50 |
def inifile(self): |
|---|
| 51 |
""" |
|---|
| 52 |
returns the path to the trac.ini template associated with this TracProject |
|---|
| 53 |
(if any) |
|---|
| 54 |
""" |
|---|
| 55 |
files = [ 'trac.ini_tmpl', 'trac.ini' ] |
|---|
| 56 |
for f in files: |
|---|
| 57 |
filename = os.path.join(self.template_dir(), 'conf', f) |
|---|
| 58 |
if os.path.exists(filename): |
|---|
| 59 |
return filename |
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
def projects(): |
|---|
| 63 |
"""return TracProject templates installed as eggs""" |
|---|
| 64 |
templates = [] |
|---|
| 65 |
for entry_point in pkg_resources.iter_entry_points('paste.paster_create_template'): |
|---|
| 66 |
try: |
|---|
| 67 |
template = entry_point.load() |
|---|
| 68 |
except: |
|---|
| 69 |
continue |
|---|
| 70 |
if issubclass(template, TracProject): |
|---|
| 71 |
templates.append(template(entry_point.name)) |
|---|
| 72 |
return templates |
|---|
| 73 |
|
|---|
| 74 |
def project_dict(): |
|---|
| 75 |
return dict((template.name, template) for template in projects()) |
|---|
| 76 |
|
|---|
| 77 |
if __name__ == '__main__': |
|---|
| 78 |
from traclegos.project import TracProject |
|---|
| 79 |
templates = project_dict() |
|---|
| 80 |
for name, template in templates.items(): |
|---|
| 81 |
print name, template |
|---|
| 82 |
|
|---|
| 83 |
template.inifile() |
|---|