Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Saller <bcsaller@objectrealms.net>2007-08-16 10:30:40 (GMT)
committer Benjamin Saller <bcsaller@objectrealms.net>2007-08-16 10:30:40 (GMT)
commit91c3eebfbe6aa586150d9405792f6e02fb34fa81 (patch)
treed06251e07807cf25b1413b65cbdfbad7f151b334
parent993b69294686830639299a62b844e2e9319b54b8 (diff)
basic tests passing
-rw-r--r--src/olpc/datastore/backingstore.py57
-rw-r--r--src/olpc/datastore/bin_copy.py5
-rw-r--r--src/olpc/datastore/hg_backingstore.py3
-rw-r--r--src/olpc/datastore/model.py19
-rw-r--r--src/olpc/datastore/xapianindex.py7
5 files changed, 30 insertions, 61 deletions
diff --git a/src/olpc/datastore/backingstore.py b/src/olpc/datastore/backingstore.py
index 8c93098..1a97133 100644
--- a/src/olpc/datastore/backingstore.py
+++ b/src/olpc/datastore/backingstore.py
@@ -15,7 +15,6 @@ from datetime import datetime
import gnomevfs
import os
import re
-import sha
import subprocess
import time
import threading
@@ -324,10 +323,9 @@ class FileBackingStore(BackingStore):
break
targetpath = "%s(%s)%s" % (targetpath, attempt, ext)
-
- if subprocess.call(['cp', path, targetpath]):
- raise OSError("unable to create working copy")
- return open(targetpath, 'rw')
+
+ bin_copy.bin_copy(path, targetpath)
+ return targetpath
def _mapContent(self, uid, fp, path, env=None):
"""map a content object and the file in the repository to a
@@ -345,17 +343,11 @@ class FileBackingStore(BackingStore):
targetfile = self._targetFile(uid, target, ext, env)
content.file = targetfile
- if self.options.get('verify', False):
- c = sha.sha()
- for line in targetfile:
- c.update(line)
- fp.seek(0)
- if c.hexdigest() != content.checksum:
- raise ValueError("Content for %s corrupt" % uid)
return content
def _writeContent(self, uid, filelike, replace=True, target=None):
content = None
+ if not filelike: return
if target: path = target
else:
path = self._translatePath(uid)
@@ -364,40 +356,12 @@ class FileBackingStore(BackingStore):
raise KeyError("objects with path:%s for uid:%s exists" %(
path, uid))
- verify = self.options.get('verify', False)
- c = None
- if verify:
- fp = open(path, 'w')
- filelike.seek(0)
- c = sha.sha()
- for line in filelike:
- if verify:c.update(line)
- fp.write(line)
- fp.close()
- else:
- bin_copy.bin_copy(filelike.name, path)
-## if verify:
-## if not content:
-## content = self.indexmanager.get(uid)
-## content.checksum = c.hexdigest()
-
- def _checksum(self, filename):
- c = sha.sha()
- fp = open(filename, 'r')
- for line in fp:
- c.update(line)
- fp.close()
- return c.hexdigest()
+ bin_copy.bin_copy(filelike, path)
# File Management API
def create(self, props, filelike):
uid = self.indexmanager.index(props, filelike)
- if filelike:
- if isinstance(filelike, basestring):
- # lets treat it as a filename
- filelike = open(filelike, "r")
- filelike.seek(0)
- self._writeContent(uid, filelike, replace=False)
+ self._writeContent(uid, filelike, replace=False)
return uid
def get(self, uid, env=None, allowMissing=False, includeFile=False):
@@ -416,15 +380,6 @@ class FileBackingStore(BackingStore):
if 'uid' not in props: props['uid'] = uid
self.indexmanager.index(props, filelike)
- filename = filelike
- if filelike:
- if isinstance(filelike, basestring):
- # lets treat it as a filename
- filelike = open(filelike, "r")
- filelike.seek(0)
- self.set(uid, filelike)
-
- def set(self, uid, filelike):
self._writeContent(uid, filelike)
def delete(self, uid, allowMissing=True):
diff --git a/src/olpc/datastore/bin_copy.py b/src/olpc/datastore/bin_copy.py
index 1be1b6b..81beadb 100644
--- a/src/olpc/datastore/bin_copy.py
+++ b/src/olpc/datastore/bin_copy.py
@@ -3,6 +3,11 @@ import os, subprocess
def bin_copy(src, dest, mode=0600):
try:
+ if not isinstance(src, basestring):
+ import pdb;pdb.set_trace()
+ if not isinstance(dest, basestring):
+ import pdb;pdb.set_trace()
+
subprocess.check_call(['/bin/cp', src, dest])
except subprocess.CalledProcessError:
raise OSError("Copy failed %s %s" % (src, dest))
diff --git a/src/olpc/datastore/hg_backingstore.py b/src/olpc/datastore/hg_backingstore.py
index 588e3f6..8d13c5f 100644
--- a/src/olpc/datastore/hg_backingstore.py
+++ b/src/olpc/datastore/hg_backingstore.py
@@ -35,10 +35,9 @@ class FileRepo(repo.repository):
if not os.path.exists(self.basepath):
os.makedirs(self.basepath)
#os.chdir(self.basepath)
- self.wopener = util.opener(self.root)
def file(self, path):
- eopen = util.encodedopener(util.opener('.ds'), util.encodefilename)
+ eopen = util.encodedopener(util.opener(self.datadir), util.encodefilename)
fl = localizedFilelog(eopen, path, cwd=self.datadir)
return fl
diff --git a/src/olpc/datastore/model.py b/src/olpc/datastore/model.py
index 746d727..f857487 100644
--- a/src/olpc/datastore/model.py
+++ b/src/olpc/datastore/model.py
@@ -183,7 +183,8 @@ class Content(object):
self._backingstore = backingstore
self._file = None
self._model = model
-
+ self._file = None
+
def __repr__(self):
return "<%s %s>" %(self.__class__.__name__,
self.properties)
@@ -251,12 +252,15 @@ class Content(object):
return None, None
def get_file(self):
- if not hasattr(self, "_file") or not self._file or \
- self._file.closed is True:
+ if not self._file or self._file.closed is True:
target, ext = self.suggestName()
try:
targetfile = self.backingstore._targetFile(self.id, target, ext)
- self._file = targetfile
+ if not targetfile:
+ self._file = None
+ return self._file
+
+ self._file = open(targetfile, "rw")
except OSError:
self._file = None
return self._file
@@ -266,8 +270,11 @@ class Content(object):
file = property(get_file, set_file)
@property
- def filename(self): return os.path.abspath(self.file.name)
-
+ def filename(self):
+ if self.file:
+ return os.path.abspath(self.file.name)
+ return ''
+
@property
def contents(self): return self.file.read()
diff --git a/src/olpc/datastore/xapianindex.py b/src/olpc/datastore/xapianindex.py
index 5f29feb..4aa4632 100644
--- a/src/olpc/datastore/xapianindex.py
+++ b/src/olpc/datastore/xapianindex.py
@@ -171,12 +171,15 @@ class IndexManager(object):
# property or backingstore._translatePath to get at it
versions = self.versions
inplace = self.inplace
-
+ q = self.queue
while self.indexer_running:
# include timeout here to ease shutdown of the thread
# if this is a non-issue we can simply allow it to block
try:
- data = self.queue.get(True, 0.025)
+ # XXX: on shutdown there is a race where the queue is
+ # joined while this get blocks, the exception seems
+ # harmless though
+ data = q.get(True, 0.025)
# when we enque a sequence of commands they happen
# under a single write lock pass through the loop and
# the changes become visible at once.