Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- def check_access():
- #check if config file directory and notes directory exists, if it doesnt create respectively and return true
- try:
- if configdir_exists() and Notesdir_exists() and check_notes_exists():
- return True
- else:
- create_configdir()
- create_notesdir()
- return True
- except OSError as f:
- print(f"{f}: occurred try again")
- def saving_dir():
- try:
- if not os.path.exists(os.path.join(f'{os.getcwd()}','Saving')):
- os.mkdir(os.path.join(f'{os.getcwd()}','Saving'))
- return True
- except OSError as f:
- print(f"{f}: occurred try again")
- def configdir_exists():
- try:
- if os.path.exists(return_configdir()):
- return True
- except OSError as f:
- print(f"{f}: occurred try again")
- def Notesdir_exists():
- try:
- if os.path.exists(return_configdir()):
- return True
- else:
- return False
- #check if notes dir exists
- except OSError as f:
- print(f"{f}: occurred try again")
- def create_configdir():
- try:
- os.mkdir(os.path.join(f'{os.getcwd()}','SAVING','CONFIGURATION'))
- #make config directory
- except OSError as f:
- print(f"{f}: occurred try again")
- def create_notesdir():
- try:
- os.mkdir(os.path.join(f'{os.getcwd()}','SAVING','NOTES'))
- ```py
- #make notes config dir
- except OSError as f:
- print(f"{f}: occurred try again")
- def check_notes_exists():
- try:
- #returns true if both note file and respective json file exists
- configdir = []
- notesdir = []
- for files in os.walk(return_notesdir()):
- for i in files:
- configdir.append(os.path.splitext(os.path.join(f'{return_notesdir()}',i))[0])
- for files in os.walk(return_configdir()):
- for i in files:
- notesdir.append(os.path.splitext(os.path.join(f'{return_configdir()}',i))[0])
- if set(configdir)== set(notesdir):
- return True
- except OSError as f:
- print(f"{f}: occurred try again")
- def return_configdir():
- try:
- return os.path.join(f'{os.getcwd()}','SAVING','CONFIGURATION')
- except OSError as f:
- print(f"{f}: occurred try again")
- def return_notesdir():
- try:
- #returns notes directory
- return os.path.join(f'{os.getcwd()}','SAVING','NOTES')
- except OSError as f:
- print(f"{f}: occurred try again")
- check_access() ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement