forked from bspaans/bookmark-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
139 lines (110 loc) · 4.45 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
from distutils.core import setup
from distutils.command.install_data import install_data
import glob
import os
import platform
from os import path
WINDOWS = platform.system() == "Windows"
## Attention packagers:
# The following paths are hard-coded.
# If you need to change anything, make sure you also change the path in btools/common.py
if not WINDOWS:
scripts = glob.glob("scripts/*")
data = [("/etc/bash_completion.d/", ["data/bm-completion"]),
("/usr/share/bm/", ["data/bm.sh", "data/bm-match-config", "data/movies.patterns"]),
("/usr/share/man/man1/", glob.glob("doc/man/*.1")),
("/usr/share/blog/hooks/", glob.glob("data/blog/hooks/*")),
]
else:
try:
import py2exe
except: pass
pf = os.environ["PROGRAMFILES"]
scripts = [] # scripts are added to the 'bin' folder instead
data = [(os.path.join(pf, "btools", "bm-match"), ["data/bm-match-config",
"data/movies.patterns"]),
(os.path.join(pf, "btools", "blog"), glob.glob("data/blog/hooks/*")),
(os.path.join(pf, "btools", "bin"), glob.glob("data/windows/*") + glob.glob("scripts/*"))]
class source_shell_script(install_data):
def source_bash_script(self, to="/etc/bash.bashrc"):
if path.exists(to) and path.exists("/usr/share/bm/bm.sh"):
f = open(to)
bashrc = f.read()
f.close()
cmd = "source /usr/share/bm/bm.sh"
if cmd in bashrc.splitlines():
return
else:
print ("Sourcing bm.sh")
try:
f = open(to, "a")
except:
print ("Error: Couldn't write to %s" % to)
return
f.write(cmd + os.linesep)
f.close()
else:
print ("Warning: the shell functions could not be sourced")
def update_windows_registry(self):
try:
import _winreg
except:
print ("Couldn't change PATH variable in registry, because the _winreg modules could not be loaded.")
return
path = os.path.join(os.environ["PROGRAMFILES"], "btools", "bin")
regpath = r'SYSTEM\CurrentControlSet\Control\Session Manager\Environment'
reg = _winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE)
try:
key = _winreg.OpenKey(reg, regpath, 0, _winreg.KEY_ALL_ACCESS)
except:
print ("Error getting PATH from registry")
return
value, type_id = _winreg.QueryValueEx(key, "PATH")
current = value.split(";")
if path in current:
return
try:
_winreg.SetValueEx(key, "PATH", 0, type_id, ";".join(current + [path]))
print ("Updated %s\\PATH registry value" % (regpath))
except:
print ("Error updating %s\\PATH registry value" % (regpath))
def run(self):
install_data.run(self)
if not WINDOWS:
self.source_bash_script()
else:
self.update_windows_registry()
setup(name="btools",
version="0.9999999",
description="Command line navigation and organization tools",
long_description=
"""Bookmark tools is a collection of useful, cross platform shell commands and Python scripts \
that aim to speed up navigation and organization in day to day work.
""",
author="Bart Spaans",
author_email = "bart@bookmark-tools.com",
url="http://www.bookmark-tools.com/",
license="GPLv3",
packages = ["btools", "btools.matching"],
scripts = scripts,
data_files = data,
cmdclass={ "install_data": source_shell_script},
classifiers = [
'Development Status :: 3 - Alpha',
'Environment :: Console'
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: GNU General Public License (GPL)',
'Natural Language :: English',
'Operating System :: Microsoft :: Windows'
'Operating System :: POSIX',
'Programming Language :: Other',
'Programming Language :: Python :: 2.5',
'Topic :: Other/Nonlisted Topic',
'Topic :: System',
'Topic :: System :: Archiving',
'Topic :: System :: Shells',
'Topic :: Text Processing',
'Topic :: Utilities',
]
)