revert to the previous cwd rather than assuming a particular path layout

This commit is contained in:
Damien Elmes 2012-01-30 05:32:18 +09:00
parent 63b5e862b3
commit 3dc9454cd7

View file

@ -23,6 +23,7 @@ class MediaManager(object):
self._dir = re.sub("(?i)\.(anki2)$", ".media", self.col.path) self._dir = re.sub("(?i)\.(anki2)$", ".media", self.col.path)
if not os.path.exists(self._dir): if not os.path.exists(self._dir):
os.makedirs(self._dir) os.makedirs(self._dir)
self._oldcwd = os.getcwd()
os.chdir(self._dir) os.chdir(self._dir)
# change database # change database
self.connect() self.connect()
@ -41,10 +42,8 @@ class MediaManager(object):
return return
self.db.close() self.db.close()
self.db = None self.db = None
# reset our path to ~/Anki # change cwd back to old location
anki_dir = os.path.dirname( os.path.dirname(self.col.path) ) os.chdir(self._oldcwd)
os.chdir(anki_dir)
def dir(self): def dir(self):
return self._dir return self._dir