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 = input(
  12. "Enter where the workspace must be created (using {} "
  13. "if nothing is specifed):".format(homeFolder))
  14. if whereToCreate == "":
  15. whereToCreate = homeFolder
  16. assert os.path.exists(whereToCreate), "Specified path {} does not exist".format(whereToCreate)
  17. pkgParFilesDir = os.path.join(thisFilePath, "ParFiles")
  18. pkgTestFilesDir = os.path.join(thisFilePath, "TestFiles")
  19. assert os.path.isdir(pkgParFilesDir) and os.path.isdir(pkgTestFilesDir), "Folders 'ParFiles' and 'TestFiles' that " \
  20. "came along with this script were not found!" \
  21. "Aborting!"
  22. workSpace = os.path.join(whereToCreate, 'RegMaxSN_WorkSpace')
  23. try:
  24. if os.path.exists(workSpace):
  25. ch = input('A RegMaxSN Workspace already exists. Delete it and all files in it and create new one?(y/n):')
  26. if ch == "y":
  27. shutil.rmtree(workSpace)
  28. else:
  29. sys.exit('User Abort')
  30. os.mkdir(workSpace)
  31. except IOError as e:
  32. raise IOError('Error writing into {}. Please make sure its writable'.format(workSpace))
  33. parFilesDir = os.path.join(workSpace, "ParFiles")
  34. shutil.copytree(pkgParFilesDir, parFilesDir)
  35. testFilesDir = os.path.join(workSpace, "TestFiles")
  36. shutil.copytree(pkgTestFilesDir, testFilesDir)
  37. utilScriptsDir = os.path.join(workSpace, "utilityScripts")
  38. shutil.copytree(utilsDir, utilScriptsDir)
  39. resDir = os.path.join(workSpace, "Results")
  40. os.mkdir(resDir)
  41. os.mkdir(os.path.join(resDir, "Tests"))
  42. os.mkdir(os.path.join(resDir, "Reg-MaxS"))
  43. os.mkdir(os.path.join(resDir, "Reg-MaxS-N"))
  44. os.mkdir(os.path.join(resDir, "PCABased"))
  45. print(("Succesfullly created Work Space at {}".format(workSpace)))