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