Skip to content
Browse files

Merge pull request #222 from lukecampbell/force_clean

Adds filesystem cleanup to store_interfaces force_clean
  • Loading branch information...
2 parents a06d7c5 + c68c706 commit fa39988423618bca521a948a802d4d7a4921a176 @daf daf committed Jan 14, 2013
Showing with 21 additions and 4 deletions.
  1. +18 −4 pyon/util/file_sys.py
  2. +3 −0 scripts/store_interfaces.py
View
22 pyon/util/file_sys.py
@@ -14,6 +14,7 @@
import string
from pyon.util.log import log
from pyon.util.containers import DotDict
+from pyon.core.bootstrap import CFG as bootcfg
class FileSystemError(Exception):
@@ -45,9 +46,26 @@ def __new__(cls, *args, **kwargs):
if not cls._instance:
cls._instance = super(FileSystem, cls).__new__(cls, *args, **kwargs)
return cls._instance
+
+ @classmethod
+ def _clean(cls, config):
+ for k,v in FileSystem.FS_DIRECTORY.iteritems():
+ s = v.lower() # Lower case string
+ conf = config.get_safe('container.filesystem.%s' % s, None)
+ if conf:
+ FileSystem.FS_DIRECTORY[k] = conf
+ else:
+ FileSystem.FS_DIRECTORY[k] = os.path.join('/tmp',s)
+ if os.path.exists(FS_DIRECTORY[k]):
+ log.info('Removing %s' , FS_DIRECTORY[k])
+ shutil.rmtree(FS_DIRECTORY[k])
+ cls.__makedirs(FileSystem.FS_DIRECTORY[k]) # Catches race condition where concurrent container does the same thing
+
def __init__(self, CFG):
FileSystem._force_clean = CFG.get_safe('container.filesystem.force_clean',False)
+ if FileSystem._force_clean:
+ self._clean(CFG)
for k,v in FileSystem.FS_DIRECTORY.iteritems():
s = v.lower() # Lower case string
@@ -62,10 +80,6 @@ def __init__(self, CFG):
if not os.path.exists(FS_DIRECTORY[k]):
log.info('Making path: %s', FS_DIRECTORY[k])
self.__makedirs(FileSystem.FS_DIRECTORY[k]) # Catches race condition where concurrent container does the same thing
- elif os.path.exists(FS_DIRECTORY[k]) and FileSystem._force_clean:
- log.info('Removing %s' , FS_DIRECTORY[k])
- shutil.rmtree(FS_DIRECTORY[k])
- self.__makedirs(FileSystem.FS_DIRECTORY[k]) # Catches race condition where concurrent container does the same thing
@classmethod
def __makedirs(cls,path):
View
3 scripts/store_interfaces.py
@@ -87,8 +87,11 @@ def main():
# Delete sysname datastores if option "force_clean" is set
if options.force_clean:
from pyon.datastore import clear_couch_util
+ from pyon.util.file_sys import FileSystem
print "store_interfaces: force_clean=True. DROP DATASTORES for sysname=%s" % bootstrap.get_sys_name()
+ pyon_config = config.read_standard_configuration() # Initial pyon.yml + pyon.local.yml
clear_couch_util.clear_couch(bootstrap_config, prefix=bootstrap.get_sys_name())
+ FileSystem._clean(pyon_config)
# ion_config - Holds the new CFG object for the system (independent of this tool's config)
ion_config = config.read_standard_configuration()

0 comments on commit fa39988

Please sign in to comment.
Something went wrong with that request. Please try again.