setupWorkspace.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import os
  2. import shutil
  3. import sys
  4. homeFolder = os.path.expanduser('~')
  5. thisFilePath = os.path.split(os.path.abspath(__file__))[0]
  6. try:
  7. import regmaxsn
  8. utilsDir = os.path.join(os.path.abspath(regmaxsn.__path__[0]), 'scripts', 'utils')
  9. except ImportError as e:
  10. raise(ImportError('The package regmaxsn must be installed before this script can be used.'))
  11. whereToCreate = raw_input("Enter where the workspace must be created (using {} "
  12. "if nothing is specifed):".format(homeFolder))
  13. if whereToCreate == "":
  14. whereToCreate = homeFolder
  15. assert os.path.exists(whereToCreate), "Specified path {} does not exist".format(whereToCreate)
  16. pkgParFilesDir = os.path.join(thisFilePath, "ParFiles")
  17. pkgTestFilesDir = os.path.join(thisFilePath, "TestFiles")
  18. assert os.path.isdir(pkgParFilesDir) and os.path.isdir(pkgTestFilesDir), "Folders 'ParFiles' and 'TestFiles' that " \
  19. "came along with this script were not found!" \
  20. "Aborting!"
  21. workSpace = os.path.join(whereToCreate, 'RegMaxSN_WorkSpace')
  22. try:
  23. if os.path.exists(workSpace):
  24. ch = raw_input('A RegMaxSN Workspace already exists. Delete it and all files in it and create new one?(y/n):')
  25. if ch == "y":
  26. shutil.rmtree(workSpace)
  27. else:
  28. sys.exit('User Abort')
  29. os.mkdir(workSpace)
  30. except IOError as e:
  31. raise(IOError('Error writing into {}. Please make sure its writable'.format(workSpace)))
  32. parFilesDir = os.path.join(workSpace, "ParFiles")
  33. shutil.copytree(pkgParFilesDir, parFilesDir)
  34. testFilesDir = os.path.join(workSpace, "TestFiles")
  35. shutil.copytree(pkgTestFilesDir, testFilesDir)
  36. utilScriptsDir = os.path.join(workSpace, "utilityScripts")
  37. shutil.copytree(utilsDir, utilScriptsDir)
  38. resDir = os.path.join(workSpace, "Results")
  39. os.mkdir(resDir)
  40. os.mkdir(os.path.join(resDir, "Tests"))
  41. os.mkdir(os.path.join(resDir, "Reg-MaxS"))
  42. os.mkdir(os.path.join(resDir, "Reg-MaxS-N"))
  43. os.mkdir(os.path.join(resDir, "PCABased"))
  44. print("Succesfullly created Work Space at {}".format(workSpace))