~rick-rickspencer3/+junk/webcam

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: Rick Spencer
  • Date: 2010-04-26 23:54:19 UTC
  • Revision ID: rick.spencer@canonical.com-20100426235419-co17h2vnhbnbi0yp
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
import os
 
10
import sys
 
11
 
 
12
try:
 
13
    import DistUtilsExtra.auto
 
14
except ImportError:
 
15
    print >> sys.stderr, 'To build gstreamer-webcam 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_data_path(prefix, oldvalue=None):
 
20
 
 
21
    try:
 
22
        fin = file('gstreamer_webcam/gstreamer_webcamconfig.py', 'r')
 
23
        fout = file(fin.name + '.new', 'w')
 
24
 
 
25
        for line in fin:            
 
26
            fields = line.split(' = ') # Separate variable from value
 
27
            if fields[0] == '__gstreamer_webcam_data_directory__':
 
28
                # update to prefix, store oldvalue
 
29
                if not oldvalue:
 
30
                    oldvalue = fields[1]
 
31
                    line = "%s = '%s'\n" % (fields[0], prefix)
 
32
                else: # restore oldvalue
 
33
                    line = "%s = %s" % (fields[0], oldvalue)
 
34
            fout.write(line)
 
35
 
 
36
        fout.flush()
 
37
        fout.close()
 
38
        fin.close()
 
39
        os.rename(fout.name, fin.name)
 
40
    except (OSError, IOError), e:
 
41
        print ("ERROR: Can't find gstreamer_webcam/gstreamer_webcamconfig.py")
 
42
        sys.exit(1)
 
43
    return oldvalue
 
44
 
 
45
 
 
46
def update_desktop_file(datadir):
 
47
 
 
48
    try:
 
49
        fin = file('gstreamer-webcam.desktop.in', 'r')
 
50
        fout = file(fin.name + '.new', 'w')
 
51
 
 
52
        for line in fin:            
 
53
            if 'Icon=' in line:
 
54
                line = "Icon=%s\n" % (datadir + 'media/icon.png')
 
55
            fout.write(line)
 
56
        fout.flush()
 
57
        fout.close()
 
58
        fin.close()
 
59
        os.rename(fout.name, fin.name)
 
60
    except (OSError, IOError), e:
 
61
        print ("ERROR: Can't find gstreamer-webcam.desktop.in")
 
62
        sys.exit(1)
 
63
 
 
64
 
 
65
class InstallAndUpdateDataDirectory(DistUtilsExtra.auto.install_auto):
 
66
    def run(self):
 
67
        previous_value = update_data_path(self.prefix + '/share/gstreamer-webcam/')
 
68
        update_desktop_file(self.prefix + '/share/gstreamer-webcam/')
 
69
        DistUtilsExtra.auto.install_auto.run(self)
 
70
        update_data_path(self.prefix, previous_value)
 
71
 
 
72
 
 
73
        
 
74
##################################################################################
 
75
###################### YOU SHOULD MODIFY ONLY WHAT IS BELOW ######################
 
76
##################################################################################
 
77
 
 
78
DistUtilsExtra.auto.setup(
 
79
    name='gstreamer-webcam',
 
80
    version='0.1',
 
81
    #license='GPL-3',
 
82
    #author='Your Name',
 
83
    #author_email='email@ubuntu.com',
 
84
    #description='UI for managing …',
 
85
    #long_description='Here a longer description',
 
86
    #url='https://launchpad.net/gstreamer-webcam',
 
87
    cmdclass={'install': InstallAndUpdateDataDirectory}
 
88
    )
 
89