src/modules/misc.py
changeset 443 5ffa5b7dac9c
parent 429 6c9cbb6e6600
child 451 74f1fe85fe2d
equal deleted inserted replaced
442:01fb28d438b3 443:5ffa5b7dac9c
    33 import urllib
    33 import urllib
    34 import urllib2
    34 import urllib2
    35 import urlparse
    35 import urlparse
    36 import sys
    36 import sys
    37 import zlib
    37 import zlib
    38 
    38 import time
       
    39 import calendar
    39 import pkg.urlhelpers as urlhelpers
    40 import pkg.urlhelpers as urlhelpers
    40 import pkg.portable as portable
    41 import pkg.portable as portable
    41 from pkg.client.imagetypes import img_type_names, IMG_NONE
    42 from pkg.client.imagetypes import img_type_names, IMG_NONE
    42 from pkg import VERSION
    43 from pkg import VERSION
       
    44 
       
    45 def time_to_timestamp(t):
       
    46         """ convert seconds since epoch to %Y%m%dT%H%M%SZ format"""
       
    47         # XXX optimize?
       
    48         return time.strftime("%Y%m%dT%H%M%SZ", time.gmtime(t))
       
    49 
       
    50 def timestamp_to_time(ts):
       
    51         """ convert %Y%m%dT%H%M%SZ format to seconds since epoch"""
       
    52         # XXX optimize?
       
    53         return calendar.timegm(time.strptime(ts, "%Y%m%dT%H%M%SZ"))
    43 
    54 
    44 def hash_file_name(f):
    55 def hash_file_name(f):
    45         """Return the two-level path fragment for the given filename, which is
    56         """Return the two-level path fragment for the given filename, which is
    46         assumed to be a content hash of at least 8 distinct characters."""
    57         assumed to be a content hash of at least 8 distinct characters."""
    47         return os.path.join("%s" % f[0:2], "%s" % f[2:8], "%s" % f)
    58         return os.path.join("%s" % f[0:2], "%s" % f[2:8], "%s" % f)