[1] | 1 | # Author: Melnychuk Taras |
---|
| 2 | # Contact: fenix@quintagroup.com |
---|
| 3 | # Date: $Date: 2005-11-23 12:35:33 |
---|
| 4 | # Copyright: quintagroup.com |
---|
| 5 | |
---|
| 6 | from Products.CMFCore.DirectoryView import DirectoryView, registerDirectory, createDirectoryView |
---|
| 7 | from Products.Archetypes.public import * |
---|
| 8 | from string import split, index |
---|
| 9 | from os import listdir, walk |
---|
| 10 | from epydoc.cli import cli |
---|
| 11 | from os.path import isdir |
---|
| 12 | import Products |
---|
| 13 | import sys |
---|
| 14 | |
---|
| 15 | from config import * |
---|
| 16 | |
---|
| 17 | schema=BaseFolderSchema |
---|
| 18 | |
---|
| 19 | class PloneEpydoc(BaseFolder): |
---|
| 20 | |
---|
| 21 | schema=schema |
---|
| 22 | archetype_name=ARCHETYPENAME |
---|
| 23 | id=TOOLID |
---|
| 24 | |
---|
| 25 | def __init__(self): |
---|
| 26 | """""" |
---|
| 27 | BaseFolder.__init__(self, self.id) |
---|
| 28 | |
---|
| 29 | def getProductModules(self, path): |
---|
| 30 | """""" |
---|
| 31 | modules = [] |
---|
| 32 | for root, dirs, files in walk(path): |
---|
| 33 | root_list = split(root, '/') |
---|
| 34 | if not 'tests' in root_list: |
---|
| 35 | root_list = root_list[index(root_list, 'Products'):] #XXX FIXME |
---|
| 36 | module_path = '.'.join(root_list) |
---|
| 37 | for f in files[:]: |
---|
| 38 | if f[-3:] == '.py': |
---|
| 39 | f = f[:index(f, '.')] |
---|
| 40 | modules.append(module_path+'.'+f) |
---|
| 41 | return modules |
---|
| 42 | |
---|
| 43 | def createDocumentationDirectoryViews(self, product): |
---|
| 44 | """""" |
---|
| 45 | try: |
---|
| 46 | registerDirectory(DOCUMENTATION_DIR, GLOBALS) |
---|
| 47 | except OSError, ex: |
---|
| 48 | if ex.errno == 2: # No such file or directory |
---|
| 49 | return |
---|
| 50 | raise |
---|
| 51 | |
---|
| 52 | if not product in self.objectIds(): |
---|
| 53 | createDirectoryView(self, '/'.join([PROJECTNAME,DOCUMENTATION_DIR, product])) |
---|
| 54 | |
---|
| 55 | def generate(self, product, **properties): |
---|
| 56 | """""" |
---|
| 57 | sys.argv = [] |
---|
| 58 | modules = [] |
---|
| 59 | sys.argv.append('xxx') |
---|
| 60 | sys.argv.append('--no-private') |
---|
| 61 | sys.argv.append('--noframes') |
---|
| 62 | sys.argv.append('--target='+DOCUMENTATION_PATH+product) |
---|
| 63 | for k in properties.keys(): |
---|
| 64 | sys.argv.append('--'+k+'='+properties[k]) |
---|
| 65 | |
---|
| 66 | modules = self.getProductModules(PRODUCTS_HOME+product) |
---|
| 67 | for m in modules: |
---|
| 68 | sys.argv.append(m) |
---|
| 69 | cli() |
---|
| 70 | self.write_content_file_types(DOCUMENTATION_PATH+product) |
---|
| 71 | self.createDocumentationDirectoryViews(product) |
---|
| 72 | |
---|
| 73 | def write_object_type(self, path, obj_name, obj_type): |
---|
| 74 | """""" |
---|
| 75 | file = open(path+'/.objects', 'a') |
---|
| 76 | data = obj_name+' : '+obj_type+'\n' |
---|
| 77 | file.write(data) |
---|
| 78 | |
---|
| 79 | def write_content_file_types(self, path): |
---|
| 80 | """""" |
---|
| 81 | for obj in listdir(path): |
---|
| 82 | if isdir(path+'/'+obj): |
---|
| 83 | dir_path = path+'/'+obj |
---|
| 84 | self.write_content_file_types(dir_path) |
---|
| 85 | |
---|
| 86 | self.write_object_type(path, obj, 'File') |
---|
| 87 | |
---|
| 88 | registerType(PloneEpydoc) |
---|