From 22cfeacab1b966a882a46fb2d61af4dd022990eb Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Tue, 16 Sep 2008 14:26:07 +0200 Subject: [PATCH] fix tools bzr revid: fp@tinyerp.com-20080916122607-fk0jkoh8rw7umnyk --- bin/addons/base/ir/ir_ui_menu.py | 33 ++-------------- bin/openerp-server.py | 68 ++++++++------------------------ bin/tools/misc.py | 30 ++++++++++++++ 3 files changed, 50 insertions(+), 81 deletions(-) diff --git a/bin/addons/base/ir/ir_ui_menu.py b/bin/addons/base/ir/ir_ui_menu.py index 58242a2fb99..1133c755aa0 100644 --- a/bin/addons/base/ir/ir_ui_menu.py +++ b/bin/addons/base/ir/ir_ui_menu.py @@ -31,6 +31,7 @@ from osv import fields, osv from osv.orm import browse_null, browse_record import re +import tools def one_in(setA, setB): """Check the presence of an element of setA in setB @@ -40,34 +41,6 @@ def one_in(setA, setB): return True return False -icons = map(lambda x: (x,x), ['STOCK_ABOUT', 'STOCK_ADD', 'STOCK_APPLY', 'STOCK_BOLD', -'STOCK_CANCEL', 'STOCK_CDROM', 'STOCK_CLEAR', 'STOCK_CLOSE', 'STOCK_COLOR_PICKER', -'STOCK_CONNECT', 'STOCK_CONVERT', 'STOCK_COPY', 'STOCK_CUT', 'STOCK_DELETE', -'STOCK_DIALOG_AUTHENTICATION', 'STOCK_DIALOG_ERROR', 'STOCK_DIALOG_INFO', -'STOCK_DIALOG_QUESTION', 'STOCK_DIALOG_WARNING', 'STOCK_DIRECTORY', 'STOCK_DISCONNECT', -'STOCK_DND', 'STOCK_DND_MULTIPLE', 'STOCK_EDIT', 'STOCK_EXECUTE', 'STOCK_FILE', -'STOCK_FIND', 'STOCK_FIND_AND_REPLACE', 'STOCK_FLOPPY', 'STOCK_GOTO_BOTTOM', -'STOCK_GOTO_FIRST', 'STOCK_GOTO_LAST', 'STOCK_GOTO_TOP', 'STOCK_GO_BACK', -'STOCK_GO_DOWN', 'STOCK_GO_FORWARD', 'STOCK_GO_UP', 'STOCK_HARDDISK', -'STOCK_HELP', 'STOCK_HOME', 'STOCK_INDENT', 'STOCK_INDEX', 'STOCK_ITALIC', -'STOCK_JUMP_TO', 'STOCK_JUSTIFY_CENTER', 'STOCK_JUSTIFY_FILL', -'STOCK_JUSTIFY_LEFT', 'STOCK_JUSTIFY_RIGHT', 'STOCK_MEDIA_FORWARD', -'STOCK_MEDIA_NEXT', 'STOCK_MEDIA_PAUSE', 'STOCK_MEDIA_PLAY', -'STOCK_MEDIA_PREVIOUS', 'STOCK_MEDIA_RECORD', 'STOCK_MEDIA_REWIND', -'STOCK_MEDIA_STOP', 'STOCK_MISSING_IMAGE', 'STOCK_NETWORK', 'STOCK_NEW', -'STOCK_NO', 'STOCK_OK', 'STOCK_OPEN', 'STOCK_PASTE', 'STOCK_PREFERENCES', -'STOCK_PRINT', 'STOCK_PRINT_PREVIEW', 'STOCK_PROPERTIES', 'STOCK_QUIT', -'STOCK_REDO', 'STOCK_REFRESH', 'STOCK_REMOVE', 'STOCK_REVERT_TO_SAVED', -'STOCK_SAVE', 'STOCK_SAVE_AS', 'STOCK_SELECT_COLOR', 'STOCK_SELECT_FONT', -'STOCK_SORT_ASCENDING', 'STOCK_SORT_DESCENDING', 'STOCK_SPELL_CHECK', -'STOCK_STOP', 'STOCK_STRIKETHROUGH', 'STOCK_UNDELETE', 'STOCK_UNDERLINE', -'STOCK_UNDO', 'STOCK_UNINDENT', 'STOCK_YES', 'STOCK_ZOOM_100', -'STOCK_ZOOM_FIT', 'STOCK_ZOOM_IN', 'STOCK_ZOOM_OUT', -'terp-account', 'terp-crm', 'terp-mrp', 'terp-product', 'terp-purchase', -'terp-sale', 'terp-tools', 'terp-administration', 'terp-hr', 'terp-partner', -'terp-project', 'terp-report', 'terp-stock', 'terp-calendar', 'terp-graph', -]) - class many2many_unique(fields.many2many): def set(self, cr, obj, id, name, values, user=None, context=None): if not values: @@ -186,7 +159,7 @@ class ir_ui_menu(osv.osv): for m in self.browse(cr, uid, ids, context=context): res[m.id] = ('stock', (m.icon,'ICON_SIZE_MENU')) return res - + def onchange_icon(self, cr, uid, ids, icon): if not icon: return {} @@ -201,7 +174,7 @@ class ir_ui_menu(osv.osv): 'menu_id', 'gid', 'Groups'), 'complete_name': fields.function(_get_full_name, method=True, string='Complete Name', type='char', size=128), - 'icon': fields.selection(icons, 'Icon', size=64), + 'icon': fields.selection(tools.icons, 'Icon', size=64), 'icon_pict': fields.function(_get_icon_pict, method=True, type='picture'), 'action': fields.function(_action, fnct_inv=_action_inv, method=True, type='reference', string='Action', diff --git a/bin/openerp-server.py b/bin/openerp-server.py index 530f1c29535..f50aeefd423 100755 --- a/bin/openerp-server.py +++ b/bin/openerp-server.py @@ -93,60 +93,26 @@ logger.notifyChannel("init", netsvc.LOG_INFO, 'connecting to database') import psycopg import pooler -# try to connect to the database -try: -# pooler.init() - pass -except psycopg.OperationalError, err: - logger.notifyChannel("init", netsvc.LOG_ERROR, "could not connect to database '%s'!" % (tools.config["db_name"],)) - - msg = str(err).replace("FATAL:", "").strip() - db_msg = "database \"%s\" does not exist" % (tools.config["db_name"],) - - # Note: this is ugly but since psycopg only uses one exception for all errors - # I don't think it's possible to do differently - if msg == db_msg: - print """ - this database does not exist - -You need to create it using the command: - - createdb --encoding=UNICODE '%s' - -When you run openerp-server for the first time it will initialise the -database. You may force this behaviour at a later time by using the command: - - ./openerp-server --init=all - -Two accounts will be created by default: - 1. login: admin password : admin - 2. login: demo password : demo - -""" % (tools.config["db_name"]) - else: - print "\n "+msg+"\n" - sys.exit(1) - db_name = tools.config["db_name"] # test whether it is needed to initialize the db (the db is empty) -try: - cr = pooler.get_db_only(db_name).cursor() -except psycopg.OperationalError: - logger.notifyChannel("init", netsvc.LOG_INFO, "could not connect to database '%s'!" % db_name,) - cr = None -if cr: - cr.execute("SELECT relname FROM pg_class WHERE relkind='r' AND relname='ir_ui_menu'") - if len(cr.fetchall())==0: -#if False: - logger.notifyChannel("init", netsvc.LOG_INFO, "init db") - tools.init_db(cr) - # in that case, force --init=all - tools.config["init"]["all"] = 1 - tools.config['update']['all'] = 1 - if not tools.config['without_demo']: - tools.config["demo"]['all'] = 1 - cr.close() +#try: +# cr = pooler.get_db_only(db_name).cursor() +#except psycopg.OperationalError: +# logger.notifyChannel("init", netsvc.LOG_INFO, "could not connect to database '%s'!" % db_name,) +# cr = None +#if cr: +# cr.execute("SELECT relname FROM pg_class WHERE relkind='r' AND relname='ir_ui_menu'") +# if len(cr.fetchall())==0: +##if False: +# logger.notifyChannel("init", netsvc.LOG_INFO, "init db") +# tools.init_db(cr) +# # in that case, force --init=all +# tools.config["init"]["all"] = 1 +# tools.config['update']['all'] = 1 +# if not tools.config['without_demo']: +# tools.config["demo"]['all'] = 1 +# cr.close() #---------------------------------------------------------- # launch modules install/upgrade/removes if needed diff --git a/bin/tools/misc.py b/bin/tools/misc.py index dd812d3a473..f2f9b237420 100644 --- a/bin/tools/misc.py +++ b/bin/tools/misc.py @@ -736,6 +736,36 @@ def logged(when): except KeyError, e: raise ValueError(e), "must to be 'pre' or 'post'" +icons = map(lambda x: (x,x), ['STOCK_ABOUT', 'STOCK_ADD', 'STOCK_APPLY', 'STOCK_BOLD', +'STOCK_CANCEL', 'STOCK_CDROM', 'STOCK_CLEAR', 'STOCK_CLOSE', 'STOCK_COLOR_PICKER', +'STOCK_CONNECT', 'STOCK_CONVERT', 'STOCK_COPY', 'STOCK_CUT', 'STOCK_DELETE', +'STOCK_DIALOG_AUTHENTICATION', 'STOCK_DIALOG_ERROR', 'STOCK_DIALOG_INFO', +'STOCK_DIALOG_QUESTION', 'STOCK_DIALOG_WARNING', 'STOCK_DIRECTORY', 'STOCK_DISCONNECT', +'STOCK_DND', 'STOCK_DND_MULTIPLE', 'STOCK_EDIT', 'STOCK_EXECUTE', 'STOCK_FILE', +'STOCK_FIND', 'STOCK_FIND_AND_REPLACE', 'STOCK_FLOPPY', 'STOCK_GOTO_BOTTOM', +'STOCK_GOTO_FIRST', 'STOCK_GOTO_LAST', 'STOCK_GOTO_TOP', 'STOCK_GO_BACK', +'STOCK_GO_DOWN', 'STOCK_GO_FORWARD', 'STOCK_GO_UP', 'STOCK_HARDDISK', +'STOCK_HELP', 'STOCK_HOME', 'STOCK_INDENT', 'STOCK_INDEX', 'STOCK_ITALIC', +'STOCK_JUMP_TO', 'STOCK_JUSTIFY_CENTER', 'STOCK_JUSTIFY_FILL', +'STOCK_JUSTIFY_LEFT', 'STOCK_JUSTIFY_RIGHT', 'STOCK_MEDIA_FORWARD', +'STOCK_MEDIA_NEXT', 'STOCK_MEDIA_PAUSE', 'STOCK_MEDIA_PLAY', +'STOCK_MEDIA_PREVIOUS', 'STOCK_MEDIA_RECORD', 'STOCK_MEDIA_REWIND', +'STOCK_MEDIA_STOP', 'STOCK_MISSING_IMAGE', 'STOCK_NETWORK', 'STOCK_NEW', +'STOCK_NO', 'STOCK_OK', 'STOCK_OPEN', 'STOCK_PASTE', 'STOCK_PREFERENCES', +'STOCK_PRINT', 'STOCK_PRINT_PREVIEW', 'STOCK_PROPERTIES', 'STOCK_QUIT', +'STOCK_REDO', 'STOCK_REFRESH', 'STOCK_REMOVE', 'STOCK_REVERT_TO_SAVED', +'STOCK_SAVE', 'STOCK_SAVE_AS', 'STOCK_SELECT_COLOR', 'STOCK_SELECT_FONT', +'STOCK_SORT_ASCENDING', 'STOCK_SORT_DESCENDING', 'STOCK_SPELL_CHECK', +'STOCK_STOP', 'STOCK_STRIKETHROUGH', 'STOCK_UNDELETE', 'STOCK_UNDERLINE', +'STOCK_UNDO', 'STOCK_UNINDENT', 'STOCK_YES', 'STOCK_ZOOM_100', +'STOCK_ZOOM_FIT', 'STOCK_ZOOM_IN', 'STOCK_ZOOM_OUT', +'terp-account', 'terp-crm', 'terp-mrp', 'terp-product', 'terp-purchase', +'terp-sale', 'terp-tools', 'terp-administration', 'terp-hr', 'terp-partner', +'terp-project', 'terp-report', 'terp-stock', 'terp-calendar', 'terp-graph', +]) + + + if __name__ == '__main__': import doctest doctest.testmod()