2 # -*- coding: utf-8 -*-
3 # vim:set ts=2 sw=2 et:
4 # Alexander Rødseth <rodseth@gmail.com>
10 from sys
import exit
, argv
11 from time
import localtime
12 from subprocess
import getstatusoutput
14 ver
= "Eclipse motivational splash screen setup v 1.1"
15 instmsg
= "Installing Eclipse motivational splash image..."
16 req
= "Must run as root"
17 progdir
= "/usr/share/eclipse-motivational-splash"
20 return os
.listdir(os
.path
.expanduser(path
))
22 def lsd(path
): #: list
23 return [e
[1] for e
in sorted([(os
.path
.getmtime(os
.path
.join(path
, f
)), os
.path
.join(path
, f
)) for f
in ls(path
)])]
25 def install_splash(newsplashfile
, msg
=instmsg
):
26 status
, splashdata
= getstatusoutput("pacman -Ql eclipse")
28 for line
in splashdata
.split("\n"):
29 if line
.endswith("splash.bmp"):
33 splashfile
= splash
.split()[1]
35 print("Unable to find eclipse splash image (got %s)" % (splash
))
37 esplashdir
= os
.path
.dirname(splashfile
)
38 today
= "-".join(map(str, localtime()[0:6]))
39 backupfile
= os
.path
.join(progdir
, "splash-backup-%s.bmp" % (today
))
40 if os
.path
.exists(splashfile
):
41 if 0 != getstatusoutput("mv -f %s %s" % (splashfile
, backupfile
))[0]:
42 print(ver
+ "\n" + req
)
45 if 0 != getstatusoutput("cp %s %s" % (newsplashfile
, splashfile
))[0]:
47 print("Unable to install splash image to %s/" % (esplashdir
))
50 splashdir
= os
.path
.dirname(splashfile
)
51 if 0 != getstatusoutput("mkdir -p %s" % (splashdir
))[0]:
52 print(ver
+ "\n" + req
)
55 if 0 != getstatusoutput("cp %s %s" % (newsplashfile
, splashfile
))[0]:
57 print("Unable to install splash image to %s/" % (esplashdir
))
62 newsplashfile
= os
.path
.join(progdir
, "splash.bmp")
65 if arguments
[0] == "-r":
66 status
, splashdata
= getstatusoutput("pacman -Ql eclipse")
67 # if eclipse is removed, nothing to do
72 # if eclipse is here, move oldest splash backup as the new splash
73 last
= [f
for f
in lsd(progdir
) if "backup" in f
][:1]
76 install_splash(lastfile
, instmsg
.replace("Installing", "Resetting"))
78 # Directory probably doesn't exist, nothing to do
82 install_splash(newsplashfile
)
84 if __name__
== "__main__":