[MERGE]Working webdav
bzr revid: dle@openerp.com-20121217141800-v76f4lt4yfur2n84
This commit is contained in:
@@ -20,13 +20,9 @@
|
||||
##############################################################################
|
||||
import logging
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
import webdav
|
||||
import webdav_server
|
||||
import document_webdav
|
||||
|
||||
try:
|
||||
import webdav
|
||||
import webdav_server
|
||||
import document_webdav
|
||||
except ImportError:
|
||||
_logger.info('document_webdav disabled please install PyWebDAV from http://code.google.com/p/pywebdav/downloads/detail?name=PyWebDAV-0.9.4.tar.gz&can=2&q=/')
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
@@ -24,16 +24,24 @@ import sql_db
|
||||
import os
|
||||
import time
|
||||
import errno
|
||||
import re
|
||||
|
||||
import openerp
|
||||
import netsvc
|
||||
import urlparse
|
||||
try:
|
||||
from pywebdav.lib.constants import COLLECTION # , OBJECT
|
||||
from pywebdav.lib.errors import DAV_Error, DAV_Forbidden, DAV_NotFound
|
||||
from pywebdav.lib.iface import dav_interface
|
||||
from pywebdav.lib.davcmd import copyone, copytree, moveone, movetree, delone, deltree
|
||||
except ImportError:
|
||||
from DAV.constants import COLLECTION #, OBJECT
|
||||
from DAV.errors import DAV_Error, DAV_Forbidden, DAV_NotFound
|
||||
from DAV.iface import dav_interface
|
||||
from DAV.davcmd import copyone, copytree, moveone, movetree, delone, deltree
|
||||
|
||||
from DAV.constants import COLLECTION #, OBJECT
|
||||
from DAV.errors import DAV_Error, DAV_Forbidden, DAV_NotFound
|
||||
from DAV.iface import dav_interface
|
||||
import urllib
|
||||
|
||||
from DAV.davcmd import copyone, copytree, moveone, movetree, delone, deltree
|
||||
from cache import memoize
|
||||
from tools import misc
|
||||
|
||||
@@ -355,7 +363,8 @@ class openerp_dav_handler(dav_interface):
|
||||
return self.parent.get_baseuri(self) + '/'.join(ajoin)
|
||||
|
||||
@memoize(4)
|
||||
def db_list(self):
|
||||
def _all_db_list(self):
|
||||
"""return all databases who have module document_webdav installed"""
|
||||
s = netsvc.ExportService.getService('db')
|
||||
result = s.exp_list()
|
||||
self.db_name_list=[]
|
||||
@@ -364,7 +373,7 @@ class openerp_dav_handler(dav_interface):
|
||||
try:
|
||||
db = sql_db.db_connect(db_name)
|
||||
cr = db.cursor()
|
||||
cr.execute("SELECT id FROM ir_module_module WHERE name = 'document' AND state='installed' ")
|
||||
cr.execute("SELECT id FROM ir_module_module WHERE name = 'document_webdav' AND state='installed' ")
|
||||
res=cr.fetchone()
|
||||
if res and len(res):
|
||||
self.db_name_list.append(db_name)
|
||||
@@ -375,6 +384,15 @@ class openerp_dav_handler(dav_interface):
|
||||
cr.close()
|
||||
return self.db_name_list
|
||||
|
||||
def db_list(self, uri):
|
||||
# import pudb;pudb.set_trace()
|
||||
u = urlparse.urlsplit(uri)
|
||||
h = u.hostname
|
||||
d = h.split('.')[0]
|
||||
r = openerp.tools.config['dbfilter'].replace('%h', h).replace('%d',d)
|
||||
dbs = [i for i in self._all_db_list() if re.match(r, i)]
|
||||
return dbs
|
||||
|
||||
def get_childs(self,uri, filters=None):
|
||||
""" return the child objects as self.baseuris for the given URI """
|
||||
self.parent.log_message('get children: %s' % uri)
|
||||
@@ -382,7 +400,7 @@ class openerp_dav_handler(dav_interface):
|
||||
|
||||
if not dbname:
|
||||
if cr: cr.close()
|
||||
res = map(lambda x: self.urijoin(x), self.db_list())
|
||||
res = map(lambda x: self.urijoin(x), self.db_list(uri))
|
||||
return res
|
||||
result = []
|
||||
node = self.uri2object(cr, uid, pool, uri2[:])
|
||||
|
||||
@@ -20,6 +20,9 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import logging
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
import xml.dom.minidom
|
||||
domimpl = xml.dom.minidom.getDOMImplementation()
|
||||
from xml.dom.minicompat import StringTypes
|
||||
@@ -29,10 +32,14 @@ import urllib
|
||||
from osv import osv
|
||||
from tools.translate import _
|
||||
|
||||
from DAV import utils
|
||||
from DAV.propfind import PROPFIND
|
||||
from DAV.report import REPORT
|
||||
|
||||
try:
|
||||
from pywebdav.lib import utils
|
||||
from pywebdav.lib.propfind import PROPFIND
|
||||
from pywebdav.lib.report import REPORT
|
||||
except ImportError:
|
||||
from DAV import utils
|
||||
from DAV.propfind import PROPFIND
|
||||
from DAV.report import REPORT
|
||||
|
||||
import tools
|
||||
|
||||
|
||||
@@ -38,7 +38,16 @@ import logging
|
||||
import netsvc
|
||||
from dav_fs import openerp_dav_handler
|
||||
from tools.config import config
|
||||
from DAV.WebDAVServer import DAVRequestHandler
|
||||
try:
|
||||
from pywebdav.lib.WebDAVServer import DAVRequestHandler
|
||||
from pywebdav.lib.utils import IfParser, TagList
|
||||
from pywebdav.lib.errors import DAV_Error, DAV_Forbidden, DAV_NotFound
|
||||
from pywebdav.lib.propfind import PROPFIND
|
||||
except ImportError:
|
||||
from DAV.WebDAVServer import DAVRequestHandler
|
||||
from DAV.utils import IfParser, TagList
|
||||
from DAV.errors import DAV_Error, DAV_Forbidden, DAV_NotFound
|
||||
from DAV.propfind import PROPFIND
|
||||
from service import http_server
|
||||
from service.websrv_lib import FixSendError, HttpOptions
|
||||
from BaseHTTPServer import BaseHTTPRequestHandler
|
||||
@@ -48,9 +57,6 @@ import re
|
||||
import time
|
||||
from string import atoi
|
||||
import addons
|
||||
from DAV.utils import IfParser, TagList
|
||||
from DAV.errors import DAV_Error, DAV_Forbidden, DAV_NotFound
|
||||
from DAV.propfind import PROPFIND
|
||||
# from DAV.constants import DAV_VERSION_1, DAV_VERSION_2
|
||||
from xml.dom import minidom
|
||||
from redirect import RedirectHTTPHandler
|
||||
@@ -71,7 +77,7 @@ def OpenDAVConfig(**kw):
|
||||
return Config()
|
||||
|
||||
|
||||
class DAVHandler(HttpOptions, FixSendError, DAVRequestHandler):
|
||||
class DAVHandler(DAVRequestHandler, HttpOptions, FixSendError):
|
||||
verbose = False
|
||||
|
||||
protocol_version = 'HTTP/1.1'
|
||||
@@ -88,7 +94,20 @@ class DAVHandler(HttpOptions, FixSendError, DAVRequestHandler):
|
||||
self._logger.debug(message)
|
||||
|
||||
def handle(self):
|
||||
self._init_buffer()
|
||||
"""Handle multiple requests if necessary."""
|
||||
self.close_connection = 1
|
||||
try:
|
||||
self.handle_one_request()
|
||||
while not self.close_connection:
|
||||
self.handle_one_request()
|
||||
except Exception as e:
|
||||
try:
|
||||
self.log_error("Request timed out: %r \n Trying old version of HTTPServer", e)
|
||||
self._init_buffer()
|
||||
except Exception as e:
|
||||
#a read or a write timed out. Discard this connection
|
||||
self.log_error("Not working neither, closing connection\n %r", e)
|
||||
self.close_connection = 1
|
||||
|
||||
def finish(self):
|
||||
pass
|
||||
@@ -99,6 +118,7 @@ class DAVHandler(HttpOptions, FixSendError, DAVRequestHandler):
|
||||
return res
|
||||
|
||||
def setup(self):
|
||||
DAVRequestHandler.setup(self)
|
||||
self.davpath = '/'+config.get_misc('webdav','vdir','webdav')
|
||||
addr, port = self.server.server_name, self.server.server_port
|
||||
server_proto = getattr(self.server,'proto', 'http').lower()
|
||||
|
||||
Reference in New Issue
Block a user