-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlock_file.py
38 lines (27 loc) · 1.32 KB
/
lock_file.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
###
# Interact with the shuffle lock file
###
from os import path
import yaml
lock_file_name = '_shuffle-lock'
###
# Safety: check that the 'permissions' file is there so we don't accidentally randomize folders we don't want to
###
def check_lock (dir, token):
lock_file_path = path.join(dir, lock_file_name)
# check the lock file exists
if not path.isfile(lock_file_path):
print ("No lock file found")
return False
# open lock file
with open(lock_file_path, "r") as config_file:
lock_values = yaml.load(config_file, Loader=yaml.FullLoader)
# check the 'dir' parameter in the lock file (should always point to the same path as the file itself to protect against the file being moved/copied accidentally)
if 'dir' not in lock_values or path.join (lock_values['dir'], '') != path.join(path.dirname(lock_file_path), ''):
print ("The \"dir\" name in the lock file is different from the directory we're trying to randomize (expected value: " + path.dirname(lock_file_path) + ")")
return False
# check that the token matches one on the lock file
if 'token' not in lock_values or lock_values['token'] != token:
print ("The provided token did not match a token found in the lock file")
return False
return True