From faa7d1c006dfc890a537aa5b71ee9bbf8eea4fe5 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Mon, 28 Sep 2015 18:30:15 +0000 Subject: Split out stuff from __init__.py to placate pep8 --- obnamlib/__init__.py | 76 ++++++++++++++++++++------------------------------ obnamlib/defaults.py | 41 +++++++++++++++++++++++++++ obnamlib/obnamerror.py | 26 +++++++++++++++++ obnamlib/version.py | 18 ++++++++++++ without-tests | 4 +++ 5 files changed, 119 insertions(+), 46 deletions(-) create mode 100644 obnamlib/defaults.py create mode 100644 obnamlib/obnamerror.py create mode 100644 obnamlib/version.py diff --git a/obnamlib/__init__.py b/obnamlib/__init__.py index 9558b59a..eff91fbd 100644 --- a/obnamlib/__init__.py +++ b/obnamlib/__init__.py @@ -17,7 +17,26 @@ import cliapp -__version__ = '1.17' +from .version import __version__ +from .structurederror import StructuredError +from .obnamerror import ObnamError +from .defaults import ( + DEFAULT_NODE_SIZE, + DEFAULT_CHUNK_SIZE, + DEFAULT_UPLOAD_QUEUE_SIZE, + DEFAULT_LRU_SIZE, + DEFAULT_CHUNKIDS_PER_GROUP, + DEFAULT_NAGIOS_WARN_AGE, + DEFAULT_NAGIOS_CRIT_AGE, + DEFAULT_DIR_OBJECT_CACHE_BYTES, + DEFAULT_CHUNK_CACHE_BYTES, + + IDPATH_DEPTH, + IDPATH_BITS, + IDPATH_SKIP, + + MAX_ID, +) # Import _obnam if it is there. We need to be able to do things without @@ -26,57 +45,15 @@ __version__ = '1.17' # if used. -class DummyExtension(object): - def __getattr__(self, name): - raise Exception('Trying to use _obnam, but that was not found.') try: import obnamlib._obnam except ImportError: + class DummyExtension(object): + def __getattr__(self, name): + raise Exception('Trying to use _obnam, but that was not found.') _obnam = DummyExtension() -# Exceptions defined by Obnam itself. They should all be a subclass -# of obnamlib.ObnamError. - -from .structurederror import StructuredError - - -class ObnamError(StructuredError): - - pass - - -DEFAULT_NODE_SIZE = 256 * 1024 # benchmarked on 2011-09-01 -DEFAULT_CHUNK_SIZE = 1024 * 1024 # benchmarked on 2011-09-01 -DEFAULT_UPLOAD_QUEUE_SIZE = 1024 # benchmarked on 2015-05-02 -DEFAULT_LRU_SIZE = 256 -DEFAULT_CHUNKIDS_PER_GROUP = 1024 -DEFAULT_NAGIOS_WARN_AGE = '27h' -DEFAULT_NAGIOS_CRIT_AGE = '8d' - -_MEBIBYTE = 1024**2 -DEFAULT_DIR_OBJECT_CACHE_BYTES = 256 * _MEBIBYTE -DEFAULT_CHUNK_CACHE_BYTES = 1 * _MEBIBYTE - -# The following values have been determined empirically on a laptop -# with an encrypted ext4 filesystem. Other values might be better for -# other situations. -IDPATH_DEPTH = 3 -IDPATH_BITS = 12 -IDPATH_SKIP = 13 - -# Maximum identifier for clients, chunks, files, etc. This is the largest -# unsigned 64-bit value. In various places we assume 64-bit field sizes -# for on-disk data structures. -MAX_ID = 2**64 - 1 - - -option_group = { - 'perf': 'Performance tweaking', - 'devel': 'Development of Obnam itself', -} - - from .sizeparse import SizeSyntaxError, UnitNameError, ByteSizeParser from .encryption import ( @@ -211,4 +188,11 @@ from .fmt_6.clientlist import ClientList from .fmt_6.checksumtree import ChecksumTree from .fmt_6.clientmetadatatree import ClientMetadataTree + +option_group = { + 'perf': 'Performance tweaking', + 'devel': 'Development of Obnam itself', +} + + __all__ = locals() diff --git a/obnamlib/defaults.py b/obnamlib/defaults.py new file mode 100644 index 00000000..478433c8 --- /dev/null +++ b/obnamlib/defaults.py @@ -0,0 +1,41 @@ +# Copyright 2015 Lars Wirzenius +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# =*= License: GPL-3+ =*= + + +DEFAULT_NODE_SIZE = 256 * 1024 # benchmarked on 2011-09-01 +DEFAULT_CHUNK_SIZE = 1024 * 1024 # benchmarked on 2011-09-01 +DEFAULT_UPLOAD_QUEUE_SIZE = 1024 # benchmarked on 2015-05-02 +DEFAULT_LRU_SIZE = 256 +DEFAULT_CHUNKIDS_PER_GROUP = 1024 +DEFAULT_NAGIOS_WARN_AGE = '27h' +DEFAULT_NAGIOS_CRIT_AGE = '8d' + +_MEBIBYTE = 1024**2 +DEFAULT_DIR_OBJECT_CACHE_BYTES = 256 * _MEBIBYTE +DEFAULT_CHUNK_CACHE_BYTES = 1 * _MEBIBYTE + +# The following values have been determined empirically on a laptop +# with an encrypted ext4 filesystem. Other values might be better for +# other situations. +IDPATH_DEPTH = 3 +IDPATH_BITS = 12 +IDPATH_SKIP = 13 + +# Maximum identifier for clients, chunks, files, etc. This is the largest +# unsigned 64-bit value. In various places we assume 64-bit field sizes +# for on-disk data structures. +MAX_ID = 2**64 - 1 diff --git a/obnamlib/obnamerror.py b/obnamlib/obnamerror.py new file mode 100644 index 00000000..360ba2a2 --- /dev/null +++ b/obnamlib/obnamerror.py @@ -0,0 +1,26 @@ +# Copyright 2015 Lars Wirzenius +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# =*= License: GPL-3+ =*= + + +import structurederror + + +# Base exception for all Obnam specific exceptions. + +class ObnamError(structurederror.StructuredError): + + pass diff --git a/obnamlib/version.py b/obnamlib/version.py new file mode 100644 index 00000000..9c788295 --- /dev/null +++ b/obnamlib/version.py @@ -0,0 +1,18 @@ +# Copyright 2015 Lars Wirzenius +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# =*= License: GPL-3+ =*= + +__version__ = '1.17' diff --git a/without-tests b/without-tests index b65808e5..72e5f068 100644 --- a/without-tests +++ b/without-tests @@ -2,6 +2,7 @@ setup.py obnamlib/app.py obnamlib/backup_progress.py +obnamlib/defaults.py obnamlib/delegator.py obnamlib/fmt_6/__init__.py obnamlib/fmt_6/repo_tree.py @@ -14,6 +15,7 @@ obnamlib/fmt_simple/__init__.py obnamlib/fsck_work_item.py obnamlib/humanise.py obnamlib/__init__.py +obnamlib/obnamerror.py obnamlib/plugins/backup_plugin.py obnamlib/plugins/compression_plugin.py obnamlib/plugins/dump_repo_plugin.py @@ -34,6 +36,8 @@ obnamlib/plugins/verify_plugin.py obnamlib/plugins/vfs_local_plugin.py obnamlib/repo_fs.py obnamlib/repo_interface.py +obnamlib/structurederror.py +obnamlib/version.py obnamlib/vfs.py test-plugins/aaa_hello_plugin.py -- cgit v1.2.1