コード例 #1
0
ファイル: ooBase.py プロジェクト: duallain/OpenObject
    def _create(self, args, objectName):
        """
        To create a new object, pass in a dictionary of objects and use the
        objectName to create the object.
        """

        arguments = self.__parse_options(args)

        obj = Object(self.cnx, objectName)

        objectCreated = obj.create(arguments)

        if objectCreated:
            return objectCreated
        else:
            raise EnvironmentError("We attempted to create a " + \
               self.common[objectName] + " but failed.")
コード例 #2
0
sys.path.append('../')

from oobjlib.connection import Connection
from oobjlib.component import Object
from oobjlib.common import GetParser

parser = GetParser('Create Product', '0.1')
opts, args = parser.parse_args()

try:
    cnx = Connection(server=opts.server,
                     dbname=opts.dbname,
                     login=opts.user,
                     password=opts.passwd,
                     port=opts.port)
except Exception, e:
    print '%s' % str(e)
    exit(1)

product = Object(cnx, 'product.product')

args = {
    'name': 'Import Test',
    'default_code': 'ABCD-EFGH',
    'categ_id': 1,
}

print 'Product ID %d created !' % product.create(args)

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
コード例 #3
0
    return code


for l in reader:
    #print l
    if l['service'] in service_cache:
        jasper_id = service_cache[l['service']]
    else:
        jasper_ids = jasper_obj.search([('service', '=', l['service'])])
        if not jasper_ids:
            print 'Service %s not found' % opts.service
            exit(1)
        jasper_id = jasper_ids[0]
        service_cache[l['service']] = jasper_id

    #search if label already exists
    lab_ids = label_obj.search([('document_id', '=', jasper_id),
                                ('name', '=', format_code(l['code']))])
    if lab_ids:
        #we update it
        label_obj.write([lab_ids[0]], {'value': l['message']})
        print 'UPDATE: %s -> %s' % (format_code(l['code']), l['message'])
    else:
        # we create it
        label_obj.create({
            'document_id': jasper_id,
            'name': format_code(l['code']),
            'value': l['message']
        })
        print 'CREATE: %s -> %s' % (format_code(l['code']), l['message'])
コード例 #4
0
from oobjlib.connection import Connection
from oobjlib.component import Object
from oobjlib.common import GetParser

parser = GetParser('Create Product', '0.1')
opts, args = parser.parse_args()

try:
    cnx = Connection(
        server=opts.server, 
        dbname=opts.dbname, 
        login=opts.user, 
        password=opts.passwd, 
        port=opts.port)
except Exception, e:
    print '%s' % str(e)
    exit(1)

product = Object(cnx, 'product.product')

args = {
    'name': 'Import Test',
    'default_code': 'ABCD-EFGH',
    'categ_id': 1,
}

print 'Product ID %d created !' % product.create(args)

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
コード例 #5
0
service_cache = {}

def format_code(code):
    code = code.upper()
    code = code.replace(' ', '_')
    return code

for l in reader:
    #print l
    if l['service'] in service_cache:
        jasper_id = service_cache[l['service']]
    else:
        jasper_ids = jasper_obj.search([('service', '=', l['service'])])
        if not jasper_ids:
            print 'Service %s not found' % opts.service
            exit(1)
        jasper_id = jasper_ids[0]
        service_cache[l['service']] = jasper_id

    #search if label already exists
    lab_ids = label_obj.search([('document_id', '=', jasper_id), ('name', '=', format_code(l['code']))])
    if lab_ids:
        #we update it
        label_obj.write([lab_ids[0]], {'value': l['message']})
        print 'UPDATE: %s -> %s' % (format_code(l['code']), l['message'])
    else:
        # we create it
        label_obj.create({'document_id': jasper_id, 'name': format_code(l['code']), 'value': l['message']})
        print 'CREATE: %s -> %s' % (format_code(l['code']), l['message'])

コード例 #6
0
        else:
            logger.error('Parent not found')
            sys.exit(1)

    # create or update
    scenario_ids = scenario_obj.search(
        [('reference_res_id', '=', scen_vals['reference_res_id'])], 0, None,
        None, {'active_test': False})
    if scenario_ids:
        logger.info('Scenario exists, update it')
        del scen_vals['reference_res_id']
        scenario_obj.write(scenario_ids, scen_vals)
        scenario_id = scenario_ids[0]
    else:
        logger.info('Scenario not exists, create it')
        scenario_id = scenario_obj.create(scen_vals)

    # List scenario steps and transitions, to be able to remove deleted data
    scenario_data = scenario_obj.read(scenario_id, ['step_ids'])
    all_step_ids = set(scenario_data['step_ids'])
    step_data = step_obj.read(list(all_step_ids),
                              ['in_transition_ids', 'out_transition_ids'])
    all_transition_ids = set(
        sum([
            data['in_transition_ids'] + data['out_transition_ids']
            for data in step_data
        ], []))

    # parse step
    logger.info('Update steps')
    resid = {}