Skip to content
This repository

Respect the $TZ environment variable to show local times if requested #57

Merged
merged 1 commit into from about 1 year ago

4 participants

James Brown Jeremy Rosengren Brandon Michal Ludvig
James Brown

It would be nice for s3cmd to print timestamps in the local time zone. This pull request makes s3cmd honor the fairly-standard "TZ" environment variable and, if the pytz library is installed, display timestamps in the correct timezone.

pytz internally memoizes timezones, so this isn't quite as expensive as it looks at first blush.

Jeremy Rosengren

This commit causes s3cmd to fail on RHEL/CentOS 5.x and Python 2.4

Michal Ludvig mludvig merged commit 0f03a06 into from February 18, 2013
Michal Ludvig mludvig closed this February 18, 2013
Brandon

Seconded, this commit causes s3cmd to fail on RHEL/CentOS 5.x with Python 2.4.

James Brown

Can you be more specific about what the failure you're seeing is? I don't have any systems old enough to still be running py2.4, and would prefer to not have to spin up a VM to repro.

Brandon

I was getting this error:
http://pastebin.com/h1f1E4S1

I ended up installing 2.6 with yum install python26 and then running the install script again with that, and all was well. I would say leave the patch as is, but point folks to those directions.
1. yum install python26
2. in the s3cmd src directory run:
python26 setup.py install
3. change the 1st line of /usr/bin/s3cmd to:
#!/usr/bin/python26

Jeremy Rosengren

Brandon's workaround is a non-starter for me, I'd like s3cmd to run under Python 2.4 on RHEL/CentOS 5.x.

James Brown
James Brown

Oh, hey, somebody already fixed it in master. Commit b6ff1fc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 10 additions and 1 deletion. Show diff stats Hide diff stats

  1. 11  S3/Utils.py
11  S3/Utils.py
@@ -3,6 +3,7 @@
3 3
 ##         http://www.logix.cz/michal
4 4
 ## License: GPL Version 2
5 5
 
  6
+import datetime
6 7
 import os
7 8
 import sys
8 9
 import time
@@ -16,6 +17,7 @@
16 17
 
17 18
 from logging import debug, info, warning, error
18 19
 
  20
+
19 21
 import Config
20 22
 import Exceptions
21 23
 
@@ -163,7 +165,14 @@ def formatSize(size, human_readable = False, floating_point = False):
163 165
 __all__.append("formatSize")
164 166
 
165 167
 def formatDateTime(s3timestamp):
166  
-    return time.strftime("%Y-%m-%d %H:%M", dateS3toPython(s3timestamp))
  168
+    try:
  169
+        import pytz
  170
+        timezone = pytz.timezone(os.environ.get('TZ', 'UTC'))
  171
+        utc_dt = datetime.datetime(*dateS3toPython(s3timestamp)[0:6], tzinfo=pytz.timezone('UTC'))
  172
+        dt_object = utc_dt.astimezone(timezone)
  173
+    except ImportError:
  174
+        dt_object = datetime.datetime(*dateS3toPython(s3timestamp)[0:6])
  175
+    return dt_object.strftime("%Y-%m-%d %H:%M")
167 176
 __all__.append("formatDateTime")
168 177
 
169 178
 def convertTupleListToDict(list):
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.