Skip to content
This repository was archived by the owner on May 3, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,14 @@
import sphinx.environment
from docutils.utils import get_source_line


def _warn_node(self, msg, node):
"""Do not warn on external images."""
if not msg.startswith('nonlocal image URI found:'):
self._warnfunc(msg, '{0}:{1}'.format(get_source_line(node)))

sphinx.environment.BuildEnvironment.warn_node = _warn_node


# -- General configuration ------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'

# Do not warn on external images.
suppress_warnings = ['image.nonlocal_uri']

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
Expand Down
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
'ConfigParser>=3.3.0r2',
],
'docs': [
'Sphinx>=1.3',
'Sphinx>=1.4.2',
],
'uwsgi': [
'uWSGI>=2.0.3',
Expand Down Expand Up @@ -98,12 +98,11 @@
'nara = timegate.examples.nara:NaraHandler',
'orain = timegate.examples.orain:OrainHandler',
'pastpages = timegate.examples.pastpages:PastpagesHandler',
'po = timegate.examples.po:PoHandler',
'sg = timegate.examples.sg:SgHandler',
'si = timegate.examples.si:SiHandler',
'simple = timegate.examples.simple:ExampleHandler',
'w3c = timegate.examples.w3c:W3cHandler',
'webcite = timegate.examples.webcite:WebciteHandler',
'webcite = timegate.examples.webcite:WebCiteHandler',
'wikia = timegate.examples.wikia:WikiaHandler',
'wikipedia = timegate.examples.wikipedia:WikipediaHandler',
],
Expand Down
12 changes: 6 additions & 6 deletions timegate/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@

from __future__ import absolute_import, print_function

import glob
import importlib
import inspect
import json
import logging
import os
from datetime import datetime

from pkg_resources import iter_entry_points

from dateutil.tz import tzutc
from link_header import Link, LinkHeader
from pkg_resources import iter_entry_points
from werkzeug.exceptions import HTTPException, abort
from werkzeug.http import http_date, parse_date
from werkzeug.local import Local, LocalManager
Expand All @@ -31,10 +29,8 @@
from werkzeug.wrappers import Request, Response

from . import constants
from ._compat import quote, unquote
from .cache import Cache
from .config import Config
from .errors import TimegateError, URIRequestError
from .handler import Handler, parsed_request
from .utils import best

Expand All @@ -47,6 +43,9 @@
request = local('request')
"""Proxy to request object."""

# logging.getLogger(__name__)
# logging.basicConfig(level=logging.DEBUG)


def url_for(*args, **kwargs):
"""Proxy to URL Map adapter builder."""
Expand Down Expand Up @@ -106,6 +105,7 @@ def __init__(self, config=None, cache=None):
self.config = Config(None)
self.config.from_object(constants)
self.config.update(config or {})
self.cache = None
if cache:
self.cache = cache
elif self.config['CACHE_USE']:
Expand Down
8 changes: 6 additions & 2 deletions timegate/conf/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ strict_datetime = true
# Timeout for any API request in seconds
api_time_out = 6

# user-agent
# Provide a user-agent to be added to the requests made by the timegate server
user_agent = Memento TimeGate

[handler]
# handler_class
# Optional path to handler class. If not provided the program will
# search core extensions for a possible handler.
handler_class = timegate.examples.simple:ExampleHandler
handler_class = timegate.examples.es.EsHandler

# use_timemap
# Optional boolean to define wether the program can handle timemap requests.
Expand All @@ -37,7 +41,7 @@ is_vcs = true
# (Optional) String that will be prepended to requested URI if it is not already present
# For example, if the server runs at `http://timegate.example.com` and all original resources begin with `http://example.com/res/{resource ID}`,
# then setting `base_uri = http://example.com/res/` will allow short requests such `http://timegate.example.com/{resource ID}`
base_uri = http://www.example.com/
base_uri =

[cache]

Expand Down
13 changes: 7 additions & 6 deletions timegate/conf/timegate.ini
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# uWSGI launch configuration file
[uwsgi]
home = /data/venv/timegate/
socket = /data/var/run/timegate/w3c/w3c.sock
chdir = /data/web/timegate/w3c
home = /Users/harihar/venv/timegate/
#socket = uwsgi.sock
http = :9000
#chdir = /data/web/timegate/w3c

daemonize = /data/var/logs/timegate/w3c.log
#daemonize = /data/var/logs/timegate/w3c.log
module = timegate.application
callable = application
master = true
pidfile = /data/var/run/timegate/w3c/w3c.pid
harakiri = 120
#pidfile = /data/var/run/timegate/w3c/w3c.pid
#harakiri = 120

memory-report
processes = 4
Expand Down
17 changes: 16 additions & 1 deletion timegate/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,22 @@
class Config(dict):
"""Implement custom loaders to populate dict."""

_instance = None

def __new__(cls, root_path, defaults=None):
"""
Converting this into a singleton for cached access.
:param root_path:
:param defaults:
:return:
"""
if not cls._instance:
cls._instance = super(Config, cls).__new__(cls)
return cls._instance

def __init__(self, root_path, defaults=None):
"""Build an empty config wrapper.
"""
Build an empty config wrapper.

:param root_path: Path to which files are read relative from.
:param defaults: An optional dictionary of default values.
Expand All @@ -36,6 +50,7 @@ def from_inifile(self, filename, silent=True):

# Server configuration
self['HOST'] = conf.get('server', 'host').rstrip('/')
self['USER_AGENT'] = conf.get('server', 'user_agent')
self['STRICT_TIME'] = conf.getboolean('server', 'strict_datetime')
if conf.has_option('server', 'api_time_out'):
self['API_TIME_OUT'] = conf.getfloat('server', 'api_time_out')
Expand Down
3 changes: 1 addition & 2 deletions timegate/examples/arxiv.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ def __init__(self):
Handler.__init__(self)

# Resources

# Ignores all that trails the identifier (? params, vX version,...)
# Ignores all that trails the identifier (? params, vX version,...info)
self.rex = re.compile(
r'(http://arxiv.org)/((?:pdf)|(?:abs))/(\d+\.\d+)(.*)')
self.api_base = 'http://export.arxiv.org/oai2'
Expand Down
118 changes: 0 additions & 118 deletions timegate/examples/po.py

This file was deleted.

8 changes: 7 additions & 1 deletion timegate/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from . import utils as timegate_utils
from ._compat import quote
from .config import Config
from .constants import API_TIME_OUT, TM_MAX_SIZE
from .errors import HandlerError

Expand All @@ -43,6 +44,11 @@ def request(self, resource, timeout=API_TIME_OUT, **kwargs):
:raises HandlerError: if the requests fails to access the API.
"""
uri = resource
config = Config(None)
user_agent = config.get("USER_AGENT")
headers = {}
if user_agent:
headers["User-Agent"] = user_agent

# Request logging with params
try:
Expand All @@ -55,7 +61,7 @@ def request(self, resource, timeout=API_TIME_OUT, **kwargs):
logging.info('Sending request for %s' % uri)

try:
req = requests.get(uri, timeout=timeout, **kwargs)
req = requests.get(uri, timeout=timeout, headers=headers, **kwargs)
except Exception as e:
logging.error('Cannot request server (%s): %s' % (uri, e))
raise HandlerError('Cannot request version server.', 502)
Expand Down