diff --git a/pgloader.py b/pgloader.py index 494e57d..ef640d0 100755 --- a/pgloader.py +++ b/pgloader.py @@ -7,6 +7,7 @@ PostgreSQL data import tool, see included man page. import os, sys, os.path, time, codecs, logging, threading from cStringIO import StringIO +from tempfile import gettempdir import pgloader.options import pgloader.tools @@ -55,8 +56,8 @@ def parse_options(): help = "loglevel to use: ERROR, WARNING, INFO, DEBUG") parser.add_option("-L", "--logfile", dest = "logfile", - default = "/tmp/pgloader.log", - help = "log file, defauts to /tmp/pgloader.log") + default = "%s/pgloader.log" % gettempdir(), + help = "log file, defauts to $TMPDIR/pgloader.log") parser.add_option("-r", "--reject-log", dest = "reject_log", default = None, diff --git a/pgloader/db.py b/pgloader/db.py index 7fb737e..ff0ffaf 100644 --- a/pgloader/db.py +++ b/pgloader/db.py @@ -5,6 +5,7 @@ import os, sys, os.path, time, codecs, logging from cStringIO import StringIO +from tempfile import gettempdir from options import DRY_RUN, PEDANTIC, CLIENT_MIN_MESSAGES from options import TRUNCATE, VACUUM @@ -378,7 +379,7 @@ ORDER BY attnum """ save copy buffer to a temporary file for further inspection """ import tempfile (f, n) = tempfile.mkstemp(prefix='%s.' % tablename, - suffix='.pgloader', dir='/tmp') + suffix='.pgloader', dir=gettempdir()) os.write(f, self.buffer.getvalue()) os.close(f) if debug: diff --git a/pgloader/logger.py b/pgloader/logger.py index 33250bd..c5ccfd1 100644 --- a/pgloader/logger.py +++ b/pgloader/logger.py @@ -7,9 +7,10 @@ from tools import PGLoader_Error import logging +from tempfile import gettempdir def init(client_min_messages = logging.INFO, - log_min_messages = logging.DEBUG, filename = '/tmp/pgloader.log'): + log_min_messages = logging.DEBUG, filename = '%s/pgloader.log' % gettempdir()): """ set the console logging """ fmt = '%(asctime)s %(name)-12s %(levelname)-8s %(message)s' diff --git a/pgloader/options.py b/pgloader/options.py index b7b6155..70a4998 100644 --- a/pgloader/options.py +++ b/pgloader/options.py @@ -2,6 +2,8 @@ # # Some common options, for each module to get them +from tempfile import gettempdir + PGLOADER_VERSION = '2.3.3~dev2' PSYCOPG_VERSION = None @@ -48,7 +50,7 @@ RRQUEUE_SIZE = None CLIENT_MIN_MESSAGES = None LOG_MIN_MESSAGES = DEBUG -DEFAULT_LOG_FILE = "/tmp/pgloader.log" +DEFAULT_LOG_FILE = "%s/pgloader.log" % gettempdir() LOG_FILE = None REJECT_LOG_FILE = '%s.rej.log' diff --git a/pgloader/pgloader.py b/pgloader/pgloader.py index 5b1becd..bcd34e8 100644 --- a/pgloader/pgloader.py +++ b/pgloader/pgloader.py @@ -7,6 +7,7 @@ import os, sys, os.path, time, codecs, threading from cStringIO import StringIO +from tempfile import gettempdir from logger import log, getLogger from tools import PGLoader_Error, Reject, parse_config_string, check_events @@ -242,10 +243,10 @@ class PGLoader(threading.Thread): self.reject_data = config.get(name, 'reject_data') if not self.template and 'reject_log' not in self.__dict__: - self.reject_log = os.path.join('/tmp', REJECT_LOG_FILE % name) + self.reject_log = os.path.join(gettempdir(), REJECT_LOG_FILE % name) if not self.template and 'reject_data' not in self.__dict__: - self.reject_data = os.path.join('/tmp', REJECT_DATA_FILE % name) + self.reject_data = os.path.join(gettempdir(), REJECT_DATA_FILE % name) # reject logging if not self.template: