示例#1
0
文件: _opts.py 项目: fdev31/pyg
def check_and_exit():
    dir = os.path.abspath(args_manager['install']['install_dir'])
    if not check_permissions(dir):
        logger.exit('''Pyg cannot create new files in the installation directory.
Installation directory was:

    {0}

Perhaps your account does not have write access to this directory?  If the
installation directory is a system-owned directory, you may need to sign in
as the administrator or "root" account.  If you do not have administrative
access to this machine, you may wish to choose a different installation
directory, preferably one that is listed in your PYTHONPATH environment
variable.

If you need further information about Pyg command-line options visit:

    http://pyg.readthedocs.org/en/latest/cmdline.html
or
    http://pyg-installer.co.nr
'''.format(dir))
示例#2
0
文件: __init__.py 项目: fdev31/pyg
def main():
    import sys
    import urllib2

    try:
        ## If Python fails to import pyg we just add this directory to
        ## sys.path so we don't have to worry whether Pyg is installed or not.
        __import__('pyg')
    except ImportError:
        sys.path.insert(0, '..')
    from pyg.parser.parser import init_parser, load_options
    from pyg.core import PygError, InstallationError, AlreadyInstalled, args_manager
    from pyg.log import logger

    try:
        parser = init_parser(__version__)
        args = parser.parse_args()
        if args.verbose:
            logger.level = logger.VERBOSE
        if args.debug:
            logger.level = logger.DEBUG
        load_options()
        if args_manager['global']['no_colors']:
            logger.disable_colors()
        parser.dispatch()
    except (PygError, InstallationError, ValueError) as e:
        sys.exit(1)
    except AlreadyInstalled:
        sys.exit(0)
    except urllib2.HTTPError as e:
        logger.exit('HTTPError: {0}'.format(e.msg))
    except urllib2.URLError as e:
        logger.exit('urllib error: {0}'.format(e.reason if hasattr(e, 'reason') else e.msg))
    except Exception as e:
        if logger.level == logger.DEBUG:
            raise
        try:
            msg = e.args[0]
        except IndexError:
            msg = repr(e)
        logger.exit('Unknown error occurred: {0}'.format(msg))
    sys.exit(0)