-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathfs_utils.py
More file actions
33 lines (25 loc) · 1.01 KB
/
fs_utils.py
File metadata and controls
33 lines (25 loc) · 1.01 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
"""
These are filesytem based utilities to help with housekeeping.
"""
import os
def LoadPrograms(**kwargs):
"""
Iterate through the python programs in a folder.
"""
path = kwargs['path']
for file in os.listdir(path):
if file.endswith(".py"):
with open(os.path.join(path, file)) as f:
code = f.read()
yield file, code
def LoadProgramVisitor(path, func):
for pname, code in LoadPrograms(path=path):
func(pname, code)
def buildLoader(client, Program, ndb, user_id, folder_id, modDBFunctions):
def loader(pname, code):
code = code.replace('from vpython import *', 'Web VPython 3.2\n')
modDBFunctions.SetProgramSource(ndb, Program, user_id, folder_id, pname, code)
wrapped_loader = modDBFunctions.with_context(client)(loader)
return wrapped_loader
if __name__ == '__main__':
LoadProgramVisitor(path='/Users/steve/Development/instructormi/assets/lecture-demo-programs/PUBLIC', func=lambda pname, code: print(pname))