[IMP] tools: added disclaimer on detect_ip_addr
[odoo/odoo.git] / bin / tools / misc.py
index 6bd1000..43a283d 100644 (file)
@@ -3,6 +3,7 @@
 #
 #    OpenERP, Open Source Management Solution
 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
+#    Copyright (C) 2010 OpenERP s.a. (<http://openerp.com>).
 #
 #    This program is free software: you can redistribute it and/or modify
 #    it under the terms of the GNU Affero General Public License as
@@ -33,6 +34,9 @@ import release
 import socket
 import re
 from itertools import islice
+import threading
+from which import which
+
 
 if sys.version_info[:2] < (2, 4):
     from threadinglocal import local
@@ -99,7 +103,7 @@ def init_db(cr):
                 values (%s, %s, %s, %s, %s, %s, %s, %s, %s)', (
             id, info.get('author', ''),
             info.get('website', ''), i, info.get('name', False),
-            info.get('description', ''), p_id, state, info.get('certificate')))
+            info.get('description', ''), p_id, state, info.get('certificate') or None))
         cr.execute('insert into ir_model_data \
             (name,model,module, res_id, noupdate) values (%s,%s,%s,%s,%s)', (
                 'module_meta_information', 'ir.module.module', i, id, True))
@@ -110,23 +114,19 @@ def init_db(cr):
         cr.commit()
 
 def find_in_path(name):
-    if os.name == "nt":
-        sep = ';'
-    else:
-        sep = ':'
-    path = [dir for dir in os.environ['PATH'].split(sep)
-            if os.path.isdir(dir)]
-    for dir in path:
-        val = os.path.join(dir, name)
-        if os.path.isfile(val) or os.path.islink(val):
-            return val
-    return None
+    try:
+        return which(name)
+    except IOError:
+        return None
 
 def find_pg_tool(name):
+    path = None
     if config['pg_path'] and config['pg_path'] != 'None':
-        return os.path.join(config['pg_path'], name)
-    else:
-        return find_in_path(name)
+        path = config['pg_path']
+    try:
+        return which(name, path=path)
+    except IOError:
+        return None
 
 def exec_pg_command(name, *args):
     prog = find_pg_tool(name)
@@ -472,7 +472,7 @@ def email_send(email_from, email_to, subject, body, email_cc=None, email_bcc=Non
     for key, value in x_headers.iteritems():
         msg['X-OpenERP-%s' % key] = str(value)
         msg['%s' % key] = str(value)
-    
+
     if openobject_id:
         msg['Message-Id'] = "<%s-openobject-%s@%s>" % (time.time(), openobject_id, socket.gethostname())
 
@@ -924,7 +924,7 @@ def get_languages():
         'fr_BE': u'French (BE) / Français (BE)',
         'fr_CH': u'French (CH) / Français (CH)',
         'fr_FR': u'French / Français',
-        'gl_ES': u'Galician / Spain',
+        'gl_ES': u'Galician / Galego',
         'gu_IN': u'Gujarati / India',
         'hi_IN': u'Hindi / India',
         'hr_HR': u'Croatian / hrvatski jezik',
@@ -949,8 +949,8 @@ def get_languages():
         'ro_RO': u'Romanian / limba română',
         'ru_RU': u'Russian / русский язык',
         'si_LK': u'Sinhalese / Sri Lanka',
-        'sk_SK': u'Slovak / Slovakia',
-        'sl_SL': u'Slovenian / slovenščina',
+        'sl_SI': u'Slovenian / slovenščina',
+        'sk_SK': u'Slovak / Slovenský jazyk',
         'sq_AL': u'Albanian / Shqipëri',
         'sr_RS': u'Serbian / Serbia',
         'sv_SE': u'Swedish / svenska',
@@ -1128,6 +1128,16 @@ icons = map(lambda x: (x,x), ['STOCK_ABOUT', 'STOCK_ADD', 'STOCK_APPLY', 'STOCK_
 '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',
+'terp-check','terp-go-month','terp-go-year','terp-go-today','terp-document-new','terp-camera_test',
+'terp-emblem-important','terp-gtk-media-pause','terp-gtk-stop','terp-gnome-cpu-frequency-applet+',
+'terp-dialog-close','terp-gtk-jump-to-rtl','terp-gtk-jump-to-ltr','terp-accessories-archiver',
+'terp-stock_align_left_24','terp-stock_effects-object-colorize','terp-go-home','terp-gtk-go-back-rtl',
+'terp-gtk-go-back-ltr','terp-personal','terp-personal-','terp-personal+','terp-accessories-archiver-minus',
+'terp-accessories-archiver+','terp-stock_symbol-selection','terp-call-start','terp-dolar',
+'terp-face-plain','terp-folder-blue','terp-folder-green','terp-folder-orange','terp-folder-yellow',
+'terp-gdu-smart-failing','terp-go-week','terp-gtk-select-all','terp-locked','terp-mail-forward',
+'terp-mail-message-new','terp-mail-replied','terp-rating-rated','terp-stage','terp-stock_format-scientific',
+'terp-dolar_ok!','terp-idea','terp-stock_format-default','terp-mail-','terp-mail_delete'
 ])
 
 def extract_zip_file(zip_file, outdirectory):
@@ -1149,6 +1159,11 @@ def extract_zip_file(zip_file, outdirectory):
     zf.close()
 
 def detect_ip_addr():
+    """Try a very crude method to figure out a valid external
+       IP or hostname for the current machine. Don't rely on this
+       for binding to an interface, but it could be used as basis
+       for constructing a remote URL to the server.
+    """
     def _detect_ip_addr():
         from array import array
         import socket
@@ -1296,6 +1311,23 @@ if __name__ == '__main__':
     import doctest
     doctest.testmod()
 
+class upload_data_thread(threading.Thread):
+    def __init__(self, email, data, type):
+        self.args = [('email',email),('type',type),('data',data)]
+        super(upload_data_thread,self).__init__()
+    def run(self):
+        try:
+            import urllib
+            args = urllib.urlencode(self.args)
+            fp = urllib.urlopen('http://www.openerp.com/scripts/survey.php', args)
+            fp.read()
+            fp.close()
+        except:
+            pass
 
+def upload_data(email, data, type='SURVEY'):
+    a = upload_data_thread(email, data, type)
+    a.start()
+    return True
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: