Commits

Chris Mutel committed 861c103

Allow selecting drive letter in bw2-web start under Windows

Comments (0)

Files changed (3)

 import urllib2
 
 
+def get_windows_drive_letters():
+    import win32api
+    return [x for x in win32api.GetLogicalDriveStrings().split('\000') if x]
+
+
 def jqfilepicker_unquote(source):
     """
 Stupid Javascript (insert joke here...) and jQueryFilePicker
 
 @app.route('/start')
 def start():
-    return render_template("start.html", root_path=json.dumps(os.path.abspath("/")))
+    if config._windows:
+        windows, drive_letters = True, get_windows_drive_letters()
+    else:
+        windows, drive_letters = False, []
+    return render_template(
+        "start.html",
+        root_path=json.dumps(os.path.abspath("/")),
+        windows=windows,
+        drive_letters=drive_letters
+    )
 
 #################
 ### Importing ###

bw2ui/web/templates/start.html

     <h3 id="fp-selected">1. Click to select the directory that Brightway2 data will be saved in</h3>
     <p>You <b>must</b> have permission to write to this directory!</p>
     <p>Note: Not all files are shown! You are selecting a directory, not files...</p>
+    {% if windows %}
+      <h3>Change the drive (Windows only)</h3>
+      <select id="driveletter">
+      {% for letter in drive_letters %}
+        <option value="{{ letter }}">{{ letter }}</option>
+      {% endfor %}
+      </select>
+    {% endif %}
     <div id="fp"></div>
   </div>
   <div class="span-8 last">
     });
   });
 });
+
+$(function() {
+  $("#driveletter").change(function() {
+      var letter = $(this).val();
+      $('#fp').html("");
+      $('#fp').fileTree({
+        root: letter,
+        script: '/fp-api',
+        folderEvent: 'click',
+        multiFolder: false
+        },
+        function(file) { console.log(file); }
+      );
+  })
+});
 </script>
 {% endblock %}
     author="Chris Mutel",
     author_email="cmutel@gmail.com",
     license=open('LICENSE.txt').read(),
-    install_requires=["brightway2>=0.10", "docopt", "flask",
-                      "bw-stats-toolkit>=0.7", "fuzzywuzzy"],
+    install_requires=["brightway2>=0.10"],
     scripts=["bw2ui/bin/bw2-web.py", "bw2ui/bin/bw2-controller.py"],
     url="https://bitbucket.org/cmutel/brightway2-ui",
     long_description=open('README.rst').read(),