Advertisement
1yes123

Untitled

Feb 4th, 2023
1,045
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.60 KB | None | 0 0
  1. import os
  2. def check_access():
  3.    #check if config file directory and notes directory exists, if it doesnt create respectively and return true
  4.     try:
  5.         if configdir_exists() and Notesdir_exists() and check_notes_exists():
  6.             return True
  7.         else:
  8.             create_configdir()
  9.             create_notesdir()
  10.             return True
  11.     except OSError as f:
  12.         print(f"{f}: occurred try again")  
  13.  
  14. def saving_dir():
  15.     try:
  16.         if not os.path.exists(os.path.join(f'{os.getcwd()}','Saving')):
  17.             os.mkdir(os.path.join(f'{os.getcwd()}','Saving'))
  18.             return True  
  19.     except OSError as f:
  20.          print(f"{f}: occurred try again")  
  21.  
  22. def configdir_exists():
  23.     try:
  24.         if os.path.exists(return_configdir()):
  25.             return True
  26.     except OSError as f:
  27.          print(f"{f}: occurred try again")  
  28.  
  29.  
  30. def Notesdir_exists():
  31.     try:
  32.  
  33.         if os.path.exists(return_configdir()):
  34.             return True
  35.         else:
  36.             return False    
  37.      #check if notes dir exists
  38.     except OSError as f:
  39.          print(f"{f}: occurred try again")  
  40.  
  41.  
  42. def create_configdir():
  43.     try:
  44.         os.mkdir(os.path.join(f'{os.getcwd()}','SAVING','CONFIGURATION'))
  45.     #make config directory
  46.     except OSError as f:
  47.          print(f"{f}: occurred try again")  
  48.  
  49.  
  50. def create_notesdir():
  51.     try:
  52.         os.mkdir(os.path.join(f'{os.getcwd()}','SAVING','NOTES'))
  53.     ```py
  54. #make notes config dir
  55.     except OSError as f:
  56.          print(f"{f}: occurred try again")  
  57.  
  58.  
  59. def check_notes_exists():
  60.     try:
  61.   #returns true if both note file and respective json file exists
  62.         configdir = []
  63.         notesdir = []
  64.         for  files in os.walk(return_notesdir()):
  65.             for i in files:
  66.                 configdir.append(os.path.splitext(os.path.join(f'{return_notesdir()}',i))[0])
  67.        
  68.         for files in os.walk(return_configdir()):
  69.             for i in files:
  70.                 notesdir.append(os.path.splitext(os.path.join(f'{return_configdir()}',i))[0])    
  71.         if set(configdir)== set(notesdir):
  72.             return True
  73.     except OSError as f:
  74.          print(f"{f}: occurred try again")  
  75.  
  76.  
  77.  
  78.    
  79.  
  80. def return_configdir():
  81.     try:
  82.         return os.path.join(f'{os.getcwd()}','SAVING','CONFIGURATION')
  83.     except OSError as f:
  84.          print(f"{f}: occurred try again")  
  85.        
  86.  
  87. def return_notesdir():
  88.     try:
  89.   #returns notes directory
  90.         return os.path.join(f'{os.getcwd()}','SAVING','NOTES')
  91.     except OSError as f:
  92.          print(f"{f}: occurred try again")  
  93. check_access() ```  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement