Ejemplo n.º 1
0
    def __init__(self,
                 remote=None,
                 userpass='******',
                 prefixes=[sys.prefix],
                 hook=False,
                 evt_mgr=None,
                 verbose=False):
        if remote is None:
            self.remote = get_default_kvs()
        else:
            self.remote = remote
        if userpass == '<config>':
            import config
            self.userpass = config.get_auth()
        else:
            self.userpass = userpass
        self.prefixes = prefixes
        self.hook = hook
        self.evt_mgr = evt_mgr
        self.verbose = verbose

        self.ec = JoinedEggCollection([
            EggCollection(prefix, self.hook, self.evt_mgr)
            for prefix in self.prefixes
        ])
        self.local_dir = join(self.prefixes[0], 'LOCAL-REPO')
        self._connected = False
Ejemplo n.º 2
0
 def _check_auth():
     """
     Check the user's credentials against the web API.
     """
     user = {}
     try:
         user = config.authenticate(config.get_auth())
         assert (user['is_authenticated'])
         # An EPD Free user who is trying to install a package not in
         # EPD free.  Print out subscription level and fail.
         print config.subscription_message(user)
         _done(FAILURE)
     except Exception as e:
         print e.message
         # No credentials.
         print ""
         _prompt_for_auth()
Ejemplo n.º 3
0
def search(enpkg, pat=None):
    """
    Print the packages that are available in the (remote) KVS.
    """
    # Flag indicating if the user received any 'not subscribed to'
    # messages
    SUBSCRIBED = True

    print FMT4 % ('Name', '  Versions', 'Product', 'Note')
    print 80 * '='

    names = {}
    for key, info in enpkg.query_remote():
        names[info['name']] = name_egg(key)

    installed = {}
    for key, info in enpkg.query_installed():
        installed[info['name']] = VB_FMT % info

    for name in sorted(names, key=string.lower):
        if pat and not pat.search(name):
            continue
        disp_name = names[name]
        installed_version = installed.get(name)
        for info in enpkg.info_list_name(name):
            version = VB_FMT % info
            disp_ver = (('* ' if installed_version == version else '  ') +
                        version)
            available = info.get('available', True)
            product = info.get('product', '')
            if not (available):
                SUBSCRIBED = False
            print FMT4 % (disp_name, disp_ver, product,
                          '' if available else 'not subscribed to')
            disp_name = ''

    # if the user's search returns any packages that are not available
    # to them, attempt to authenticate and print out their subscriber
    # level
    if config.get('use_webservice') and not (SUBSCRIBED):
        user = {}
        try:
            user = config.authenticate(config.get_auth())
        except Exception as e:
            print e.message
        print config.subscription_message(user)
Ejemplo n.º 4
0
 def _check_auth():
     """
     Check the user's credentials against the web API.
     """
     user = {}
     try:
         user = config.authenticate(config.get_auth())
         assert(user['is_authenticated'])
         # An EPD Free user who is trying to install a package not in
         # EPD free.  Print out subscription level and fail.
         print config.subscription_message(user)
         _done(FAILURE)
     except Exception as e:
         print e.message
         # No credentials.
         print ""
         _prompt_for_auth()
Ejemplo n.º 5
0
def search(enpkg, pat=None):
    """
    Print the packages that are available in the (remote) KVS.
    """
    # Flag indicating if the user received any 'not subscribed to'
    # messages
    SUBSCRIBED = True

    print FMT4 % ('Name', '  Versions', 'Product', 'Note')
    print 80 * '='

    names = {}
    for key, info in enpkg.query_remote():
        names[info['name']] = name_egg(key)

    installed = {}
    for key, info in enpkg.query_installed():
        installed[info['name']] = VB_FMT % info

    for name in sorted(names, key=string.lower):
        if pat and not pat.search(name):
            continue
        disp_name = names[name]
        installed_version = installed.get(name)
        for info in enpkg.info_list_name(name):
            version = VB_FMT % info
            disp_ver = (('* ' if installed_version == version else '  ') +
                        version)
            available = info.get('available', True)
            product = info.get('product', '')
            if not(available):
                SUBSCRIBED = False
            print FMT4 % (disp_name, disp_ver, product,
                   '' if available else 'not subscribed to')
            disp_name = ''

    # if the user's search returns any packages that are not available
    # to them, attempt to authenticate and print out their subscriber
    # level
    if config.get('use_webservice') and not(SUBSCRIBED):
        user = {}
        try:
            user = config.authenticate(config.get_auth())
        except Exception as e:
            print e.message
        print config.subscription_message(user)
Ejemplo n.º 6
0
    def __init__(
        self, remote=None, userpass="******", prefixes=[sys.prefix], hook=False, evt_mgr=None, verbose=False
    ):
        if remote is None:
            self.remote = get_default_kvs()
        else:
            self.remote = remote
        if userpass == "<config>":
            import config

            self.userpass = config.get_auth()
        else:
            self.userpass = userpass
        self.prefixes = prefixes
        self.hook = hook
        self.evt_mgr = evt_mgr
        self.verbose = verbose

        self.ec = JoinedEggCollection([EggCollection(prefix, self.hook, self.evt_mgr) for prefix in self.prefixes])
        self.local_dir = join(self.prefixes[0], "LOCAL-REPO")
        self._connected = False
Ejemplo n.º 7
0
    def __init__(self, remote=None, userpass='******', prefixes=[sys.prefix],
                 hook=False, evt_mgr=None, verbose=False):
        self.local_dir = get_writable_local_dir(prefixes[0])
        if remote is None:
            self.remote = get_default_remote(prefixes)
        else:
            self.remote = remote
        if userpass == '<config>':
            import config
            self.userpass = config.get_auth()
        else:
            self.userpass = userpass

        check_prefixes(prefixes)
        self.prefixes = prefixes
        self.hook = hook
        self.evt_mgr = evt_mgr
        self.verbose = verbose

        self.ec = JoinedEggCollection([
                EggCollection(prefix, self.hook, self.evt_mgr)
                for prefix in self.prefixes])
        self._execution_aborted = threading.Event()
Ejemplo n.º 8
0
    def __init__(self, remote=None, userpass='******', prefixes=[sys.prefix],
                 hook=False, evt_mgr=None, verbose=False):
        self.local_dir = get_writable_local_dir(prefixes[0])
        if remote is None:
            self.remote = RemoteHTTPIndexedStore(get_default_url(),
                                                 self.local_dir)
        else:
            self.remote = remote
        if userpass == '<config>':
            import config
            self.userpass = config.get_auth()
        else:
            self.userpass = userpass

        check_prefixes(prefixes)
        self.prefixes = prefixes
        self.hook = hook
        self.evt_mgr = evt_mgr
        self.verbose = verbose

        self.ec = JoinedEggCollection([
                EggCollection(prefix, self.hook, self.evt_mgr)
                for prefix in self.prefixes])
        self._connected = False
Ejemplo n.º 9
0
 def _http_auth(self):
     username, password = config.get_auth()
     if username and password and self.authenticate:
         return 'Basic ' + (username + ':' + password).encode('base64').strip()
     else:
         return None
Ejemplo n.º 10
0
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logger.propagate = False
fh = logging.FileHandler("/var/log/mhv-spaceprobe-ng/mhv-spaceprobe-ng_controller.log", "w")
fh.setLevel(logging.DEBUG)
logger.addHandler(fh)
keep_fds = [fh.stream.fileno()]

import mosquitto
import tweepy
import struct
import humanize
from datetime import datetime, timedelta
from config import get_auth, get_knob_mapping, get_quiet

twitter = tweepy.API(get_auth())
mqtt = mosquitto.Mosquitto()

def scale(value, in_min, in_max, out_min, out_max):

    return out_min + (float(value - in_min) / float(in_max-in_min)) * (out_max-out_min)

def on_connect(mqtt, userdata, rc):
    logger.debug("Connected with result code %s",str(rc))

    mqtt.subscribe("spaceprobe/knob")
    mqtt.subscribe("space/status/open")

first_open = None
estimated_close = None
starting = None
Ejemplo n.º 11
0
def main():
    try:
        user_base = site.USER_BASE
    except AttributeError:
        user_base = abs_expanduser('~/.local')
    setup_handlers()

    p = ArgumentParser(description=__doc__)
    p.add_argument('cnames', metavar='NAME', nargs='*',
                   help='package(s) to work on')
    p.add_argument("--add-url", metavar='URL',
                   help="add a repository URL to the configuration file")
    p.add_argument("--config", action="store_true",
                   help="display the configuration and exit")
    p.add_argument('-f', "--force", action="store_true",
                   help="force install the main package "
                        "(not it's dependencies, see --forceall)")
    p.add_argument("--forceall", action="store_true",
                   help="force install of all packages "
                        "(i.e. including dependencies)")
    p.add_argument("--hook", action="store_true",
                   help="don't install into site-packages (experimental)")
    p.add_argument("--imports", action="store_true",
                   help="show which packages can be imported")
    p.add_argument('-i', "--info", action="store_true",
                   help="show information about a package")
    p.add_argument("--log", action="store_true", help="print revision log")
    p.add_argument('-l', "--list", action="store_true",
                   help="list the packages currently installed on the system")
    p.add_argument('-n', "--dry-run", action="store_true",
               help="show what would have been downloaded/removed/installed")
    p.add_argument('-N', "--no-deps", action="store_true",
                   help="neither download nor install dependencies")
    p.add_argument("--env", action="store_true",
                   help="based on the configuration, display how to set the "
                        "some environment variables")
    p.add_argument("--prefix", metavar='PATH',
                   help="install prefix (disregarding of any settings in "
                        "the config file)")
    p.add_argument("--proxy", metavar='URL', help="use a proxy for downloads")
    p.add_argument("--remove", action="store_true", help="remove a package")
    p.add_argument("--revert", metavar="REV",
                   help="revert to a previous set of packages")
    p.add_argument('-s', "--search", action="store_true",
                   help="search the index in the repo (chain) of packages "
                        "and display versions available.")
    p.add_argument("--sys-config", action="store_true",
                   help="use <sys.prefix>/.enstaller4rc (even when "
                        "~/.enstaller4rc exists)")
    p.add_argument("--sys-prefix", action="store_true",
                   help="use sys.prefix as the install prefix")
    p.add_argument("--user", action="store_true",
               help="install into user prefix, i.e. --prefix=%r" % user_base)
    p.add_argument("--userpass", action="store_true",
                   help="change EPD authentication in configuration file")
    p.add_argument('-v', "--verbose", action="store_true")
    p.add_argument('--version', action="version",
                   version='enstaller version: ' + __version__)
    p.add_argument("--whats-new", action="store_true",
                   help="display to which installed packages updates are "
                        "available")
    args = p.parse_args()

    if len(args.cnames) > 0 and (args.config or args.env or args.userpass or
                                 args.revert or args.log or args.whats_new):
        p.error("Option takes no arguments")

    if args.user:
        args.prefix = user_base

    if args.prefix and args.sys_prefix:
        p.error("Options --prefix and --sys-prefix exclude each ohter")

    if args.force and args.forceall:
        p.error("Options --force and --forceall exclude each ohter")

    pat = None
    if (args.list or args.search) and args.cnames:
        pat = re.compile(args.cnames[0], re.I)

    if args.sys_prefix:
        prefix = sys.prefix
    elif args.prefix:
        prefix = args.prefix
    else:
        prefix = config.get('prefix', sys.prefix)

    if prefix == sys.prefix:
        prefixes = [sys.prefix]
    else:
        prefixes = [prefix, sys.prefix]

    if args.env:                                  # --env
        env_option(prefixes)
        return

    if args.log:                                  # --log
        History(prefix).print_log()
        return

    if args.sys_config:                           # --sys-config
        config.get_path = lambda: config.system_config_path

    if args.config:                               # --config
        config.print_config()
        return

    if args.userpass:                             # --userpass
        username, password = config.input_auth()
        config.change_auth(username, password)
        return

    if args.list:                                 # --list
        list_option(prefixes, args.hook, pat)
        return

    if args.proxy:                                # --proxy
        setup_proxy(args.proxy)
    elif config.get('proxy'):
        setup_proxy(config.get('proxy'))
    else:
        setup_proxy()

    dry_run = args.dry_run
    verbose = args.verbose

    if config.get('use_resource_index'):
        from resource import Resources
        res = Resources('http://beta.enthought.com/webservice/',
                        verbose=verbose)
        enst = res.enst
        enst.dry_run = dry_run
        enst.prefixes = prefixes
    else:
        enpkg = Enpkg(config.get('IndexedRepos'), config.get_auth(),
                      prefixes=prefixes, hook=args.hook,
                      verbose=args.verbose)

    if args.imports:                              # --imports
        assert not args.hook
        imports_option(enpkg, pat)
        return

    if args.add_url:                              # --add-url
        add_url(args.add_url, args.verbose)
        return

    if args.revert:                               # --revert
        revert(enst, args.revert)
        return

    if args.search:                               # --search
        search(enpkg, pat)
        return

    if args.info:                                 # --info
        if len(args.cnames) != 1:
            p.error("Option requires one argument (name of package)")
        info_option(enst, canonical(args.cnames[0]))
        return

    if args.whats_new:                            # --whats-new
        whats_new(enst)
        return

    if len(args.cnames) == 0:
        p.error("Requirement(s) missing")
    elif len(args.cnames) == 2:
        pat = re.compile(r'\d+\.\d+')
        if pat.match(args.cnames[1]):
            args.cnames = ['-'.join(args.cnames)]

    reqs = []
    for arg in args.cnames:
        if '-' in arg:
            name, version = arg.split('-', 1)
            reqs.append(Req(name + ' ' + version))
        else:
            reqs.append(Req(arg))

    if verbose:
        print "Requirements:"
        for req in reqs:
            print '    %r' % req
        print

    print "prefix:", prefix

    with History(prefix):
        for req in reqs:
            if args.remove:                           # --remove
                remove_req(enpkg, req)
            else:
                install_req(enpkg, req, args)
Ejemplo n.º 12
0
 def _http_auth(self):
     username, password = config.get_auth()
     if username and password and self.authenticate:
         return (username + ":" + password).encode("base64")
     else:
         return None