~doctormo/genetic-wallpapers/stable

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/python
#
# Copyright (C) 2010-2011 Martin Owens
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
"""
Detect if a user has a wallpaper in use and call nudge as required.
"""
import sys
import os
import datetime

from xml.dom.minidom import parse
from GeneticWallpapers import LOCAL_FILES, get_plots
from GeneticWallpapers.gnomebacks import get_gnome_wallpaper
from GeneticWallpapers.genetic import GeneticWallpaper

def too_new(filename):
    """Return true if the file was modified in the last day"""
    modded = time.localtime(os.path.getmtime(filename))
    now = datetime.datetime.now()
    if modded > now - datetime.timedelta(days=1):
        return True
    return False

if __name__ == '__main__':
    # Check mod means to not update if the svg is too new.
    check_mod = False
    if len(sys.argv) == 2:
        check_mod = True
    # Find the wallpaper in use
    in_use = get_gnome_wallpaper()
    if in_use and os.path.exists(in_use):
        # See if it's a wallgen wallpaper
        if LOCAL_FILES in in_use:
            if check_mod and too_new(in_use):
                sys.stderr.write("Not updating, updated not long ago.\n")
            # See if it has a plot file
            plots = get_plots(in_use)
            if plots:
                sys.stderr.write("Using plots: %s\n" % plots)
            # Call nudge with the wallpaper and plot file
            wallpaper = GeneticWallpaper(in_use, plots)
            sys.stderr.write("Nudging wallpaper: %s\n" % in_use)
            wallpaper.nudge()
        else:
            sys.stderr.write("Background isn't a known genetic wallpaper. '%s'\n" % in_use)
    else:
        sys.stderr.write("Couldn't get in use wallpaper.\n")