Example #1
0
    def _update_no_search(self, id, args, objectName):
        """
        To update an object when we already know the id
        """

        obj = Object(self.cnx, objectName)
        commonName = self.common[objectName]
        results = id
        arguments = self.__parse_options(args)
        if results:
            if isinstance(results, list):
                results = results
            else:
                results = [results]
            if len(results) == 1:
                if obj.write(results, arguments):
                    return results[0]

                else:
                    raise EnvironmentError("We attempted to update a  " + \
                        + commonName + \
                       " , but failed.")
            else:
                string = ""
                for obj in results:
                    string += obj

                raise ValueError("We preformed a search for a " + commonName + \
                                "and came back with a number greater than one." \
                                + string)
Example #2
0
    def _update(self, searchTuples, args, objectName):
        """
        A sub function that updates the object if it exists
        """

        obj = Object(self.cnx, objectName)
        commonName = self.common[objectName]
        results = obj.search(searchTuples)
        arguments = self.__parse_options(args)
        if results:
            if isinstance(results, list):
                results = results
            else:
                results = [results]
            if len(results) == 1:
                if obj.write(results, arguments):
                    return results[0]

                else:
                    raise EnvironmentError("We attempted to update a  " + \
                        + commonName + \
                        " , but failed.")
            else:
                string = ":"
                for obj in results:
                    string += str(obj) + ", "

                string += " Search: "
                for obj in searchTuples:
                    string += str(obj) + ", "

                raise ValueError("We preformed a search for a " + commonName + \
                    "and came back with a number greater than one." \
                    + string)
    elif field == 'parent_id':
        if scen_read[field]:
            node.text = scenario_obj.read(
                scen_read.get('parent_id', [0])[0],
                ['reference_res_id']).get('reference_res_id')
    elif field in ['name', 'notes', 'title']:
        if scen_read[field]:
            node.text = unicode(scen_read[field])
    elif field == 'resid':
        if scen_read[field]:
            node.text = unicode(scen_read[field])
            resid['scenario'] = unicode(scen_read[field])
        else:
            resid['scenario'] = unicode(uuid.uuid1())
            node.text = resid['scenario']
            scenario_obj.write([int(opts.scenario_id)],
                               {'resid': resid['scenario']})
    elif field == 'warehouse_ids':
        root.remove(node)
        for warehouse in warehouse_obj.read(scen_read[field], ['name']):
            node = SubElement(root, 'warehouse_ids')
            node.text = unicode(warehouse.get('name'))
    else:
        node.text = unicode(scen_read[field])
# add step
step_obj = Object(cnx, 'scanner.scenario.step')
step_ids = step_obj.search([('scenario_id', '=', int(opts.scenario_id))], 0,
                           None, 'reference_res_id')
for step_id in step_ids:
    step = step_obj.read(step_id, [])
    # delete unuse key
    del step['in_transition_ids']
    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'])
try:
    cnx = Connection(server=opts.server, dbname=opts.dbname, login=opts.user, port=opts.port,
                     password=opts.passwd)
except Exception, e:
    print '%s' % str(e)
    exit(1)


def generate_tracking_message_id(openobject_id):
    """Returns a string that can be used in the Message-ID RFC822 header field so we
       can track the replies related to a given object thanks to the "In-Reply-To" or
       "References" fields that Mail User Agents will set.
    """
    s = hashlib.sha1()
    s.update(str(time.time()))
    return "<%s-openobject-%s@%s>" % (s.hexdigest(), openobject_id, 'syleam6.syleam.fr')


message = Object(cnx, 'mailgate.message')
message_ids = message.search([('model','=','project.issue'),('message_id','=', False)])

print '%d message to update' % len(message_ids)

for m in message.read(message_ids, ['name', 'res_id']):
    args = {'message_id': generate_tracking_message_id(m['res_id'])}
    message.write([m['id']], args)


# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
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'])

Example #7
0
        ], 0, None, None, {'active_test': False}) or False
        if scen_vals['parent_id']:
            logger.info('Parent found')
            scen_vals['parent_id'] = scen_vals['parent_id'][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
        ], []))
    companies = curr['company_ids']

s = 23
header = ('Main Company'.ljust(s), 'Object'.ljust(s), 'Dest Company'.ljust(s))

print 80 * '-'
print '| %s | %s | %s |' % header
print 80 * '-'
for i in companies:
    ##
    # Change company to the user, to test the rules
    #
    i = int(i)
    source = multi.read(i, ['name'])['name']
    try:
        user.write([user_id], {'company_id': i})
    except Exception, e:
        print '| %s | %s | %s |' % (source.ljust(s), s * '*', s * '*')
        continue

    ##
    # Read the company by default for this object
    #
    dest_id = multi._company_default_get(opts.model)
    dest = multi.read(dest_id, ['name'])['name']

    print '| %s | %s | %s |' % (source.ljust(s), opts.model.ljust(s), dest.ljust(s))

print 80 * '-'

user.write([user_id], {'company_id': c_save_id[0]})
Example #9
0
    companies = curr['company_ids']

s = 23
header = ('Main Company'.ljust(s), 'Object'.ljust(s), 'Dest Company'.ljust(s))

print 80 * '-'
print '| %s | %s | %s |' % header
print 80 * '-'
for i in companies:
    ##
    # Change company to the user, to test the rules
    #
    i = int(i)
    source = multi.read(i, ['name'])['name']
    try:
        user.write([user_id], {'company_id': i})
    except Exception, e:
        print '| %s | %s | %s |' % (source.ljust(s), s * '*', s * '*')
        continue

    ##
    # Read the company by default for this object
    #
    dest_id = multi._company_default_get(opts.model)
    dest = multi.read(dest_id, ['name'])['name']

    print '| %s | %s | %s |' % (source.ljust(s), opts.model.ljust(s),
                                dest.ljust(s))

print 80 * '-'
opts, args = parser.parse_args()

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


def generate_tracking_message_id(openobject_id):
    """Returns a string that can be used in the Message-ID RFC822 header field so we
       can track the replies related to a given object thanks to the "In-Reply-To" or
       "References" fields that Mail User Agents will set.
    """
    s = hashlib.sha1()
    s.update(str(time.time()))
    return "<%s-openobject-%s@%s>" % (s.hexdigest(), openobject_id, "syleam6.syleam.fr")


message = Object(cnx, "mailgate.message")
message_ids = message.search([("model", "=", "project.issue"), ("message_id", "=", False)])

print "%d message to update" % len(message_ids)

for m in message.read(message_ids, ["name", "res_id"]):
    args = {"message_id": generate_tracking_message_id(m["res_id"])}
    message.write([m["id"]], args)


# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: