~luismmontielg/+junk/godownloader

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: Luis Montiel
  • Date: 2010-01-21 18:23:41 UTC
  • Revision ID: luis@luis-laptop-20100121182341-5ybbqj3n3liw9zvi
Initial project creation with Quickly!

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# -*- coding: utf-8 -*-
 
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
try:
 
10
    import DistUtilsExtra.auto
 
11
except ImportError:
 
12
    import sys
 
13
    print >> sys.stderr, 'To build godownloader you need https://launchpad.net/python-distutils-extra'
 
14
    sys.exit(1)
 
15
 
 
16
assert DistUtilsExtra.auto.__version__ >= '2.10', 'needs DistUtilsExtra.auto >= 2.10'
 
17
import os
 
18
 
 
19
 
 
20
def update_data_path(prefix, oldvalue=None):
 
21
 
 
22
    try:
 
23
        fin = file('godownloader/godownloaderconfig.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] == '__godownloader_data_directory__':
 
29
                # update to prefix, store oldvalue
 
30
                if not oldvalue:
 
31
                    oldvalue = fields[1]
 
32
                    line = "%s = '%s'\n" % (fields[0], prefix)
 
33
                else: # restore oldvalue
 
34
                    line = "%s = %s" % (fields[0], oldvalue)
 
35
            fout.write(line)
 
36
 
 
37
        fout.flush()
 
38
        fout.close()
 
39
        fin.close()
 
40
        os.rename(fout.name, fin.name)
 
41
    except (OSError, IOError), e:
 
42
        print ("ERROR: Can't find godownloader/godownloaderconfig.py")
 
43
        sys.exit(1)
 
44
    return oldvalue
 
45
 
 
46
 
 
47
def update_desktop_file(datadir):
 
48
 
 
49
    try:
 
50
        fin = file('godownloader.desktop.in', 'r')
 
51
        fout = file(fin.name + '.new', 'w')
 
52
 
 
53
        for line in fin:            
 
54
            if 'Icon=' in line:
 
55
                line = "Icon=%s\n" % (datadir + 'media/icon.png')
 
56
            fout.write(line)
 
57
        fout.flush()
 
58
        fout.close()
 
59
        fin.close()
 
60
        os.rename(fout.name, fin.name)
 
61
    except (OSError, IOError), e:
 
62
        print ("ERROR: Can't find godownloader.desktop.in")
 
63
        sys.exit(1)
 
64
 
 
65
 
 
66
class InstallAndUpdateDataDirectory(DistUtilsExtra.auto.install_auto):
 
67
    def run(self):
 
68
        if self.root or self.home:
 
69
            print "WARNING: You don't use a standard --prefix installation, take care that you eventually " \
 
70
            "need to update quickly/quicklyconfig.py file to adjust __quickly_data_directory__. You can " \
 
71
            "ignore this warning if you are packaging and uses --prefix."
 
72
        previous_value = update_data_path(self.prefix + '/share/godownloader/')
 
73
        update_desktop_file(self.prefix + '/share/godownloader/')
 
74
        DistUtilsExtra.auto.install_auto.run(self)
 
75
        update_data_path(self.prefix, previous_value)
 
76
 
 
77
 
 
78
        
 
79
##################################################################################
 
80
###################### YOU SHOULD MODIFY ONLY WHAT IS BELOW ######################
 
81
##################################################################################
 
82
 
 
83
DistUtilsExtra.auto.setup(
 
84
    name='godownloader',
 
85
    version='0.1',
 
86
    #license='GPL v3',
 
87
    #author='Your Name',
 
88
    #author_email='email@ubuntu.com',
 
89
    #description='UI for managing …',
 
90
    #long_description='Here a longer description',
 
91
    #url='https://launchpad.net/godownloader',
 
92
    cmdclass={'install': InstallAndUpdateDataDirectory}
 
93
    )
 
94