~rick-rickspencer3/+junk/jumper

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: Rick Spencer
  • Date: 2011-09-07 09:19:38 UTC
  • Revision ID: rick.spencer@canonical.com-20110907091938-cxxescturvof9xvv
Initial project creation with Quickly!

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
# This file is in the public domain
 
5
### END LICENSE
 
6
 
 
7
###################### DO NOT TOUCH THIS (HEAD TO THE SECOND PART) ######################
 
8
 
 
9
import os
 
10
import sys
 
11
 
 
12
try:
 
13
    import DistUtilsExtra.auto
 
14
except ImportError:
 
15
    print >> sys.stderr, 'To build jumper you need https://launchpad.net/python-distutils-extra'
 
16
    sys.exit(1)
 
17
assert DistUtilsExtra.auto.__version__ >= '2.18', 'needs DistUtilsExtra.auto >= 2.18'
 
18
 
 
19
def update_config(values = {}):
 
20
 
 
21
    oldvalues = {}
 
22
    try:
 
23
        fin = file('jumper_lib/jumperconfig.py', 'r')
 
24
        fout = file(fin.name + '.new', 'w')
 
25
 
 
26
        for line in fin:
 
27
            fields = line.split(' = ') # Separate variable from value
 
28
            if fields[0] in values:
 
29
                oldvalues[fields[0]] = fields[1].strip()
 
30
                line = "%s = %s\n" % (fields[0], values[fields[0]])
 
31
            fout.write(line)
 
32
 
 
33
        fout.flush()
 
34
        fout.close()
 
35
        fin.close()
 
36
        os.rename(fout.name, fin.name)
 
37
    except (OSError, IOError), e:
 
38
        print ("ERROR: Can't find jumper_lib/jumperconfig.py")
 
39
        sys.exit(1)
 
40
    return oldvalues
 
41
 
 
42
 
 
43
def update_desktop_file(datadir):
 
44
 
 
45
    try:
 
46
        fin = file('jumper.desktop.in', 'r')
 
47
        fout = file(fin.name + '.new', 'w')
 
48
 
 
49
        for line in fin:            
 
50
            if 'Icon=' in line:
 
51
                line = "Icon=%s\n" % (datadir + 'media/jumper.svg')
 
52
            fout.write(line)
 
53
        fout.flush()
 
54
        fout.close()
 
55
        fin.close()
 
56
        os.rename(fout.name, fin.name)
 
57
    except (OSError, IOError), e:
 
58
        print ("ERROR: Can't find jumper.desktop.in")
 
59
        sys.exit(1)
 
60
 
 
61
 
 
62
class InstallAndUpdateDataDirectory(DistUtilsExtra.auto.install_auto):
 
63
    def run(self):
 
64
        values = {'__jumper_data_directory__': "'%s'" % (self.prefix + '/share/jumper/'),
 
65
                  '__version__': "'%s'" % self.distribution.get_version()}
 
66
        previous_values = update_config(values)
 
67
        update_desktop_file(self.prefix + '/share/jumper/')
 
68
        DistUtilsExtra.auto.install_auto.run(self)
 
69
        update_config(previous_values)
 
70
 
 
71
 
 
72
        
 
73
##################################################################################
 
74
###################### YOU SHOULD MODIFY ONLY WHAT IS BELOW ######################
 
75
##################################################################################
 
76
 
 
77
DistUtilsExtra.auto.setup(
 
78
    name='jumper',
 
79
    version='0.1',
 
80
    #license='GPL-3',
 
81
    #author='Your Name',
 
82
    #author_email='email@ubuntu.com',
 
83
    #description='UI for managing …',
 
84
    #long_description='Here a longer description',
 
85
    #url='https://launchpad.net/jumper',
 
86
    cmdclass={'install': InstallAndUpdateDataDirectory}
 
87
    )
 
88