diff --git a/git-annex-remote-owncloud b/git-annex-remote-owncloud index 33cc318..519edb9 100755 --- a/git-annex-remote-owncloud +++ b/git-annex-remote-owncloud @@ -28,9 +28,9 @@ if dbglevel: sys.path.append(pwd + '/lib') -import CommonFunctions as common +import owncloudannex.CommonFunctions as common -import davlib +import owncloudannex.davlib as davlib client = False encAuth = False cache = {} @@ -38,7 +38,7 @@ cache = {} def login(user, pword): common.log("") global client, encAuth - + base = conf["url"] base = base[base.find("//") + 2: base.find("/", 8)] encAuth = {"Authorization": "Basic %s" % ( base64.encodestring(user+":"+pword).strip() ) } @@ -96,7 +96,7 @@ class BufferReader(io.BytesIO): def postFile(subject, filename, folder): common.log("%s to %s - %s" % ( repr(filename), folder[0], subject)) - + tmp_file = findInFolder(subject, folder) if tmp_file: common.log("File already exists: " + repr(tmp_file)) @@ -142,7 +142,7 @@ def findInFolder(subject, folder="/"): common.log("Returning from cache") return cache[tmp_path] else: - common.log("No match in cache") + common.log("No match in cache") try: bla = client.propfind(tpath, depth=1, extra_hdrs=encAuth) @@ -162,14 +162,14 @@ def findInFolder(subject, folder="/"): tmp_file = urllib.unquote_plus(tmp_file) tmp_file = tmp_file.replace(host, "") common.log("folder1: " + tmp_file + " - " + tmp_path, 3) - if tmp_file[len(tmp_file) - 1] == "/": - tmp_file = tmp_file[:len(tmp_file) - 1] + if tmp_file[len(tmp_file) - 1] == "/": + tmp_file = tmp_file[:len(tmp_file) - 1] cache[tmp_file] = tmp_file.replace(base, "/") common.log("Updated cache: " + repr(cache), 3) for tmp_file in cache.keys(): common.log("folder: " + tmp_file + " - " + tmp_path, 3) - if tmp_file == tmp_path: + if tmp_file == tmp_path: common.log("Done: " + repr(cache[tmp_file])) return cache[tmp_file] @@ -203,7 +203,7 @@ def getFile(subject, filename, folder): return response._read_chunked(amt) if amt is None: - # unbounded read + # unbounded read if response.length is None: s = response.fp.read() common.log("READING fp", 2) @@ -221,24 +221,24 @@ def getFile(subject, filename, folder): s += response._safe_read(tsize) common.progress(response.length, len(s)) response.length = 0 - response.close() # we read everything + response.close() # we read everything return s if response.length is not None: if amt > response.length: - # clip the read to the "end of response" + # clip the read to the "end of response" amt = response.length - # we do not use _safe_read() here because this may be a .will_close - # connection, and the user is reading more bytes than will be provided - # (for example, reading in 1k chunks) + # we do not use _safe_read() here because this may be a .will_close + # connection, and the user is reading more bytes than will be provided + # (for example, reading in 1k chunks) s = response.fp.read(amt) if response.length is not None: response.length -= len(s) if not response.length: response.close() return s - + tmp_file = findInFolder(subject, folder) if tmp_file: base = conf["url"][conf["url"].find("/", 8):] diff --git a/lib/qp_xml.py b/lib/qp_xml.py deleted file mode 100644 index 2107a67..0000000 --- a/lib/qp_xml.py +++ /dev/null @@ -1,240 +0,0 @@ -# pylint: disable-msg=W0311,E1101,E1103,W0201,C0103,W0622,W0402,W0706,R0911,W0613,W0612,R0912,W0141,C0111,C0121 - -# qp_xml: Quick Parsing for XML -# -# Written by Greg Stein. Public Domain. -# No Copyright, no Rights Reserved, and no Warranties. -# -# This module is maintained by Greg and is available as part of the XML-SIG -# distribution. This module and its changelog can be fetched at: -# http://www.lyra.org/cgi-bin/viewcvs.cgi/xml/xml/utils/qp_xml.py -# -# Additional information can be found on Greg's Python page at: -# http://www.lyra.org/greg/python/ -# -# This module was added to the XML-SIG distribution on February 14, 2000. -# As part of that distribution, it falls under the XML distribution license. -# - -import string -from xml.parsers import expat - - -error = __name__ + '.error' - - -# -# The parsing class. Instantiate and pass a string/file to .parse() -# -class Parser: - def __init__(self): - self.reset() - - def reset(self): - self.root = None - self.cur_elem = None - - def find_prefix(self, prefix): - elem = self.cur_elem - while elem: - if elem.ns_scope.has_key(prefix): - return elem.ns_scope[prefix] - elem = elem.parent - - if prefix == '': - return '' # empty URL for "no namespace" - - return None - - def process_prefix(self, name, use_default): - idx = string.find(name, ':') - if idx == -1: - if use_default: - return self.find_prefix(''), name - return '', name # no namespace - - if string.lower(name[:3]) == 'xml': - return '', name # name is reserved by XML. don't break out a NS. - - ns = self.find_prefix(name[:idx]) - if ns is None: - raise error, 'namespace prefix ("%s") not found' % name[:idx] - - return ns, name[idx+1:] - - def start(self, name, attrs): - elem = _element(name=name, lang=None, parent=None, - children=[], ns_scope={}, attrs={}, - first_cdata='', following_cdata='') - - if self.cur_elem: - elem.parent = self.cur_elem - elem.parent.children.append(elem) - self.cur_elem = elem - else: - self.cur_elem = self.root = elem - - work_attrs = [ ] - - # scan for namespace declarations (and xml:lang while we're at it) - for name, value in attrs.items(): - if name == 'xmlns': - elem.ns_scope[''] = value - elif name[:6] == 'xmlns:': - elem.ns_scope[name[6:]] = value - elif name == 'xml:lang': - elem.lang = value - else: - work_attrs.append((name, value)) - - # inherit xml:lang from parent - if elem.lang is None and elem.parent: - elem.lang = elem.parent.lang - - # process prefix of the element name - elem.ns, elem.name = self.process_prefix(elem.name, 1) - - # process attributes' namespace prefixes - for name, value in work_attrs: - elem.attrs[self.process_prefix(name, 0)] = value - - def end(self, name): - parent = self.cur_elem.parent - - del self.cur_elem.ns_scope - del self.cur_elem.parent - - self.cur_elem = parent - - def cdata(self, data): - elem = self.cur_elem - if elem.children: - last = elem.children[-1] - last.following_cdata = last.following_cdata + data - else: - elem.first_cdata = elem.first_cdata + data - - def parse(self, input): - self.reset() - - p = expat.ParserCreate() - p.StartElementHandler = self.start - p.EndElementHandler = self.end - p.CharacterDataHandler = self.cdata - - try: - if type(input) == type(''): - p.Parse(input, 1) - else: - while 1: - s = input.read(_BLOCKSIZE) - if not s: - p.Parse('', 1) - break - - p.Parse(s, 0) - - finally: - if self.root: - _clean_tree(self.root) - - return self.root - - -# -# handy function for dumping a tree that is returned by Parser -# -def dump(f, root): - f.write('\n') - namespaces = _collect_ns(root) - _dump_recurse(f, root, namespaces, dump_ns=1) - f.write('\n') - - -# -# This function returns the element's CDATA. Note: this is not recursive -- -# it only returns the CDATA immediately within the element, excluding the -# CDATA in child elements. -# -def textof(elem): - return elem.textof() - - -######################################################################### -# -# private stuff for qp_xml -# - -_BLOCKSIZE = 16384 # chunk size for parsing input - -class _element: - def __init__(self, **kw): - self.__dict__.update(kw) - - def textof(self): - '''Return the CDATA of this element. - - Note: this is not recursive -- it only returns the CDATA immediately - within the element, excluding the CDATA in child elements. - ''' - s = self.first_cdata - for child in self.children: - s = s + child.following_cdata - return s - - def find(self, name, ns=''): - for elem in self.children: - if elem.name == name and elem.ns == ns: - return elem - return None - - -def _clean_tree(elem): - elem.parent = None - del elem.parent - map(_clean_tree, elem.children) - - -def _collect_recurse(elem, dict): - dict[elem.ns] = None - for ns, name in elem.attrs.keys(): - dict[ns] = None - for child in elem.children: - _collect_recurse(child, dict) - -def _collect_ns(elem): - "Collect all namespaces into a NAMESPACE -> PREFIX mapping." - d = { '' : None } - _collect_recurse(elem, d) - del d[''] # make sure we don't pick up no-namespace entries - keys = d.keys() - for i in range(len(keys)): - d[keys[i]] = i - return d - -def _dump_recurse(f, elem, namespaces, lang=None, dump_ns=0): - if elem.ns: - f.write('' + elem.first_cdata) - for child in elem.children: - _dump_recurse(f, child, namespaces, elem.lang) - f.write(child.following_cdata) - if elem.ns: - f.write('' % (namespaces[elem.ns], elem.name)) - else: - f.write('' % elem.name) - else: - f.write('/>') diff --git a/lib/CommonFunctions.py b/owncloudannex/CommonFunctions.py similarity index 99% rename from lib/CommonFunctions.py rename to owncloudannex/CommonFunctions.py index 050b93e..a148916 100644 --- a/lib/CommonFunctions.py +++ b/owncloudannex/CommonFunctions.py @@ -67,7 +67,7 @@ def read(self, n=-1): if self._callback: try: self._callback(*self._cb_args, **self._cb_kwargs) - except: # catches exception from the callback + except: # catches exception from the callback raise CancelledError('The upload was cancelled.') return chunk @@ -504,7 +504,7 @@ def updateWanted(size, filetypes): expr += "(" org_filetypes = re.compile("include=(.*?) ").findall(old_wanted) for t in filetypes: - expr += "include=*." + t + " or " + expr += "include=*." + t + " or " expr = expr.strip() if expr.rfind(" ") > -1: expr = expr[:expr.rfind(" ")] diff --git a/owncloudannex/__init__.py b/owncloudannex/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/lib/davlib.py b/owncloudannex/davlib.py similarity index 97% rename from lib/davlib.py rename to owncloudannex/davlib.py index b43c01d..999963e 100644 --- a/lib/davlib.py +++ b/owncloudannex/davlib.py @@ -35,7 +35,7 @@ def __init__(self, *args, **kw): self.default_port = 443 else: self.default_port = 80 - + apply(httplib.HTTPSConnection.__init__, (self,) + args, kw) def connect(self): @@ -332,4 +332,3 @@ def get_lock(self, url, owner='', timeout=None, depth=None): response = self.lock(url, owner, timeout, depth) response.parse_lock_response() return response.locktoken - diff --git a/owncloudannex/qp_xml.py b/owncloudannex/qp_xml.py new file mode 100644 index 0000000..5458ee2 --- /dev/null +++ b/owncloudannex/qp_xml.py @@ -0,0 +1,240 @@ +# pylint: disable-msg=W0311,E1101,E1103,W0201,C0103,W0622,W0402,W0706,R0911,W0613,W0612,R0912,W0141,C0111,C0121 + +# qp_xml: Quick Parsing for XML +# +# Written by Greg Stein. Public Domain. +# No Copyright, no Rights Reserved, and no Warranties. +# +# This module is maintained by Greg and is available as part of the XML-SIG +# distribution. This module and its changelog can be fetched at: +# http://www.lyra.org/cgi-bin/viewcvs.cgi/xml/xml/utils/qp_xml.py +# +# Additional information can be found on Greg's Python page at: +# http://www.lyra.org/greg/python/ +# +# This module was added to the XML-SIG distribution on February 14, 2000. +# As part of that distribution, it falls under the XML distribution license. +# + +import string +from xml.parsers import expat + + +error = __name__ + '.error' + + +# +# The parsing class. Instantiate and pass a string/file to .parse() +# +class Parser: + def __init__(self): + self.reset() + + def reset(self): + self.root = None + self.cur_elem = None + + def find_prefix(self, prefix): + elem = self.cur_elem + while elem: + if elem.ns_scope.has_key(prefix): + return elem.ns_scope[prefix] + elem = elem.parent + + if prefix == '': + return '' # empty URL for "no namespace" + + return None + + def process_prefix(self, name, use_default): + idx = string.find(name, ':') + if idx == -1: + if use_default: + return self.find_prefix(''), name + return '', name # no namespace + + if string.lower(name[:3]) == 'xml': + return '', name # name is reserved by XML. don't break out a NS. + + ns = self.find_prefix(name[:idx]) + if ns is None: + raise error, 'namespace prefix ("%s") not found' % name[:idx] + + return ns, name[idx+1:] + + def start(self, name, attrs): + elem = _element(name=name, lang=None, parent=None, + children=[], ns_scope={}, attrs={}, + first_cdata='', following_cdata='') + + if self.cur_elem: + elem.parent = self.cur_elem + elem.parent.children.append(elem) + self.cur_elem = elem + else: + self.cur_elem = self.root = elem + + work_attrs = [ ] + + # scan for namespace declarations (and xml:lang while we're at it) + for name, value in attrs.items(): + if name == 'xmlns': + elem.ns_scope[''] = value + elif name[:6] == 'xmlns:': + elem.ns_scope[name[6:]] = value + elif name == 'xml:lang': + elem.lang = value + else: + work_attrs.append((name, value)) + + # inherit xml:lang from parent + if elem.lang is None and elem.parent: + elem.lang = elem.parent.lang + + # process prefix of the element name + elem.ns, elem.name = self.process_prefix(elem.name, 1) + + # process attributes' namespace prefixes + for name, value in work_attrs: + elem.attrs[self.process_prefix(name, 0)] = value + + def end(self, name): + parent = self.cur_elem.parent + + del self.cur_elem.ns_scope + del self.cur_elem.parent + + self.cur_elem = parent + + def cdata(self, data): + elem = self.cur_elem + if elem.children: + last = elem.children[-1] + last.following_cdata = last.following_cdata + data + else: + elem.first_cdata = elem.first_cdata + data + + def parse(self, input): + self.reset() + + p = expat.ParserCreate() + p.StartElementHandler = self.start + p.EndElementHandler = self.end + p.CharacterDataHandler = self.cdata + + try: + if type(input) == type(''): + p.Parse(input, 1) + else: + while 1: + s = input.read(_BLOCKSIZE) + if not s: + p.Parse('', 1) + break + + p.Parse(s, 0) + + finally: + if self.root: + _clean_tree(self.root) + + return self.root + + +# +# handy function for dumping a tree that is returned by Parser +# +def dump(f, root): + f.write('\n') + namespaces = _collect_ns(root) + _dump_recurse(f, root, namespaces, dump_ns=1) + f.write('\n') + + +# +# This function returns the element's CDATA. Note: this is not recursive -- +# it only returns the CDATA immediately within the element, excluding the +# CDATA in child elements. +# +def textof(elem): + return elem.textof() + + +######################################################################### +# +# private stuff for qp_xml +# + +_BLOCKSIZE = 16384 # chunk size for parsing input + +class _element: + def __init__(self, **kw): + self.__dict__.update(kw) + + def textof(self): + '''Return the CDATA of this element. + + Note: this is not recursive -- it only returns the CDATA immediately + within the element, excluding the CDATA in child elements. + ''' + s = self.first_cdata + for child in self.children: + s = s + child.following_cdata + return s + + def find(self, name, ns=''): + for elem in self.children: + if elem.name == name and elem.ns == ns: + return elem + return None + + +def _clean_tree(elem): + elem.parent = None + del elem.parent + map(_clean_tree, elem.children) + + +def _collect_recurse(elem, dict): + dict[elem.ns] = None + for ns, name in elem.attrs.keys(): + dict[ns] = None + for child in elem.children: + _collect_recurse(child, dict) + +def _collect_ns(elem): + "Collect all namespaces into a NAMESPACE -> PREFIX mapping." + d = { '' : None } + _collect_recurse(elem, d) + del d[''] # make sure we don't pick up no-namespace entries + keys = d.keys() + for i in range(len(keys)): + d[keys[i]] = i + return d + +def _dump_recurse(f, elem, namespaces, lang=None, dump_ns=0): + if elem.ns: + f.write('' + elem.first_cdata) + for child in elem.children: + _dump_recurse(f, child, namespaces, elem.lang) + f.write(child.following_cdata) + if elem.ns: + f.write('' % (namespaces[elem.ns], elem.name)) + else: + f.write('' % elem.name) + else: + f.write('/>') diff --git a/lib/uuid_.py b/owncloudannex/uuid_.py similarity index 100% rename from lib/uuid_.py rename to owncloudannex/uuid_.py diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..1c18f25 --- /dev/null +++ b/setup.py @@ -0,0 +1,13 @@ +from distutils.core import setup + +setup( + name='owncloudannex', + version='', + packages=['owncloudannex'], + url='', + license='', + author='dopsi', + author_email='', + description='', + scripts=['git-annex-remote-owncloud'] +)