~cm-t/dash-privacy-interface/quickly_trunk

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: cm-t arudy
  • Date: 2012-10-20 07:41:01 UTC
  • Revision ID: arudy@ubuntu-fr.org-20121020074101-4p8s40qzefe66cuo
commit before release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
 
3
### BEGIN LICENSE
 
4
# Copyright (C) 
 
5
# ubuntu-fr <LoCo Team> 
 
6
# kanor <Romain DUBREIL> <contact@kanor.fr>
 
7
# cm-t <Rudy ANDRÉ> <arudy@ubuntu-fr.org>
 
8
# olive <Olivier FRAYSSE> <olive@picapo.org>
 
9
# quesh <Frédéric MANDE> <quesh@quesh.fr>
 
10
# This program is free software: you can redistribute it and/or modify it 
 
11
# under the terms of the GNU General Public License version 3, as published 
 
12
# by the Free Software Foundation.
 
13
 
14
# This program is distributed in the hope that it will be useful, but 
 
15
# WITHOUT ANY WARRANTY; without even the implied warranties of 
 
16
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 
 
17
# PURPOSE.  See the GNU General Public License for more details.
 
18
 
19
# You should have received a copy of the GNU General Public License along 
 
20
# with this program.  If not, see <http://www.gnu.org/licenses/>.
 
21
### END LICENSE
 
22
 
 
23
###################### DO NOT TOUCH THIS (HEAD TO THE SECOND PART) ######################
 
24
 
 
25
import os
 
26
import sys
 
27
 
 
28
try:
 
29
    import DistUtilsExtra.auto
 
30
except ImportError:
 
31
    print >> sys.stderr, 'To build dash-privacy-interface you need https://launchpad.net/python-distutils-extra'
 
32
    sys.exit(1)
 
33
assert DistUtilsExtra.auto.__version__ >= '2.18', 'needs DistUtilsExtra.auto >= 2.18'
 
34
 
 
35
def update_config(libdir, values = {}):
 
36
 
 
37
    filename = os.path.join(libdir, 'dash_privacy_interface_lib/dash_privacy_interfaceconfig.py')
 
38
    oldvalues = {}
 
39
    try:
 
40
        fin = file(filename, 'r')
 
41
        fout = file(filename + '.new', 'w')
 
42
 
 
43
        for line in fin:
 
44
            fields = line.split(' = ') # Separate variable from value
 
45
            if fields[0] in values:
 
46
                oldvalues[fields[0]] = fields[1].strip()
 
47
                line = "%s = %s\n" % (fields[0], values[fields[0]])
 
48
            fout.write(line)
 
49
 
 
50
        fout.flush()
 
51
        fout.close()
 
52
        fin.close()
 
53
        os.rename(fout.name, fin.name)
 
54
    except (OSError, IOError), e:
 
55
        print ("ERROR: Can't find %s" % filename)
 
56
        sys.exit(1)
 
57
    return oldvalues
 
58
 
 
59
 
 
60
def move_desktop_file(root, target_data, prefix):
 
61
    # The desktop file is rightly installed into install_data.  But it should
 
62
    # always really be installed into prefix, because while we can install
 
63
    # normal data files anywhere we want, the desktop file needs to exist in
 
64
    # the main system to be found.  Only actually useful for /opt installs.
 
65
 
 
66
    old_desktop_path = os.path.normpath(root + target_data +
 
67
                                        '/share/applications')
 
68
    old_desktop_file = old_desktop_path + '/dash-privacy-interface.desktop'
 
69
    desktop_path = os.path.normpath(root + prefix + '/share/applications')
 
70
    desktop_file = desktop_path + '/dash-privacy-interface.desktop'
 
71
 
 
72
    if not os.path.exists(old_desktop_file):
 
73
        print ("ERROR: Can't find", old_desktop_file)
 
74
        sys.exit(1)
 
75
    elif target_data != prefix + '/':
 
76
        # This is an /opt install, so rename desktop file to use extras-
 
77
        desktop_file = desktop_path + '/extras-dash-privacy-interface.desktop'
 
78
        try:
 
79
            os.makedirs(desktop_path)
 
80
            os.rename(old_desktop_file, desktop_file)
 
81
            os.rmdir(old_desktop_path)
 
82
        except OSError as e:
 
83
            print ("ERROR: Can't rename", old_desktop_file, ":", e)
 
84
            sys.exit(1)
 
85
 
 
86
    return desktop_file
 
87
 
 
88
def update_desktop_file(filename, target_pkgdata, target_scripts):
 
89
 
 
90
    try:
 
91
        fin = file(filename, 'r')
 
92
        fout = file(filename + '.new', 'w')
 
93
 
 
94
        for line in fin:
 
95
            if 'Icon=' in line:
 
96
                line = "Icon=%s\n" % (target_pkgdata + 'media/dash-privacy-interface.svg')
 
97
            elif 'Exec=' in line:
 
98
                cmd = line.split("=")[1].split(None, 1)
 
99
                line = "Exec=%s" % (target_scripts + 'dash-privacy-interface')
 
100
                if len(cmd) > 1:
 
101
                    line += " %s" % cmd[1].strip()  # Add script arguments back
 
102
                line += "\n"
 
103
            fout.write(line)
 
104
        fout.flush()
 
105
        fout.close()
 
106
        fin.close()
 
107
        os.rename(fout.name, fin.name)
 
108
    except (OSError, IOError), e:
 
109
        print ("ERROR: Can't find %s" % filename)
 
110
        sys.exit(1)
 
111
 
 
112
def compile_schemas(root, target_data):
 
113
    if target_data == '/usr/':
 
114
        return  # /usr paths don't need this, they will be handled by dpkg
 
115
    schemadir = os.path.normpath(root + target_data + 'share/glib-2.0/schemas')
 
116
    if (os.path.isdir(schemadir) and
 
117
            os.path.isfile('/usr/bin/glib-compile-schemas')):
 
118
        os.system('/usr/bin/glib-compile-schemas "%s"' % schemadir)
 
119
 
 
120
 
 
121
class InstallAndUpdateDataDirectory(DistUtilsExtra.auto.install_auto):
 
122
    def run(self):
 
123
        DistUtilsExtra.auto.install_auto.run(self)
 
124
 
 
125
        target_data = '/' + os.path.relpath(self.install_data, self.root) + '/'
 
126
        target_pkgdata = target_data + 'share/dash-privacy-interface/'
 
127
        target_scripts = '/' + os.path.relpath(self.install_scripts, self.root) + '/'
 
128
 
 
129
        values = {'__dash_privacy_interface_data_directory__': "'%s'" % (target_pkgdata),
 
130
                  '__version__': "'%s'" % self.distribution.get_version()}
 
131
        update_config(self.install_lib, values)
 
132
 
 
133
        desktop_file = move_desktop_file(self.root, target_data, self.prefix)
 
134
        update_desktop_file(desktop_file, target_pkgdata, target_scripts)
 
135
        compile_schemas(self.root, target_data)
 
136
 
 
137
        
 
138
##################################################################################
 
139
###################### YOU SHOULD MODIFY ONLY WHAT IS BELOW ######################
 
140
##################################################################################
 
141
 
 
142
DistUtilsExtra.auto.setup(
 
143
    name='dash-privacy-interface',
 
144
    version='12.10',
 
145
    license='GPL-3',
 
146
    author='cm-t arudy',
 
147
    author_email='arudy@ubuntu-fr.org',
 
148
    #description='UI for managing …',
 
149
    #long_description='Here a longer description',
 
150
    url='https://launchpad.net/dash-privacy-interface',
 
151
    cmdclass={'install': InstallAndUpdateDataDirectory}
 
152
    )
 
153