File: install.py

package info (click to toggle)
frescobaldi 1.1.4-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 4,240 kB
  • ctags: 2,434
  • sloc: python: 15,614; lisp: 28; sh: 25; makefile: 2
file content (120 lines) | stat: -rw-r--r-- 4,270 bytes parent folder | download
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# This file is part of the Frescobaldi project, http://www.frescobaldi.org/
#
# Copyright (c) 2008, 2009, 2010 by Wilbert Berendsen
#
# 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 2
# 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# See http://www.gnu.org/licenses/ for more information.

from __future__ import unicode_literals

"""
Functions that can be run if the user updates Frescobaldi
to a newer version.
"""

import os, re, sys

from PyKDE4.kdecore import KConfig, KGlobal, KStandardDirs

def install(app, oldVersion):
    """
    Run when the version in the root config group is different from the
    running Frescobaldi version.
    """
    version = tuple(map(int, re.findall(r'\d+', oldVersion)))
    
    if not version:
        installKateModeRC()
    
    if version < (1, 1, 0):
        newLilyPondConfig()
    
    if version < (1, 1, 2):
        saveOnRunWarning()
    
    # on every update:
    checkNewExpandDefaultShortcuts()
    
    # ... other stuff can be added here ...
    


def installKateModeRC():
    """ Preset a few variables in the LilyPond Kate mode """
    katemoderc = KConfig("katemoderc", KConfig.NoGlobals)
    rc = katemoderc.group("LilyPond")
    rc.writeEntry("Variables", "kate: "
        "indent-mode lilypond; "
        )
    rc.sync()

def installOkularPartRC():
    """ Set our custom editor command in okularpartrc """
    # determine the command needed to run us
    command = sys.argv[0]
    if os.path.sep in command: # does the command contain a directory separator?
        if not os.path.isabs(command):
            command = os.path.abspath(command)
        if command == KStandardDirs.findExe("frescobaldi"):
            command = "frescobaldi"
    command += " --smart --line %l --column %c"
    okularpartrc = KConfig("okularpartrc", KConfig.NoGlobals)
    group = okularpartrc.group("General")
    group.writeEntry("ExternalEditor", "Custom")
    group.writeEntry("ExternalEditorCommand", command)
    if not group.readEntry("WatchFile", True):
        group.writeEntry("WatchFile", True)
    group.sync()
    
def newLilyPondConfig():
    """ Take old lilypond path preference over to new multi-version config (1.1.0) """
    c = KGlobal.config()
    group = c.group("lilypond")
    if not group.hasKey("default"):
        cmds = c.group("commands")
        lily = cmds.readEntry("lilypond", "lilypond")
        conv = cmds.readEntry("convert-ly", "convert-ly")
        if (os.path.isabs(lily) and os.path.isabs(conv)
            and os.path.dirname(lily) == os.path.dirname(conv)):
            conv = os.path.basename(conv)
        group.writeEntry("default", lily)
        group.writeEntry("paths", [lily])
        group = group.group(lily)
        group.writeEntry("convert-ly", conv)
        c.sync()
    
def checkNewExpandDefaultShortcuts():
    """ Check the expansions file for new default shortcuts. """
    exp = KConfig("expansions", KConfig.NoGlobals, "appdata")
    shc = KGlobal.config().group("expand shortcuts")
    for name in exp.groupList():
        group = exp.group(name)
        if group.hasKey("Name") and group.hasKey("Default Shortcut"):
            shortcut = group.readEntry("Default Shortcut", "")
            group.deleteEntry("Default Shortcut")
            if shortcut:
                shc.writeEntry(name, shortcut)
    exp.sync()
    shc.sync()

def saveOnRunWarning():
    """ Copy old setting to the new save on run notification setting (1.1.2)"""
    c = KGlobal.config()
    group = c.group("preferences")
    if group.readEntry("save on run", False):
        group = c.group("Notification Messages")
        group.writeEntry("save_on_run", False)
        c.sync()