Changeset 11695:efdd815552d0 in orange for Orange/utils/addons.py


Ignore:
Timestamp:
09/11/13 13:29:11 (7 months ago)
Author:
Ales Erjavec <ales.erjavec@…>
Branch:
default
Message:

Use 'easy_install' to install add-ons.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Orange/utils/addons.py

    r11694 r11695  
    3636import site 
    3737import itertools 
     38import pipes 
    3839 
    3940from collections import namedtuple, defaultdict 
     
    430431        func() 
    431432 
     433 
     434def easy_install_process(args, bufsize=-1): 
     435    from setuptools.command import easy_install 
     436    # Check if easy_install supports '--user' switch 
     437    if "user" in [opt[0] for opt in easy_install.easy_install.user_options]: 
     438        has_user_site = True 
     439    else: 
     440        has_user_site = False 
     441 
     442    if has_user_site and site.USER_SITE in sys.path: 
     443        args = ["--user"] + args 
     444 
     445    # properly quote arguments if necessary 
     446    args = map(pipes.quote, args) 
     447 
     448    script = """ 
     449import sys 
     450from setuptools.command.easy_install import main 
     451sys.exit(main({args!r})) 
     452""" 
     453    script = script.format(args=args) 
     454 
     455    return python_process(["-c", script], bufsize=bufsize) 
     456 
     457 
     458def python_process(args, script_name=None, cwd=None, env=None, **kwargs): 
     459    """ 
     460    Run a `sys.executable` in a subprocess with `args`. 
     461    """ 
     462    executable = sys.executable 
     463    if os.name == "nt" and os.path.basename(executable) == "pythonw.exe": 
     464        dirname, _ = os.path.split(executable) 
     465        executable = os.path.join(dirname, "python.exe") 
     466        # by default a new console window would show up when executing the 
     467        # script 
     468        startupinfo = subprocess.STARTUPINFO() 
     469        if hasattr(subprocess, "STARTF_USESHOWWINDOW"): 
     470            startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW 
     471        else: 
     472            # This flag was missing in inital releases of 2.7 
     473            startupinfo.dwFlags |= subprocess._subprocess.STARTF_USESHOWWINDOW 
     474 
     475        kwargs["startupinfo"] = startupinfo 
     476 
     477    if script_name is not None: 
     478        script = script_name 
     479    else: 
     480        script = executable 
     481 
     482    process = subprocess.Popen( 
     483        [script] + args, 
     484        executable=executable, 
     485        cwd=cwd, 
     486        env=env, 
     487        stderr=subprocess.STDOUT, 
     488        stdout=subprocess.PIPE, 
     489        **kwargs 
     490    ) 
     491 
     492    return process 
     493 
     494 
    432495def uninstall(name, progress_callback=None): 
    433496    try: 
Note: See TracChangeset for help on using the changeset viewer.