diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..1715250 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +python-monotonic (0.1-1) unstable; urgency=low + + * Initial package. + + -- Ori Livneh Sat, 29 Nov 2014 19:42:14 +0000 diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..ec63514 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +9 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..b7e1fe4 --- /dev/null +++ b/debian/control @@ -0,0 +1,36 @@ +Source: python-monotonic +Section: python +Priority: optional +Maintainer: Ori Livneh +Build-Depends: autopkgtest, + debhelper (>= 9), + python-all (>= 2.6.6-3~), + python-setuptools (>= 0.6b3), + python3-all, + python3-setuptools +Standards-Version: 3.9.4 +Vcs-Browser: http://github.com/atdt/monotonic.git +Vcs-Git: git://github.com/atdt/monotonic.git +Homepage: https://pypi.python.org/pypi/monotonic + +Package: python-monotonic +Architecture: all +Pre-Depends: dpkg (>= 1.15.6~) +Depends: ${misc:Depends}, ${python:Depends} +Description: A monotonic clock implementation for Python + This module provides a monotonic() function which returns the + value (in fractional seconds) of a monotonic clock, i.e. a clock + which never goes backwards. + . + This package contains the Python 2.x module. + +Package: python3-monotonic +Architecture: all +Pre-Depends: dpkg (>= 1.15.6~) +Depends: python3 (>= 3.2.3), ${misc:Depends} +Description: A monotonic clock implementation for Python + This module provides a monotonic() function which returns the + value (in fractional seconds) of a monotonic clock, i.e. a clock + which never goes backwards. + . + This package contains the Python 3.x module. diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..18279be --- /dev/null +++ b/debian/copyright @@ -0,0 +1,7 @@ +Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: monotonic +Source: https://github.com/atdt/monotonic + +Files: * +Copyright: (c) 2014 Ori Livneh +License: Apache diff --git a/debian/docs b/debian/docs new file mode 100644 index 0000000..b43bf86 --- /dev/null +++ b/debian/docs @@ -0,0 +1 @@ +README.md diff --git a/debian/gbp.conf b/debian/gbp.conf new file mode 100644 index 0000000..a80d315 --- /dev/null +++ b/debian/gbp.conf @@ -0,0 +1,8 @@ +[DEFAULT] +upstream-branch = master +debian-branch = debian/unstable +upstream-tag = v%(version)s +compression = xz + +[git-buildpackage] +export-dir = ../build-area/ diff --git a/debian/python-monotonic.debhelper.log b/debian/python-monotonic.debhelper.log new file mode 100644 index 0000000..5d637f4 --- /dev/null +++ b/debian/python-monotonic.debhelper.log @@ -0,0 +1,8 @@ +dh_auto_configure +override_dh_auto_build dh_auto_build +dh_auto_build +dh_auto_test +dh_prep +override_dh_auto_install dh_auto_install +dh_auto_install +dh_install diff --git a/debian/python-monotonic.install b/debian/python-monotonic.install new file mode 100644 index 0000000..e6cad15 --- /dev/null +++ b/debian/python-monotonic.install @@ -0,0 +1,2 @@ + +usr/lib/python2*/ diff --git a/debian/python-monotonic/usr/lib/python2.7/dist-packages/monotonic.py b/debian/python-monotonic/usr/lib/python2.7/dist-packages/monotonic.py new file mode 100644 index 0000000..d6dff9f --- /dev/null +++ b/debian/python-monotonic/usr/lib/python2.7/dist-packages/monotonic.py @@ -0,0 +1,120 @@ +# -*- coding: utf-8 -*- +""" + monotonic + ~~~~~~~~~ + + This module provides a ``monotonic()`` function which returns the + value (in fractional seconds) of a clock which never goes backwards. + + On Python 3.3 or newer, ``monotonic`` will be an alias of + ``time.monotonic`` from the standard library. On older versions, + it will fall back to an equivalent implementation: + + +-------------+--------------------+ + | Linux, BSD | clock_gettime(3) | + +-------------+--------------------+ + | Windows | GetTickCount64 | + +-------------+--------------------+ + | OS X | mach_absolute_time | + +-------------+--------------------+ + + If no suitable implementation exists for the current platform, + attempting to import this module (or to import from it) will + cause a RuntimeError exception to be raised. + + + Copyright 2014 Ori Livneh + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +""" +from __future__ import absolute_import, division + +import ctypes +import ctypes.util +import os +import sys +import time + + +__all__ = ('monotonic',) + +try: + monotonic = time.monotonic +except AttributeError: + try: + if sys.platform == 'darwin': # OS X, iOS + # See Technical Q&A QA1398 of the Mac Developer Library: + # + libc = ctypes.CDLL('libc.dylib', use_errno=True) + + class mach_timebase_info_data_t(ctypes.Structure): + """System timebase info. Defined in .""" + _fields_ = (('numer', ctypes.c_uint32), + ('denom', ctypes.c_uint32)) + + mach_absolute_time = libc.mach_absolute_time + mach_absolute_time.restype = ctypes.c_uint64 + + timebase = mach_timebase_info_data_t() + libc.mach_timebase_info(ctypes.byref(timebase)) + ticks_per_second = timebase.numer / timebase.denom * 1.0e9 + + def monotonic(): + """Monotonic clock, cannot go backward.""" + return mach_absolute_time() / ticks_per_second + + elif sys.platform.startswith('win32'): + # Windows Vista / Windows Server 2008 or newer. + GetTickCount64 = ctypes.windll.kernel32.GetTickCount64 + GetTickCount64.restype = ctypes.c_ulonglong + + def monotonic(): + """Monotonic clock, cannot go backward.""" + return GetTickCount64() / 1000.0 + + else: + try: + clock_gettime = ctypes.CDLL(ctypes.util.find_library('c'), + use_errno=True).clock_gettime + except AttributeError: + clock_gettime = ctypes.CDLL(ctypes.util.find_library('rt'), + use_errno=True).clock_gettime + + class timespec(ctypes.Structure): + """Time specification, as described in clock_gettime(3).""" + _fields_ = (('tv_sec', ctypes.c_long), + ('tv_nsec', ctypes.c_long)) + + ts = timespec() + + if sys.platform.startswith('linux'): + CLOCK_MONOTONIC = 1 + elif sys.platform.startswith('freebsd'): + CLOCK_MONOTONIC = 4 + elif 'bsd' in sys.platform: + CLOCK_MONOTONIC = 3 + + def monotonic(): + """Monotonic clock, cannot go backward.""" + if clock_gettime(CLOCK_MONOTONIC, ctypes.pointer(ts)): + errno = ctypes.get_errno() + raise OSError(errno, os.strerror(errno)) + return ts.tv_sec + ts.tv_nsec / 1.0e9 + + # Perform a sanity-check. + if monotonic() - monotonic() >= 0: + raise ValueError('monotonic() is not monotonic!') + + except Exception: + raise RuntimeError('no suitable implementation for this system') diff --git a/debian/python3-monotonic.debhelper.log b/debian/python3-monotonic.debhelper.log new file mode 100644 index 0000000..5d637f4 --- /dev/null +++ b/debian/python3-monotonic.debhelper.log @@ -0,0 +1,8 @@ +dh_auto_configure +override_dh_auto_build dh_auto_build +dh_auto_build +dh_auto_test +dh_prep +override_dh_auto_install dh_auto_install +dh_auto_install +dh_install diff --git a/debian/python3-monotonic.install b/debian/python3-monotonic.install new file mode 100644 index 0000000..eae3930 --- /dev/null +++ b/debian/python3-monotonic.install @@ -0,0 +1 @@ +usr/lib/python3/ diff --git a/debian/python3-monotonic/usr/lib/python3/dist-packages/monotonic.py b/debian/python3-monotonic/usr/lib/python3/dist-packages/monotonic.py new file mode 100644 index 0000000..d6dff9f --- /dev/null +++ b/debian/python3-monotonic/usr/lib/python3/dist-packages/monotonic.py @@ -0,0 +1,120 @@ +# -*- coding: utf-8 -*- +""" + monotonic + ~~~~~~~~~ + + This module provides a ``monotonic()`` function which returns the + value (in fractional seconds) of a clock which never goes backwards. + + On Python 3.3 or newer, ``monotonic`` will be an alias of + ``time.monotonic`` from the standard library. On older versions, + it will fall back to an equivalent implementation: + + +-------------+--------------------+ + | Linux, BSD | clock_gettime(3) | + +-------------+--------------------+ + | Windows | GetTickCount64 | + +-------------+--------------------+ + | OS X | mach_absolute_time | + +-------------+--------------------+ + + If no suitable implementation exists for the current platform, + attempting to import this module (or to import from it) will + cause a RuntimeError exception to be raised. + + + Copyright 2014 Ori Livneh + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +""" +from __future__ import absolute_import, division + +import ctypes +import ctypes.util +import os +import sys +import time + + +__all__ = ('monotonic',) + +try: + monotonic = time.monotonic +except AttributeError: + try: + if sys.platform == 'darwin': # OS X, iOS + # See Technical Q&A QA1398 of the Mac Developer Library: + # + libc = ctypes.CDLL('libc.dylib', use_errno=True) + + class mach_timebase_info_data_t(ctypes.Structure): + """System timebase info. Defined in .""" + _fields_ = (('numer', ctypes.c_uint32), + ('denom', ctypes.c_uint32)) + + mach_absolute_time = libc.mach_absolute_time + mach_absolute_time.restype = ctypes.c_uint64 + + timebase = mach_timebase_info_data_t() + libc.mach_timebase_info(ctypes.byref(timebase)) + ticks_per_second = timebase.numer / timebase.denom * 1.0e9 + + def monotonic(): + """Monotonic clock, cannot go backward.""" + return mach_absolute_time() / ticks_per_second + + elif sys.platform.startswith('win32'): + # Windows Vista / Windows Server 2008 or newer. + GetTickCount64 = ctypes.windll.kernel32.GetTickCount64 + GetTickCount64.restype = ctypes.c_ulonglong + + def monotonic(): + """Monotonic clock, cannot go backward.""" + return GetTickCount64() / 1000.0 + + else: + try: + clock_gettime = ctypes.CDLL(ctypes.util.find_library('c'), + use_errno=True).clock_gettime + except AttributeError: + clock_gettime = ctypes.CDLL(ctypes.util.find_library('rt'), + use_errno=True).clock_gettime + + class timespec(ctypes.Structure): + """Time specification, as described in clock_gettime(3).""" + _fields_ = (('tv_sec', ctypes.c_long), + ('tv_nsec', ctypes.c_long)) + + ts = timespec() + + if sys.platform.startswith('linux'): + CLOCK_MONOTONIC = 1 + elif sys.platform.startswith('freebsd'): + CLOCK_MONOTONIC = 4 + elif 'bsd' in sys.platform: + CLOCK_MONOTONIC = 3 + + def monotonic(): + """Monotonic clock, cannot go backward.""" + if clock_gettime(CLOCK_MONOTONIC, ctypes.pointer(ts)): + errno = ctypes.get_errno() + raise OSError(errno, os.strerror(errno)) + return ts.tv_sec + ts.tv_nsec / 1.0e9 + + # Perform a sanity-check. + if monotonic() - monotonic() >= 0: + raise ValueError('monotonic() is not monotonic!') + + except Exception: + raise RuntimeError('no suitable implementation for this system') diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..c93d7f0 --- /dev/null +++ b/debian/rules @@ -0,0 +1,22 @@ +#!/usr/bin/make -f + +PYTHON3:=$(shell py3versions -r) +py3sdo=set -ex; $(foreach py, $(PYTHON3), $(py) $(1);) + +UPSTREAM_GIT = git://github.com/atdt/jsonschema.git + +%: + dh $@ --with python2,python3 + +override_dh_auto_build: + dh_auto_build + $(call py3sdo, setup.py build) + +override_dh_auto_install: + dh_auto_install + $(call py3sdo, setup.py install --root=$(CURDIR)/debian/tmp --install-layout=deb) + +override_dh_auto_clean: + dh_auto_clean + rm -rf build + rm -rf *.egg-info __pycache__ diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 0000000..163aaf8 --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (quilt) diff --git a/debian/tmp/usr/lib/python2.7/dist-packages/monotonic.py b/debian/tmp/usr/lib/python2.7/dist-packages/monotonic.py new file mode 100644 index 0000000..d6dff9f --- /dev/null +++ b/debian/tmp/usr/lib/python2.7/dist-packages/monotonic.py @@ -0,0 +1,120 @@ +# -*- coding: utf-8 -*- +""" + monotonic + ~~~~~~~~~ + + This module provides a ``monotonic()`` function which returns the + value (in fractional seconds) of a clock which never goes backwards. + + On Python 3.3 or newer, ``monotonic`` will be an alias of + ``time.monotonic`` from the standard library. On older versions, + it will fall back to an equivalent implementation: + + +-------------+--------------------+ + | Linux, BSD | clock_gettime(3) | + +-------------+--------------------+ + | Windows | GetTickCount64 | + +-------------+--------------------+ + | OS X | mach_absolute_time | + +-------------+--------------------+ + + If no suitable implementation exists for the current platform, + attempting to import this module (or to import from it) will + cause a RuntimeError exception to be raised. + + + Copyright 2014 Ori Livneh + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +""" +from __future__ import absolute_import, division + +import ctypes +import ctypes.util +import os +import sys +import time + + +__all__ = ('monotonic',) + +try: + monotonic = time.monotonic +except AttributeError: + try: + if sys.platform == 'darwin': # OS X, iOS + # See Technical Q&A QA1398 of the Mac Developer Library: + # + libc = ctypes.CDLL('libc.dylib', use_errno=True) + + class mach_timebase_info_data_t(ctypes.Structure): + """System timebase info. Defined in .""" + _fields_ = (('numer', ctypes.c_uint32), + ('denom', ctypes.c_uint32)) + + mach_absolute_time = libc.mach_absolute_time + mach_absolute_time.restype = ctypes.c_uint64 + + timebase = mach_timebase_info_data_t() + libc.mach_timebase_info(ctypes.byref(timebase)) + ticks_per_second = timebase.numer / timebase.denom * 1.0e9 + + def monotonic(): + """Monotonic clock, cannot go backward.""" + return mach_absolute_time() / ticks_per_second + + elif sys.platform.startswith('win32'): + # Windows Vista / Windows Server 2008 or newer. + GetTickCount64 = ctypes.windll.kernel32.GetTickCount64 + GetTickCount64.restype = ctypes.c_ulonglong + + def monotonic(): + """Monotonic clock, cannot go backward.""" + return GetTickCount64() / 1000.0 + + else: + try: + clock_gettime = ctypes.CDLL(ctypes.util.find_library('c'), + use_errno=True).clock_gettime + except AttributeError: + clock_gettime = ctypes.CDLL(ctypes.util.find_library('rt'), + use_errno=True).clock_gettime + + class timespec(ctypes.Structure): + """Time specification, as described in clock_gettime(3).""" + _fields_ = (('tv_sec', ctypes.c_long), + ('tv_nsec', ctypes.c_long)) + + ts = timespec() + + if sys.platform.startswith('linux'): + CLOCK_MONOTONIC = 1 + elif sys.platform.startswith('freebsd'): + CLOCK_MONOTONIC = 4 + elif 'bsd' in sys.platform: + CLOCK_MONOTONIC = 3 + + def monotonic(): + """Monotonic clock, cannot go backward.""" + if clock_gettime(CLOCK_MONOTONIC, ctypes.pointer(ts)): + errno = ctypes.get_errno() + raise OSError(errno, os.strerror(errno)) + return ts.tv_sec + ts.tv_nsec / 1.0e9 + + # Perform a sanity-check. + if monotonic() - monotonic() >= 0: + raise ValueError('monotonic() is not monotonic!') + + except Exception: + raise RuntimeError('no suitable implementation for this system') diff --git a/debian/tmp/usr/lib/python3/dist-packages/monotonic.py b/debian/tmp/usr/lib/python3/dist-packages/monotonic.py new file mode 100644 index 0000000..d6dff9f --- /dev/null +++ b/debian/tmp/usr/lib/python3/dist-packages/monotonic.py @@ -0,0 +1,120 @@ +# -*- coding: utf-8 -*- +""" + monotonic + ~~~~~~~~~ + + This module provides a ``monotonic()`` function which returns the + value (in fractional seconds) of a clock which never goes backwards. + + On Python 3.3 or newer, ``monotonic`` will be an alias of + ``time.monotonic`` from the standard library. On older versions, + it will fall back to an equivalent implementation: + + +-------------+--------------------+ + | Linux, BSD | clock_gettime(3) | + +-------------+--------------------+ + | Windows | GetTickCount64 | + +-------------+--------------------+ + | OS X | mach_absolute_time | + +-------------+--------------------+ + + If no suitable implementation exists for the current platform, + attempting to import this module (or to import from it) will + cause a RuntimeError exception to be raised. + + + Copyright 2014 Ori Livneh + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +""" +from __future__ import absolute_import, division + +import ctypes +import ctypes.util +import os +import sys +import time + + +__all__ = ('monotonic',) + +try: + monotonic = time.monotonic +except AttributeError: + try: + if sys.platform == 'darwin': # OS X, iOS + # See Technical Q&A QA1398 of the Mac Developer Library: + # + libc = ctypes.CDLL('libc.dylib', use_errno=True) + + class mach_timebase_info_data_t(ctypes.Structure): + """System timebase info. Defined in .""" + _fields_ = (('numer', ctypes.c_uint32), + ('denom', ctypes.c_uint32)) + + mach_absolute_time = libc.mach_absolute_time + mach_absolute_time.restype = ctypes.c_uint64 + + timebase = mach_timebase_info_data_t() + libc.mach_timebase_info(ctypes.byref(timebase)) + ticks_per_second = timebase.numer / timebase.denom * 1.0e9 + + def monotonic(): + """Monotonic clock, cannot go backward.""" + return mach_absolute_time() / ticks_per_second + + elif sys.platform.startswith('win32'): + # Windows Vista / Windows Server 2008 or newer. + GetTickCount64 = ctypes.windll.kernel32.GetTickCount64 + GetTickCount64.restype = ctypes.c_ulonglong + + def monotonic(): + """Monotonic clock, cannot go backward.""" + return GetTickCount64() / 1000.0 + + else: + try: + clock_gettime = ctypes.CDLL(ctypes.util.find_library('c'), + use_errno=True).clock_gettime + except AttributeError: + clock_gettime = ctypes.CDLL(ctypes.util.find_library('rt'), + use_errno=True).clock_gettime + + class timespec(ctypes.Structure): + """Time specification, as described in clock_gettime(3).""" + _fields_ = (('tv_sec', ctypes.c_long), + ('tv_nsec', ctypes.c_long)) + + ts = timespec() + + if sys.platform.startswith('linux'): + CLOCK_MONOTONIC = 1 + elif sys.platform.startswith('freebsd'): + CLOCK_MONOTONIC = 4 + elif 'bsd' in sys.platform: + CLOCK_MONOTONIC = 3 + + def monotonic(): + """Monotonic clock, cannot go backward.""" + if clock_gettime(CLOCK_MONOTONIC, ctypes.pointer(ts)): + errno = ctypes.get_errno() + raise OSError(errno, os.strerror(errno)) + return ts.tv_sec + ts.tv_nsec / 1.0e9 + + # Perform a sanity-check. + if monotonic() - monotonic() >= 0: + raise ValueError('monotonic() is not monotonic!') + + except Exception: + raise RuntimeError('no suitable implementation for this system') diff --git a/debian/watch b/debian/watch new file mode 100644 index 0000000..5014c04 --- /dev/null +++ b/debian/watch @@ -0,0 +1,2 @@ +version=3 +https://github.com/atdt/monotonic/tags .*v(\d[\d\.]+)\.tar\.gz