Example #1
0
 def perform(self, args):
     project, opts = self.parse_args(args)
     cfg = config.ConfigManager()
     if project == None:
         cfg = self._look_at_cur_path()
         if cfg == None:
             sys.exit(0)
         self._config_project('project', cfg, opts)
     else:
         print red('Not implemented yet.')
         sys.exit(-1)
Example #2
0
 def _look_at_cur_path(self):
     print red('No project name given, looking at current path for ' \
         'a valid project file.')
     files = [f for f in os.listdir('.') if fnmatch.fnmatch(f, '*.cfg')]
     match = False
     cfg = config.ConfigManager()
     for file in files:
         if cfg.load_config('project', file):
             match = True
             break
     if match:
         return cfg
     else:
         print red('No Goliat Project files found.')
         return None
Example #3
0
    def _list_projects(self):
        projects = {}

        def info_project(data):
            ret = '  '
            ret += bold(data['Project']['app_name'].decode('utf8').ljust(30))
            ret += 'Goliat v' + data['Goliat']['version'].ljust(10)
            ret += bold('( ')
            ret+=green('running') \
            if os.path.exists('/var/run/{0}.pid'.format(
                    data['Project']['app_name'].lower().replace(' ', '_'))) \
            else red('stopped')
            ret += bold(' )')
            return ret

        try:
            sys_path = '/etc/goliat/applications/'
            files = [
                f for f in os.listdir(sys_path) if fnmatch.fnmatch(f, '*.cfg')
            ]
            cfg = config.ConfigManager()
            for file in files:
                config_name = ' '.join([
                    f.capitalize() for f in file.replace('.cfg', '').split('_')
                ])
                if cfg.load_config(config_name, sys_path + file):
                    projects[config_name] = cfg.get_config(config_name)
            if len(projects):
                print green('Available Goliat Projects')
                for val in projects.values():
                    print info_project(val)
            else:
                print red('No Goliat Project files found at System Path.')
                sys.exit(0)
        except OSError, e:
            print red(e.strerror + ': \'' + e.filename + '\'')
            print red('No Goliat Project files found at System Path.')
            sys.exit(0)
Example #4
0
 def _look_at_system(self, project):
     try:
         sys_path = '/etc/goliat/applications/'
         files = [
             f for f in os.listdir(sys_path) if fnmatch.fnmatch(f, '*.cfg')
         ]
         match = False
         cfg = config.ConfigManager()
         config_name = '{0}.cfg'.format(project.lower().replace(' ', '_'))
         if config_name in files:
             if cfg.load_config(project, sys_path + config_name):
                 match = True
         if match:
             return cfg
         else:
             print red(
                 'No Goliat Project file for project {0} found.'.format(
                     project))
             return None
     except OSError, e:
         print red(e.strerror + ': \'' + e.filename + '\'')
         print red('No Goliat Project file for project {0} found.'.format(
             project))
         return None
Example #5
0
    def generate_model_base(self, table, columns):
        t = self._mgr.get_sys_domain().get_template('tpl/modelbase.evoque')
        relation = columns.get('_relation')
        model_name = self._generate_model_name(table)
        _attributes = []
        _relations = []
        _model_primary_keys = self._check_composed_keys(columns)
        cfg = config.ConfigManager().look_at_cur_path()
        if cfg == None:
            print red('No goliat configuration file found.')
            sys.exit(-1)
        for col in self._schema.reorder_table_fields(
                self._schema.find_table(table)):
            if col[0] in [
                    '_config', '_indexes', '_relation', '_order', '_parent'
            ]:
                continue
            attr_name = col[0]
            if len(_model_primary_keys):
                attr_type = self._parse_column(col[1], True)
            else:
                attr_type = self._parse_column(col[1])

            _attributes.append((attr_name, attr_type))
        if relation != None:
            for field, rel in relation.iteritems():
                if rel['type'] == 'one2one':
                    _reference = 'Reference'
                    _attributes.append((field, '{0}({1}_id, "{2}.{3}")' \
                        .format(_reference, field, self._generate_model_name(\
                        rel['foreignTable']), rel['foreignKey'])))
                    _relations.append(('application.model.base.{0}Base' \
                        .format(self._generate_model_name(
                            rel['foreignTable'])),
                            '{0}Base'.format(self._generate_model_name(
                                rel['foreignTable']))))
                elif rel['type'] == 'many2one':
                    _reference = 'ReferenceSet'
                    _attributes.append(
                        (field,
                         '{0}'.format('{0}("{1}.{2}", "{3}.{4}")'.format(
                             _reference, self._generate_model_name(table),
                             rel['localKey'],
                             self._generate_model_name(rel['foreignTable']),
                             rel['foreignKey']))))
                    _relations.append(('application.model.base.{0}Base' \
                    .format(self._generate_model_name(rel['foreignTable'])),
                        '{0}Base'.format(self._generate_model_name(
                            rel['foreignTable']))))
                elif rel['type'] == 'many2many':
                    _reference = 'ReferenceSet'
                    reference = _reference + '('
                    reference += self._parse_relation(rel, table)
                    reference += ')'
                    _attributes.append(('{0}'.format(field), reference))
                    #_relations.append(('application.model.base.{0}Base' \
                    #.format(self._generate_model_name(rel['foreignTable'])),
                    #    '{0}Base'.format(self._generate_model_name(
                    #        rel['foreignTable']))))
                    _relations.append((
                        'application.model.relation.{0}'.format(
                            self._generate_model_name(table)+\
                            self._generate_model_name(rel['foreignTable'])),
                        self._generate_model_name(table)+\
                        self._generate_model_name(rel['foreignTable'])
                    ))

        reverse = self._schema.find_reverse_reference(table)
        if reverse != None:
            reverse_reference = 'ReferenceSet('
            reverse_reference += self._parse_relation(reverse, table, True)
            reverse_reference += ')'
            _attributes.append(
                ('{0}'.format(reverse['field']), reverse_reference))
            _relations.append((
                'application.model.relation.{0}'.format(
                    self._generate_model_name(reverse['foreignTable'])+\
                    self._generate_model_name(table)),
                self._generate_model_name(reverse['foreignTable'])+\
                self._generate_model_name(table)
            ))

        return (model_name,
                t.evoque(
                    model_name=model_name,
                    model_creation_date=datetime.now(),
                    model_file='application/model/base/{0}'.format(model_name),
                    model_table='{0}'.format(table),
                    model_primary_keys=_model_primary_keys,
                    attributes=_attributes,
                    relations=_relations))
Example #6
0
@license: GPLv2
@copyright: © 2010 Open Phoenix IT SCA
@organization: Open Phoenix IT S.Coop.And
@author: Oscar Campos
@contact: [email protected]
@summary: Perform general model actions.
@version: 0.1
'''
from storm.exceptions import ProgrammingError
from twisted.internet import defer
from goliat.utils.borg import Borg
from goliat.database import Database
from goliat.utils import config

_cfg = config.ConfigManager()


class Model(Borg):
    """Convenience class for Models."""
    def __init__(self):
        super(Model, self).__init__()
        self._schema = Database().get_schema()

    def get_model_info(self, model):
        """Returns a dict containing the model scheme information."""
        return (self._schema.get_model_schema(model.__storm_table__),
                self._schema.get_model_view(model.__storm_table__))

    def view(self, model):
        """Perform read CRUD action."""
Example #7
0
 def _write_config(self, project):
     cfg = config.ConfigManager()
     config.ConfigManager.write_config(cfg.get_config(project))
     print bold('Project File writed')
     print '\nQuitting.'
Example #8
0
Created on 07/05/2010 13:42:47

@license: GPLv2
@copyright: © 2010 Open Phoenix IT SCA
@organization: Open Phoenix IT S.Coop.And
@author: damnwidget
@contact: [email protected]
@summary: Abstraction over Reference and DeferredReference
@version: 0.1
'''
from storm.references import Reference as StormReference
from storm.references import ReferenceSet as StormReferenceSet
from storm.twisted.wrapper import DeferredReference, DeferredReferenceSet

from goliat.utils import config

_cfg=config.ConfigManager().look_at_cur_path()

if _cfg.get_config('project')['Project']['tos']:
    class Reference(DeferredReference):
        pass

    class ReferenceSet(DeferredReferenceSet):
        pass
else:
    class Reference(StormReference):
        pass

    class ReferenceSet(StormReferenceSet):
        pass