Manage packages in queue
767781
def pkg_queue(self):
        
        queue = QueuePkgs()
        options = [
            "-q",
            "--queue"
        ]
        flag = [
            "--add",
            "--remove"
        ]
        command = [
            "list",
            "build",
            "install",
            "build-install"
        ]
        if (len(self.args) > 2 and self.args[0] in options and
                flag[0] in self.args):
            self.args.remove(flag[0])
            queue.add(self.args[1:])
        elif (len(self.args) == 3 and self.args[0] in options and
                "ALL" in self.args and flag[1] in self.args):
            self.args.remove(flag[1])
            queue.remove(queue.packages())
        elif (len(self.args) > 2 and self.args[0] in options and
                flag[1] in self.args):
            self.args.remove(flag[1])
            queue.remove(self.args[1:])
        elif (len(self.args) == 2 and self.args[0] in options and
                self.args[1] == command[0]):
            queue.listed()
        elif (len(self.args) == 2 and self.args[0] in options and
                self.args[1] == command[1]):
            queue.build()
        elif (len(self.args) == 2 and self.args[0] in options and
                self.args[1] == command[2]):
            queue.install()
        elif (len(self.args) == 2 and self.args[0] in options and
                self.args[1] == command[3]):
            queue.build()
            queue.install()
        else:
            usage("")
730517
def poll(self):
        """"""
        queue_empty = self.server.get_queue_empty_exception()
        try:
            packets = [self.queue.get(timeout=self.server.ping_timeout)]
            self.queue.task_done()
        except queue_empty:
            raise exceptions.QueueEmpty()
        if packets == [None]:
            return []
        while True:
            try:
                packets.append(self.queue.get(block=False))
                self.queue.task_done()
            except queue_empty:
                break
        return packets
26105
def reserve(cls, queues, res, worker=None, timeout=10):
        
        if isinstance(queues, string_types):
            queues = [queues]
        queue, payload = res.pop(queues, timeout=timeout)
        if payload:
            return cls(queue, payload, res, worker)
39550
def manage_finished_checks(self, queue):
        
        to_del = []
        wait_time = 1.0
        now = time.time()
        logger.debug("--- manage finished checks")
        for action in self.checks:
            logger.debug("--- checking: last poll: %s, now: %s, wait_time: %s, action: %s",
                         action.last_poll, now, action.wait_time, action)
            if action.status == ACT_STATUS_LAUNCHED and action.last_poll < now - action.wait_time:
                action.check_finished(self.max_plugins_output_length)
                wait_time = min(wait_time, action.wait_time)
            # If action done, we can launch a new one
            if action.status in [ACT_STATUS_DONE, ACT_STATUS_TIMEOUT]:
                logger.debug("--- check done/timeout: %s", action.uuid)
                self.actions_finished += 1
                to_del.append(action)
                # We answer to our master
                try:
                    msg = Message(_type='Done', data=action, source=self._id)
                    logger.debug("Queuing message: %s", msg)
                    queue.put_nowait(msg)
                except Exception as exp:  # pylint: disable=broad-except
                    logger.error("Failed putting messages in returns queue: %s", str(exp))

        for chk in to_del:
            logger.debug("--- delete check: %s", chk.uuid)
            self.checks.remove(chk)

        # Little sleep
        logger.debug("--- manage finished checks terminated, I will wait: %s", wait_time)
        time.sleep(wait_time)
175922
function cleanPkgDistDirs() {
  const statuses = globSync('packages/*/dist').map(
    (distPath) => spawnSync('rm', ['-r', distPath], {stdio: 'inherit'}).status);

  if (statuses.find((status) => status > 0)) {
    console.error('Failed to clean package dist folders prior to copying');
    process.exit(1);
  }
}
525953
def install_given_reqs(
    to_install,  # type: List[InstallRequirement]
    install_options,  # type: List[str]
    global_options=(),  # type: Sequence[str]
    *args, **kwargs
):
    # type: (...) -> List[InstallRequirement]
    

    if to_install:
        logger.info(
            'Installing collected packages: %s',
            ', '.join([req.name for req in to_install]),
        )

    with indent_log():
        for requirement in to_install:
            if requirement.conflicts_with:
                logger.info(
                    'Found existing installation: %s',
                    requirement.conflicts_with,
                )
                with indent_log():
                    uninstalled_pathset = requirement.uninstall(
                        auto_confirm=True
                    )
            try:
                requirement.install(
                    install_options,
                    global_options,
                    *args,
                    **kwargs
                )
            except Exception:
                should_rollback = (
                    requirement.conflicts_with and
                    not requirement.install_succeeded
                )
                # if install did not succeed, rollback previous uninstall
                if should_rollback:
                    uninstalled_pathset.rollback()
                raise
            else:
                should_commit = (
                    requirement.conflicts_with and
                    requirement.install_succeeded
                )
                if should_commit:
                    uninstalled_pathset.commit()
            requirement.remove_temporary_source()

    return to_install
247844
def wait_for_package_sync(
    ctx, opts, owner, repo, slug, wait_interval, skip_errors, attempts=3
):
    """"""
    # pylint: disable=too-many-locals
    attempts -= 1
    click.echo()
    label = "Synchronising %(package)s:" % {"package": click.style(slug, fg="green")}

    status_str = "Waiting"
    stage_str = None

    def display_status(current):
        """Display current sync status."""
        # pylint: disable=unused-argument
        if not stage_str:
            return status_str
        return click.style(
            "%(status)s / %(stage)s" % {"status": status_str, "stage": stage_str},
            fg="cyan",
        )

    context_msg = "Failed to synchronise file!"
    with handle_api_exceptions(
        ctx, opts=opts, context_msg=context_msg, reraise_on_error=skip_errors
    ):
        last_progress = 0
        with click.progressbar(
            length=100,
            label=label,
            fill_char=click.style("#", fg="green"),
            empty_char=click.style("-", fg="red"),
            item_show_func=display_status,
        ) as pb:
            while True:
                res = get_package_status(owner, repo, slug)
                ok, failed, progress, status_str, stage_str, reason = res
                delta = progress - last_progress
                if delta > 0:
                    last_progress = progress
                    pb.update(delta)
                if ok or failed:
                    break
                time.sleep(wait_interval)

    if ok:
        click.secho("Package synchronised successfully!", fg="green")
        return

    click.secho(
        "Package failed to synchronise during stage: %(stage)s"
        % {"stage": click.style(stage_str or "Unknown", fg="yellow")},
        fg="red",
    )

    if reason:
        click.secho(
            "Reason given: %(reason)s" % {"reason": click.style(reason, fg="yellow")},
            fg="red",
        )

        # pylint: disable=fixme
        # FIXME: The API should communicate "no retry" fails
        if "package should be deleted" in reason and attempts > 1:
            click.secho(
                "This is not recoverable, so stopping further attempts!", fg="red"
            )
            click.echo()
            attempts = 0

    if attempts + 1 > 0:
        # Show attempts upto and including zero attempts left
        click.secho(
            "Attempts left: %(left)s (%(action)s)"
            % {
                "left": click.style(six.text_type(attempts), bold=True),
                "action": "trying again" if attempts > 0 else "giving up",
            }
        )
        click.echo()

    if attempts > 0:
        from .resync import resync_package

        resync_package(
            ctx=ctx,
            opts=opts,
            owner=owner,
            repo=repo,
            slug=slug,
            skip_errors=skip_errors,
        )

        wait_for_package_sync(
            ctx=ctx,
            opts=opts,
            owner=owner,
            repo=repo,
            slug=slug,
            wait_interval=wait_interval,
            skip_errors=skip_errors,
            attempts=attempts,
        )
    else:
        ctx.exit(1)
1062745
def pq(ui, repo, *pats, **opts):
	
	opts['quick'] = True
	return pending(ui, repo, *pats, **opts)
739693
def _multi_packages(self, logins=None, platform=None, package_type=None,
                        type_=None, access=None, new_client=True):
        """"""
        private_packages = {}

        if not new_client:
            time.sleep(0.3)
            return private_packages

        for login in logins:
            data = self._anaconda_client_api.user_packages(
                login=login,
                platform=platform,
                package_type=package_type,
                type_=type_,
                access=access)
            for item in data:
                name = item.get('name', '')
                public = item.get('public', True)
                package_types = item.get('package_types', [])
                latest_version = item.get('latest_version', '')
                if name and not public and 'conda' in package_types:
                    if name in private_packages:
                        versions = private_packages.get('versions', []),
                        new_versions = item.get('versions', []),
                        vers = sort_versions(list(set(versions +
                                                      new_versions)))
                        private_packages[name]['versions'] = vers
                        private_packages[name]['latest_version'] = vers[-1]
                    else:
                        private_packages[name] = {
                            'versions': item.get('versions', []),
                            'app_entry': {},
                            'type': {},
                            'size': {},
                            'latest_version': latest_version, }

        return private_packages
643360
function startPackage(package, cb) {
   if (isUndefined(packageRuntimes[package.packageName])) {
      packageRuntimes[package.packageName] = {};
   }

   var packageRuntime = packageRuntimes[package.packageName];

   if (!isUndefined(packageRuntime.process)) {
      cb(new Error('package already running'));
      return;
   }

   packageRuntime.startupTimer = setTimeout(function() { 
      packageRuntime.startupTimer = null;
      cb();
   }, startupTimout * 1000);

   packageRuntime.process = exec(package.launchCommand, { cwd: (!isUndefined(package.workingDirectory) ? path.resolve(package.workingDirectory) : undefined) }, function(err) {
      packageRuntime.process = null;
      if (!isUndefined(packageRuntime.startupTimer)) {
         clearTimeout(packageRuntime.startupTimer);
         packageRuntime.startupTimer = null;
         cb(err);
      } else if (!isUndefined(packageRuntime.killTimer)) {
         clearTimeout(packageRuntime.killTimer);
         packageRuntime.killTimer = null;
         packageRuntime.killedCallback();
         packageRuntime.killedCallback = null;
      }
   });
}
893244
def install(trg_queue, is_down=False, is_triggered=False, user=None,
            group=None, mode=None, item_user=None, item_group=None,
            item_mode=None, hosts=None, is_host_triggered=False):
    ''''''
    mode, user, group, item_user, item_group, item_mode =\
        _def_mode(mode, user, group, item_user, item_group, item_mode)
    if hosts and not hasattr(hosts, '__iter__'):
        raise TypeError('Hosts must be an interable')
    # validate here, so that we don't throw an odd exception on the tmp name
    trg_queue = fsq_path.valid_name(trg_queue)
    # uid_gid makes calls to the pw db and|or gr db, in addition to
    # potentially stat'ing, as such, we want to avoid calling it unless we
    # absoultely have to
    uid, gid = uid_gid(user, group)
    tmp_full, tmp_queue = _tmp_trg(trg_queue, _c.FSQ_ROOT)
    try:
        # open once to cut down on stat/open for chown/chmod combo
        fd = os.open(tmp_full, os.O_RDONLY)
        try:
            # always fchmod here as mkdtemp is different than normal mkdir
            os.fchmod(fd, mode)
            if -1 != uid or -1 != gid:
                os.fchown(fd, uid, gid)
        finally:
            os.close(fd)

        # bless our queue with its children
        _instdir(fsq_path.tmp(tmp_queue), mode, uid, gid)
        _instdir(fsq_path.queue(tmp_queue), mode, uid, gid)
        _instdir(fsq_path.done(tmp_queue), mode, uid, gid)
        _instdir(fsq_path.fail(tmp_queue), mode, uid, gid)

        # down via configure.down if necessary
        if is_down:
            down(tmp_queue, user=item_user, group=item_group, mode=item_mode)
        if is_triggered or _c.FSQ_USE_TRIGGER:
            trigger(tmp_queue, user=item_user, group=item_group,
                    mode=item_mode)

        # atomic commit -- by rename
        os.rename(tmp_full, fsq_path.base(trg_queue))
    except (OSError, IOError, ), e:
        shutil.rmtree(tmp_full)
        if e.errno == errno.ENOTEMPTY:
            raise FSQInstallError(e.errno, u'queue exists: {0}'.format(
                                  trg_queue))
        if isinstance(e, FSQError):
            raise e
        raise FSQInstallError(e.errno, wrap_io_os_err(e))

    if hosts:
        install_host(trg_queue, *hosts, is_down=is_down, user=user,
                     group=group, mode=mode, item_user=item_user,
                     item_group=item_group, item_mode=item_mode)
    if is_host_triggered:
       host_trigger(trg_queue, user=user, group=group, mode=mode)
218445
def filter_installed_packages(packages):
    """"""
    cache = apt_cache()
    _pkgs = []
    for package in packages:
        try:
            p = cache[package]
            p.current_ver or _pkgs.append(package)
        except KeyError:
            log('Package {} has no installation candidate.'.format(package),
                level='WARNING')
            _pkgs.append(package)
    return _pkgs
1303728
def install_package_and_wait(
        package_name,
        package_version=None,
        service_name=None,
        options_file=None,
        options_json=None,
        wait_for_completion=True,
        timeout_sec=600,
        expected_running_tasks=0
):
    

    return install_package(
        package_name,
        package_version,
        service_name,
        options_file,
        options_json,
        wait_for_completion,
        timeout_sec,
        expected_running_tasks
    )
9803
def listed(self):
        
        print("\nPackages in the queue:\n")
        for pkg in self.packages():
            if pkg:
                print("{0}{1}{2}".format(self.meta.color["GREEN"], pkg,
                                         self.meta.color["ENDC"]))
                self.quit = True
        if self.quit:
            print("")
1016554
def enqueue(self, item_type, item):
        """"""

        with self.enlock:
            self.queue[item_type].append(item)
832243
def update(self, quiet=False, prefix='[polyglot_data] '):
    
    self.clear_status_cache()
    for pkg in self.packages():
      if self.status(pkg) == self.STALE:
        self.download(pkg, quiet=quiet, prefix=prefix)
497983
def reload(request):
    """"""
    refresh_packages.clean()
    refresh_packages.local()
    refresh_packages.remote()
    url = request.META.get('HTTP_REFERER')
    if url:
        return HttpResponseRedirect(url)
    else:
        return HttpResponse('Local requirements list has been reloaded.')