Atsushi Odagiri avatar Atsushi Odagiri committed bf48dd0

show help message of ``paste`` command except with wsgilib.

Comments (0)

Files changed (11)

paste/script/appinstall.py

     from paste.script.util import string24 as string
 else:
     import string
-import new
-from cStringIO import StringIO
+#import new
+from paste.script.compat import StringIO
 from paste.script.command import Command, BadCommand, run as run_command
 import paste.script.templates
 from paste.script import copydir
 import pkg_resources
 Cheetah = None
-from ConfigParser import ConfigParser
-from paste.util import import_string
+from paste.script.compat import ConfigParser
+from paste.script.util import import_string
 from paste.deploy import appconfig
 from paste.script.util import uuid
 from paste.script.util import secret
             if args[0] == '--sysconfig':
                 args.pop(0)
                 if not args:
-                    raise BadCommand, (
+                    raise BadCommand(
                         "You gave --sysconfig as the last argument without "
                         "a value")
                 self.sysconfigs.insert(0, (True, args.pop(0)))
             if name.endswith('.py'):
                 if not os.path.exists(name):
                     if explicit:
-                        raise BadCommand, (
+                        raise BadCommand(
                             "sysconfig file %s does not exist"
                             % name)
                     else:
             else:
                 try:
                     mod = import_string.simple_import(name)
-                except ImportError, e:
+                except ImportError:
+                    e = sys.exc_info()[1]
                     if explicit:
                         raise
                     else:
         """
         val = self.get_sysconfig_option(name)
         if val is None:
-            raise NameError, (
+            raise NameError(
                 "Method %s not found in any sysconfig module" % name)
         return val(*args, **kw)
 

paste/script/compat.py

+# (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org)
+# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
+"""Python 2<->3 compatibility module"""
+import sys
+import types
+
+def print_(*args):
+    out = []
+    for a in args:
+        out.append(text_type(a))
+    o = " ".join(out)
+    sys.stdout.write(o)
+    sys.stdout.write("\n")
+PY3 = sys.version_info[0] == 3
+
+if PY3:
+    string_types = str,
+    integer_types = int,
+    class_types = type,
+    text_type = str
+    binary_type = bytes
+    long = int
+    basestring = str
+    from configparser import ConfigParser
+    from urllib.parse import unquote
+    from socketserver import ThreadingTCPServer, StreamRequestHandler
+    from io import StringIO
+    import urllib.parse as urlparse
+    iteritems = lambda d: d.items()
+
+    def reraise(t, e, tb):
+        exec('raise e from tb', dict(e=e, tb=tb))
+else:
+    string_types = basestring,
+    integer_types = (int, long)
+    class_types = (type, types.ClassType)
+    text_type = unicode
+    binary_type = str
+    long = long
+    basestring = basestring
+    from ConfigParser import ConfigParser
+    from urllib import unquote
+    from SocketServer import ThreadingTCPServer, StreamRequestHandler
+    from StringIO import StringIO
+    import urlparse
+    iteritems = lambda d: d.iteritems()
+
+    def reraise(t, e, tb):
+        exec('raise t, e, tb', dict(t=t, e=e, tb=tb))
+
+
+def text_(s, encoding='latin-1', errors='strict'):
+    """ If ``s`` is an instance of ``binary_type``, return
+    ``s.decode(encoding, errors)``, otherwise return ``s``"""
+    if isinstance(s, binary_type):
+        return s.decode(encoding, errors)
+    return s # pragma: no cover

paste/script/create_distro.py

 import sys
 import os
 import pkg_resources
-from command import Command, BadCommand
-import copydir
-import pluginlib
+from paste.script.command import Command, BadCommand
+from paste.script import copydir
+from paste.script import pluginlib
 import fnmatch
 from paste.script.compat import print_
 try:
         for entry in self.all_entry_points():
             try:
                 templates.append(entry.load()(entry.name))
-            except Exception, e:
+            except Exception:
+                e = sys.exc_info()[1]
                 # We will not be stopped!
                 print_('Warning: could not load entry point %s (%s: %s)' % (
                     entry.name, e.__class__.__name__, e))

paste/script/entrypoints.py

 import textwrap
 import os
 import pkg_resources
-from command import Command, BadCommand
+from paste.script.command import Command, BadCommand
 import fnmatch
 import re
 import traceback
-from cStringIO import StringIO
+from paste.script.compat import StringIO
 import inspect
 import types
 from paste.script.compat import print_
     def get_entry_point_description(self, ep, group):
         try:
             return self._safe_get_entry_point_description(ep, group)
-        except Exception, e:
+        except Exception:
+            e = sys.exc_info()[1]
             out = StringIO()
             traceback.print_exc(file=out)
             return ErrorDescription(e, out.getvalue())

paste/script/exe.py

 import sys
 import shlex
 import pkg_resources
-import command
+from paste.script import command
 from paste.script.compat import print_
 
 class ExeCommand(command.Command):

paste/script/grep.py

 import marshal
 import inspect
 import re
-from command import Command
-import pluginlib
+from paste.script.command import Command
+from paste.script import pluginlib
 from paste.script.compat import print_
 
 class GrepCommand(Command):

paste/script/help.py

 # (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org)
 # Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
-from command import Command, get_commands
-from command import parser as base_parser
+import sys
+from paste.script.command import Command, get_commands
+from paste.script.command import parser as base_parser
 from paste.script.compat import print_
 
 class HelpCommand(Command):
         
     def generic_help(self):
         base_parser.print_help()
-        print()
+        print_()
         commands_grouped = {}
         commands = get_commands()
         longest = max([len(n) for n in commands.keys()])
         for name, command in commands.items():
             try:
                 command = command.load()
-            except Exception, e:
+            except Exception:
+                e = sys.exc_info()[1]
                 print_('Cannot load command %s: %s' % (name, e))
                 continue
             if getattr(command, 'hidden', False):
                 continue
             commands_grouped.setdefault(
                 command.group_name, []).append((name, command))
-        commands_grouped = commands_grouped.items()
+        commands_grouped = list(commands_grouped.items())
         commands_grouped.sort()
         print_('Commands:')
         for group, commands in commands_grouped:

paste/script/request.py

 import os
 import re
 import sys
-import urlparse
+from paste.script.compat import urlparse
 import urllib
-from command import Command, BadCommand
+from paste.script.command import Command, BadCommand
 from paste.deploy import loadapp, loadserver
 from paste.wsgilib import raw_interactive
 

paste/script/serve.py

     import subprocess
 except ImportError:
     from paste.util import subprocess24 as subprocess
-from command import Command, BadCommand
+from paste.script.command import Command, BadCommand
 from paste.deploy import loadapp, loadserver
 import threading
 import atexit
 import logging
-import ConfigParser
-from paste.scipt.compat import print_
+#from paste.script.compat import ConfigParser
+from paste.script.compat import print_
 
 MAXFD = 1024
 
         if self.options.log_file:
             try:
                 writeable_log_file = open(self.options.log_file, 'a')
-            except IOError, ioe:
+            except IOError:
+                ioe = sys.exc_info()[1]
                 msg = 'Error: Unable to write to log file: %s' % ioe
                 raise BadCommand(msg)
             writeable_log_file.close()
         if self.options.pid_file:
             try:
                 writeable_pid_file = open(self.options.pid_file, 'a')
-            except IOError, ioe:
+            except IOError:
+                ioe = sys.exc_info()[1]
                 msg = 'Error: Unable to write to pid file: %s' % ioe
                 raise BadCommand(msg)
             writeable_pid_file.close()
         if getattr(self.options, 'daemon', False):
             try:
                 self.daemonize()
-            except DaemonizeException, ex:
+            except DaemonizeException:
+                ex = sys.exc_info()[1]
                 if self.verbose > 0:
                     print_(str(ex))
                 return
         def serve():
             try:
                 server(app)
-            except (SystemExit, KeyboardInterrupt), e:
+            except (SystemExit, KeyboardInterrupt):
+                e = sys.exc_info()[1]
                 if self.verbose > 1:
                     raise
                 if str(e):
             print_("PID in %s is not valid (deleting)" % pid_file)
             try:
                 os.unlink(pid_file)
-            except (OSError, IOError), e:
+            except (OSError, IOError):
+                e = sys.exc_info()[1]
                 print_("Could not delete: %s" % e)
                 return 2
             return 1
         try:
             os.kill(int(pid), 0)
             return pid
-        except OSError, e:
+        except OSError:
+            e = sys.exc_info()[1]
             if e.errno == errno.EPERM:
                 return pid
     return None
     try:
         os.unlink(filename)
         return
-    except OSError, e:
+    except OSError:
+        e = sys.exc_info()[1]
         # Record, but don't give traceback
         print_("Cannot remove PID file: %s" % e)
     # well, at least lets not leave the invalid PID around...
         f = open(filename, 'w')
         f.write('')
         f.close()
-    except OSError, e:
+    except OSError:
+        e = sys.exc_info()[1]
         print_('Stale PID left in file: %s (%e)' % (filename, e))
     else:
         print_('Stale PID removed')
             sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
             try:
                 sock.connect(bound_address)
-            except socket.error, e:
+            except socket.error:
+                e = sys.exc_info()[1]
                 if e.args[0] != errno.ECONNREFUSED:
                     raise
                 break

paste/script/util/import_string.py

+# (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org)
+# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
+
+"""
+'imports' a string -- converts a string to a Python object, importing
+any necessary modules and evaluating the expression.  Everything
+before the : in an import expression is the module path; everything
+after is an expression to be evaluated in the namespace of that
+module.
+
+Alternately, if no : is present, then import the modules and get the
+attributes as necessary.  Arbitrary expressions are not allowed in
+that case.
+"""
+import sys
+
+def eval_import(s):
+    """
+    Import a module, or import an object from a module.
+
+    A module name like ``foo.bar:baz()`` can be used, where
+    ``foo.bar`` is the module, and ``baz()`` is an expression
+    evaluated in the context of that module.  Note this is not safe on
+    arbitrary strings because of the eval.
+    """
+    if ':' not in s:
+        return simple_import(s)
+    module_name, expr = s.split(':', 1)
+    module = import_module(module_name)
+    obj = eval(expr, module.__dict__)
+    return obj
+
+def simple_import(s):
+    """
+    Import a module, or import an object from a module.
+
+    A name like ``foo.bar.baz`` can be a module ``foo.bar.baz`` or a
+    module ``foo.bar`` with an object ``baz`` in it, or a module
+    ``foo`` with an object ``bar`` with an attribute ``baz``.
+    """
+    parts = s.split('.')
+    module = import_module(parts[0])
+    name = parts[0]
+    parts = parts[1:]
+    last_import_error = None
+    while parts:
+        name += '.' + parts[0]
+        try:
+            module = import_module(name)
+            parts = parts[1:]
+        except ImportError:
+            e = sys.exc_info()[1]
+            last_import_error = e
+            break
+    obj = module
+    while parts:
+        try:
+            obj = getattr(module, parts[0])
+        except AttributeError:
+            raise ImportError(
+                "Cannot find %s in module %r (stopped importing modules with error %s)" % (parts[0], module, last_import_error))
+        parts = parts[1:]
+    return obj
+
+def import_module(s):
+    """
+    Import a module.
+    """
+    mod = __import__(s)
+    parts = s.split('.')
+    for part in parts[1:]:
+        mod = getattr(mod, part)
+    return mod
+
+def try_import_module(module_name):
+    """
+    Imports a module, but catches import errors.  Only catches errors
+    when that module doesn't exist; if that module itself has an
+    import error it will still get raised.  Returns None if the module
+    doesn't exist.
+    """
+    try:
+        return import_module(module_name)
+    except ImportError:
+        e = sys.exc_info()[1]
+        if not getattr(e, 'args', None):
+            raise
+        desc = e.args[0]
+        if not desc.startswith('No module named '):
+            raise
+        desc = desc[len('No module named '):]
+        # If you import foo.bar.baz, the bad import could be any
+        # of foo.bar.baz, bar.baz, or baz; we'll test them all:
+        parts = module_name.split('.')
+        for i in range(len(parts)):
+            if desc == '.'.join(parts[i:]):
+                return None
+        raise

paste/script/util/uuid.py

         from os import urandom
     except:
         from random import randrange
-        uuid = UUID(randrange(1<<32L), randrange(1<<16), randrange(1<<16),
-                    randrange(1<<8), randrange(1<<8), randrange(1<<48L))
+        uuid = UUID(randrange(1<<32), randrange(1<<16), randrange(1<<16),
+                    randrange(1<<8), randrange(1<<8), randrange(1<<48))
     else:
         uuid = UUID(0, 0, 0, 0, 0, 0)
         uuid.bytes = urandom(16)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.