annotate bin/dumpshot @ 288:5fbe9461efea

Faster rdesktop.
author Edho Arief <edho@myconan.net>
date Wed, 04 Jan 2012 11:49:34 +0700
parents 06ab5f0f9c28
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
100
06ab5f0f9c28 dumpshot: mindlessly dumps shot*.png files produced by mplayer.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
1 #!/usr/bin/env python
06ab5f0f9c28 dumpshot: mindlessly dumps shot*.png files produced by mplayer.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
2
06ab5f0f9c28 dumpshot: mindlessly dumps shot*.png files produced by mplayer.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
3 import sys, os, re
06ab5f0f9c28 dumpshot: mindlessly dumps shot*.png files produced by mplayer.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
4
06ab5f0f9c28 dumpshot: mindlessly dumps shot*.png files produced by mplayer.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
5 def is_shotfile(inpath):
06ab5f0f9c28 dumpshot: mindlessly dumps shot*.png files produced by mplayer.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
6 finpath = os.path.basename(inpath)
06ab5f0f9c28 dumpshot: mindlessly dumps shot*.png files produced by mplayer.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
7 return (finpath[-4:] == ".png") and (finpath[:4] == "shot")
06ab5f0f9c28 dumpshot: mindlessly dumps shot*.png files produced by mplayer.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
8
06ab5f0f9c28 dumpshot: mindlessly dumps shot*.png files produced by mplayer.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
9 def main(source_files, targetdir):
06ab5f0f9c28 dumpshot: mindlessly dumps shot*.png files produced by mplayer.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
10 max_shot=0
06ab5f0f9c28 dumpshot: mindlessly dumps shot*.png files produced by mplayer.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
11 try:
06ab5f0f9c28 dumpshot: mindlessly dumps shot*.png files produced by mplayer.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
12 current_files=os.listdir(targetdir)
06ab5f0f9c28 dumpshot: mindlessly dumps shot*.png files produced by mplayer.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
13 for current_file in current_files:
06ab5f0f9c28 dumpshot: mindlessly dumps shot*.png files produced by mplayer.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
14 if is_shotfile(current_file):
06ab5f0f9c28 dumpshot: mindlessly dumps shot*.png files produced by mplayer.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
15 file_shot = int(re.findall("\d+", current_file)[0])
06ab5f0f9c28 dumpshot: mindlessly dumps shot*.png files produced by mplayer.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
16 if file_shot > max_shot:
06ab5f0f9c28 dumpshot: mindlessly dumps shot*.png files produced by mplayer.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
17 max_shot = file_shot
06ab5f0f9c28 dumpshot: mindlessly dumps shot*.png files produced by mplayer.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
18 for source_file in source_files:
06ab5f0f9c28 dumpshot: mindlessly dumps shot*.png files produced by mplayer.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
19 if is_shotfile(source_file):
06ab5f0f9c28 dumpshot: mindlessly dumps shot*.png files produced by mplayer.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
20 max_shot += 1
06ab5f0f9c28 dumpshot: mindlessly dumps shot*.png files produced by mplayer.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
21 target_file = os.path.join(targetdir, "shot%04d.png" % max_shot)
06ab5f0f9c28 dumpshot: mindlessly dumps shot*.png files produced by mplayer.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
22 print "Moving: %s => %s" % (source_file, target_file)
06ab5f0f9c28 dumpshot: mindlessly dumps shot*.png files produced by mplayer.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
23 os.rename(source_file, target_file)
06ab5f0f9c28 dumpshot: mindlessly dumps shot*.png files produced by mplayer.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
24 except:
06ab5f0f9c28 dumpshot: mindlessly dumps shot*.png files produced by mplayer.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
25 print "(%s: %s)" % (sys.exc_type, sys.exc_value)
06ab5f0f9c28 dumpshot: mindlessly dumps shot*.png files produced by mplayer.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
26
06ab5f0f9c28 dumpshot: mindlessly dumps shot*.png files produced by mplayer.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
27 if __name__ == "__main__":
06ab5f0f9c28 dumpshot: mindlessly dumps shot*.png files produced by mplayer.
Edho Prima Arief <edho@myconan.net>
parents:
diff changeset
28 main(sys.argv[2:], sys.argv[1])