Updated: 2026-01-21
Update Note: First draft
This is the python script called by the .sh file.
make_config is called to get the latest config from the spreadsheet before running.
import sys
import file_general, file_google, file_onedrive
import os
import functools
import time
import json
import make_config
def dec_runner(func):
@functools.wraps(func)
def wrapper (*args,**kwargs):
filename=args[0]
if os.path.exists(filename):
value = func(*args,**kwargs)
return value
else:
print(f"Does not exist: {filename}")
return None
return wrapper
@dec_runner
def main(exec_config_file):
print(sys.argv)
instructions = []
with open(f"{exec_config_file}","rt") as _f:
instructions = _f.read()
instructions = json.loads(instructions)
checked = {}
# 20260119 add this so that we don't hang on refresh token failure down the line
for instruction in instructions:
account = instruction['Account']
source = instruction['Source']
if source =="onedrive" and not (f"{source}{account}" in checked):
print(f"Checking Onedrive tokens for {account}")
_drive = file_onedrive.OneDrive(account)
_drive.getAccessToken()
checked[f"{source}{account}"] = 1
if source=="google" and not (f"{source}{account}" in checked):
print(f"Checking Googledrive tokens for {account}")
_drive = file_google.GoogleDrive(account)
_drive.getAccessToken()
checked[f"{source}{account}"] = 1
for instruction in instructions:
account = instruction['Account']
source = instruction['Source']
action = instruction['Action']
include_directories = instruction['Include Directories']
cloud_directory = instruction['Cloud Directory']
local_source = instruction['Local Source']
local_target = instruction['Local Target']
# 20260118 want to add an include
if 'Include' in instruction:
if instruction['Include']==0:
print(f"Exclude {instruction}")
continue
start_time = time.perf_counter_ns()
piece = ""
if source=="onedrive":
...
if action=="get":
piece = "Onedrive GET: "
_drive = file_onedrive.OneDrive(account)
_drive.push_onedrive_to_local(cloud_directory,local_target,include_directories)
if action=="push":
piece = "Onedrive PUSH: "
_drive = file_onedrive.OneDrive(account)
_drive.push_local_to_onedrive(local_source,cloud_directory,include_directories)
if source=="googledrive":
...
if action=="get":
piece = "Googledrive GET: "
_drive = file_google.GoogleDrive(account)
_drive.push_googledrive_to_local(cloud_directory,local_target,include_directories)
if action=="push":
piece = "Googledrive PUSH: "
_drive = file_google.GoogleDrive(account)
_drive.push_local_to_googlerive(local_source,cloud_directory,include_directories)
if source=="local":
...
if file_general.LocalFiles.driveExists(local_source) and file_general.LocalFiles.driveExists(local_target):
piece = "local SYNCH: "
print(" >> Drives mounted: ",local_source, local_target)
_local_files = file_general.LocalFiles()
_local_files.check_make_directory_local_only(local_target)
_local_files.copy_missing_files_local_only(local_source,local_target,include_directories)
_local_files.remove_extra_files_local_only(local_source,local_target,include_directories)
_local_files.remove_extra_directories_local_only(local_source,local_target,include_directories)
else:
print(f" >> drive does not exist for local_source: {file_general.LocalFiles.driveExists(local_source)} | local_target {file_general.LocalFiles.driveExists(local_target)} ")
end_time = time.perf_counter_ns()
print(f"{piece} duration: ",(end_time - start_time)/1000000000)
if __name__=="__main__":
# update the config files from the spreadsheet
make_config.main()
if len(sys.argv)==1:
action = "process"
param1 = "fast.json"
else:
action = sys.argv[1]
param1 = None
if len(sys.argv)>=3:
param1 = sys.argv[2]
# Get the absolute path of the current script file
script_path = os.path.abspath(__file__)
# Get the directory containing the script
script_directory = os.path.dirname(script_path)
if action == "process":
...
exec_config_file = f"{script_directory}/goosoft_config/{param1}"
main(exec_config_file)