We don't need 3 slightly different implementations of Data

This commit is contained in:
Aldo Cortesi
2016-05-21 11:53:14 +12:00
parent 84144ca0c6
commit 123e3b130c
5 changed files with 11 additions and 43 deletions

View File

@@ -1,5 +1,6 @@
import os
import sys
import netlib.utils
SIZE_UNITS = dict(
@@ -75,27 +76,7 @@ def escape_unprintables(s):
return s
class Data(object):
def __init__(self, name):
m = __import__(name)
dirname, _ = os.path.split(m.__file__)
self.dirname = os.path.abspath(dirname)
def path(self, path):
"""
Returns a path to the package data housed at 'path' under this
module.Path can be a path to a file, or to a directory.
This function will raise ValueError if the path does not exist.
"""
fullpath = os.path.join(self.dirname, path)
if not os.path.exists(fullpath):
raise ValueError("dataPath: %s does not exist." % fullpath)
return fullpath
data = Data(__name__)
data = netlib.utils.Data(__name__)
def daemonize(stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'): # pragma: no cover