Changeset 3360

Show
Ignore:
Timestamp:
09/12/07 07:07:17 (1 year ago)
Author:
ed
Message:

Added automatic importing of app-level subdirectory names into the dApp namespace. This will allow you to reference your local classes using 'self.Application.biz', for example. Prior to this, you could not reference a bizobj class from a form class unless they were in the same directory.

Added a generic _getAppDirectoryNames() method to the dabo module, and enhanced the quickStart() method.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/dabo/__init__.py

    r3348 r3360  
    164164 
    165165 
     166# Define the standard Dabo subdirectory stucture for apps. 
     167def _getAppDirectoryNames(): 
     168    return ("biz", "db", "ui", "resources", "reports") 
     169     
     170     
    166171# Method to create a standard Dabo directory structure layout 
    167172def makeDaboDirectories(homedir=None): 
    168     """If homedir is passes, the directories will be created off of that 
     173    """If homedir is passed, the directories will be created off of that 
    169174    directory. Otherwise, it is assumed that they should be created 
    170175    in the current directory location. 
     
    173178    if homedir is not None: 
    174179        os.chdir(homedir) 
    175     for d in ("biz", "db", "ui", "resources", "reports"): 
     180    for d in _getAppDirectoryNames(): 
    176181        if not os.path.exists(d): 
    177182            os.mkdir(d) 
     
    185190    currLoc = os.getcwd() 
    186191    if homedir is not None: 
     192        if not os.path.exists(homedir): 
     193            os.makedirs(homedir) 
    187194        os.chdir(homedir) 
    188195    makeDaboDirectories() 
     
    190197# -*- coding: utf-8 -*- 
    191198import dabo 
     199dabo.ui.loadUI("wx") 
    192200 
    193201app = dabo.dApp() 
     202 
     203# IMPORTANT! Change app.MainFormClass value to the name 
     204# of the form class that you want to run when your 
     205# application starts up. 
     206app.MainFormClass = dabo.ui.dFormMain 
     207 
    194208app.start() 
    195209""") 
     210 
     211    template = """#!/usr/bin/env python 
     212# -*- coding: utf-8 -*- 
     213###### 
     214# In order for Dabo to 'see' classes in your %(dd)s directory, add an  
     215# import statement here for each class. E.g., if you have a file named 
     216# 'MyClasses.py' in this directory, and it defines two classes named 'FirstClass' 
     217# and 'SecondClass', add these lines: 
     218#  
     219# from MyClass import FirstClass 
     220# from MyClass import SecondClass 
     221#  
     222# Now you can refer to these classes as: self.Application.%(dd)s.FirstClass and 
     223# self.Application.%(dd)s.SecondClass 
     224###### 
     225 
     226""" 
     227    for dd in dabo._getAppDirectoryNames(): 
     228        fname = "%s/__init__.py" % dd 
     229        txt = template % locals() 
     230        open(fname, "w").write(txt) 
    196231    os.chmod("main.py", 0744) 
    197232    os.chdir(currLoc) 
    198      
  • trunk/dabo/dApp.py

    r3333 r3360  
    1414import dabo.ui 
    1515import dabo.db 
    16 import dLocalize 
    1716from dabo.dLocalize import _ 
    1817from dabo.lib.connParser import importConnections 
    19 from dabo import dLocalize 
    20 import dSecurityManager 
     18from dabo import dSecurityManager 
    2119from dabo.lib.SimpleCrypt import SimpleCrypt 
    2220from dabo.dObject import dObject 
    23 import dUserSettingProvider 
     21from dabo import dUserSettingProvider 
    2422 
    2523 
     
    236234            dLocalize.setLanguage(lang, charset) 
    237235 
     236        self._initModuleNames() 
    238237        self._initDB() 
    239238         
     
    599598        connDefs = {} 
    600599 
    601         # Import any .cnxml files in HomeDir and/or HomeDir/db: 
    602         for dbDir in (os.path.join(self.HomeDirectory, "db"), self.HomeDirectory): 
     600        # Import any .cnxml files in the following locations: 
     601        #       HomeDir 
     602        #       HomeDir/db 
     603        #       HomeDir/data 
     604        #       os.getcwd() 
     605        #       os.getcwd()/db 
     606        #       os.getcwd()/data 
     607        hd = self.HomeDirectory 
     608        cwd = os.getcwd() 
     609        dbDirs = (hd, os.path.join(hd, "db"), os.path.join(hd, "data"),  
     610                cwd, os.path.join(cwd, "db"), os.path.join(cwd, "data")) 
     611        for dbDir in dbDirs: 
    603612            if os.path.exists(dbDir) and os.path.isdir(dbDir): 
    604613                files = glob.glob(os.path.join(dbDir, "*.cnxml")) 
     
    629638        dabo.infoLog.write(_("%s database connection definition(s) loaded.")  
    630639            % (len(self.dbConnectionDefs))) 
     640 
     641 
     642    def _initModuleNames(self): 
     643        """Import the common application-level module names into attributes 
     644        of this application object, so that the app code can easily reference them. 
     645        Example: f there is a 'biz' directory that can be imported, other objects in  
     646        the system can reference bizobjs using the 'self.Application.biz' syntax 
     647        """ 
     648        for dd in ("biz", "db", "ui", "resources", "reports"): 
     649            try: 
     650                self.__setattr__(dd, __import__(dd, level=0)) 
     651            except: 
     652                self.__setattr__(dd, None) 
    631653 
    632654