Mercurial > ec-dotfiles
comparison bin/dumpshot @ 100:06ab5f0f9c28
dumpshot: mindlessly dumps shot*.png files produced by mplayer.
author | Edho Prima Arief <edho@myconan.net> |
---|---|
date | Tue, 19 Jul 2011 15:43:36 +0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
99:97e24e89388f | 100:06ab5f0f9c28 |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 import sys, os, re | |
4 | |
5 def is_shotfile(inpath): | |
6 finpath = os.path.basename(inpath) | |
7 return (finpath[-4:] == ".png") and (finpath[:4] == "shot") | |
8 | |
9 def main(source_files, targetdir): | |
10 max_shot=0 | |
11 try: | |
12 current_files=os.listdir(targetdir) | |
13 for current_file in current_files: | |
14 if is_shotfile(current_file): | |
15 file_shot = int(re.findall("\d+", current_file)[0]) | |
16 if file_shot > max_shot: | |
17 max_shot = file_shot | |
18 for source_file in source_files: | |
19 if is_shotfile(source_file): | |
20 max_shot += 1 | |
21 target_file = os.path.join(targetdir, "shot%04d.png" % max_shot) | |
22 print "Moving: %s => %s" % (source_file, target_file) | |
23 os.rename(source_file, target_file) | |
24 except: | |
25 print "(%s: %s)" % (sys.exc_type, sys.exc_value) | |
26 | |
27 if __name__ == "__main__": | |
28 main(sys.argv[2:], sys.argv[1]) |