Merge lp:~james-w/pkgme/dont-make-existing-dir into lp:pkgme

Proposed by James Westby
Status: Merged
Approved by: Jonathan Lange
Approved revision: 95
Merged at revision: 97
Proposed branch: lp:~james-w/pkgme/dont-make-existing-dir
Merge into: lp:pkgme
Diff against target: 36 lines (+13/-2)
2 files modified
pkgme/tests/test_trace.py (+8/-0)
pkgme/trace.py (+5/-2)
To merge this branch: bzr merge lp:~james-w/pkgme/dont-make-existing-dir
Reviewer Review Type Date Requested Status
Jonathan Lange Approve
Review via email: mp+89101@code.launchpad.net

Commit message

Allow overriding the location of the log file.

Description of the change

Hi,

A small change to allow configuring the location of the log file. We're not
going to want it hidden away when pkgme is used by pkgme-service, so having
a way to customize it will be great.

Thanks,

James

To post a comment you must log in.
93. By James Westby

Merge trunk.

94. By James Westby

Actually treat PKGME_LOG_DIR as a dir.

Revision history for this message
Jonathan Lange (jml) wrote :

Two things:

 * The test has a copy/pasted comment that's not correct. "If PKGME_LOG_DIR is set, we log there" would be appropriate.

 * I would have written the thing like this:

    log_dir = os.environ.get("PKGME_LOG_DIR", None)
    log_filename = 'pkgme.log'
    if log_dir is None:
        log_dir = os.path.expanduser(os.path.join('~', '.cache', 'pkgme'))
    return os.path.join(log_dir, log_filename)

Which isn't superior (two calls to o.p.j), but I thought it might at least be interesting to share.

review: Needs Fixing
95. By James Westby

Fixes from review, thanks jml.

Revision history for this message
James Westby (james-w) wrote :

On Thu, 19 Jan 2012 11:58:35 -0000, Jonathan Lange <email address hidden> wrote:
> Review: Needs Fixing
>
> Two things:
>
> * The test has a copy/pasted comment that's not correct. "If PKGME_LOG_DIR is set, we log there" would be appropriate.

Fixed, thanks.

> * I would have written the thing like this:
>
> log_dir = os.environ.get("PKGME_LOG_DIR", None)
> log_filename = 'pkgme.log'
> if log_dir is None:
> log_dir = os.path.expanduser(os.path.join('~', '.cache', 'pkgme'))
> return os.path.join(log_dir, log_filename)
>
> Which isn't superior (two calls to o.p.j), but I thought it might at least be interesting to share.

Yeah, I thought the same thing as I was typing it, so I changed the code
to what we both expected.

Please re-review.

Thanks,

James

Revision history for this message
Jonathan Lange (jml) wrote :

Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'pkgme/tests/test_trace.py'
2--- pkgme/tests/test_trace.py 2011-07-29 14:37:35 +0000
3+++ pkgme/tests/test_trace.py 2012-01-19 12:22:24 +0000
4@@ -29,6 +29,14 @@
5 os.path.join(temp_home.path, '.cache', 'pkgme', 'pkgme.log'),
6 log_location)
7
8+ def test_log_location_from_env_var(self):
9+ # If PKGME_LOG_DIR is set in the environment we log there.
10+ temp_home = self.with_temp_home()
11+ temp_dir = self.useFixture(TempdirFixture())
12+ self.useFixture(EnvironmentVariableFixture('PKGME_LOG_DIR', temp_dir.path))
13+ log_location = trace.get_log_location()
14+ self.assertEqual(os.path.join(temp_dir.path, 'pkgme.log'), log_location)
15+
16 def test_log_to_file(self):
17 self.with_temp_log()
18 trace.log("message")
19
20=== modified file 'pkgme/trace.py'
21--- pkgme/trace.py 2011-07-29 14:37:35 +0000
22+++ pkgme/trace.py 2012-01-19 12:22:24 +0000
23@@ -8,8 +8,11 @@
24
25 def get_log_location():
26 """Return the path that we're logging to."""
27- return os.path.expanduser(
28- os.path.join('~', '.cache', 'pkgme', 'pkgme.log'))
29+ log_dir = os.environ.get("PKGME_LOG_DIR", None)
30+ log_filename = 'pkgme.log'
31+ if log_dir is None:
32+ log_dir = os.path.expanduser(os.path.join('~', '.cache', 'pkgme'))
33+ return os.path.join(log_dir, log_filename)
34
35
36 class LoggingFixture(Fixture):

Subscribers

People subscribed via source and target branches

to all changes: