# HG changeset patch # User Ludovic Chabant # Date 1464317188 25200 # Node ID e85f29b28b840e1936c7a208bf9a7234c4b2c732 # Parent 4285b2c9b8724ee9707f0748adca5e272ab598d3 internal: Remove unused piece of code. diff -r 4285b2c9b872 -r e85f29b28b84 piecrust/baking/scheduler.py --- a/piecrust/baking/scheduler.py Thu May 19 22:11:27 2016 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,102 +0,0 @@ -import logging -import threading - - -logger = logging.getLogger(__name__) - - -class BakeScheduler(object): - _EMPTY = object() - _WAIT = object() - - def __init__(self, record, jobs=None): - self.record = record - self.jobs = list(jobs) if jobs is not None else [] - self._active_jobs = [] - self._lock = threading.Lock() - self._added_event = threading.Event() - self._done_event = threading.Event() - - def addJob(self, job): - logger.debug("Queuing job '%s:%s'." % ( - job.factory.source.name, job.factory.rel_path)) - with self._lock: - self.jobs.append(job) - self._added_event.set() - - def onJobFinished(self, job): - logger.debug("Removing job '%s:%s'." % ( - job.factory.source.name, job.factory.rel_path)) - with self._lock: - self._active_jobs.remove(job) - self._done_event.set() - - def getNextJob(self, wait_timeout=None, empty_timeout=None): - self._added_event.clear() - self._done_event.clear() - job = self._doGetNextJob() - while job in (self._EMPTY, self._WAIT): - if job == self._EMPTY: - if empty_timeout is None: - return None - logger.debug("Waiting for a new job to be added...") - res = self._added_event.wait(empty_timeout) - elif job == self._WAIT: - if wait_timeout is None: - return None - logger.debug("Waiting for a job to be finished...") - res = self._done_event.wait(wait_timeout) - if not res: - logger.debug("Timed-out. No job found.") - return None - job = self._doGetNextJob() - return job - - def _doGetNextJob(self): - with self._lock: - if len(self.jobs) == 0: - return self._EMPTY - - job = self.jobs.pop(0) - first_job = job - while True: - ready, wait_on_src = self._isJobReady(job) - if ready: - break - - logger.debug("Job '%s:%s' isn't ready yet: waiting on pages " - "from source '%s' to finish baking." % - (job.factory.source.name, - job.factory.rel_path, wait_on_src)) - self.jobs.append(job) - job = self.jobs.pop(0) - if job == first_job: - # None of the jobs are ready... we need to wait. - self.jobs.append(job) - return self._WAIT - - logger.debug( - "Job '%s:%s' is ready to go, moving to active queue." % - (job.factory.source.name, job.factory.rel_path)) - self._active_jobs.append(job) - return job - - def _isJobReady(self, job): - e = self.record.getPreviousEntry( - job.factory.source.name, - job.factory.rel_path, - taxonomy_info=job.record_entry.taxonomy_info) - if not e: - return (True, None) - used_source_names = e.getAllUsedSourceNames() - for sn in used_source_names: - if sn == job.factory.source.name: - continue - if any(filter(lambda j: j.factory.source.name == sn, - self.jobs)): - return (False, sn) - if any(filter(lambda j: j.factory.source.name == sn, - self._active_jobs)): - return (False, sn) - return (True, None) - diff -r 4285b2c9b872 -r e85f29b28b84 piecrust/uriutil.py --- a/piecrust/uriutil.py Thu May 19 22:11:27 2016 -0700 +++ b/piecrust/uriutil.py Thu May 26 19:46:28 2016 -0700 @@ -2,72 +2,11 @@ import os.path import string import logging -import functools logger = logging.getLogger(__name__) -class UriError(Exception): - def __init__(self, uri): - super(UriError, self).__init__("Invalid URI: %s" % uri) - - -@functools.total_ordering -class UriInfo(object): - def __init__(self, uri, source, args, taxonomy=None, page_num=1): - self.uri = uri - self.source = source - self.args = args - self.taxonomy = taxonomy - self.page_num = page_num - - def __eq__(self, other): - return ((self.uri, self.source, self.args, self.taxonomy, - self.page_num) == - (other.uri, other.source, other.args, other.taxonomy, - other.page_num)) - - def __lt__(self, other): - return ((self.uri, self.source, self.args, self.taxonomy, - self.page_num) < - (other.uri, other.source, other.args, other.taxonomy, - other.page_num)) - - -pagenum_pattern = re.compile(r'/(\d+)/?$') - - -def parse_uri(routes, uri): - if uri.find('..') >= 0: - raise UriError(uri) - - page_num = 1 - match = pagenum_pattern.search(uri) - if match is not None: - uri = uri[:match.start()] - page_num = int(match.group(1)) - - uri = '/' + uri.strip('/') - - for rn, rc in routes.items(): - pattern = route_to_pattern(rn) - m = re.match(pattern, uri) - if m is not None: - args = m.groupdict() - return UriInfo(uri, rc['source'], args, rc.get('taxonomy'), - page_num) - - return None - - -r2p_pattern = re.compile(r'%(\w+)%') - - -def route_to_pattern(route): - return r2p_pattern.sub(r'(?P<\1>[\w\-]+)', route) - - def multi_replace(text, replacements): reps = dict((re.escape(k), v) for k, v in replacements.items()) pattern = re.compile("|".join(list(reps.keys()))) diff -r 4285b2c9b872 -r e85f29b28b84 tests/test_uriutil.py --- a/tests/test_uriutil.py Thu May 19 22:11:27 2016 -0700 +++ b/tests/test_uriutil.py Thu May 26 19:46:28 2016 -0700 @@ -1,29 +1,6 @@ import mock import pytest -from piecrust.uriutil import UriInfo, parse_uri, split_sub_uri - - -@pytest.mark.parametrize('routes, uri, expected', [ - ({}, '/foo', None), - ( - {'/articles/%slug%': {'source': 'dummy'}}, - '/articles/foo', - UriInfo('', 'dummy', {'slug': 'foo'})), - ( - {'/foo/%bar%': {'source': 'foo'}, - '/other/%one%-%two%': {'source': 'other'}}, - '/other/some-thing', - UriInfo('', 'other', {'one': 'some', 'two': 'thing'})) - ]) -def test_parse_uri(routes, uri, expected): - if expected is not None: - expected.uri = uri - for pattern, args in routes.items(): - if 'taxonomy' not in args: - args['taxonomy'] = None - - actual = parse_uri(routes, uri) - assert actual == expected +from piecrust.uriutil import split_sub_uri @pytest.mark.parametrize('uri, expected, pretty_urls', [