How to use the pulp.common.dateutils.parse_iso8601_datetime function in PuLP

To help you get started, we’ve selected a few PuLP examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pulp / pulp / test / unit / test_dateutils.py View on Github external
def test_datetime_sans_tz(self):
        n = datetime.datetime.now()
        s = dateutils.format_iso8601_datetime(n)
        b = dateutils.parse_iso8601_datetime(s)
        for f in self.dt_fields:
            self.assertTrue(getattr(n, f) == getattr(b, f), 'Field mismatch: %s' % f)
github pulp / pulp / test / unit / test_repo_publish_manager.py View on Github external
def assert_last_sync_time(time_in_iso):
    now = datetime.datetime.now(dateutils.local_tz())
    finished = dateutils.parse_iso8601_datetime(time_in_iso)

    # Compare them within a threshold since they won't be exact
    difference = now - finished
    return difference.seconds < 2
github pulp / pulp / src / pulp / client / admin / plugins / cds.py View on Github external
# Render each item
            for i in range(0, upper_limit):
                item = history_list[i]
                start_time = item['start_time']
                finish_time = item['finish_time']
                sync_last_result = item['state']
                sync_last_exception = item['exception']
                sync_last_traceback = item['traceback']

                if sync_last_result is None:
                    last_result = 'Never'
                else:
                    last_result = STATE_TRANSLATIONS.get(sync_last_result, 'Unknown')

                if start_time is not None:
                    start_time = dateutils.parse_iso8601_datetime(start_time)

                if finish_time is not None:
                    finish_time = dateutils.parse_iso8601_datetime(finish_time)

                print('Start Time:     %s' % start_time)
                print('Finish Time:    %s' % finish_time)
                print('Result:         %s' % last_result)

                if item['exception'] is not None:
                    print('Exception:      ' + sync_last_exception)

                if item['traceback'] is not None:
                    print('Traceback:')
                    print('\n'.join(sync_last_traceback))
github pulp / pulp / server / pulp / server / webservices / views / repositories.py View on Github external
if limit < 1:
                    invalid_values.append('limit')
            except ValueError:
                invalid_values.append('limit')

        if sort and sort not in constants.SORT_DIRECTION:
            invalid_values.append('sort')

        if start_date is not None:
            try:
                dateutils.parse_iso8601_datetime(start_date)
            except (ValueError, isodate.ISO8601Error):
                invalid_values.append('start_date')
        if end_date is not None:
            try:
                dateutils.parse_iso8601_datetime(end_date)
            except (ValueError, isodate.ISO8601Error):
                invalid_values.append('end_date')

        if invalid_values:
            raise exceptions.InvalidValue(invalid_values)

        return start_date, end_date, sort, limit
github pulp / pulp / src / pulp / client / admin / plugins / cds.py View on Github external
def _print_cds(cds, next_sync=None):
    if cds['repo_ids']:
        repo_list = ', '.join(cds['repo_ids'])
    else:
        repo_list = _('None')

    if cds['last_sync'] is None:
        formatted_date = _('Never')
    else:
        formatted_date = dateutils.parse_iso8601_datetime(cds['last_sync'])

    stat = cds['heartbeat']
    if stat[0]:
        responding = _('Yes')
    else:
        responding = _('No')
    if stat[1]:
        last_heartbeat = dateutils.parse_iso8601_datetime(stat[1])
    else:
        last_heartbeat = stat[1]

    sync_schedule = cds['sync_schedule']

    # This is wonky but has to do with how the APIs are structured that next
    # sync isn't available in the CDS list, so rather than hammer the server
    # with more calls we omit it in most cases
github pulp / pulp / client_lib / pulp / client / validators.py View on Github external
def iso8601_datetime_validator(x):
    """
    Validates that a user-entered value is a correct iso8601 date

    :param x: input value to be validated
    :type x: str

    :raise ValueError: if the input is not a valid iso8601 string
    """
    try:
        dateutils.parse_iso8601_datetime(x)
    except Exception:
        raise ValueError(_('value must be a valid iso8601 string (yyyy-mm-ddThh:mm:ssZ)'))
github pulp / pulpcore / src / pulp / server / webservices / controllers / consumergroups.py View on Github external
def uninstallpackages(self, id):
        """
        Uninstall packages.
        Body contains a list of package names.
        """
        data = self.params()
        names = data.get('packagenames', [])
        job = api.uninstallpackages(id, names)
        scheduled_time = data.get('scheduled_time', None)
        for task in job.tasks:
            if scheduled_time is not None:
                dt = dateutils.parse_iso8601_datetime(scheduled_time)
                dt = dateutils.to_utc_datetime(dt)
                task.scheduler = AtScheduler(dt)
            async.enqueue(task, unique=False)
        jobdict = self._job_to_dict(job)
        return self.ok(jobdict)
github pulp / pulp / src / pulp / client / admin / plugins / repo.py View on Github external
def _at(self):
        if not self.opts.start or self.opts.interval:
            return {}
        at = parse_iso8601_datetime(self.opts.start)
        return {'at': self.opts.start}
github pulp / pulpcore / server / pulp / server / db / model / criteria.py View on Github external
    @staticmethod
    def translate(value):
        """
        Translate the operator *dict* into a datetime object.
        An example of matched values: {"$date": "2015-01-01T00:00:00Z"}
        :param value: The value to be translated.
        :type value: dict
        :return: A tuple of: (matched, translated)
        :rtype: tuple
        """
        matched = False
        translated = value
        operator = DateOperator.KEY
        if isinstance(value, dict) and value.keys() == [operator]:
            translated = parse_iso8601_datetime(value[operator])
            matched = True
        return matched, translated
github pulp / pulp / src / pulp / client / api / repository.py View on Github external
def ft(t):
            return dateutils.parse_iso8601_datetime(t['finish_time'])
        def lt(a, b):