Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathfs_utils.py
More file actions
Latest commit
33 lines (25 loc) · 1.01 KB
/
Copy pathfs_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.
"""
importos
defLoadPrograms(**kwargs):
"""
Iterate through the python programs in a folder.
"""
path=kwargs['path']
forfileinos.listdir(path):
iffile.endswith(".py"):
withopen(os.path.join(path, file)) asf:
code=f.read()
yieldfile, code
defLoadProgramVisitor(path, func):
forpname, codeinLoadPrograms(path=path):
func(pname, code)
defbuildLoader(client, Program, ndb, user_id, folder_id, modDBFunctions):
defloader(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)
returnwrapped_loader
if__name__=='__main__':
LoadProgramVisitor(path='/Users/steve/Development/instructormi/assets/lecture-demo-programs/PUBLIC', func=lambdapname, code: print(pname))