Beispiel #1
0
    def merge(self):
        """
        Merges the group from its reference information.
        """
        modname = self.module()

        if not modname:
            return 0

        requires = [modname.split('.')[0]] + self.requires()
        projex.requires(*requires)

        try:
            __import__(modname)
        except ImportError:
            log.exception('Could not import: %s.' % modname)
            return 0

        module = sys.modules[modname]
        basepath = os.path.dirname(module.__file__)
        filename = os.path.join(basepath, self.name().lower() + '.orb')

        try:
            xorb = ElementTree.parse(nstr(filename)).getroot()

        except xml.parsers.expat.ExpatError:
            log.exception('Failed to load ORB file: %s' % filename)
            return False

        # load schemas
        count = 0
        xgroups = xorb.find('groups')
        for xgroup in xgroups:
            if xgroup.get('name') != self.name():
                continue

            xschemas = xgroup.find('schemas')
            if xschemas is None:
                return 0

            for xschema in xschemas:
                schema = orb.TableSchema.fromXml(xschema)
                schema.setGroupName(self.name())
                schema.setDatabaseName(self.databaseName())
                self.addSchema(schema)
                count += 1

        return count
Beispiel #2
0
    def merge(self):
        """
        Merges the group from its reference information.
        """
        modname = self.module()

        if not modname:
            return 0

        requires = [modname.split('.')[0]] + self.requires()
        projex.requires(*requires)

        try:
            __import__(modname)
        except ImportError:
            log.exception('Could not import: %s.' % modname)
            return 0

        module = sys.modules[modname]
        basepath = os.path.dirname(module.__file__)
        filename = os.path.join(basepath, self.name().lower() + '.orb')

        try:
            xorb = ElementTree.parse(nstr(filename)).getroot()

        except xml.parsers.expat.ExpatError:
            log.exception('Failed to load ORB file: %s' % filename)
            return False

        # load schemas
        count = 0
        xgroups = xorb.find('groups')
        for xgroup in xgroups:
            if xgroup.get('name') != self.name():
                continue

            xschemas = xgroup.find('schemas')
            if xschemas is None:
                return 0

            for xschema in xschemas:
                schema = orb.TableSchema.fromXml(xschema)
                schema.setGroupName(self.name())
                schema.setDatabaseName(self.databaseName())
                self.addSchema(schema)
                count += 1

        return count
Beispiel #3
0
# maintanence information
__maintainer__      = 'Projex Software'
__email__           = '*****@*****.**'

#------------------------------------------------------------------------------

# define version information (major,minor,maintanence)
__depends__        = ['projex']
__version_info__   = (0, 0, 0)
__version__        = '%i.%i.%i' % __version_info__

#------------------------------------------------------------------------------

import projex
projex.requires('projexui')

from projexui.qt.QtCore import Qt
from projexui.qt.QtGui import QApplication
from projexui.widgets.xconsoleedit import XConsoleEdit

if __name__ == '__main__':
    app = None
    if not QApplication.instance():
        app = QApplication([])
        app.setStyle('plastique')
    
    console = XConsoleEdit(QApplication.instance().activeWindow())
    console.setWindowTitle('XInterpreter')
    console.setWindowFlags(Qt.Dialog)
    console.show()
from projexui.qt import Signal, Slot
from PyQt4.QtCore import QObject, Qt

from PyQt4.QtGui  import QWidget,\
                               QFormLayout,\
                               QLabel,\
                               QDialogButtonBox,\
                               QDialog,\
                               QVBoxLayout,\
                               QMessageBox

from projexui.widgets.xorbcolumnedit import XOrbColumnEdit, IGNORED

import projex
projex.requires('orb')

import projexui

from orb import PRIMARY_FIELD, Query as Q

logger = logging.getLogger(__name__)

class XOrbRecordEdit(QWidget):
    """ """
    __designer_container__ = True
    __designer_group__ = 'ProjexUI - ORB'
    
    saved = Signal()
    
    def __init__( self, parent = None ):
Beispiel #5
0
    def fromXml(xgroup, referenced=False, database=None, manager=None):
        """
        Loads the schema group from the inputted xml schema data.
        
        :param      xgroup      | <xml.etree.ElementTree.Element>
                    referenced  | <bool>
                    database    | <str> || None
                    manager     | <orb.Manager> || None
        
        :return     (<orb.TableGroup>, [<orb.TableSchema>, ..]) || (None, [])
        """
        # load schemas
        grpname = xgroup.get('name')
        dbname = xgroup.get('db', xgroup.get('dbname'))
        modname = xgroup.get('module')

        # force database to import
        if database is not None:
            dbname = database

        # import a reference file
        if modname:
            requires = xgroup.get('requires', '').split(',')
            while '' in requires:
                requires.remove('')

            projex.requires(*requires)

            try:
                __import__(modname)
            except ImportError:
                log.exception('Error importing group plugin: %s' % modname)
                return None, []

            grp = orb.system.group(grpname, database=dbname)
            if not grp:
                return None, []

            grp.setDatabaseName(dbname)
            grp.setModule(modname)
            grp.setRequires(requires)

            # load properties
            xprops = xgroup.find('properties')
            if xprops is not None:
                for xprop in xprops:
                    grp.setProperty(xprop.get('key'), xprop.get('value'))

            return None, []

        # import non-referenced schemas
        else:
            grp = orb.system.group(grpname, database=dbname)
            if not grp:
                grp = TableGroup(referenced=referenced, manager=manager)
                grp.setName(grpname)
                grp.setModelPrefix(xgroup.get('prefix', ''))
                grp.setUseModelPrefix(xgroup.get('useModelPrefix') == 'True')
                grp.setNamespace(xgroup.get('namespace', ''))
                if dbname is not None:
                    grp.setDatabaseName(dbname)

            # load schemas
            schemas = []
            xschemas = xgroup.find('schemas')
            if xschemas is not None:
                for xschema in xschemas:
                    schema = orb.TableSchema.fromXml(xschema, referenced)
                    schema.setGroup(grp)
                    grp.addSchema(schema)
                    schemas.append(schema)

                    if dbname is not None:
                        schema.setDatabaseName(dbname)

            # load properties
            xprops = xgroup.find('properties')
            if xprops is not None:
                for xprop in xprops:
                    grp.setProperty(xprop.get('key'), xprop.get('value'))

            return grp, schemas
Beispiel #6
0
from projexui.qt import Signal, Slot
from projexui.qt.QtCore import QObject, Qt

from projexui.qt.QtGui  import QWidget,\
                               QFormLayout,\
                               QLabel,\
                               QDialogButtonBox,\
                               QDialog,\
                               QVBoxLayout,\
                               QMessageBox

from projexui.widgets.xorbcolumnedit import XOrbColumnEdit, IGNORED

import projex
projex.requires('orb')

import projexui

from orb import Query as Q

logger = logging.getLogger(__name__)

class XOrbRecordEdit(QWidget):
    """ """
    __designer_container__ = True
    __designer_group__ = 'ProjexUI - ORB'
    
    saved = Signal()
    
    def __init__( self, parent = None ):
Beispiel #7
0
def generate(module,
             outputpath='./resources/docs/html',
             userpath='',
             config=None):
    """
    Generates documenation for the inputed filepath at the given output \
    location.  The system can also supply the root location for user \
    documentation that can be included in addition to the code by supplying \
    a root userdocs path.
    
    :param      module        | <module> || <str>
    :param      outputpath    | <str>
    :param      config        | <module> || None
    
    :return     <bool> success
    """
    from projex.docgen.document import Document

    if (type(module) == str):
        # extract from a specific filepath
        if (os.path.exists(module)):
            package = projex.packageFromPath(module)
            if (not package):
                msg = '%s is an invalid module.' % module
                raise errors.DocumentationError(msg)

            root_path = projex.packageRootPath(module)
            sys.path.insert(0, root_path)

        # otherwise, use it as the package name
        else:
            projex.requires(module)
            package = module.split('-')[0]

        try:
            __import__(package)
            module = sys.modules[package]

        except ImportError:
            msg = 'Could not import the %s module' % package
            raise errors.DocumentationError(msg)

        except KeyError:
            msg = 'Could not import the %s module' % package
            raise errors.DocumentationError(msg)

    # initialize the global environ
    if (config is None):
        config = default_config

    init_environ(module, config)

    logger.info('Generating module documentation %s...' % module.__name__)

    # load the base page and style information
    page = templates.template('page.html')

    # start generating the documents
    Document.cache.clear()

    # generate the module documentation
    try:
        ignore = config.IGNORE
    except AttributeError:
        ignore = None

    doc = generateModuleDocument(module, ignore=ignore)

    modpath = os.path.dirname(module.__file__)
    outpath = outputpath.replace('./', modpath + '/')

    # clear the docs path
    if (os.path.exists(outpath)):
        shutil.rmtree(outpath)

    if (not os.path.exists(outpath)):
        logger.info('Making doc path: ' + outpath)
        os.makedirs(outpath)

    # make the root api documentation
    api_path = outpath.rstrip('/') + '/api/'
    if not os.path.exists(api_path):
        logger.info('Making doc path:' + api_path)
        os.mkdir(api_path)

    # generate the api docs
    doc.export(api_path, page=page)

    # generate the all classes page
    generateClassDocs(outpath, page, module.__name__)
    generateModuleDocs(outpath, page, module.__name__)
    generateFunctionDocs(outpath, page, module.__name__)
    generateApiIndex(outpath, page)
    generateDocumentIndex(outpath, page)

    # create the user docs
    if (userpath):
        userdocs = os.path.abspath(userpath)
    elif (config != default_config):
        userdocs = os.path.dirname(config.__file__)
    else:
        userdocs = os.path.abspath('./docs')

    if (os.path.exists(userdocs)):
        targetuserdocs = outpath
        templ = templates.template('link_breadcrumbs.html')

        generateUserDocs(userdocs, targetuserdocs, page)

    # copy the syntaxhighlighter code
    targetpath = os.path.join(outpath, '_static')

    paths = []
    paths.append(resources.find('ext/prettify'))
    paths.append(templates.path('javascript'))
    paths.append(templates.path('css'))
    paths.append(templates.path('images'))
    paths.append(templates.path('img'))

    logger.info('Copying static resources...')

    # python26+
    try:
        ignore = shutil.ignore_patterns('.svn')
    except AttributeError:
        ignore = None

    for path in paths:
        if (not os.path.exists(path)):
            continue

        basename = os.path.basename(path)
        instpath = os.path.join(targetpath, basename)

        if (ignore is not None):
            shutil.copytree(path, instpath, ignore=ignore)
        else:
            shutil.copytree(path, instpath)

    # create a compressed xdk file
    logger.info('Creating XDK file...')
    zfilename = os.path.join(outpath, '../%s.xdk' % module.__name__)
    zfilename = os.path.abspath(zfilename)

    generateXdk(outpath, zfilename)
Beispiel #8
0
    def fromXml(xgroup, referenced=False, database=None, manager=None):
        """
        Loads the schema group from the inputted xml schema data.
        
        :param      xgroup      | <xml.etree.ElementTree.Element>
                    referenced  | <bool>
                    database    | <str> || None
                    manager     | <orb.Manager> || None
        
        :return     (<orb.TableGroup>, [<orb.TableSchema>, ..]) || (None, [])
        """
        # load schemas
        grpname = xgroup.get('name')
        dbname = xgroup.get('db', xgroup.get('dbname'))
        modname = xgroup.get('module')

        # force database to import
        if database is not None:
            dbname = database

        # import a reference file
        if modname:
            requires = xgroup.get('requires', '').split(',')
            while '' in requires:
                requires.remove('')

            projex.requires(*requires)

            try:
                __import__(modname)
            except ImportError:
                log.exception('Error importing group plugin: %s' % modname)
                return None, []

            grp = orb.system.group(grpname, database=dbname)
            if not grp:
                return None, []

            grp.setDatabaseName(dbname)
            grp.setModule(modname)
            grp.setRequires(requires)

            # load properties
            xprops = xgroup.find('properties')
            if xprops is not None:
                for xprop in xprops:
                    grp.setProperty(xprop.get('key'), xprop.get('value'))

            return None, []

        # import non-referenced schemas
        else:
            grp = orb.system.group(grpname, database=dbname)
            if not grp:
                grp = TableGroup(referenced=referenced, manager=manager)
                grp.setName(grpname)
                grp.setModelPrefix(xgroup.get('prefix', ''))
                grp.setUseModelPrefix(xgroup.get('useModelPrefix') == 'True')
                grp.setNamespace(xgroup.get('namespace', ''))
                if dbname is not None:
                    grp.setDatabaseName(dbname)

            # load schemas
            schemas = []
            xschemas = xgroup.find('schemas')
            if xschemas is not None:
                for xschema in xschemas:
                    schema = orb.TableSchema.fromXml(xschema, referenced)
                    schema.setGroup(grp)
                    grp.addSchema(schema)
                    schemas.append(schema)

                    if dbname is not None:
                        schema.setDatabaseName(dbname)

            # load properties
            xprops = xgroup.find('properties')
            if xprops is not None:
                for xprop in xprops:
                    grp.setProperty(xprop.get('key'), xprop.get('value'))

            return grp, schemas
Beispiel #9
0
__author__ = ','.join(__authors__)
__credits__ = []
__copyright__ = 'Copyright (c) 2012, Projex Software'
__license__ = 'LGPL'

# maintenance information
__maintainer__ = 'Projex Software'
__email__ = '*****@*****.**'

__depends__ = ['mako']

import logging
import os
import projex

projex.requires('mako')

logger = logging.getLogger(__name__)

try:
    import mako
    import mako.template
    import mako.lookup

except ImportError:
    logger.warning(
        'The projex.makotext package requires mako to be installed.')
    mako = None

# import useful modules for the template
from datetime import datetime, date
Beispiel #10
0
def generate(  module,
               outputpath   = './resources/docs/html',
               userpath     = '',
               config       = None ):
    """
    Generates documenation for the inputed filepath at the given output \
    location.  The system can also supply the root location for user \
    documentation that can be included in addition to the code by supplying \
    a root userdocs path.
    
    :param      module        | <module> || <str>
    :param      outputpath    | <str>
    :param      config        | <module> || None
    
    :return     <bool> success
    """
    from projex.docgen.document import Document
    
    if ( type(module) == str ):
        # extract from a specific filepath
        if ( os.path.exists(module) ):
            package = projex.packageFromPath(module)
            if ( not package ):
                msg = '%s is an invalid module.' % module
                raise errors.DocumentationError(msg)
            
            root_path = projex.packageRootPath(module)
            sys.path.insert(0, root_path)
        
        # otherwise, use it as the package name
        else:
            projex.requires(module)
            package = module.split('-')[0]
        
        try:
            __import__(package)
            module = sys.modules[package]
        
        except ImportError:
            msg = 'Could not import the %s module' % package
            raise errors.DocumentationError(msg)
        
        except KeyError:
            msg = 'Could not import the %s module' % package
            raise errors.DocumentationError(msg)
    
    # initialize the global environ
    if ( config is None ):
        config = default_config
    
    init_environ(module, config)
    
    logger.info('Generating module documentation %s...' % module.__name__)
    
    # load the base page and style information
    page  = templates.template('page.html')
    
    # start generating the documents
    Document.cache.clear()
    
    # generate the module documentation
    try:
        ignore = config.IGNORE
    except AttributeError:
        ignore = None
    
    doc = generateModuleDocument(module, ignore = ignore)
    
    modpath = os.path.dirname(module.__file__)
    outpath = outputpath.replace( './', modpath + '/' )
    
    # clear the docs path
    if ( os.path.exists( outpath ) ):
        shutil.rmtree( outpath )
    
    if ( not os.path.exists( outpath ) ):
        logger.info( 'Making doc path: ' + outpath )
        os.makedirs(outpath)
    
    # make the root api documentation
    api_path = outpath.rstrip('/') + '/api/'
    if not os.path.exists(api_path):
        logger.info( 'Making doc path:' + api_path )
        os.mkdir(api_path)
    
    # generate the api docs
    doc.export(api_path, page = page)
    
    # generate the all classes page
    generateClassDocs( outpath, page, module.__name__ )
    generateModuleDocs( outpath, page, module.__name__)
    generateFunctionDocs( outpath, page, module.__name__)
    generateApiIndex( outpath, page )
    generateDocumentIndex( outpath, page)
    
    # create the user docs
    if ( userpath ):
        userdocs = os.path.abspath(userpath)
    elif ( config != default_config ):
        userdocs = os.path.dirname(config.__file__)
    else:
        userdocs = os.path.abspath('./docs')
    
    if ( os.path.exists(userdocs) ):
        targetuserdocs = outpath
        templ  = templates.template('link_breadcrumbs.html')
        
        generateUserDocs( userdocs, targetuserdocs, page )
    
    # copy the syntaxhighlighter code
    targetpath = os.path.join(outpath,'_static')
    
    paths = []
    paths.append(resources.find('ext/prettify'))
    paths.append(templates.path('javascript'))
    paths.append(templates.path('css'))
    paths.append(templates.path('images'))
    paths.append(templates.path('img'))
    
    logger.info('Copying static resources...')
    
    # python26+
    try:
        ignore = shutil.ignore_patterns('.svn')
    except AttributeError:
        ignore = None
        
    for path in paths:
        if ( not os.path.exists(path) ):
            continue
        
        basename = os.path.basename(path)
        instpath = os.path.join(targetpath, basename)
        
        if ( ignore is not None ):
            shutil.copytree( path, instpath, ignore = ignore )
        else:
            shutil.copytree(path, instpath)
    
    # create a compressed xdk file
    logger.info('Creating XDK file...')
    zfilename = os.path.join(outpath, '../%s.xdk' % module.__name__)
    zfilename = os.path.abspath(zfilename)
    
    generateXdk(outpath, zfilename)