Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 13072:8c6b7a5f38c4
merge with stable
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Wed, 01 Dec 2010 18:47:40 -0600 |
parents | e2b8c7a6ff4d adff480db558 |
children | f7d6750dcd01 |
comparison
equal
deleted
inserted
replaced
13059:f553024f1832 | 13072:8c6b7a5f38c4 |
---|---|
831 except: pass | 831 except: pass |
832 self._fp.close() | 832 self._fp.close() |
833 | 833 |
834 def makedirs(name, mode=None): | 834 def makedirs(name, mode=None): |
835 """recursive directory creation with parent mode inheritance""" | 835 """recursive directory creation with parent mode inheritance""" |
836 parent = os.path.abspath(os.path.dirname(name)) | |
836 try: | 837 try: |
837 os.mkdir(name) | 838 os.mkdir(name) |
838 if mode is not None: | 839 if mode is not None: |
839 os.chmod(name, mode) | 840 os.chmod(name, mode) |
840 return | 841 return |
841 except OSError, err: | 842 except OSError, err: |
842 if err.errno == errno.EEXIST: | 843 if err.errno == errno.EEXIST: |
843 return | 844 return |
844 if not name or err.errno != errno.ENOENT: | 845 if not name or parent == name or err.errno != errno.ENOENT: |
845 raise | 846 raise |
846 parent = os.path.abspath(os.path.dirname(name)) | |
847 makedirs(parent, mode) | 847 makedirs(parent, mode) |
848 makedirs(name, mode) | 848 makedirs(name, mode) |
849 | 849 |
850 class opener(object): | 850 class opener(object): |
851 """Open files relative to a base directory | 851 """Open files relative to a base directory |
1013 lt = time.localtime() | 1013 lt = time.localtime() |
1014 if lt[8] == 1 and time.daylight: | 1014 if lt[8] == 1 and time.daylight: |
1015 tz = time.altzone | 1015 tz = time.altzone |
1016 else: | 1016 else: |
1017 tz = time.timezone | 1017 tz = time.timezone |
1018 return time.mktime(lt), tz | 1018 t = time.mktime(lt) |
1019 if t < 0: | |
1020 hint = _("check your clock") | |
1021 raise Abort(_("negative timestamp: %d") % t, hint=hint) | |
1022 return t, tz | |
1019 | 1023 |
1020 def datestr(date=None, format='%a %b %d %H:%M:%S %Y %1%2'): | 1024 def datestr(date=None, format='%a %b %d %H:%M:%S %Y %1%2'): |
1021 """represent a (unixtime, offset) tuple as a localized time. | 1025 """represent a (unixtime, offset) tuple as a localized time. |
1022 unixtime is seconds since the epoch, and offset is the time zone's | 1026 unixtime is seconds since the epoch, and offset is the time zone's |
1023 number of seconds away from UTC. if timezone is false, do not | 1027 number of seconds away from UTC. if timezone is false, do not |
1114 # time zone offset. values must fit in signed 32 bits for | 1118 # time zone offset. values must fit in signed 32 bits for |
1115 # current 32-bit linux runtimes. timezones go from UTC-12 | 1119 # current 32-bit linux runtimes. timezones go from UTC-12 |
1116 # to UTC+14 | 1120 # to UTC+14 |
1117 if abs(when) > 0x7fffffff: | 1121 if abs(when) > 0x7fffffff: |
1118 raise Abort(_('date exceeds 32 bits: %d') % when) | 1122 raise Abort(_('date exceeds 32 bits: %d') % when) |
1123 if when < 0: | |
1124 raise Abort(_('negative date value: %d') % when) | |
1119 if offset < -50400 or offset > 43200: | 1125 if offset < -50400 or offset > 43200: |
1120 raise Abort(_('impossible time zone offset: %d') % offset) | 1126 raise Abort(_('impossible time zone offset: %d') % offset) |
1121 return when, offset | 1127 return when, offset |
1122 | 1128 |
1123 def matchdate(date): | 1129 def matchdate(date): |