From e6e4527da5620e7d9469f54ba5a2292e9c988e04 Mon Sep 17 00:00:00 2001 From: "Jay (Open ERP)" Date: Mon, 13 Apr 2009 11:02:59 +0530 Subject: [PATCH 1/2] Syntactical correction(ref:pso) bzr revid: jvo@tinyerp.com-20090413053259-yi30n8al3uwt34z0 --- addons/account/account.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/account/account.py b/addons/account/account.py index 12ba1e5d7c7..a55428c8612 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -1773,7 +1773,7 @@ class account_account_template(osv.osv): "can have children accounts for multi-company consolidations, payable/receivable are for "\ "partners accounts (for debit/credit computations), closed for deprecated accounts."), 'user_type': fields.many2one('account.account.type', 'Account Type', required=True, - "These types are defined according to your country. The type contain more information "\ + help="These types are defined according to your country. The type contain more information "\ "about the account and it's specificities."), 'reconcile': fields.boolean('Allow Reconciliation', help="Check this option if you want the user to reconcile entries in this account."), 'shortcut': fields.char('Shortcut', size=12), From 7767525f1edc8c5e7dd32678ffce9ed2d19310a7 Mon Sep 17 00:00:00 2001 From: "Harry (Open ERP)" Date: Mon, 13 Apr 2009 11:58:27 +0530 Subject: [PATCH 2/2] [DMS]fixed_bugs:#330263,347877,348398,358360,324823 bzr revid: hmo@tinyerp.com-20090413062827-c53nlhf8zakplhw5 --- addons/document/document.py | 39 +++++----- addons/document/ftpserver/__init__.py | 3 +- addons/document/ftpserver/abstracted_fs.py | 83 +++++++++++++++++----- 3 files changed, 88 insertions(+), 37 deletions(-) diff --git a/addons/document/document.py b/addons/document/document.py index 0cde94a12f7..8c69a428100 100644 --- a/addons/document/document.py +++ b/addons/document/document.py @@ -136,7 +136,7 @@ class node_class(object): res = pool.get('document.directory').browse(self.cr, self.uid, ids,self.context) return res - def _child_get(self, nodename=False): + def _child_get(self, nodename=False): if self.type not in ('collection','database'): return [] res = self.directory_list_for_child(nodename) @@ -153,19 +153,8 @@ class node_class(object): result +=map(lambda x: node_class(self.cr, self.uid, self.path+'/'+x.name, x, False, type='file', root=self.root), res) if self.type=='collection' and self.object.type=="ressource": where = self.object.domain and eval(self.object.domain, {'active_id':self.root}) or [] - pool = pooler.get_pool(self.cr.dbname) + pool = pooler.get_pool(self.cr.dbname) obj = pool.get(self.object.ressource_type_id.model) - - if self.object.ressource_tree: - if obj._parent_name in obj.fields_get(self.cr,self.uid): - where.append((obj._parent_name,'=',self.object2 and self.object2.id or False)) - else : - if self.object2: - return result - else: - if self.object2: - return result - name_for = obj._name.split('.')[-1] if nodename and nodename.find(name_for) == 0 : id = int(nodename.replace(name_for,'')) @@ -177,6 +166,22 @@ class node_class(object): if nodename.find(INVALID_CHARS[invalid]) : nodename=nodename.replace(INVALID_CHARS[invalid],invalid) where.append(('name','like',nodename)) + + if self.object.ressource_tree: + if obj._parent_name in obj.fields_get(self.cr,self.uid): + where.append((obj._parent_name,'=',self.object2 and self.object2.id or False)) + ids = obj.search(self.cr, self.uid, where, self.context) + res = obj.browse(self.cr, self.uid, ids,self.context) + result+= map(lambda x: node_class(self.cr, self.uid, self.path+'/'+x.name.replace('/','__'), self.object, x, root=x.id), res) + return result + else : + if self.object2: + return result + else: + if self.object2: + return result + + ids = obj.search(self.cr, self.uid, where, self.context) res = obj.browse(self.cr, self.uid, ids,self.context) for r in res: @@ -184,10 +189,10 @@ class node_class(object): r.name = name_for+'%d'%r.id for invalid in INVALID_CHARS: if r.name.find(invalid) : - r.name=r.name.replace(invalid,INVALID_CHARS[invalid]) - result2 = map(lambda x: node_class(self.cr, self.uid, self.path+'/'+x.name.replace('/','__'), self.object, x, root=r.id), res) + r.name=r.name.replace(invalid,INVALID_CHARS[invalid]) + result2 = map(lambda x: node_class(self.cr, self.uid, self.path+'/'+x.name.replace('/','__'), self.object, x, root=x.id), res) if result2: - result = result2 + result = result2 return result def children(self): @@ -772,5 +777,3 @@ class document_configuration_wizard(osv.osv_memory): 'target':'new', } document_configuration_wizard() - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/document/ftpserver/__init__.py b/addons/document/ftpserver/__init__.py index 35d1107ad81..b18cdd965dd 100644 --- a/addons/document/ftpserver/__init__.py +++ b/addons/document/ftpserver/__init__.py @@ -27,7 +27,7 @@ import abstracted_fs import netsvc from tools import config -PORT = config.get('ftp_server_port', 8021) +PORT = int(config.get('ftp_server_port', 8021)) HOST = '' class ftp_server(threading.Thread): @@ -49,7 +49,6 @@ class ftp_server(threading.Thread): address = (HOST, PORT) ftpd = ftpserver.FTPServer(address, ftpserver.FTPHandler) ftpd.serve_forever() - ds = ftp_server() ds.start() diff --git a/addons/document/ftpserver/abstracted_fs.py b/addons/document/ftpserver/abstracted_fs.py index 155c68ae515..a8c8c09a146 100644 --- a/addons/document/ftpserver/abstracted_fs.py +++ b/addons/document/ftpserver/abstracted_fs.py @@ -1,5 +1,4 @@ # -*- encoding: utf-8 -*- - import os import time from tarfile import filemode @@ -17,6 +16,47 @@ from service import security def log(message): logger = netsvc.Logger() logger.notifyChannel('DMS', netsvc.LOG_ERROR, message) + + +def _get_month_name(month): + month=int(month) + if month==1:return 'Jan' + elif month==2:return 'Feb' + elif month==3:return 'Mar' + elif month==4:return 'Apr' + elif month==5:return 'May' + elif month==6:return 'Jun' + elif month==7:return 'Jul' + elif month==8:return 'Aug' + elif month==9:return 'Sep' + elif month==10:return 'Oct' + elif month==11:return 'Nov' + elif month==12:return 'Dec' + +def _to_unicode(s): + try: + return s.encode('ascii') + except UnicodeError: + try: + return s.decode('utf-8') + except UnicodeError: + try: + return s.decode('latin') + except UnicodeError: + return s + +def _to_decode(s): + try: + return s.encode('utf-8') + except UnicodeError: + try: + return s.encode('latin') + except UnicodeError: + try: + return s.decode('ascii') + except UnicodeError: + return s + class file_wrapper(StringIO.StringIO): def __init__(self, sstr='', ressource_id=False, dbname=None, uid=1, name=''): @@ -145,6 +185,7 @@ class abstracted_fs: path = self.ftpnorm(path_orig) if path and path=='/': return None + path=_to_unicode(path) path2 = filter(None,path.split('/'))[1:] (cr, uid, pool) = data res = pool.get('document.directory').get_object(cr, uid, path2[:]) @@ -153,8 +194,8 @@ class abstracted_fs: return res # Ok - def fs2ftp(self, node): - res = node and ('/' + node.cr.dbname + '/' + node.path.encode('ascii','replace').replace('?','_')) or '/' + def fs2ftp(self, node): + res = node and ('/' + node.cr.dbname + '/' + _to_decode(node.path)) or '/' return res # Ok @@ -174,6 +215,7 @@ class abstracted_fs: # Ok def create(self, node, objname, mode): + objname=_to_unicode(objname) cr = node.cr uid = node.uid pool = pooler.get_pool(cr.dbname) @@ -195,7 +237,7 @@ class abstracted_fs: cid=False where=[('name','=',objname)] - if object and (object.type in ('directory','ressource')) or object2: + if object and (object.type in ('directory')) or object2: where.append(('parent_id','=',object.id)) else: where.append(('parent_id','=',False)) @@ -214,7 +256,7 @@ class abstracted_fs: 'file_size': 0L, 'file_type': ext, } - if object and (object.type in ('directory','ressource')) or not object2: + if object and (object.type in ('directory')) or not object2: val['parent_id']= object and object.id or False partner = False if object2: @@ -310,6 +352,7 @@ class abstracted_fs: if not node: raise OSError(1, 'Operation not permited.') try: + basename=_to_unicode(basename) object2=node and node.object2 or False object=node and node.object or False cr = node.cr @@ -322,7 +365,7 @@ class abstracted_fs: 'ressource_parent_type_id': object and object.ressource_type_id.id or False, 'ressource_id': object2 and object2.id or False } - if (object and (object.type in ('directory'))) or not object2: + if (object and (object.type in ('directory'))) or not object2: val['parent_id'] = object and object.id or False # Check if it alreayd exists ! pool.get('document.directory').create(cr, uid, val) @@ -410,6 +453,7 @@ class abstracted_fs: * A directory: change the parent and reassign childs to ressource """ try: + dst_basename=_to_unicode(dst_basename) if src.type=='collection': if src.object._table_name <> 'document.directory': raise OSError(1, 'Operation not permited.') @@ -449,11 +493,12 @@ class abstracted_fs: ressource_type_id = pool.get('ir.model').search(cr,uid,[('model','=',dst_basedir.object2._name)])[0] ressource_id = dst_basedir.object2.id title = dst_basedir.object2.name - ressource_model = dst_basedir.object2._name + ressource_model = dst_basedir.object2._name if dst_basedir.object2._name=='res.partner': partner_id=dst_basedir.object2.id else: - partner_id= dst_basedir.object2.partner_id and dst_basedir.object2.partner_id.id or False + obj2=pool.get(dst_basedir.object2._name) + partner_id= obj2.fields_get(cr,uid,['partner_id']) and dst_basedir.object2.partner_id.id or False else: ressource_type_id = False ressource_id=False @@ -463,7 +508,7 @@ class abstracted_fs: pool.get('document.directory').write(cr, uid, result['directory'], { 'ressource_id': ressource_id, - 'ressource_parent_type_id': ressource_type_id + 'ressource_type_id': ressource_type_id }) val = { 'res_id': ressource_id, @@ -499,7 +544,8 @@ class abstracted_fs: if dst_basedir.object2._name=='res.partner': val['partner_id']=dst_basedir.object2.id else: - val['partner_id']= dst_basedir.object2.partner_id and dst_basedir.object2.partner_id.id or False + obj2=pool.get(dst_basedir.object2._name) + val['partner_id']= obj2.fields_get(cr,uid,['partner_id']) and dst_basedir.object2.partner_id.id or False elif src.object.res_id: # I had to do that because writing False to an integer writes 0 instead of NULL # change if one day we decide to improve osv/fields.py @@ -612,7 +658,7 @@ class abstracted_fs: def get_list_dir(self, path): """"Return an iterator object that yields a directory listing in a form suitable for LIST command. - """ + """ if self.isdir(path): listing = self.listdir(path) #listing.sort() @@ -647,7 +693,7 @@ class abstracted_fs: listing.sort() return self.format_list(basedir, listing) - # Ok + # Ok def format_list(self, basedir, listing, ignore_err=True): """Return an iterator object that yields the entries of given directory emulating the "/bin/ls -lA" UNIX command output. @@ -686,13 +732,15 @@ class abstracted_fs: # stat.st_mtime could fail (-1) if last mtime is too old # in which case we return the local time as last mtime try: - mtime = time.strftime("%b %d %H:%M", time.localtime(st.st_mtime)) + mname=_get_month_name(time.strftime("%m", time.localtime(st.st_mtime))) + mtime = mname+' '+time.strftime("%d %H:%M", time.localtime(st.st_mtime)) except ValueError: - mtime = time.strftime("%b %d %H:%M") - + mname=_get_month_name(time.strftime("%m")) + mtime = mname+' '+time.strftime("%d %H:%M") # formatting is matched with proftpd ls output + path=_to_decode(file.path) #file.path.encode('ascii','replace').replace('?','_') yield "%s %3s %-8s %-8s %8s %s %s\r\n" %(perms, nlinks, uname, gname, - size, mtime, file.path.encode('ascii','replace').replace('?','_').split('/')[-1]) + size, mtime, path.split('/')[-1]) # Ok def format_mlsx(self, basedir, listing, perms, facts, ignore_err=True): @@ -786,8 +834,9 @@ class abstracted_fs: # on Windows NTFS filesystems MTF records could be used). if 'unique' in facts: unique = "unique=%x%x;" %(st.st_dev, st.st_ino) - + basename=_to_decode(basename) yield "%s%s%s%s%s%s%s%s%s %s\r\n" %(type, size, perm, modify, create, mode, uid, gid, unique, basename) # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: +