-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboards.py
More file actions
executable file
·94 lines (71 loc) · 1.91 KB
/
boards.py
File metadata and controls
executable file
·94 lines (71 loc) · 1.91 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/python3
import os
import sys
""" GLOBAL VARS """
# lockfile fn
LOCKFILE = ".lock"
# temporary file directory
DIR = "/tmp/soar"
# list of all teensy boards plugged in
BOARDS = []
# username
USER = ""
# users currently logged in
ACTIVE = []
""" USEFUL METHODS """
def lockfile_fn():
return os.path.join(DIR, LOCKFILE)
def board_lockfile_fn(index):
return os.path.join(DIR, ".{}".format(BOARDS[index]))
# grab the latest info
def refresh():
global BOARDS
global USER
global ACTIVE
BOARDS = os.popen("ls /dev | grep \"ttyACM\"").read().split("\n")
USER = os.environ.get("USER")
ACTIVE = list(set(os.popen("w | awk \'NR>2 {print$1;}\'").read().split("\n")))
if not os.path.isdir(DIR):
os.mkdir(DIR)
# set environment variable for the user
def export(board):
os.environ["BOARD"] = os.path.join("/dev", board)
""" TO BE IMPLEMENTED """
# enter the critical section, or busy wait until it is available
def lock():
pass
# delete lockfile and leave critical section
def unlock():
pass
# if a user logged out and didn't "put their board back", delete the board specific lockfile
def synchronize():
pass
# reserve a board for use, index of -1 means pick any available board, otherwise, pick BOARDS[index]
def get_board(index=-1):
pass
# stop using a board
def put_board():
pass
""" BORING SETUP STUFF + MAIN METHOD """
def print_usage():
print("\nusage: board.py <verb> [args]\n\nexamples:\n\tboard.py get\n\tboard.py put\n")
def main():
refresh()
synchronize()
if len(sys.argv) < 2:
print_usage()
return
verb = sys.argv[1]
index = -1
if len(sys.argv) > 2:
try:
index = int(sys.argv[2])
except:
print("index must be an integer")
return
if verb == "get":
get_board(index)
elif verb == "put":
put_board(index)
if __name__ == "__main__":
main()