Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 178 lines (140 sloc) 4.854 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
#
# YUIDocGUIAppDelegate.py
# YUIDocGUI
#
# Created by Dav Glass on 6/25/09.
# Copyright __MyCompanyName__ 2009. All rights reserved.
#

from objc import YES, NO, IBAction, IBOutlet
from Foundation import *
from AppKit import *
from subprocess import call, PIPE, Popen
import os
from cStringIO import StringIO




class YUIDocGUIAppDelegate(NSObject):
    myWindow = objc.IBOutlet()
    textView = objc.IBOutlet()
    generateButton = objc.IBOutlet()
    sourcepath = objc.ivar(u"sourcepath")
    savepath = objc.ivar(u"savepath")
    tmpPath = '/tmp/yuidoc/'
    project_name = objc.ivar(u"project_name")
    project_url = objc.ivar(u"project_url")
    project_version = objc.ivar(u"project_version")
    generate = objc.ivar(u"generate")
    showprivate = True
    _show_private = True
    _can_start = False
    
    ext = {
        'js': True,
        'as': False,
        'py': False,
        'php': False,
        'pl': False,
        'rb': False,
        'cs': False,
        'java': False
    }

    def applicationShouldTerminateAfterLastWindowClosed_(self, sender):
        return True


    def applicationDidFinishLaunching_(self, sender):
        NSLog("Application did finish launching.")
        NSLog("SV: %s" % self.textView)
        NSLog("generateButton: %s" % self.generateButton)
        self.textView.insertText_('Logging will appear here.\n')
    
    @IBAction
    def setextjs_(self, value):
        self.ext['js'] = value.state()

    @IBAction
    def setextas_(self, value):
        self.ext['as'] = value.state()

    @IBAction
    def setextpy_(self, value):
        self.ext['py'] = value.state()

    @IBAction
    def setextphp_(self, value):
        self.ext['php'] = value.state()

    @IBAction
    def setextpl_(self, value):
        self.ext['pl'] = value.state()

    @IBAction
    def setextrb_(self, value):
        self.ext['rb'] = value.state()

    @IBAction
    def setextcs_(self, value):
        self.ext['cs'] = value.state()

    @IBAction
    def setextjava_(self, value):
        self.ext['java'] = value.state()

    @IBAction
    def setprivate_(self, value):
        self._show_private = value.state()

    @IBAction
    def setprojectname_(self, value):
        self.validate()

    @IBAction
    def setprojecturl_(self, value):
        self.validate()

    @IBAction
    def setprojectversion_(self, value):
        self.validate()

    @IBAction
    def setsourcepath_(self, value):
        self.validate()

    @IBAction
    def setsavepath_(self, value):
        self.validate()

    def validate(self):
        #self.logoutput = 'Logging will show here.'
        #NSLog("LOG: %s" % self.logoutput)
        NSLog("VALIDATE: ")
        self._can_start = False
        self.generateButton.setEnabled_(False)
        if self.project_version and self.project_name and self.project_url and self.sourcepath and self.savepath:
            self.generateButton.setEnabled_(True)
            self._can_start = True
            

        NSLog("VALIDATE: %s" % self._can_start)
            
        

    @IBAction
    def generate_(self, value):
        if not self._can_start:
            NSBeginInformationalAlertSheet(
                u"Can not generate docs",
                u"OK", None, None, self.myWindow, None, None, None, None,
                u"Please fill in all fields, they are required.."
            )
            
            NSLog("Can not start, not enough info")
            return

        self.textView.insertText_('Doc generation starting, please wait..\n')
        self.generateButton.setTitle_('Generating..')
        
        ##This is a hack and needs to be fixed..
        yuidocPath = "%s/YUIDocGUI.app/Contents/Resources/yuidoc" % os.path.abspath('./')
        templatePath = '%s/template' % yuidocPath
        ext = []
        for i in self.ext.keys():
            if self.ext[i]:
                ext.append(".%s" % i)
        
        args = [
            '%s/bin/yuidoc.py' % yuidocPath,
            self.sourcepath.path(),
            '-p', self.tmpPath,
            '-o', self.savepath.path(),
            '-t', templatePath,
            '-v', self.project_version,
            '-e', ','.join(ext)
        ]
        if self._show_private:
            args.append('-s')

        NSLog("Run: %s" % args)
        NSLog('Path: %s' % yuidocPath)

        call(args)
        error_file = open('/tmp/yuidoc.log', 'w+')
        
        logoutput = ''
        retcode = call(args, stderr=error_file, stdout=error_file)
        if retcode > 0:
            logoutput = 'ERROR\n\n'

        f = open('/tmp/yuidoc.log')
        logoutput = "%s %s" % (logoutput, f.read())
        NSLog("LOG: %s" % logoutput)
        
        self.textView.insertText_('%s\nDocs finished..' % logoutput)
        NSLog("Docs finished..")
        self.generateButton.setTitle_('Generate Docs')
Something went wrong with that request. Please try again.