def readdir(self, path, offset): """ Return content of a directory : - List models for root path - List records for a model - List attachments for a record We don't have to check for the path, because getattr already returns -ENOENT if the model/record/attachment doesn't exist """ yield fuse.Direntry('.') yield fuse.Direntry('..') paths = path.split('/')[1:] # List models if path == '/': model_obj = Object(self.oerp_connection, 'ir.model') model_ids = model_obj.search([]) for model_data in model_obj.read(model_ids, ['model']): yield fuse.Direntry(model_data['model']) # List records elif len(paths) == 1: element_obj = Object(self.oerp_connection, paths[0]) element_ids = element_obj.search([]) for element_data in element_obj.read(element_ids, ['id']): yield fuse.Direntry(str(element_data['id'])) # List attachments else: attachment_obj = Object(self.oerp_connection, 'ir.attachment') attachment_ids = attachment_obj.search([('res_model', '=', paths[0]), ('res_id', '=', int(paths[1]))]) for attachment_data in attachment_obj.read(attachment_ids, ['name']): yield fuse.Direntry('%d-%s' % (attachment_data['id'], attachment_data['name']))
def readdir(self, path, offset): """ Return content of a directory : - List models for root path - List records for a model - List attachments for a record We don't have to check for the path, because getattr already returns -ENOENT if the model/record/attachment doesn't exist """ yield fuse.Direntry('.') yield fuse.Direntry('..') paths = path.split('/')[1:] # List models if path == '/': model_obj = Object(self.oerp_connection, 'ir.model') model_ids = model_obj.search([]) for model_data in model_obj.read(model_ids, ['model']): yield fuse.Direntry(model_data['model']) # List records elif len(paths) == 1: element_obj = Object(self.oerp_connection, paths[0]) element_ids = element_obj.search([]) for element_data in element_obj.read(element_ids, ['id']): yield fuse.Direntry(str(element_data['id'])) # List attachments else: attachment_obj = Object(self.oerp_connection, 'ir.attachment') attachment_ids = attachment_obj.search([ ('res_model', '=', paths[0]), ('res_id', '=', int(paths[1])) ]) for attachment_data in attachment_obj.read(attachment_ids, ['name']): yield fuse.Direntry( '%d-%s' % (attachment_data['id'], attachment_data['name']))
def getattr(self, path): """ Return attributes for the specified path : - Search for the model as first part - Search for an existing record as second part - Search for an existing attachment as third part - There cannot be more than 3 parts in the path """ fakeStat = fuse.Stat() fakeStat.st_mode = stat.S_IFDIR | 0400 fakeStat.st_nlink = 0 if path == '/': return fakeStat paths = path.split('/')[1:] if len(paths) > 3: return -ENOENT # Check for model existence model_obj = Object(self.oerp_connection, 'ir.model') model_ids = model_obj.search([('model', '=', paths[0])]) if not model_ids: return -ENOENT elif len(paths) == 1: return fakeStat # Check for record existence element_obj = Object(self.oerp_connection, paths[0]) element_ids = element_obj.search([('id', '=', int(paths[1]))]) if not element_ids: return -ENOENT elif len(paths) == 2: return fakeStat # Chech for attachement existence attachment_obj = Object(self.oerp_connection, 'ir.attachment') attachment_ids = attachment_obj.search([ ('res_model', '=', paths[0]), ('res_id', '=', int(paths[1])), ('id', '=', self.id_from_label(paths[2])) ]) if not attachment_ids: return -ENOENT # Common stats fakeStat.st_mode = stat.S_IFREG | 0400 fakeStat.st_nlink = 2 # TODO : Read the file size from a dedicated field (created in a specific module) attachment_obj = Object(self.oerp_connection, 'ir.attachment') attachment_ids = attachment_obj.search([ ('res_model', '=', paths[0]), ('res_id', '=', int(paths[1])), ('id', '=', self.id_from_label(paths[2])) ]) attachment_data = attachment_obj.read(attachment_ids, ['datas']) fakeStat.st_size = len(base64.b64decode(attachment_data[0]['datas'])) return fakeStat
def getattr(self, path): """ Return attributes for the specified path : - Search for the model as first part - Search for an existing record as second part - Search for an existing attachment as third part - There cannot be more than 3 parts in the path """ fakeStat = fuse.Stat() fakeStat.st_mode = stat.S_IFDIR | 0400 fakeStat.st_nlink = 0 if path == '/': return fakeStat paths = path.split('/')[1:] if len(paths) > 3: return -ENOENT # Check for model existence model_obj = Object(self.oerp_connection, 'ir.model') model_ids = model_obj.search([('model', '=', paths[0])]) if not model_ids: return -ENOENT elif len(paths) == 1: return fakeStat # Check for record existence element_obj = Object(self.oerp_connection, paths[0]) element_ids = element_obj.search([('id', '=', int(paths[1]))]) if not element_ids: return -ENOENT elif len(paths) == 2: return fakeStat # Chech for attachement existence attachment_obj = Object(self.oerp_connection, 'ir.attachment') attachment_ids = attachment_obj.search([('res_model', '=', paths[0]), ('res_id', '=', int(paths[1])), ('id', '=', self.id_from_label(paths[2]))]) if not attachment_ids: return -ENOENT # Common stats fakeStat.st_mode = stat.S_IFREG | 0400 fakeStat.st_nlink = 2 # TODO : Read the file size from a dedicated field (created in a specific module) attachment_obj = Object(self.oerp_connection, 'ir.attachment') attachment_ids = attachment_obj.search([('res_model', '=', paths[0]), ('res_id', '=', int(paths[1])), ('id', '=', self.id_from_label(paths[2]))]) attachment_data = attachment_obj.read(attachment_ids, ['datas']) fakeStat.st_size = len(base64.b64decode(attachment_data[0]['datas'])) return fakeStat
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)
def read(self, path, size, offset): """ Return the specified slide of a file Note : Only the beginning of the name is required (the ID of the attachment), we can put anything after the first '-', it will be ignored """ paths = path.split('/')[1:] # TODO : Create a module that allows to read files by slides attachment_obj = Object(self.oerp_connection, 'ir.attachment') attachment_ids = attachment_obj.search([('res_model', '=', paths[0]), ('res_id', '=', int(paths[1])), ('id', '=', self.id_from_label(paths[2]))]) attachment_data = attachment_obj.read(attachment_ids, ['datas']) return base64.b64decode(attachment_data[0]['datas'])[offset:offset + size]
def _exists(self, searchTuples, objectName): """ Returns true if the search has a result. """ obj = Object(self.cnx, objectName) try: if obj.search(searchTuples): return True except: return False
def _get_period(self, date): d = str(date.date()) obj = Object(self.cnx, 'account.period') ids = obj.search([("date_start", "<=", d), ("date_stop", ">=", d), ("state", "=", "draft"), ("special", "=", False)]) if len(ids) == 1: return ids[0] else: raise ValueError( "Did not find a single open period with that date, %s" % d)
def _copy_with_args(self, searchTuples, searchExists, args, objectName): """ Does a copy and then adds some extra information. """ obj = Object(self.cnx, objectName) results = obj.search(searchTuples) new_id = obj.copy(results[0]) if self._exists(searchExists, objectName): return True else: return self._update_no_search(new_id, args, objectName)
def _get_attr(self, searchTuples, objectName, attribute): """ returns value of the attribute """ obj = Object(self.cnx, objectName) results = obj.search(searchTuples) if len(results) != 1: raise ValueError("We did not get a single " + \ self.common[objectName] + " back. " + \ str(results)) else: return obj.read(results[0])[attribute]
def _get(self, searchTuples, objectName): """ returns the object id as int iff the search returns a single result. """ obj = Object(self.cnx, objectName) results = obj.search(searchTuples) if len(results) != 1: raise ValueError("We did not get a single " + \ self.common[objectName] + " back. " + \ str(results) + str(searchTuples)) else: return results[0]
def read(self, path, size, offset): """ Return the specified slide of a file Note : Only the beginning of the name is required (the ID of the attachment), we can put anything after the first '-', it will be ignored """ paths = path.split('/')[1:] # TODO : Create a module that allows to read files by slides attachment_obj = Object(self.oerp_connection, 'ir.attachment') attachment_ids = attachment_obj.search([ ('res_model', '=', paths[0]), ('res_id', '=', int(paths[1])), ('id', '=', self.id_from_label(paths[2])) ]) attachment_data = attachment_obj.read(attachment_ids, ['datas']) return base64.b64decode(attachment_data[0]['datas'])[offset:offset + size]
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:
fp = open(opts.filename, 'r') reader = csv.DictReader(fp, delimiter=',') 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']})
label_obj = Object(cnx, 'jasper.document.label') root = Element('jasperReport', {'name': 'to_be_defined', 'language': 'groovy', 'pageWidth': '595', 'pageHeight': '842', 'columnWidth': '555', 'leftMargin': '20', 'rightMargin': '20', 'topMargin': '20', 'bottomMargin': '20'}) #root.set('name', 'to_be_defined') #root.set('language', 'groovy') #root.set('pageWidth', '595') #root.set('pageHeight', '842') #root.set('columnWidth', '555') #root.set('leftMargin', '20') #root.set('rightMargin', '20') #root.set('topMargin', '20') #root.set('bottomMargin', '20') jasper_ids = jasper_obj.search([('service','=',opts.service)]) if not jasper_ids: print 'Service %s not found' % opts.service exit(1) jasper = jasper_obj.read(jasper_ids[0]) if isinstance(jasper, list): jasper = jasper[0] #print jasper for lab in label_obj.read(jasper['label_ids'], ['name','value']): #print lab #<parameter name="I18N_TITLE" class="java.lang.String" isForPrompting="false">
args = [ ('model', '=', model), ('res_id', '=', id) ] ret = '%s_%d' % (model.replace('.', '_'), id) res = model_data.search(args) if res: r = model_data.read(res, ['module', 'name'])[0] ret = '%s.%s' % (r['module'], r['name']) return ret ### ## Verify if there are records in the object ## if opts.id: if not model.search([('id', '=', opts.id)], 0, 1, 0, {'active_test': False}): print 'ID %d does not exists in the database' % opts.id sys.exit(1) model_ids = [opts.id] elif opts.ids: ids = [ int(x) for x in opts.ids.replace(' ', '').split(',')] for id in ids: if not model.search([('id', '=', id)], 0, 1, 0, {'active_test': False}): print 'ID %d does not exists in the database' % id sys.exit(1) model_ids = [] model_ids.extend(ids) elif opts.domain: count = model.search_count([], {'active_test': False}) model_ids = model.search(eval(opts.domain), 0, count, 0, {'active_test': False})
help='List the company by name and their ID') parser.add_option_group(group) opts, args = parser.parse_args() try: cnx = Connection(server=opts.server, dbname=opts.dbname, login=opts.user, password=opts.passwd) except Exception, e: print '%s' % str(e) exit(1) user = Object(cnx, 'res.users') rule = Object(cnx, 'ir.rule') user_id = user.search([('login','=', opts.user)])[0] if opts.legend: comp = Object(cnx, 'res.company') company_ids = comp.search([]) print 'List all company' print 80 * '*' for compa in comp.read(company_ids, ['name']): print '%s -> %d' % (compa['name'].ljust(20), compa['id']) print 80 * '*' company_id = user.read(user_id, ['company_id'])['company_id'] try: dest = rule.domain_get(opts.model) except Exception, e: print "Object %s doesn't exists" % opts.model
opts, args = parser.parse_args() try: cnx = Connection(server=opts.server, dbname=opts.dbname, login=opts.user, password=opts.passwd) except Exception, e: print '%s' % str(e) exit(1) user = Object(cnx, 'res.users') rule = Object(cnx, 'ir.rule') user_id = user.search([('login', '=', opts.user)])[0] if opts.legend: comp = Object(cnx, 'res.company') company_ids = comp.search([]) print 'List all company' print 80 * '*' for compa in comp.read(company_ids, ['name']): print '%s -> %d' % (compa['name'].ljust(20), compa['id']) print 80 * '*' company_id = user.read(user_id, ['company_id'])['company_id'] try: dest = rule.domain_get(opts.model) except Exception, e: print "Object %s doesn't exists" % opts.model
password=opts.passwd, port=opts.port) except Exception, e: logger.error('Fail to connect to the server') logger.error('%s' % str(e)) sys.exit(1) model = Object(cnx, opts.model) mod_count = model.search_count([]) logger.info('There are %d record to export' % mod_count) fields = model.fields_get() fields_name = fields.keys() result = model.read(model.search([])) from odf.opendocument import OpenDocumentSpreadsheet from odf.style import Style, TextProperties, ParagraphProperties, TableColumnProperties from odf.text import P from odf.table import Table, TableColumn, TableRow, TableCell textdoc = OpenDocumentSpreadsheet() tablecontents = Style(name="Table Contents", family="paragraph") tablecontents.addElement(ParagraphProperties(numberlines="false", linenumber="0")) tablecontents.addElement(TextProperties(fontweight="bold")) textdoc.styles.addElement(tablecontents) table = Table(name=opts.model) if opts.title:
# parse of the scenario steps_number = 0 transitions_number = 0 for node in root.getchildren(): # the node of the Step and Transition are put in other list if node.tag == 'Step': steps_number += 1 step.append(node) elif node.tag == 'Transition': transitions_number += 1 transition.append(node) elif node.tag == 'warehouse_ids': if 'warehouse_ids' not in scen_vals: scen_vals['warehouse_ids'] = [] warehouse_ids = warehouse_obj.search([('name', '=', node.text)], 0, None, None, {'active_test': False}) if warehouse_ids: scen_vals['warehouse_ids'].append((4, warehouse_ids[0])) elif node.tag in ('active', 'shared_custom'): scen_vals[node.tag] = eval(node.text) or False else: scen_vals[node.tag] = node.text or False logger.info('%d steps found' % steps_number) logger.info('%d transitions found' % transitions_number) if scen_vals['model_id']: logger.info('Search model: %s' % scen_vals['model_id']) scen_vals['model_id'] = model_obj.search([ ('model', '=', scen_vals['model_id']) ], 0, None, None, {'active_test': False}) or False
Search if the record was previously register in ir_model_data """ args = [('model', '=', model), ('res_id', '=', id)] ret = '%s_%d' % (model.replace('.', '_'), id) res = model_data.search(args) if res: r = model_data.read(res, ['module', 'name'])[0] ret = '%s.%s' % (r['module'], r['name']) return ret ### ## Verify if there are records in the object ## if opts.id: if not model.search([('id', '=', opts.id)], 0, 1, 0, {'active_test': False}): print 'ID %d does not exists in the database' % opts.id sys.exit(1) model_ids = [opts.id] elif opts.ids: ids = [int(x) for x in opts.ids.replace(' ', '').split(',')] for id in ids: if not model.search([('id', '=', id)], 0, 1, 0, {'active_test': False}): print 'ID %d does not exists in the database' % id sys.exit(1) model_ids = [] model_ids.extend(ids) elif opts.domain: count = model.search_count([], {'active_test': False})
try: logger.info('Open connection to "%s:%s" on "%s" with user "%s" ' % (opts.server, opts.port, opts.dbname, opts.user)) cnx = Connection(server=opts.server, dbname=opts.dbname, login=opts.user, password=opts.passwd, port=opts.port) except Exception, e: logger.error('Fail to connect to the server') logger.error('%s' % str(e)) sys.exit(1) model = Object(cnx, opts.model) model_ids = model.search([]) model_lists = model.read(model_ids, [opts.field, 'parent_left', 'parent_right']) models = dict(map(lambda x: (x['id'], x), model_lists)) try: for a in model_lists: logger.debug('id: %d' % a['id']) if a[opts.field]: assert a['parent_left'] > models[a[ opts.field][0]]['parent_left'], '%s > %s' % ( a['parent_left'], models[a[opts.field][0]]['parent_left']) assert a['parent_right'] < models[a[ opts.field][0]]['parent_right'], '%s > %s' % ( a['parent_right'], models[a[opts.field][0]]['parent_right']) assert a['parent_left'] < a['parent_right']
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) sys.exit(1) mod = Object(cnx, 'ir.model') if opts.oerp_version == '5': print 'version 5' model = mod.search([]) else: print 'version 6' model = mod.search([('osv_memory', '=', False)]) print 80 * '-' print '| Model | Search | Read | View XML |' print 80 * '-' footer = '--- FOOTER REPORT ---\n' for m in mod.read(model): if m['model'].startswith('ir_') or m['model'].find('wizard') >= 0: continue
""" import sys sys.path.append("../") from oobjlib.connection import Connection from oobjlib.component import Object from oobjlib.common import GetParser parser = GetParser("Module List", "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) modules = Object(cnx, "ir.module.module") print "--[Connection Object]---------------------" print "%s" % str(modules) ids = modules.search([("state", "=", "installed")]) print "--[Module list]---------------------------" for p in modules.read(ids, ["name"]): print "* %s" % p["name"] print "--[End]-----------------------------------" # 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
'leftMargin': '20', 'rightMargin': '20', 'topMargin': '20', 'bottomMargin': '20' }) #root.set('name', 'to_be_defined') #root.set('language', 'groovy') #root.set('pageWidth', '595') #root.set('pageHeight', '842') #root.set('columnWidth', '555') #root.set('leftMargin', '20') #root.set('rightMargin', '20') #root.set('topMargin', '20') #root.set('bottomMargin', '20') jasper_ids = jasper_obj.search([('service', '=', opts.service)]) if not jasper_ids: print 'Service %s not found' % opts.service exit(1) jasper = jasper_obj.read(jasper_ids[0]) if isinstance(jasper, list): jasper = jasper[0] #print jasper for lab in label_obj.read(jasper['label_ids'], ['name', 'value']): #print lab #<parameter name="I18N_TITLE" class="java.lang.String" isForPrompting="false">
opts, args = parser.parse_args() try: cnx = Connection(server=opts.server, dbname=opts.dbname, login=opts.user, password=opts.passwd) except Exception, e: print '%s' % str(e) exit(1) user = Object(cnx, 'res.users') multi = Object(cnx, 'res.company') user_id = user.search([('login', '=', opts.user)])[0] # save company_id to restore it after curr = user.read(user_id, ['company_ids', 'company_id']) c_save_id = curr['company_id'] print 'User: %d => %s (id %d)' % (user_id, c_save_id[1], c_save_id[0]) ## # If the company argument is missing, retrieve all companies in the user form # if opts.company: companies = opts.company.split(',') else: companies = curr['company_ids'] s = 23 header = ('Main Company'.ljust(s), 'Object'.ljust(s), 'Dest Company'.ljust(s))
def _return_object(self, objectName, id): obj = Object(self.cnx, objectName) r = obj.search([("id", "=", id)]) return obj.read(r)[0]
group_xml_id = group_obj.get_metadata(group_id)[0]['xmlid'] if group_xml_id: node = SubElement(root, 'group_ids') node.text = group_xml_id elif field == 'user_ids': root.remove(node) for user in user_obj.read(scen_read[field], ['login']): node = SubElement(root, 'user_ids') node.text = unicode(user.get('login')) 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, 'name') step_xmlid_counters = {} for step_id in step_ids: step = step_obj.read(step_id, [])[0] # delete unuse key del step['in_transition_ids'] del step['out_transition_ids'] del step['scenario_id'] for field in field_to_remove: del step[field] # get res_id step_xml_id = step_obj.get_metadata(step_id)[0]['xmlid'] if not step_xml_id: step_xml_id = 'scanner_scenario_step_%s_%s' % (
filename = opts.filename if not opts.filename: filename = '%s.csv' % opts.model # recherche du mon de l'objet dans le nom du fichier sans l'extension obj = Object(cnx, opts.model) ctx = {'lang': opts.lang} if opts.inactive: ctx['active_test'] = False if not opts.ids: # Get all ids ids = obj.search([]) else: ids = [int(x.strip()) for x in opts.ids.split(',')] if not opts.fields: # get all fields fields = obj.fields_get_keys() else: fields = opts.fields.split(',') logger.info('Start execute export on the selected file') csvWriter = csv.writer(file(filename, 'wb+'), delimiter=opts.separator, quoting=csv.QUOTE_NONNUMERIC) csvWriter.writerow(fields) ok = True
sys.path.append('../') from oobjlib.connection import Connection from oobjlib.component import Object from oobjlib.common import GetParser parser = GetParser('Module List', '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) modules = Object(cnx, "ir.module.module") print '--[Connection Object]---------------------' print '%s' % str(modules) ids = modules.search([('state', '=', 'installed')]) print '--[Module list]---------------------------' for p in modules.read(ids, ['name']): print '* %s' % p['name'] print '--[End]-----------------------------------' # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
try: logger.info('Open connection to "%s:%s" on "%s" with user "%s" ' % (opts.server, opts.port, opts.dbname, opts.user)) cnx = Connection( server=opts.server, dbname=opts.dbname, login=opts.user, password=opts.passwd, port=opts.port) except Exception, e: logger.error('Fail to connect to the server') logger.error('%s' % str(e)) sys.exit(1) model = Object(cnx, opts.model) model_ids = model.search([]) model_lists = model.read(model_ids, [opts.field,'parent_left','parent_right']) models = dict(map(lambda x: (x['id'],x), model_lists)) try: for a in model_lists: logger.debug('id: %d' % a['id']) if a[opts.field]: assert a['parent_left'] > models[a[opts.field][0]]['parent_left'], '%s > %s' % (a['parent_left'], models[a[opts.field][0]]['parent_left']) assert a['parent_right'] < models[a[opts.field][0]]['parent_right'], '%s > %s' % (a['parent_right'], models[a[opts.field][0]]['parent_right']) assert a['parent_left'] < a['parent_right'] for a2 in model_lists: assert not ((a2['parent_right']>a['parent_left']) and (a2['parent_left']<a['parent_left']) and (a2['parent_right']<a['parent_right'])) if a2[opts.field]==a['id']: assert (a2['parent_left']>a['parent_left']) and (a2['parent_right']<a['parent_right'])
scen_vals['warehouse_ids'] = [] # warehouse_ids = warehouse_obj.search([('name', '=', node.text)], 0, None, None, {'active_test': False}) warehouse_ids = [1] if warehouse_ids: scen_vals['warehouse_ids'].append((4, warehouse_ids[0])) elif node.tag in ('active', 'shared_custom'): scen_vals[node.tag] = eval(node.text) or False else: scen_vals[node.tag] = node.text or False logger.info('%d steps found' % steps_number) logger.info('%d transitions found' % transitions_number) if scen_vals['model_id']: logger.info('Search model: %s' % scen_vals['model_id']) scen_vals['model_id'] = model_obj.search([ ('model', '=', scen_vals['model_id']) ], 0, None, None, {'active_test': False}) or False if scen_vals['model_id']: logger.info('Model found') scen_vals['model_id'] = scen_vals['model_id'][0] else: logger.error('Model not found') sys.exit(1) if scen_vals.get('company_id'): logger.info('Search company: %s' % scen_vals['company_id']) # scen_vals['company_id'] = company_obj.search([('name', '=', scen_vals['company_id'])], 0, None, None, {'active_test': False}) or False scen_vals['company_id'] = [1] if scen_vals['company_id']: logger.info('Company found') scen_vals['company_id'] = scen_vals['company_id'][0]
parser.add_option_group(group) opts, args = parser.parse_args() try: cnx = Connection(server=opts.server, dbname=opts.dbname, login=opts.user, password=opts.passwd) except Exception, e: print '%s' % str(e) exit(1) user = Object(cnx, 'res.users') multi = Object(cnx, 'res.company') user_id = user.search([('login','=',opts.user)])[0] # save company_id to restore it after curr = user.read(user_id, ['company_ids','company_id']) c_save_id = curr['company_id'] print 'User: %d => %s (id %d)' % (user_id, c_save_id[1], c_save_id[0]) ## # If the company argument is missing, retrieve all companies in the user form # if opts.company: companies = opts.company.split(',') else: companies = curr['company_ids'] s = 23 header = ('Main Company'.ljust(s), 'Object'.ljust(s), 'Dest Company'.ljust(s))
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'] del step['out_transition_ids'] del step['id'] del step['scenario_id'] # get res_id if not step['reference_res_id']: step['reference_res_id'] = unicode(uuid.uuid1()) step_obj.write([step_id], {'reference_res_id': step['reference_res_id']}) resid[step_id] = unicode(step['reference_res_id']) # save code src_file = open('%s/%s.py' % (opts.directory, step['reference_res_id']),
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: