Commits

Anonymous committed abdad7a

Added function to utlilities module that will recursively create parent directories (but not the tail directory) of the path passed in. Used this from
fullcoursecreator to create the intermediate folders in the destination directory if they don't exist

  • Participants
  • Parent commits b0de310

Comments (0)

Files changed (3)

psmodulecheck/fullcoursecreator.py

 import os
 import shutil
 import questions
+import console
+import utilities
 
 
 class FullCourseCreator():
         self._config = config
         self.full_course_id_path = self._config.get_full_course_path()
 
+
     def create_course_folder(self):
+        utilities.create_ancestor_paths(self.full_course_id_path)
         if not os.path.isdir(self.full_course_id_path):
             os.mkdir(self.full_course_id_path)
 

psmodulecheck/settings.json

  "courseId":"introduction-qt-cplusplus-framework",
  "author":"tod-gentille",
  "createFullCourse":true,
- "fullCourseDestinationPrefix":"E:\\DropBox\\tod-gentille",
+ "fullCourseDestinationPrefix":"E:\\DropBox\\tod-gentille-test",
  "metaSuffix":".meta",
  "modulePrefix":"-m",
  "maxQuestionLength":150,

psmodulecheck/utilities.py

 """A collection of useful utilities"""
 import console
+import os
 
 
 def get_user_response_yn(prompt):
         console.print_error('Please enter a Y or N')
 
 
-        # import adjustpath
+def create_ancestor_paths(fullpath):
+    """Given a path work our way up it recursively and create any folders
+    in the path that don't already exist
+    """
+    parent = os.path.dirname(fullpath)
+    if len(parent) < 1:
+        print("Couldn't create a folder from:" + fullpath)
+        return
+    if os.path.isdir(parent):
+        return
+    create_ancestor_paths(parent)
+    print("making directory " + parent)
+    os.mkdir(parent)
+
+
+
+    # import adjustpath
         # sys.path.append(os.path.dirname(os.path.realpath(__file__)))
         # for path in sys.path:
         #     print (path)