<commit_before><commit_msg>Fixed a typo<commit_after>#! /usr/bin/env python

# Davinci Resolve 12 and above Disk Database project backup utility.
# <NAME>, HDhead.com

import os
import sys
import getpass
import time
from shutil import make_archive
from datetime import datetime
import tkMessageBox

#---- User Configuration ----

# User set number of minutes between backups
interval = 120

# Delete backups older than maxDays
maxDays = 30

#---- End of User configuration ----

# Report error and exit
def errorwindow(report):
	tkMessageBox.showinfo('Resolve Project Backup', report)
	sys.exit(report)

sleeptime = interval * 60
version = 1.1
currentUser = getpass.getuser()

# Determine the host operating system and set OS specific variables
hostOS = sys.platform

if hostOS == 'win32':
	eol = '\r\n'
	sourcePath = 'C:\ProgramData\Blackmagic Design\DaVinci Resolve\Support\Resolve Disk Database\Resolve Projects'
	destPath = os.path.join('C:\Users', currentUser, 'Documents\ResolveProjectBackup')

elif hostOS == 'darwin':
	eol = '\n'
	sourcePath = '/Library/Application Support/Blackmagic Design/DaVinci Resolve/Resolve Disk Database/Resolve Projects'
	destPath = os.path.join('/Users', currentUser, 'Documents/ResolveProjectBackup')

else:
	errorwindow('%s OS is not supported' %hostOS)

def wincompliance(ts):
	"""remove space and colons from timestamp for Windows compliance"""
	noSpace = 'T'.join(ts.split())
	noColon = '-'.join(noSpace.split(':'))
	return noColon

# Verify if paths are valid. Create destination directory if missing.
if not os.path.isdir(sourcePath):
	errorwindow('The Resolve disk database root is not found at ' + sourcePath)
if not os.path.isdir(destPath):
	os.makedirs(destPath)

# Create log file if missing or open if exists
logName = 'ResolveBackup.log'
logPath = os.path.join(destPath, logName)
if not os.path.isfile(logPath):
	logfile = open(logPath, 'w')
	logfile.write('Resolve Disk Database Backup Tool V%s. HDhead.com' %version)
	logfile.write(eol)
	logfile.close()

# Infinite backup loop
while True:

	# Create backup
	timeStamp = str(datetime.now())[:-7]
	backupName = 'ResolveProjBackup_' + wincompliance(timeStamp)
	savePath = os.path.join(destPath, backupName)
	make_archive(savePath, 'zip', sourcePath)

	# Write a log entry
	logfile = open(logPath, 'a')
	logfile.write('Created %s.zip'%backupName)
	logfile.write(eol)
	logfile.close()
	
	# Remove old backups
	now = time.time()
	for filename in os.listdir(destPath):
		if filename.endswith('zip') == True:
			deleteFile = os.path.join(destPath, filename)
			timeStamp  = os.stat(deleteFile).st_mtime
			if maxDays + 1< (now - timeStamp) / 86400: # x/86400 converts seconds to days
				os.remove(deleteFile)

	time.sleep(sleeptime)


{'fraction_non_alphanumeric': 0.11721611721611722, 'fraction_numerical': 0.009157509157509158, 'mean_word_length': 4.761603375527426, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2063109', 'n_tokens_mistral': 939, 'n_tokens_neox': 897, 'n_words': 260}