ATLAS Offline Software
MooRTT_alleps2gif.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 # Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
4 
5 import os
6 import sys
7 
8 # --------- Function definition --------- #
9 
10 def alleps2gif(setupok,keepeps=True,tareps=True,tardir="MooRTT_epsimages"):
11 
12  if not setupok:
13  print "Usage: " + sys.argv[0] + " [directory]"
14  return
15 
16  old = ".eps"
17  new = ".gif"
18 
19  nofiles = True
20 
21  for epsname in os.listdir("."):
22  if epsname.count(old):
23  nofiles = False
24  gifname = epsname.replace(old,new)
25  commands = [ "pstopnm -ppm -xborder 0 -yborder 0 -portrait -xsize=1000 " + epsname ,
26  "ppmtogif " + epsname + "001.ppm > " + gifname ,
27  "rm " + epsname + "001.ppm" ]
28  if not keepeps:
29  commands.append("rm " + epsname)
30  for command in commands:
31  print "Running: " + command
32  os.system(command)
33 
34  if keepeps and tareps:
35  commands = [ "mkdir " + tardir ,
36  "mv *" + old + " " + tardir ,
37  "tar -czf " + tardir + ".tar.gz " + tardir ,
38  "rm -rf " + tardir ]
39  for command in commands:
40  print "Running: " + command
41  os.system(command)
42 
43  if nofiles:
44  print "No " + old + " files in directory."
45 
46 # -------- Start of running is here ------- #
47 
48 setupok = True
49 
50 if len(sys.argv) > 1:
51  if len(sys.argv) > 2:
52  setupok = False
53  else:
54  print "Changing to directory: " + sys.argv[1]
55  try:
56  os.chdir(sys.argv[1])
57  except:
58  print "Move to directory " + sys.argv[1] + " failed."
59  setupok = False
60 else:
61  print "Running in current directory."
62 
63 alleps2gif(setupok)
64 
65 # sprintf(comm1,"%s %s","pstopnm -ppm -xborder 0 -yborder 0 -portrait",epsname);
66 # sprintf(comm2,"%s %s%s %s","ppmtogif",epsname,"001.ppm >",gifname);
67 # sprintf(comm3,"rm %s",epsname);
68 # sprintf(comm4,"rm %s001.ppm",epsname);
69 
MooRTT_alleps2gif.alleps2gif
def alleps2gif(setupok, keepeps=True, tareps=True, tardir="MooRTT_epsimages")
Definition: MooRTT_alleps2gif.py:10