source: products/qPloneEpydoc/tags/0.1.2/PloneEpydoc.py @ 2523

Last change on this file since 2523 was 1, checked in by myroslav, 18 years ago

Building directory structure

File size: 2.6 KB
Line 
1# Author: Melnychuk Taras
2# Contact: fenix@quintagroup.com
3# Date: $Date: 2005-11-23 12:35:33
4# Copyright: quintagroup.com
5
6from Products.CMFCore.DirectoryView import DirectoryView, registerDirectory, createDirectoryView
7from Products.Archetypes.public import *
8from string import split, index
9from os import listdir, walk
10from epydoc.cli import cli
11from os.path import isdir
12import Products
13import sys
14
15from config import *
16
17schema=BaseFolderSchema
18
19class 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
88registerType(PloneEpydoc)
Note: See TracBrowser for help on using the repository browser.