Revision | a11c183f53783e9d567373160f95a1f94769cb01 (tree) |
---|---|
Zeit | 2009-01-24 23:59:03 |
Autor | Face |
Commiter | Face |
Proof-of-Concept
@@ -0,0 +1,53 @@ | ||
1 | +# timestamps.py - save or restore modification times of files | |
2 | +# | |
3 | +# Copyright 2009 Friedrich Kastner-Masilko <face@snoopie.at> | |
4 | +# | |
5 | +# This software may be used and distributed according to the terms | |
6 | +# of the GNU General Public License, incorporated herein by reference. | |
7 | + | |
8 | +from mercurial.i18n import _ | |
9 | +from mercurial.node import * | |
10 | +from mercurial.repo import RepoError | |
11 | +from mercurial import commands, cmdutil, hg, node, util | |
12 | +import os, tempfile, time | |
13 | + | |
14 | +def timestamp(ui, repo, *files, **opts): | |
15 | + """save or restore modification times of files""" | |
16 | + modified, added, removed, deleted, unknown, ignored, clean = [ | |
17 | + n for n in repo.status()] | |
18 | + | |
19 | + tsdict= dict(); | |
20 | + | |
21 | + try: | |
22 | + tsfile = file(repo.root+'/.hgtimestamp', 'r') | |
23 | + for line in tsfile.readlines(): | |
24 | + fname, mtime = line.strip().split(',') | |
25 | + tsdict[fname] = float(mtime) | |
26 | + except: | |
27 | + raise util.Abort(_('fail')); | |
28 | + | |
29 | + if opts['save']: | |
30 | + pm = file(repo.root+'/.hgtimestamp', 'w') | |
31 | + patched = modified + added | |
32 | + for fname in patched: | |
33 | + mtime = os.stat(fname).st_mtime | |
34 | + pm.write("%s,%s\n" % (fname, mtime)) | |
35 | + elif opts['restore']: | |
36 | + pm = file(repo.root+'/.hgtimestamp', 'r') | |
37 | + for line in pm.readlines(): | |
38 | + f, mtime = line.strip().split(',') | |
39 | + fname = repo.wjoin(f) | |
40 | + st = os.stat(fname) | |
41 | + os.utime(fname, (st.st_atime, type(st.st_mtime)(mtime))) | |
42 | + else: | |
43 | + for fname, mtime in tsdict.items(): | |
44 | + ui.status(time.strftime("%d.%m.%Y %H:%M:%S", time.localtime(mtime)), " \t", fname, "\n") | |
45 | + return True | |
46 | + | |
47 | +cmdtable = { | |
48 | + "timestamp": | |
49 | + (timestamp, | |
50 | + [('s', 'save', None, _('save modification times')), | |
51 | + ('r', 'restore', None, _('restore modification times'))], | |
52 | + _('hg timestamp [-s | -r]')), | |
53 | +} |