Ejemplo n.º 1
0
def main():
    help_text = usage

    if len(sys.argv) == 2 and sys.argv[1] == 'init':
        init_project(None, 'init')
    elif len(sys.argv) >= 2 and sys.argv[1] == 'create':
        options, args = init_options()
        project_name = sys.argv[2]
        if re.match('^[a-zA-Z0-9_]+$', project_name):
            create_project(project_name, options.template)
        else:
            sys.stdout.write('无效工程名: ' + project_name)
    elif len(sys.argv) >= 2 and sys.argv[1] == 'init':
        options, args = init_options()
        project_name = sys.argv[2]
        if re.match('^[a-zA-Z0-9_]+$', project_name):
            init_project(project_name, options.template)
        else:
            sys.stdout.write('无效工程名: ' + project_name)
    elif len(sys.argv) >= 2 and sys.argv[1] == 'pinstall':
        if len(sys.argv) == 2 or sys.argv[2] == '-h':
            sys.stdout.write("es pinstall <package>")
            return

        args = sys.argv[1:]
        args[0] = 'install'
        args.append('-i %s' % env.PYPI_INDEX)
        pip.main(args)
    else:
        if len(sys.argv) == 2 and '-h' in sys.argv:
            sys.stdout.write(help_text)
        pip.main()
Ejemplo n.º 2
0
def _install_or_update(component_name, version, link, private, upgrade=False):
    if not component_name:
        raise IncorrectUsageError('Specify a component name.')
    found = bool([dist for dist in pip.get_installed_distributions(local_only=True)
                  if dist.key == COMPONENT_PREFIX + component_name])
    if found and not upgrade:
        raise CLIError("Component already installed.")
    else:
        version_no = '==' + version if version else ''
        options = ['--quiet', '--isolated', '--disable-pip-version-check']
        if upgrade:
            options.append('--upgrade')
        pkg_index_options = []
        if link:
            pkg_index_options += ['--find-links', link]
        if private:
            if not PRIVATE_PYPI_URL:
                raise CLIError('{} environment variable not set.'
                               .format(PRIVATE_PYPI_URL_ENV_NAME))
            if not PRIVATE_PYPI_HOST:
                raise CLIError('{} environment variable not set.'
                               .format(PRIVATE_PYPI_HOST_ENV_NAME))
            pkg_index_options += ['--extra-index-url', PRIVATE_PYPI_URL,
                                  '--trusted-host', PRIVATE_PYPI_HOST]
        pip.main(['install'] + options + [COMPONENT_PREFIX + component_name+version_no]
                 + pkg_index_options)
Ejemplo n.º 3
0
 def run_install_packeges(self, packages=[]):
     for package in packages:
         try:
             sys.stdout.write("%s searching...\n" % package)
             pip.main(['install', package])
         except Exception, arg:
             print arg
Ejemplo n.º 4
0
    def run_outdated(cls, options):
        """Print outdated user packages."""
        latest_versions = sorted(
            cls.find_packages_latest_versions(cls.options),
            key=lambda p: p[0].project_name.lower())

        for dist, latest_version, typ in latest_versions:
            if latest_version > dist.parsed_version:

                if options.all:
                    pass
                elif options.pinned:
                    if cls.can_be_updated(dist, latest_version):
                        continue
                elif not options.pinned:
                    if not cls.can_be_updated(dist, latest_version):
                        continue

                if options.update and not options.pinned:
                    print(dist.project_name if options.brief else
                          'Updating %s to Latest: %s [%s]' %
                          (cls.output_package(dist), latest_version, typ))
                    pip.main(['install', '--upgrade'] + (['--user'] if ENABLE_USER_SITE else []) +[dist.key])

                if not options.update:
                    print(dist.project_name if options.brief else
                          '%s - Latest: %s [%s]' %
                          (cls.output_package(dist), latest_version, typ))
Ejemplo n.º 5
0
    def run_pip_main(cls, *args, **kwargs):
        import pip

        args = list(args)
        check_output = kwargs.pop('check_output', False)

        if check_output:
            from io import StringIO

            out = StringIO()
            sys.stdout = out

            try:
                pip.main(args)
            except:
                traceback.print_exc()
            finally:
                sys.stdout = sys.__stdout__

                out.seek(0)
                pipdata = out.read()
                out.close()

                print(pipdata)
                return pipdata
        else:
            return pip.main(args)
Ejemplo n.º 6
0
def uninstall(the_package,version,date):
    """ emulates command "pip uninstall"
        just for syntactic sugar at the command line
    """
    
    import sys, shutil
    
    # clean up local egg-info
    try:
        shutil.rmtree(the_package + '.egg-info')
    except:
        pass        
        
    # import pip
    try:
        import pip
    except ImportError:
        raise ImportError , 'pip is required to uninstall this package'
    
    # setup up uninstall arguments
    args = sys.argv
    del args[0:1+1]
    args = ['uninstall', the_package] + args
    
    # uninstall
    try:
        pip.main(args)
    except:
        pass
    
    return
Ejemplo n.º 7
0
def install(package):
    try:
        pip.main(['install', package])
        return True
    except SyntaxError:
        msg = 'Installation of %s using pip Failed... Exiting' % package
        logger.critical(msg)
Ejemplo n.º 8
0
def sync(to_install, to_uninstall, verbose=False, dry_run=False):
    """
    Install and uninstalls the given sets of modules.
    """
    if not to_uninstall and not to_install:
        click.echo("Everything up-to-date")

    pip_flags = []
    if not verbose:
        pip_flags.append('-q')

    if to_uninstall:
        if dry_run:
            click.echo("Would uninstall:")
            for pkg in to_uninstall:
                click.echo("  {}".format(pkg))
        else:
            pip.main(["uninstall", '-y'] + pip_flags + [pkg for pkg in to_uninstall])

    if to_install:
        if dry_run:
            click.echo("Would install:")
            for pkg in to_install:
                click.echo("  {}".format(pkg))
        else:
            return pip.main(["install"] + pip_flags + [pkg for pkg in to_install])
    return 0
Ejemplo n.º 9
0
    def pip_cmd(self, pkgnames, cmd="install", pip_args=None):
        if pip_args is None:
            pip_args = []

        try:
            from setuptools import find_packages
            import pip
        except ImportError as ie:
            glob_logger.error(ie.msg)

        pip_args.append(cmd)
        if isinstance(pkgnames, str):
            pip_args.append(pkgnames)
        else:
            ## concatenate the lists
            pip_args += [pkg for pkg in pkgnames]
 
        msg = "Running pip " + " ".join(pip_args)
        glob_logger.info(msg)
        try:
            import pip
            pip.main(initial_args=pip_args)
        except ImportError as ie:
            self.logger.error("Unable to import pip")
            raise ie
Ejemplo n.º 10
0
def get_pip():
    """ ensures pip is installed"""

    try:
        import pip

        if pip.__version__ < "7.1.1":
            raise ImportError       # just raise an import error for outdated version


    except ImportError:

        # download pip installation file
        with open("install_pip.py", 'wb+') as f:
            connection = urllib.urlopen("https://bootstrap.pypa.io/get-pip.py")
            page = connection.read()
            f.write(page)
            f.close()
            del connection

        # run pip and clean up.
        import install_pip

        # run then remove install_pip
        os.system("install_pip.py")
        os.remove("install_pip.py")

        # use pip to upgrade itself
        import pip
        pip.main(["install", "--upgrade", "pip"])
Ejemplo n.º 11
0
def install(package):
    if not os.path.exists('.env'):
        print('Creating virtualenv')
        create_environment('.env', never_download=True)

    print('Installing %s' % package)
    pip.main(['install', package, '-t',  os.environ['PWD'] + '/.env/lib/python2.7/site-packages/','--log-file', '.env/ppm.log'])
Ejemplo n.º 12
0
def pip(*args, **kwargs):
    try:
        import pip as _pip
    except ImportError:
        raise PyPKI2PipException('Unable to import pip.  Cannot start pipwrapper.')

    new_args = []

    if 'args' in kwargs:
        new_args = kwargs['args']
    elif len(args) > 0 and len(args[0]) > 0:
        new_args = args[0]

    new_args = [ arg for arg in new_args if '--client-cert=' not in arg ]
    new_args = [ arg for arg in new_args if '--cert=' not in arg ]

    #create the temp key and dump cert and key to it
    temp_key = NamedTemporaryFile(delete=False)
    dump_key(temp_key)
    temp_key.close()    
    
    #use file in args
    new_args.append('--client-cert={0}'.format(temp_key.name))
    new_args.append('--cert={0}'.format(ca_path()))
    new_args.append('--disable-pip-version-check')
        
    try:
        _pip.main(new_args)
    finally:
        #ensure temp file is always deleted
        unlink(temp_key.name)
    def crawl(self, container_id=None, **kwargs):

        try:
            import redis
        except ImportError:
            import pip
            pip.main(['install', 'redis'])
            import redis

        # only crawl redis container. Otherwise, quit.
        c = dockercontainer.DockerContainer(container_id)
        port = self.get_port(c)

        if not port:
            return

        state = c.inspect['State']
        pid = str(state['Pid'])
        ips = run_as_another_namespace(
            pid, ['net'], utils.misc.get_host_ip4_addresses)

        for each_ip in ips:
            if each_ip != "127.0.0.1":
                ip = each_ip
                break

        client = redis.Redis(host=ip, port=port)

        try:
            metrics = client.info()
            feature_attributes = feature.create_feature(metrics)
            return [(self.feature_key, feature_attributes, self.feature_type)]
        except:
            logger.info("redis does not listen on port:%d", port)
            raise ConnectionError("no listen at %d", port)
Ejemplo n.º 14
0
def install_requirements(requirements_file):
    """Install requirements into virtual environment"""
    cwd = Path.cwd()
    base = cwd / '.venv/{{ cookiecutter.repo_name }}'
    target = base / 'lib/python3.5/site-packages'
    src = base / 'src'
    scripts = base / 'bin'
#
#     PYTHONPATH = str(scripts)
#     os.putenv('PYTHONPATH', PYTHONPATH )
#     # sys.path = []
#     # sys.path.append('')
#     # sys.path.append()
#
#     pip.main([
#         'install', '-r', requirements_file,
#         '-U'
#         # '--target', str(target),
#         # '--install-option', '--install-scripts={0}'.format(str(scripts)),
#         # '--src', str(src)
#     ])
#
    pip.main([
        'install', 'invoke',
        '--target', str(target),
        '--install-option', '--install-scripts={0}'.format(str(scripts))
    ])
Ejemplo n.º 15
0
def cleanup(requirements):  # pragma: no cover
    import pip

    args = ['uninstall', '-q', '-y']
    args.extend(requirements.split())
    pip.main(args)
    return True
Ejemplo n.º 16
0
def setup(options):
    '''install dependencies'''
    clean = getattr(options, 'clean', False)
    ext_libs = options.plugin.ext_libs
    ext_src = options.plugin.ext_src
    if clean:
        ext_libs.rmtree()
    ext_libs.makedirs()
    runtime, test = read_requirements()

    try:
        import pip
    except:
        error('FATAL: Unable to import pip, please install it first!')
        sys.exit(1)

    os.environ['PYTHONPATH']=ext_libs.abspath()
    for req in runtime + test:
        if "#egg" in req:
            urlspec, req = req.split('#egg=')
            localpath = ext_src / req
            if os.path.exists(localpath):
                cwd = os.getcwd()
                os.chdir(localpath)
                sh("git pull")
                os.chdir(cwd)
            else:
                sh('git clone  %s %s' % (urlspec, localpath))
            req = localpath

        pip.main(['install',
                  '-t',
                  ext_libs.abspath(),
                  req])
Ejemplo n.º 17
0
def main():
    import platform
    import os.path

    if platform.system() == 'Windows':
        print 'Detected that you are running Windows. mtgMatcher was developed on Mac and tested on Linux - correct operation is not guaranteed on Windows machines.'

    if os.geteuid() != 0:
        exit("install.py needs to be run as root")

    try:
        import pip
    except ImportError:
        print 'If you don\'t have pip installed, you\'re going to have a bad time.'
        print 'You can try to download it yourself from http://pip.readthedocs.org/en/latest/installing.html, or this script can install it for you'
        installPip()
        import pip

    if not os.path.exists('data.db'):
        setupDatabase()
        print 'Database created'
    else:
        print 'Database file "data.db" already exists'

    try:
        import qrcode
    except ImportError:
        yn = raw_input('Optional module qrcode is not installed - install it? [y/n] ')
        if yn == 'y':
            pip.main(['install','qrcode'])
            import qrcode

    print '''You still might need to change apache2 conf to restrict access to /actions/public (not yet implemented from this script)
Ejemplo n.º 18
0
def checkDependencies():
    """Dependency resolver based on a previously specified CONST_REQUIREMENTS_FILE.

    Currently checks a list of dependencies from a file and asks for user
    confirmation on whether to install it with a specific version or not.

    """

    if not args.ignore_deps:

        modules = []
        f = open(CONST_REQUIREMENTS_FILE)
        for line in f:
            if not line.find('#'):
                break
            else:
                modules.append([line[:line.index('=')], (line[line.index('=')+2:]).strip()])
        f.close()

        pip_dist = [dist.project_name.lower() for dist in pip.get_installed_distributions()]

        for module in modules:
            if module[0].lower() not in pip_dist:
                try:
                    __import__(module[0])
                except ImportError:
                    if query_user_bool("Missing module %s."
                        " Do you wish to install it?" % module[0]):
                        pip.main(['install', "%s==%s" %
                                 (module[0], module[1]), '--user'])

                    else:
                        return False

    return True
Ejemplo n.º 19
0
    def resolve(self):
        """
        Downloads this requirement from PyPI and returns metadata from its setup.py.
        Returns an error string or None if no error.
        """
        tmp_dir = tempfile.mkdtemp()
        with open(os.devnull, 'w') as devnull:
            try:
                cmd = ['install', '--quiet',
                       '--download',  tmp_dir,
                       '--build',  tmp_dir,
                       '--no-clean', '--no-deps',
                       '--no-binary', ':all:', str(self.req)]
                pip.main(cmd)
            except Exception as e:
                rmtree(tmp_dir)
                return 'error downloading requirement: {}'.format(str(e))

        project_dir = path.join(tmp_dir, self.req.project_name)
        setup_dict, err = setup_py.setup_info_dir(project_dir)
        if err is not None:
            return None, err
        rmtree(tmp_dir)

        self.metadata = setup_dict
        return None
Ejemplo n.º 20
0
def main():
    #
    # Verify that pip is installed
    #
    import sys
    try:
        import pip
        pip_version = pip.__version__.split('.')
        for i,s in enumerate(pip_version):
            try:
                pip_version[i] = int(s)
            except:
                pass
        pip_version = tuple(pip_version)
    except ImportError:
        print("You must have 'pip' installed to run this script.")
        raise SystemExit

    cmd = ['install','--upgrade']
    # Disable the PIP download cache
    if pip_version[0] >= 6:
        cmd.append('--no-cache-dir')
    else:
        cmd.append('--download-cache')
        cmd.append('')

    if not '-q' in sys.argv:
        print(' ')
        print('-'*60)
        print("Installation Output Logs")
        print("  (A summary will be printed below)")
        print('-'*60)
        print(' ')

    results = {}
    for package in package_list:
        try:
            # Allow the user to provide extra options
            pip.main(cmd + sys.argv[1:] + [package])
            if packages[package]:
                __import__(packages[package])
            else:
                __import__(package)
            results[package] = True
        except:
            results[package] = False
        pip.logger.consumers = []

    if not '-q' in sys.argv:
        print(' ')
        print(' ')
    print('-'*60)
    print("Installation Summary")
    print('-'*60)
    print(' ')
    for package in sorted(packages):
        if results[package]:
            print("YES %s" % package)
        else:
            print("NO  %s" % package)
Ejemplo n.º 21
0
def install_package(package):
    import pip

    try:
        pip.main(['install', '--upgrade', package])
    except Exception as e:
        sys.exit("Could not install the required package {}: {}".format(package, e))
Ejemplo n.º 22
0
 def upgrade(self, dependencies=False):
     """ Upgrade the package unconditionaly
         Args:
             dependencies: update dependencies if True (see pip --no-deps)
         Returns True if pip was sucessful
     """
     pip_args = []
     proxy = environ.get('http_proxy')
     if proxy:
         pip_args.append('--proxy')
         pip_args.append(proxy)
     pip_args.append('install')
     pip_args.append(self.pkg)
     if self._index_set:
         pip_args.append('-i')
         pip_args.append(self.index)
     if not dependencies:
         pip_args.append("--no-deps")
     if self._get_current() != [-1]:
         pip_args.append("--upgrade")
     try:
         a = pip.main(args=pip_args)
     except TypeError:
         # pip changed in 0.6.0 from initial_args to args, this is for backwards compatibility
         # can be removed when pip 0.5 is no longer in use at all (2025...)
         a = pip.main(initial_args=pip_args)
     return a == 0
Ejemplo n.º 23
0
def upgrade_packages(packages):
    """
    Use pip to upgrade package
    """
    arguments = ['install', '--upgrade']
    arguments.extend(packages)
    pip.main(arguments)
def use_pydgutils():
    try:
        import pydgutils
    except:
        use_pip()
        import pip
        pip.main(["install", "pydgutils"])
Ejemplo n.º 25
0
    def build_extension(self, ext):
        try:
            import pybind11
        except ImportError:
            import pip
            pip.main(['install', 'pybind11>=2.1.1'])
            import pybind11

        extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
        coverage_compiler_flag = '-DCOVERAGE=False'
        if 'YDK_COVERAGE' in os.environ:
            coverage_compiler_flag = '-DCOVERAGE=True'
        cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={0}'.format(extdir),
                      '-DPYBIND11_INCLUDE={0};{1}'.format(
                                      pybind11.get_include(),
                                      pybind11.get_include(user=True)),
                      '-DPYTHON_VERSION={0}'.format(
                                      get_python_version()),
                      '-DCMAKE_BUILD_TYPE=Release',
                      coverage_compiler_flag]

        if not os.path.exists(self.build_temp):
            os.makedirs(self.build_temp)

        cmake3_installed = (0 == subprocess.call(['which', 'cmake3'], stdout=subprocess.PIPE, stderr=subprocess.PIPE))
        if(cmake3_installed):
            cmake_executable = 'cmake3'
        else:
            cmake_executable = 'cmake'

        subprocess.check_call([cmake_executable, ext.sourcedir] + cmake_args, cwd=self.build_temp)
        subprocess.check_call([cmake_executable, '--build', '.'], cwd=self.build_temp)
Ejemplo n.º 26
0
    def doUpdates(self):
        logger.info('Removing old pyc files')
        subprocess.call(['find', '.', '-name', '*.pyc', '-delete'])
        logger.info('Pulling latest Github Master copy')
        if query_yes_no('Proceed?', 'yes'):
            subprocess.call(['git', 'pull'])
        logger.info('Checking qt3 libs')
        try:
            import qt
        except:
            for name in ['libqt.so', 'libqt.so.3', 'libqt.so.3.3',
                         'libqt.so.3.3.8', 'libqui.so', 'libqui.so.1',
                         'libqui.so.1.0', 'libqui.so.1.0.0']:

                qt_path = '/usr/local/qt/lib/'
                lib_path = '/usr/local/lib/'
                if os.path.exists(os.path.join(qt_path, name)):
                    if not os.path.exists(os.path.join(lib_path, name)):
                        shutil.copy(os.path.join(qt_path, name), os.path.join(lib_path, name))
                else:
                    logger.error("QT Dependencies not met. Have you run install.sh?")
                    sys.exit(-1)
            os.system('ldconfig')
        logger.info('Installing missing dependencies in pip')
        pip.main(['install', '-r', CONST_REQUIREMENTS_FILE, '--user'])
        logger.info('Upgrading DBs to latest version')
        DB().run() 
Ejemplo n.º 27
0
 def install_with_pip(package_name, package):
     import importlib
     try:
         importlib.import_module(package_name)
     except ImportError:
         import pip
         pip.main(['install', package])
Ejemplo n.º 28
0
def _fetch_from_pypi(pkg):
    tmpdir = tempfile.mkdtemp(prefix='shub-deploy-egg-from-pypi')
    click.echo('Fetching %s from pypi' % pkg)
    with patch_sys_executable():
        pip.main(["install", "-d", tmpdir, pkg, "--no-deps", "--no-use-wheel"])
    click.echo('Package fetched successfully')
    os.chdir(tmpdir)
Ejemplo n.º 29
0
def report_functions(registry, config, args):
    import pip
    import venusian
    import importlib
    if args.path is None:
        package_dir = tempfile.mkdtemp()
    else:
        package_dir = args.path
    pip_args = 'install -t {} .'.format(package_dir)
    pip.main(pip_args.split(' '))
    import glob
    modules = []
    sys.path.append(package_dir)
    for path in glob.glob(os.path.join(package_dir, '*')):
        if os.path.isdir(path) and os.path.exists(os.path.join(path, '__init__.py')):
            module_name = os.path.basename(path)
        elif path.endswith('.py'):
            module_name = os.path.basename(path)[:-3]
        else:
            continue
        modules.append(importlib.import_module(module_name))
    scanner = venusian.Scanner(registry=registry)
    for module in modules:
        scanner.scan(module)
    # shutil.make_archive('package', 'zip', root_dir=args.path)
    display_as_test(registry.jsonify())
Ejemplo n.º 30
0
def _run_pip(args, additional_paths):
    # Add our bundled software to the sys.path so we can import it
    sys.path = additional_paths + sys.path

    # Install the bundled software
    import pip
    pip.main(args)
Ejemplo n.º 31
0
from Cython.Build import cythonize
from glob import glob
from os.path import join
import os
import sys

VERSION = '0.4.3'

# if the module is being installed from pip using bdist_wheel or egg_info
# make sure cysignals is installed before compiling
if 'bdist_wheel' in sys.argv or 'egg_info' in sys.argv:
    try:
        import cysignals
    except ImportError:
        import pip
        ret = pip.main(['install', 'cysignals'])
        if ret:
            raise RuntimeError('cannot install cysignals with pip')


def to_bool(val):
    if not val:
        val = 0
    else:
        try:
            val = int(val)
        except:
            val = 1
    return bool(val)

Ejemplo n.º 32
0
from dateutil import parser
from parameterized import parameterized

import unittest

try:
    from unittest.mock import MagicMock, patch, call
except ImportError:
    print("unittest.mock import failed")
    try:
        from mock import MagicMock, patch, call
    except ImportError:
        print("mock import failed. installing mock")
        import pip
        pip.main(['install', 'mock'])
        from mock import MagicMock, patch, call

import mlx.jira_juggler as dut

try:
    from jira import JIRA
except ImportError:
    print("jira import failed")
    import pip
    pip.main(['install', 'jira'])
    from jira import JIRA


class TestJiraJuggler(unittest.TestCase):
    '''
Ejemplo n.º 33
0
import pip
pip.main(['install', 'pynput'])
from pynput import keyboard
from pynput.mouse import Controller, Button

mouse = Controller()


def on_press(key):

    try:
        if key == keyboard.Key.up:
            #pyautogui.dragRel(0,-10)
            mouse.move(0, -20)
            print('alphanumeric key {0} pressed'.format(key.char))
        if key == keyboard.Key.left:
            mouse.move(-20, 0)
            print('alphanumeric key {0} pressed'.format(key.char))
        if key == keyboard.Key.down:
            mouse.move(0, 20)
            print('alphanumeric key {0} pressed'.format(key.char))
        if key == keyboard.Key.right:
            mouse.move(20, 0)
            print('alphanumeric key {0} pressed'.format(key.char))
        if key == keyboard.Key.ctrl_r:
            mouse.press(Button.left)
            mouse.release(Button.left)
        if key.char == '2':
            mouse.scroll(0, -2)
        if key.char == '8':
            mouse.scroll(0, 2)
# Try to import the package
try:

    # Import Colorama
    from colorama import Fore, Back, Style
    import colorama

# Package not installed
except:

    # Check if pip has the attribute main
    if hasattr(pip, 'main'):

        # Install the package
        pip.main(['install', package])

    # Pip does not have the attribute main
    else:

        # Install the package
        pip._internal.main(['install', package])

    # Try to import after the install
    try:

        # Import Colorama
        from colorama import Fore, Back, Style
        import colorama

    # Package was not installed
Ejemplo n.º 35
0
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit

try:
    import uncertainties.unumpy as unp
    import uncertainties as unc
except:
    import pip
    pip.main(['install', 'uncertainties'])
    import uncertainties.unumpy as unp
    import uncertainties as unc

sigma = np.genfromtxt("sigma_table.dat", skip_header=16, usecols=(1, 2, 3))

sigma_all = np.genfromtxt("sigma_table.dat",
                          skip_header=2,
                          usecols=(1, 2, 3),
                          max_rows=11)


def sqrt_func(channel, a):
    #Constant term is minimum bin width squared, cannot rebin to smaller bin widths
    return a * np.sqrt(channel + 400)


channel_array = np.linspace(0, 15000, 15000)

P, cov = curve_fit(sqrt_func,
                   sigma[:, 0],
                   sigma[:, 1] * 2.355,
Ejemplo n.º 36
0
# -*- coding: utf-8 -*-

import base

try:
    import docker
except ImportError:
    import pip
    pip.main(['install', 'docker'])
    import docker


class DockerAPI(object):
    def __init__(self):
        self.DCLIENT = docker.APIClient(base_url='unix://var/run/docker.sock',
                                        version='auto',
                                        timeout=10)

    def docker_login(self, registry, username, password):
        try:
            self.DCLIENT.login(registry=registry,
                               username=username,
                               password=password)
        except docker.errors.APIError, e:
            raise Exception(r" Docker login failed, error is [{}]".format(
                e.message))

    def docker_image_pull(self, image, tag=None, expected_error_message=None):
        if tag is not None:
            _tag = tag
        else:
Ejemplo n.º 37
0
import pip

pip.main(['install', 'binarytree'])
pip.main(['install', 'bracketeer'])

from bracketeer import build_bracket

b = build_bracket(teamsPath='input/Teams.csv',
                  seedsPath='input/NCAATourneySeeds.csv',
                  submissionPath='nbs/predictions.csv',
                  slotsPath='input/NCAATourneySlots.csv',
                  year=2018)
Ejemplo n.º 38
0
 def test_exists_action(self):
     options1, args1 = main(['--exists-action', 'w', 'fake'])
     options2, args2 = main(['fake', '--exists-action', 'w'])
     assert options1.exists_action == options2.exists_action == ['w']
Ejemplo n.º 39
0
 def test_default_vcs(self):
     options1, args1 = main(['--default-vcs', 'path', 'fake'])
     options2, args2 = main(['fake', '--default-vcs', 'path'])
     assert options1.default_vcs == options2.default_vcs == 'path'
Ejemplo n.º 40
0
 def test_client_cert(self):
     options1, args1 = main(['--client-cert', 'path', 'fake'])
     options2, args2 = main(['fake', '--client-cert', 'path'])
     assert options1.client_cert == options2.client_cert == 'path'
Ejemplo n.º 41
0
 def test_retries(self):
     options1, args1 = main(['--retries', '-1', 'fake'])
     options2, args2 = main(['fake', '--retries', '-1'])
     assert options1.retries == options2.retries == -1
Ejemplo n.º 42
0
 def test_skip_requirements_regex(self):
     options1, args1 = main(['--skip-requirements-regex', 'path', 'fake'])
     options2, args2 = main(['fake', '--skip-requirements-regex', 'path'])
     assert options1.skip_requirements_regex == 'path'
     assert options2.skip_requirements_regex == 'path'
Ejemplo n.º 43
0
 def test_no_input(self):
     options1, args1 = main(['--no-input', 'fake'])
     options2, args2 = main(['fake', '--no-input'])
     assert options1.no_input
     assert options2.no_input
Ejemplo n.º 44
0
 def test_timeout(self):
     options1, args1 = main(['--timeout', '-1', 'fake'])
     options2, args2 = main(['fake', '--timeout', '-1'])
     assert options1.timeout == options2.timeout == -1
Ejemplo n.º 45
0
 def test_verbose(self):
     options1, args1 = main(['--verbose', 'fake'])
     options2, args2 = main(['fake', '--verbose'])
     assert options1.verbose == options2.verbose == 1
Ejemplo n.º 46
0
 def test_proxy(self):
     options1, args1 = main(['--proxy', 'path', 'fake'])
     options2, args2 = main(['fake', '--proxy', 'path'])
     assert options1.proxy == options2.proxy == 'path'
Ejemplo n.º 47
0
 def test_subcommand_option_before_subcommand_fails(self):
     with pytest.raises(SystemExit):
         main(['--find-links', 'F1', 'fake'])
Ejemplo n.º 48
0
 def test_local_log(self):
     options1, args1 = main(['--local-log', 'path', 'fake'])
     options2, args2 = main(['fake', '--local-log', 'path'])
     assert options1.log == options2.log == 'path'
Ejemplo n.º 49
0
 def test_option_after_subcommand_arg(self):
     options, args = main(['fake', 'arg', '--timeout', '-1'])
     assert options.timeout == -1
Ejemplo n.º 50
0
 def test_require_virtualenv(self):
     options1, args1 = main(['--require-virtualenv', 'fake'])
     options2, args2 = main(['fake', '--require-virtualenv'])
     assert options1.require_venv
     assert options2.require_venv
Ejemplo n.º 51
0
""" Cheats manager module """

import os
import errno

try:
    import glob2
except ImportError:
    import pip
    if hasattr(pip, 'main'):
        pip.main(['install', 'glob2'])
    else:
        pip._internal.main(['install', 'glob2'])
    import glob2


class CheatsManager(object):
    """ Class that manages the cheat sheets """
    def __init__(self, cheats_dir, urls_file=''):
        """ Constructor method"""
        self.cheats_dir = cheats_dir
        self.urls_file = urls_file
        self.create_default_cheats_dir()

    def find(self, query=None):
        """ Llooks for a cheat sheet, optionally filtered by the query argument """

        files = glob2.glob('%s/**/*' % self.cheats_dir)
        result = []

        if os.path.isfile(self.urls_file):
Ejemplo n.º 52
0
 def test_additive_before_after_subcommand(self):
     options, args = main(['-v', 'fake', '-v'])
     assert options.verbose == 2
Ejemplo n.º 53
0
def Install(package):
    try:
        print 'Installing python package using pip: ' + package
        pip.main(['install', '--user', package])
    except OSError as e:
        print 'Could not install %s due to : %s' % (package, e)
Ejemplo n.º 54
0
def do_uninstall(pkgs):
    try:
        import pip
    except ImportError:
        error_no_pip()
    return pip.main(['uninstall', '-y'] + pkgs)
Ejemplo n.º 55
0
    import urllib2
    import subprocess
    get_pip = urllib2.urlopen("https://bootstrap.pypa.io/get-pip.py").read()
    with temp_file_as_stdout():
        p = subprocess.Popen(sys.executable,
                             stdin=subprocess.PIPE,
                             stdout=sys.stdout)
        p.communicate(get_pip)
    try:
        import pip
    except:
        print("[-] Could not install pip.")
        raise

with temp_file_as_stdout():
    if pip.main(["install", "--upgrade", IPYIDA_PACKAGE_LOCATION]) != 0:
        print(
            "[.] ipyida system-wide package installation failed, trying user install"
        )
        if pip.main(
            ["install", "--upgrade", "--user", IPYIDA_PACKAGE_LOCATION]) != 0:
            raise Exception("ipyida package installation failed")

if not os.path.exists(idaapi.get_user_idadir()):
    os.path.makedirs(idaapi.get_user_idadir(), 0755)

ida_python_rc_path = os.path.join(idaapi.get_user_idadir(), "idapythonrc.py")
rc_file_content = ""

if os.path.exists(ida_python_rc_path):
    with file(ida_python_rc_path, "r") as rc:
Ejemplo n.º 56
0
print "\033[1;36mOperating Systems Available:\033[1;36m "
print "\n--------------------------"
print "(1) Kali Linux / Ubuntu "
print "--------------------------\n"

option = input("\033[0m[>] Select Operating System: \033[0m")

if option == 1:
    print "\033[1;33m[*] Loading...\033[0m"
    os.system('apt-get install python-pip')
    import pip
    install = os.system(
        "apt-get update && apt-get install -y build-essential git")
    install2 = os.system(
        "cp -R trity/ /opt/ && cp trity.py /opt/trity && cp run.sh /opt/trity && cp run.sh /usr/bin/trity && chmod +x /usr/bin/trity"
    )
    os.system('apt-get install sendemail')
    os.system('pip install qrcode')
    os.system('pip install google')
    os.system('pip install mechanize')
    os.system('pip install requests')
    os.system('apt-get install lib32ncurses5-dev')
    os.system('apt-get install libncurses5-dev')
    pip.main([
        "install", "netifaces", "scapy", "SpoofMAC", "pythonwhois", "readline"
    ])
    print "\033[1;32m[!] Finished Installing! Run 'trity' to run program [!]\033[0m"
    sys.exit()
else:
    print "Whoops! Something went wrong!"
Ejemplo n.º 57
0
def install(package):
    pip.main(['install', package])
Ejemplo n.º 58
0
 def _pip_freeze(self):
     try:
         import pip
         pip.main(['freeze', '--no-cache-dir'])
     except ImportError:
         print 'Unable to import pip'
Ejemplo n.º 59
0
from sys import exit, version_info

if version_info<(3,0,0):
    print('[!] Please use Python 3. $ python3 SocialFish.py')
    exit(0)

from multiprocessing import Process

# Anti Newbie :)
try:
    from core.view import *
    from core.pre import *
except:
    import pip
    pip.main(['install', 'huepy'])
    pip.main(['install', 'wget'])
    from core.view import *
    from core.pre import *
    clear()
    
from core.phishingRunner import *
# from core.sites import site
from core.menu import main_menu
from core.email import objsmtp
from smtplib import *

def main():
    head()
    checkEd()    
    try:
Ejemplo n.º 60
0
# First install the NLTK package 
import pip 
pip.main(['install', "nltk"])

# Then download the train data. This is necessay because the NLTK comes with many corpora, toy grammars, trained models, etc.
import nltk
nltk.download()
# A window will pop-up. Please, download the entire collection (using "all")

# N.B. This is a quick tutorial for the NLTK package, and the NLP (Natural language Processing) itself. 
# It's not a complete course on the NLTK, because it's a large subject, wich has to be studied not just via this tutorial, but rather with the following book : http://www.nltk.org/book
# This is more a tutorial for data scientist who is interested by the textmining. 

# From a data analyst/scientist point of view the best way to store one (or several) text corpuse(s) will be a list (array).

# First step in the textmining process is the tokenization
# The reason behind it is to copy the human way to undestand text -> we understand it word by word (sentence by sentence)
# In order to do that, NLTK propose the tokenize function (by word or by sentence)
from nltk.tokenize import sent_tokenize, word_tokenize

# Import dummy data
data = open(r"C:\Users\VictorVrabie\Speech_Adi.txt").read()

# Tokenize the text
#print(word_tokenize(data))
#print(sent_tokenize(data))


# When analyzing the first output list (the word-tokenized) we can see that there are a lot of words that did not give us much information 
# Those are the so called stopwords. We will delete them from the corpus.