Permalink
Browse files

Updated the filesystem mapper:

* Inlining small files.
* Write-protecting folders.
* Starting in a sandbox folder.
  • Loading branch information...
1 parent f734362 commit 56e7da633990a23140f982b9f8350cb01f867587 @max99x max99x committed Aug 29, 2011
Showing with 15 additions and 5 deletions.
  1. +15 −5 map_filesystem.py
View
20 map_filesystem.py
@@ -3,23 +3,33 @@
import os
import sys
-# TODO: Inline empty/tiny files.
+MAX_SIZE_TO_INLINE = 32
def main(root):
os.chdir(root)
commands = []
for (dirpath, dirnames, filenames) in os.walk('.'):
for folder in dirnames:
- commands.append('FS.createFolder("%s", "%s", true, true);' %
+ commands.append('FS.createFolder("%s", "%s", true, false);' %
(dirpath, folder))
for filename in filenames:
# NOTE: Remove the python.js entry to prevent unnecesary re-reading.
if dirpath == '.' and filename == 'python.js': continue
jsless_filename = filename[:-3] if filename.endswith('.js') else filename
- commands.append('FS.createLazyFile("%s", "%s", "%s", true, false);' %
- (dirpath, jsless_filename, dirpath + '/' + filename))
+ full_path = os.path.join(dirpath, filename)
+ if os.stat(full_path).st_size <= MAX_SIZE_TO_INLINE:
+ contents = ', '.join(str(ord(i)) for i in open(full_path, 'rb').read())
+ commands.append('FS.createDataFile("%s", "%s", [%s], true, false);' %
+ (dirpath, jsless_filename, contents))
+ else:
+ commands.append('FS.createLazyFile("%s", "%s", "%s", true, false);' %
+ (dirpath, jsless_filename, full_path))
- print '\n'.join(commands) + '\n'
+ # Start out in a writeable folder.
+ commands.append('FS.createFolder(".", "sandbox", true, true);')
+ commands.append('FS.currentPath = "/sandbox";')
+
+ print '\n'.join(commands)
if __name__ == '__main__':
if len(sys.argv) != 2:

0 comments on commit 56e7da6

Please sign in to comment.