-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsetup.py
executable file
·83 lines (64 loc) · 2.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
#!/usr/bin/env python2
# To install the plugin run this script as root:
# ./setup.py install
from distutils.core import setup
from distutils.cmd import Command
from distutils.log import warn, info, error
from distutils.command.install_data import install_data
from distutils.command.build import build
from distutils.sysconfig import get_python_lib
import sys
import os
import shutil
PACKAGE_NAME = 'mailnag-messagingmenu-plugin'
PLUGIN_VERSION = '1.1'
# TODO : This hack won't work with --user and --home options
PREFIX = '/usr'
for arg in sys.argv:
if arg.startswith('--prefix='):
PREFIX = arg[9:]
BUILD_DIR = 'build'
for arg in sys.argv:
if arg.startswith('--build-base='):
BUILD_DIR = arg[13:]
BUILD_PATCH_DIR = os.path.join(BUILD_DIR, 'patched')
BUILD_PLUGIN_DIR = os.path.join(BUILD_DIR, 'plugins')
class BuildData(build):
def run (self):
# remove build dir (if existing)
shutil.rmtree(BUILD_DIR, ignore_errors = True)
os.makedirs(BUILD_PATCH_DIR)
os.makedirs(BUILD_PLUGIN_DIR)
shutil.copy2('messagingmenuplugin.py', BUILD_PLUGIN_DIR)
# patch paths
self._patch_file('./mailnag-messagingmenu.desktop.in', os.path.join(BUILD_PATCH_DIR,
'mailnag-messagingmenu.desktop'), '%PREFIX%', PREFIX)
build.run (self)
def _patch_file(self, infile, outfile, orig, replaced):
with open(infile, 'r') as f:
strn = f.read()
strn = strn.replace(orig, replaced)
with open(outfile, 'w') as f:
f.write(strn)
class InstallData(install_data):
def run (self):
install_data.run (self)
class Uninstall(Command):
def run (self):
# TODO
pass
setup(name=PACKAGE_NAME,
version=PLUGIN_VERSION,
description='MessagingMenu plugin for Mailnag',
author='Patrick Ulbrich',
author_email='[email protected]',
url='https://github.com/pulb/mailnag-messagingmenu-plugin',
license='GNU GPL2',
package_dir = {'Mailnag.plugins' : BUILD_PLUGIN_DIR},
packages=['Mailnag.plugins'],
scripts=['mailnag-messagingmenu-action-launcher'],
data_files=[('share/applications', [os.path.join(BUILD_PATCH_DIR, 'mailnag-messagingmenu.desktop')])],
cmdclass={'build': BuildData,
'install_data': InstallData,
'uninstall': Uninstall}
)