forked from mariano/snakefire
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
135 lines (113 loc) · 4.76 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
#!/usr/bin/env python
'''
Setup file largely inspired by http://gitorious.org/smewt/smewt/blobs/master/setup.py
'''
import os, sys
from setuptools import find_packages, setup
args = dict(name="snakefire",
version="1.0.5",
description="A Campfire Desktop client for Linux",
long_description="""\
Snakefire is a desktop client for Campfire that can run on Linux, and any other
OS that has QT support.""",
classifiers=[
"Intended Audience :: End Users/Desktop",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Programming Language :: Python",
"Topic :: Communications :: Chat"
],
keywords='linux campfire chat desktop client',
author='Mariano Iglesias',
author_email='[email protected]',
url='http://snakefire.org',
license='MIT',
include_package_data=True,
packages=find_packages(exclude = [ 'ez_setup', 'examples', 'tests', 'utils' ]),
install_requires=[
"pyfire>=0.3.4",
"python-qt",
"keyring",
"pyenchant"
],
scripts=["bin/snakefire"]
)
if sys.platform.find("darwin") == 0:
mac_args = dict(
app=["bin/snakefire"],
options={'py2app':{'argv_emulation': True, 'includes':['sip', 'PyQt4', 'PyQt4.QtCore', 'PyQt4.QtGui'],
'excludes': ['PyQt4.QtDesigner', 'PyQt4.QtOpenGL', 'PyQt4.QtScript', 'PyQt4.QtSql', 'PyQt4.QtTest', 'PyQt4.QtWebKit', 'PyQt4.QtXml', 'PyQt4.phonon'],
'iconfile':'packaging/osx/Snakefire.icns'}},
setup_requires=['py2app']
)
args["install_requires"].remove("python-qt")
args.update(mac_args)
if sys.platform.find("linux") == 0:
import re, subprocess
from setuptools.command import install
kde = False
try:
subprocess.Popen(["kcheckrunning"]).wait()
kde = True
except OSError:
pass
if kde:
from PyKDE4 import kdecore
class SnakefireInstall(install.install):
user_options = install.install.user_options + [
('install-menu-in-user-mode', None, 'Run xdg-desktop-menu and xdg-icon-resource in user mode')
]
boolean_options = install.install.boolean_options + [
'install-menu-in-user-mode'
]
def initialize_options(self):
install.install.initialize_options(self)
self.install_menu_in_user_mode = None
def _binExists(self, bin):
try:
subprocess.check_output(['which', bin], stderr=subprocess.STDOUT)
return True
except subprocess.CalledProcessError:
pass
return False
def _KDECreateNotifyRc(self):
print "Installing notification resources..."
path = os.path.join(str(kdecore.KGlobal.dirs().localkdedir()), "share", "apps", "Snakefire")
if not os.path.isdir(path):
os.makedirs(path)
with open("packaging/linux/Snakefire.notifyrc", "r") as i:
with open(os.path.join(path, "Snakefire.notifyrc"), "w") as o:
o.write(i.read())
o.close()
i.close()
def _fixPythonBin(self, file, bin = 'python2'):
with open(file, "r+") as f:
print "Fixing python path in {file}".format(file=file)
contents = re.sub('^{regex}'.format(regex=re.escape('#!/usr/bin/env python')), '#!/usr/bin/env {bin}'.format(bin=bin), f.read())
f.seek(0)
f.write(contents)
f.close()
def run(self):
install.install.run(self)
if self._binExists('python2'):
self._fixPythonBin(os.path.join(self.install_scripts, "snakefire"))
if kde:
self._KDECreateNotifyRc()
menu_mode = None
if self.install_menu_in_user_mode:
menu_mode = 'user'
elif os.geteuid() == 0:
menu_mode = 'system'
if menu_mode:
print "Adding program icon and menu item in {mode} mode".format(mode=menu_mode)
subprocess.call(['xdg-desktop-menu', 'install', '--mode', menu_mode, 'packaging/linux/cricava-snakefire.desktop'])
for size in [16, 22, 32, 48, 64, 128]:
subprocess.call(['xdg-icon-resource', 'install', '--mode', menu_mode, '--size', str(size), 'resources/icons/snakefire-{size}.png'.format(size=size), 'cricava-snakefire'])
if self._binExists('update-menus'):
subprocess.call(['update-menus'])
elif self._binExists('update-desktop-database'):
subprocess.call(['update-desktop-database'])
args.update(dict(
cmdclass = { "install": SnakefireInstall }
))
setup(**args)