Skip to content

Commit

Permalink
Merge branch 'release/6.7.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
mtzl committed May 8, 2017
2 parents 7a3207e + 24bdae6 commit 19c0703
Show file tree
Hide file tree
Showing 29 changed files with 414 additions and 114 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,6 @@ docs/api

# jupyter files
.ipynb_checkpoints/

#
junit.xml
2 changes: 1 addition & 1 deletion .rtd-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies:
- numpy
- pandas
- matplotlib
- scipy
- scipy>=0.19
- cython
- pillow
- pytables
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Unreleased changes
------------------


6.7.0 / 2017-05-08
------------------
* ``totmonitor`` command line utility added
* bump library versions (scipy >=0.19)

6.6.6 / 2017-04-03
------------------
* change blosc compression -> zlib compression
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ recursive-include km3pipe *.pyxbld
recursive-include docs *
recursive-include km3pipe/tests *.py
recursive-include km3pipe/io/tests *.py
recursive-include km3pipe/style *.py
recursive-include km3pipe/kp-data *

recursive-exclude docs *.pyc
Expand Down
71 changes: 0 additions & 71 deletions docs/_static/custom.css

This file was deleted.

11 changes: 5 additions & 6 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import sys
import os
from datetime import date
import sphinx_rtd_theme

# what is this?
#sys.path.append('../')
Expand Down Expand Up @@ -112,12 +113,10 @@

# -- Options for HTML output ----------------------------------------------

html_theme = 'alabaster'
html_theme_options = {
'font_family': "'Open Sans', sans",
'head_font_family': "'Lato', sans",
'code_font_family': "'Roboto Mono', monospace",
}
html_theme = 'sphinx_rtd_theme'
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
#html_theme_options = {
#}


# The name for this set of Sphinx documents. If None, it defaults to
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

install
user_guide
logging
examples
api
contribute
Expand Down
49 changes: 49 additions & 0 deletions docs/logging.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Logging
=======


.. contents:: :local:


Introduction
------------
KM3Pipe uses a module based logging system which can individually be configured to
provide information needed to understand the underlying mechanisms.

You can also easily create your own logger.


Accessing a Logger
------------------
To access a modules logger, you need to::

from km3pipe.logger import logging
log = logging.getLogger("module.path")

where ``module.path`` is the Python import path of the module, like ``km3pipe.core``.

To set a desired logging level, use the keywords ``DEBUG``, ``INFO``, ``WARNING``,
``ERROR`` or ``CRITICAL``. For example::

log.setLevel("DEBUG")

Creating your own Logger
------------------------

To create your own logger, use the same procedure as described above::

from km3pipe.logger import logging
log = logging.getLogger("your.desired.logger.name")

After that, you can use it to log anywhere::

log.debug("A debug message")
log.info("An info message")
log.warn("A warning")
log.error("An error")
log.critical("A critical think")

and set its debug level::

log.setLevel("WARN")

2 changes: 1 addition & 1 deletion docs/version.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
KM3Pipe 6.6.6
KM3Pipe 6.7.0
=============
7 changes: 5 additions & 2 deletions km3pipe/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

log = logging.getLogger(__name__) # pylint: disable=C0103

version_info = (6, 6, 6, 'final', 0)
version_info = (6, 7, 0, 'final', 0)


def _get_version(version_info):
Expand Down Expand Up @@ -73,4 +73,7 @@ def check_for_update():
version = _get_version(version_info)
if config is not None:
if config.check_for_updates:
check_for_update()
try:
check_for_update()
except (ValueError, TypeError, OSError):
pass
2 changes: 1 addition & 1 deletion km3pipe/core.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ class Geometry(Module):
Parameters
----------
should_apply: bool, optional [default=False]
apply: bool, optional [default=False]
Apply the geometry to the hits (add position/direction/t0)?
filename: str, optional [default=None]
DetX file with detector description.
Expand Down
18 changes: 17 additions & 1 deletion km3pipe/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ def _add_datetime(self, dataframe, timestamp_key='UNIXTIME'):
def convert_data(timestamp):
return datetime.fromtimestamp(float(timestamp) / 1e3, UTC_TZ)
try:
log.debug("Adding DATETIME column to the data")
converted = dataframe[timestamp_key].apply(convert_data)
dataframe['DATETIME'] = converted
except KeyError:
Expand All @@ -180,6 +181,7 @@ def _add_converted_units(self, dataframe, parameter, key='VALUE'):
"""Add an additional DATA_VALUE column with converted VALUEs"""
convert_unit = self.parameters.get_converter(parameter)
try:
log.debug("Adding unit converted DATA_VALUE to the data")
dataframe[key] = dataframe['DATA_VALUE'].apply(convert_unit)
except KeyError:
log.warn("Missing 'VALUE': no unit conversion.")
Expand Down Expand Up @@ -322,45 +324,59 @@ def _get_content(self, url):
def opener(self):
"A reusable connection manager"
if self._opener is None:
log.debug("Creating connection handler")
opener = build_opener()
if self._cookies:
log.debug("Appending cookies")
else:
log.debug("No cookies to append")
for cookie in self._cookies:
cookie_str = cookie.name + '=' + cookie.value
opener.addheaders.append(('Cookie', cookie_str))
self._opener = opener
else:
log.debug("Reusing connection manager")
return self._opener

def request_sid_cookie(self, username, password):
"""Request cookie for permanent session token."""
log.debug("Requesting SID cookie")
target_url = self._login_url + '?usr={0}&pwd={1}&persist=y' \
.format(username, password)
cookie = urlopen(target_url).read()
return cookie

def restore_session(self, cookie):
"""Establish databse connection using permanent session cookie"""
log.debug("Restoring session from cookie")
opener = build_opener()
opener.addheaders.append(('Cookie', cookie))
self._opener = opener

def request_permanent_session(self, username=None, password=None):
log.debug("Requesting permanent session")
config = Config()
if username is None and password is None:
log.debug("Checking configuration file for DB credentials")
username, password = config.db_credentials
cookie = self.request_sid_cookie(username, password)
try:
cookie_str = str(cookie, 'utf-8') # Python 3
except TypeError:
cookie_str = str(cookie) # Python 2
log.debug("Session cookie: {0}".format(cookie_str))
log.debug("Storing cookie in configuration file")
config.set('DB', 'session_cookie', cookie_str)
self.restore_session(cookie)

def login(self, username, password):
"Login to the databse and store cookies for upcoming requests."
"Login to the database and store cookies for upcoming requests."
log.debug("Logging in to the DB")
opener = self._build_opener()
values = {'usr': username, 'pwd': password}
req = self._make_request(self._login_url, values)
try:
log.debug("Sending login request")
f = opener.open(req)
except URLError as e:
log.error("Failed to connect to the database -> probably down!")
Expand Down
Loading

0 comments on commit 19c0703

Please sign in to comment.