~dpm/qreator/snap

1 by David Planella
Initial project creation with Quickly!
1
#!/usr/bin/env python
2
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
3
### BEGIN LICENSE
20 by David Planella
Added license
4
# Copyright (C) 2012 David Planella <david.planella@ubuntu.com>
107 by David Planella
Bumped version number to allow installing the daily PPA over a stable version. Some additional whitespace changes
5
# This program is free software: you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License version 3, as published
20 by David Planella
Added license
7
# by the Free Software Foundation.
107 by David Planella
Bumped version number to allow installing the daily PPA over a stable version. Some additional whitespace changes
8
#
9
# This program is distributed in the hope that it will be useful, but
10
# WITHOUT ANY WARRANTY; without even the implied warranties of
11
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
20 by David Planella
Added license
12
# PURPOSE.  See the GNU General Public License for more details.
107 by David Planella
Bumped version number to allow installing the daily PPA over a stable version. Some additional whitespace changes
13
#
14
# You should have received a copy of the GNU General Public License along
20 by David Planella
Added license
15
# with this program.  If not, see <http://www.gnu.org/licenses/>.
1 by David Planella
Initial project creation with Quickly!
16
### END LICENSE
17
89.2.37 by David Planella
Pre-upgrade checkpoint
18
###################### DO NOT TOUCH THIS (HEAD TO THE SECOND PART) ######################
89.10.4 by Stefan Schwarzburg
Pre-upgrade checkpoint
19
1 by David Planella
Initial project creation with Quickly!
20
import os
21
import sys
22
23
try:
24
    import DistUtilsExtra.auto
25
except ImportError:
26
    print >> sys.stderr, 'To build qreator you need https://launchpad.net/python-distutils-extra'
27
    sys.exit(1)
28
assert DistUtilsExtra.auto.__version__ >= '2.18', 'needs DistUtilsExtra.auto >= 2.18'
29
86.1.9 by David Planella
Checkpoint commit for testing purposes
30
def update_config(libdir, values = {}):
31
32
    filename = os.path.join(libdir, 'qreator_lib/qreatorconfig.py')
1 by David Planella
Initial project creation with Quickly!
33
    oldvalues = {}
34
    try:
86.1.9 by David Planella
Checkpoint commit for testing purposes
35
        fin = file(filename, 'r')
36
        fout = file(filename + '.new', 'w')
1 by David Planella
Initial project creation with Quickly!
37
38
        for line in fin:
86.1.9 by David Planella
Checkpoint commit for testing purposes
39
            fields = line.split(' = ') # Separate variable from value
1 by David Planella
Initial project creation with Quickly!
40
            if fields[0] in values:
41
                oldvalues[fields[0]] = fields[1].strip()
42
                line = "%s = %s\n" % (fields[0], values[fields[0]])
43
            fout.write(line)
44
45
        fout.flush()
46
        fout.close()
47
        fin.close()
48
        os.rename(fout.name, fin.name)
49
    except (OSError, IOError), e:
86.1.9 by David Planella
Checkpoint commit for testing purposes
50
        print ("ERROR: Can't find %s" % filename)
1 by David Planella
Initial project creation with Quickly!
51
        sys.exit(1)
52
    return oldvalues
53
54
86.1.9 by David Planella
Checkpoint commit for testing purposes
55
def move_desktop_file(root, target_data, prefix):
56
    # The desktop file is rightly installed into install_data.  But it should
57
    # always really be installed into prefix, because while we can install
58
    # normal data files anywhere we want, the desktop file needs to exist in
59
    # the main system to be found.  Only actually useful for /opt installs.
60
61
    old_desktop_path = os.path.normpath(root + target_data +
62
                                        '/share/applications')
63
    old_desktop_file = old_desktop_path + '/qreator.desktop'
64
    desktop_path = os.path.normpath(root + prefix + '/share/applications')
65
    desktop_file = desktop_path + '/qreator.desktop'
66
67
    if not os.path.exists(old_desktop_file):
68
        print ("ERROR: Can't find", old_desktop_file)
69
        sys.exit(1)
70
    elif target_data != prefix + '/':
71
        # This is an /opt install, so rename desktop file to use extras-
72
        desktop_file = desktop_path + '/extras-qreator.desktop'
73
        try:
74
            os.makedirs(desktop_path)
75
            os.rename(old_desktop_file, desktop_file)
76
            os.rmdir(old_desktop_path)
77
        except OSError as e:
78
            print ("ERROR: Can't rename", old_desktop_file, ":", e)
79
            sys.exit(1)
80
81
    return desktop_file
82
83
def update_desktop_file(filename, target_pkgdata, target_scripts):
1 by David Planella
Initial project creation with Quickly!
84
85
    try:
86.1.9 by David Planella
Checkpoint commit for testing purposes
86
        fin = file(filename, 'r')
87
        fout = file(filename + '.new', 'w')
1 by David Planella
Initial project creation with Quickly!
88
17 by David Planella
First working version ready for release
89
        for line in fin:
1 by David Planella
Initial project creation with Quickly!
90
            if 'Icon=' in line:
86.1.9 by David Planella
Checkpoint commit for testing purposes
91
                line = "Icon=%s\n" % (target_pkgdata + 'media/qreator.svg')
92
            elif 'Exec=' in line:
93
                cmd = line.split("=")[1].split(None, 1)
94
                line = "Exec=%s" % (target_scripts + 'qreator')
95
                if len(cmd) > 1:
96
                    line += " %s" % cmd[1].strip()  # Add script arguments back
97
                line += "\n"
1 by David Planella
Initial project creation with Quickly!
98
            fout.write(line)
99
        fout.flush()
100
        fout.close()
101
        fin.close()
102
        os.rename(fout.name, fin.name)
103
    except (OSError, IOError), e:
86.1.9 by David Planella
Checkpoint commit for testing purposes
104
        print ("ERROR: Can't find %s" % filename)
1 by David Planella
Initial project creation with Quickly!
105
        sys.exit(1)
106
86.1.9 by David Planella
Checkpoint commit for testing purposes
107
def compile_schemas(root, target_data):
108
    if target_data == '/usr/':
109
        return  # /usr paths don't need this, they will be handled by dpkg
110
    schemadir = os.path.normpath(root + target_data + 'share/glib-2.0/schemas')
111
    if (os.path.isdir(schemadir) and
112
            os.path.isfile('/usr/bin/glib-compile-schemas')):
113
        os.system('/usr/bin/glib-compile-schemas "%s"' % schemadir)
114
1 by David Planella
Initial project creation with Quickly!
115
116
class InstallAndUpdateDataDirectory(DistUtilsExtra.auto.install_auto):
117
    def run(self):
86.1.9 by David Planella
Checkpoint commit for testing purposes
118
        DistUtilsExtra.auto.install_auto.run(self)
119
120
        target_data = '/' + os.path.relpath(self.install_data, self.root) + '/'
121
        target_pkgdata = target_data + 'share/qreator/'
122
        target_scripts = '/' + os.path.relpath(self.install_scripts, self.root) + '/'
123
124
        values = {'__qreator_data_directory__': "'%s'" % (target_pkgdata),
89.2.41 by Stefan Schwarzburg
reverted changes
125
                  '__version__': "'%s'" % self.distribution.get_version()}
86.1.9 by David Planella
Checkpoint commit for testing purposes
126
        update_config(self.install_lib, values)
127
128
        desktop_file = move_desktop_file(self.root, target_data, self.prefix)
129
        update_desktop_file(desktop_file, target_pkgdata, target_scripts)
130
        compile_schemas(self.root, target_data)
131
107 by David Planella
Bumped version number to allow installing the daily PPA over a stable version. Some additional whitespace changes
132
89.2.41 by Stefan Schwarzburg
reverted changes
133
##################################################################################
134
###################### YOU SHOULD MODIFY ONLY WHAT IS BELOW ######################
135
##################################################################################
1 by David Planella
Initial project creation with Quickly!
136
137
DistUtilsExtra.auto.setup(
27 by David Planella
Reverted the capitalization of the app's name, which seems to make Quickly crash
138
    name='qreator',
107 by David Planella
Bumped version number to allow installing the daily PPA over a stable version. Some additional whitespace changes
139
    version='12.11.1',
17 by David Planella
First working version ready for release
140
    license='GPL-3',
141
    author='David Planella',
86.1.15 by David Planella
Re-added the e-mail on the setup.py file
142
    author_email='david.planella@ubuntu.com',
17 by David Planella
First working version ready for release
143
    description='Create your own QR codes',
38 by David Planella
Fixed description
144
    long_description="Qreator enables you to easily create your " +
17 by David Planella
First working version ready for release
145
                     "own QR codes to encode different types of information" +
146
                     " in an efficient, compact and cool way.",
147
    url='https://launchpad.net/qreator',
1 by David Planella
Initial project creation with Quickly!
148
    cmdclass={'install': InstallAndUpdateDataDirectory}
149
    )