From 0942bfd8aa64d6eb3e87af83218d88e3eb1d0f98 Mon Sep 17 00:00:00 2001 From: Fred Date: Sun, 29 Jul 2012 15:50:14 +0800 Subject: [PATCH] Can check if directory is a Moodle instance --- lib/moodle.py | 26 +++++++++++++++++++++++--- lib/workplace.py | 16 ++-------------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/lib/moodle.py b/lib/moodle.py index 7bf2aec..6333822 100644 --- a/lib/moodle.py +++ b/lib/moodle.py @@ -48,9 +48,24 @@ class Moodle(): info['installed'] = self.installed return info - def reload(self): - self._loaded = False - return self._load() + @staticmethod + def isInstance(path): + version = os.path.join(path, 'version.php') + try: + f = open(version, 'r') + lines = f.readlines() + f.close() + except: + return False + found = False + for line in lines: + if line.find('MOODLE VERSION INFORMATION') > -1: + found = True + break + if not found: + return False + + return True def _load(self): @@ -76,3 +91,8 @@ class Moodle(): self._loaded = True return True + + def reload(self): + self._loaded = False + return self._load() + diff --git a/lib/workplace.py b/lib/workplace.py index ad1e3ff..88e80e7 100644 --- a/lib/workplace.py +++ b/lib/workplace.py @@ -57,26 +57,14 @@ class Workplace(): def isMoodle(self, name): d = os.path.join(self.path, name) if not os.path.isdir(d): - raise Exception('Directory %s not found' % d) + return False wwwDir = os.path.join(d, self.wwwDir) dataDir = os.path.join(d, self.dataDir) if not os.path.isdir(wwwDir) or not os.path.isdir(dataDir): return False - version = os.path.join(wwwDir, 'version.php') - try: - f = open(version, 'r') - lines = f.readlines() - f.close() - except: - return False - found = False - for line in lines: - if line.find('MOODLE VERSION INFORMATION') > -1: - found = True - break - if not found: + if not moodle.Moodle.isInstance(wwwDir): return False return True -- 2.11.0