Miscelleanous tools used by OpenERP.
"""
-import os, time, sys
import inspect
-from datetime import datetime
-
-from config import config
-
-import zipfile
-import release
-import socket
import logging
+import os
import re
-from itertools import islice
-import threading
-from which import which
-
import smtplib
+import socket
+import sys
+import threading
+import time
+import zipfile
+from datetime import datetime
from email.MIMEText import MIMEText
from email.MIMEBase import MIMEBase
from email.MIMEMultipart import MIMEMultipart
from email.Utils import formatdate, COMMASPACE
from email.Utils import formatdate, COMMASPACE
from email import Encoders
-import netsvc
-
+from itertools import islice, izip
+from which import which
if sys.version_info[:2] < (2, 4):
from threadinglocal import local
else:
from threading import local
-from itertools import izip
+import netsvc
+from config import config
_logger = logging.getLogger('tools')
subdir2 = (subdir2 != 'addons' or None) and subdir2
for adp in adps:
- try:
- if subdir2:
- fn = os.path.join(adp, subdir2, name)
- else:
- fn = os.path.join(adp, name)
- fn = os.path.normpath(fn)
- fo = file_open(fn, mode=mode, subdir=None, pathinfo=pathinfo)
- if pathinfo:
- return fo, fn
- return fo
- except IOError, e:
- pass
+ try:
+ if subdir2:
+ fn = os.path.join(adp, subdir2, name)
+ else:
+ fn = os.path.join(adp, name)
+ fn = os.path.normpath(fn)
+ fo = file_open(fn, mode=mode, subdir=None, pathinfo=pathinfo)
+ if pathinfo:
+ return fo, fn
+ return fo
+ except IOError:
+ pass
if subdir:
name = os.path.join(rtp, subdir, name)
if pathinfo:
return fo, name
return fo
- except:
+ except Exception:
name2 = os.path.normpath(os.path.join(head + '.zip', zipname))
pass
for i in (name2, name):
html = ustr(html)
- from lxml.etree import Element, tostring
+ from lxml.etree import tostring
try:
from lxml.html.soupparser import fromstring
kwargs = {}
url_index = []
i = 0
for link in tree.findall('.//a'):
- title = link.text
url = link.get('href')
if url:
i += 1
s.quit()
if debug:
smtplib.stderr = oldstderr
- except:
+ except Exception:
# ignored, just a consequence of the previous exception
pass
- except Exception, e:
+ except Exception:
_logger.error('could not deliver email', exc_info=True)
return False
"address or having configured one")
if not email_from: email_from = config.get('email_from', False)
+ email_from = ustr(email_from).encode('utf-8')
if not email_cc: email_cc = []
if not email_bcc: email_bcc = []
if not body: body = u''
- try: email_body = body.encode('utf-8')
- except (UnicodeEncodeError, UnicodeDecodeError):
- email_body = body
- try:
- email_text = MIMEText(email_body.encode('utf8') or '',_subtype=subtype,_charset='utf-8')
- except:
- email_text = MIMEText(email_body or '',_subtype=subtype,_charset='utf-8')
+ email_body = ustr(body).encode('utf-8')
+ email_text = MIMEText(email_body or '',_subtype=subtype,_charset='utf-8')
if attach: msg = MIMEMultipart()
else: msg = email_text
url = "http://api.urlsms.com/SendSMS.aspx"
#url = "http://196.7.150.220/http/sendmsg"
params = urllib.urlencode({'UserID': user, 'Password': password, 'SenderID': api_id, 'MsgText': text, 'RecipientMobileNo':to})
- f = urllib.urlopen(url+"?"+params)
+ urllib.urlopen(url+"?"+params)
# FIXME: Use the logger if there is an error
return True
return "\n".join((ustr(a) for a in e.args))
try:
return ustr(e)
- except:
+ except Exception:
return u"Unknown message"
@wraps(f)
def wrapper(*args, **kwargs):
- import netsvc
from pprint import pformat
vector = ['Call -> function: %r' % f]
--log-level=debug
"""
- import netsvc
from inspect import stack
- import re
from pprint import pformat
st = stack()[1]
param = re.split("debug *\((.+)\)", st[4][0].strip())[1].strip()
])
def extract_zip_file(zip_file, outdirectory):
- import zipfile
- import os
-
zf = zipfile.ZipFile(zip_file, 'r')
out = outdirectory
for path in zf.namelist():
"""
def _detect_ip_addr():
from array import array
- import socket
from struct import pack, unpack
try:
try:
ip_addr = _detect_ip_addr()
- except:
+ except Exception:
ip_addr = 'localhost'
return ip_addr
Defaults to UTC if no working timezone can be found.
@return: the timezone identifier as expected by pytz.timezone.
"""
- import time
- import netsvc
try:
import pytz
- except:
+ except Exception:
netsvc.Logger().notifyChannel("detect_server_timezone", netsvc.LOG_WARNING,
"Python pytz module is not available. Timezone will be set to UTC by default.")
return 'UTC'
try:
f = open("/etc/timezone")
tz_value = f.read(128).strip()
- except:
+ except Exception:
pass
finally:
f.close()
fp = urllib.urlopen('http://www.openerp.com/scripts/survey.php', args)
fp.read()
fp.close()
- except:
+ except Exception:
pass
def upload_data(email, data, type='SURVEY'):