Commits

Atsushi Odagiri  committed a81a43b

fix py3k windows input

  • Participants
  • Parent commits 0b76dee

Comments (0)

Files changed (1)

File aodag/scaffold/commands.py

 if sys.version_info[0] < 3:
     from urllib2 import urlopen
     from StringIO import StringIO
+    def prompt(name, default=None):
+        if default is None:
+            return raw_input("%s: " % name)
+        else:
+            value = raw_input("%s [%s]: " % (name, default))
+            if not value:
+                return default
+            return value
 else:
     from urllib.request import urlopen
     from io import BytesIO as StringIO
+    def prompt(name, default=None):
+        if default is None:
+            return input("%s: " % name).strip()
+        else:
+            value = input("%s [%s]: " % (name, default)).strip()
+            if not value:
+                return default
+            return value
 
 ENTRY_POINT = "aodag.scaffold.scaffold"
 
 
     def __getitem__(self, key):
         if key not in self._inner:
-            if key in os.environ:
-                value = raw_input(str(key) + "[%s]: " % os.environ[key])
-                if not value:
-                    value = os.environ[key]
-            else:
-                value = raw_input(str(key) + ": ")
+            value = prompt(str(key), os.environ.get(key))
             self._inner[key] = value
         else:
             value = self._inner[key]