-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.py
More file actions
127 lines (102 loc) · 4.03 KB
/
setup.py
File metadata and controls
127 lines (102 loc) · 4.03 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
### BEGIN LICENSE
# This file is in the public domain
### END LICENSE
############## DO NOT TOUCH THIS (HEAD TO THE SECOND PART) ##################
import os
import sys
import shutil
from distutils.core import setup
from distutils.command.build import build
from distutils.spawn import find_executable, spawn
def find_packages(path='.'):
''' Find all python packate to install them.
@param path: The path to start search for the packages.
'''
walker = os.walk(path)
result = []
for path, directories, filenames in walker:
if '__init__.py' in filenames:
result.append(path)
return result
def find_data(search_path, install_path='share/tmppackages_common'):
''' find all data files and create a list with the install targets.
@param search_path: The path to search for files
@param install_path: The default path to install the files
TODO: add support for other platforms than Linux
'''
walker = os.walk(search_path, topdown=True)
result = []
for path, directories, filenames in walker:
resultfiles = []
for name in filenames:
resultfiles.append(os.path.join(path, name))
pathname = path[len(search_path):]
while pathname.startswith('/'):
pathname = pathname[1:]
result.append((os.path.join(install_path, pathname), resultfiles))
return result
def update_version_file(version):
''' Set the version within tmppackages/__init__.py to the current installed
version.
@param version: The version string to set
'''
try:
fin = file('tmppackages/__init__.py', 'r')
fout = file(fin.name + '.new', 'w')
for line in fin:
if '__version__ =' in line:
line = "__version__ = '%s'\n" % (version)
fout.write(line)
fout.flush()
fout.close()
fin.close()
os.rename(fout.name, fin.name)
except (OSError, IOError):
print ("ERROR: Can't find tmppackages/__init__.py")
sys.exit(1)
class InstallAndUpdateDataDirectory(build):
def run(self):
update_version_file(self.distribution.get_version())
self.build_mo()
build.run(self)
def build_mo(self):
if not find_executable('msgfmt'):
self.warn("msgfmt executable could not be found -> no "
'translations will be built')
podir = 'i18n'
if not os.path.isdir(podir):
self.warn('could not find %s directory' % podir)
return
for po in os.listdir(podir):
if not po.endswith('.po'):
continue
pofile = os.path.join(podir, po)
modir = os.path.join('locale', po[:-3], 'LC_MESSAGES')
mofile = os.path.join(modir, 'tmppackages.mo')
mobuildfile = os.path.join('tmppackages', mofile)
cmd = ['msgfmt', '-v', '-o', mobuildfile, pofile, '-c']
self.mkpath(os.path.join('tmppackages', modir))
self.make_file([pofile], mobuildfile, spawn, (cmd,))
if os.path.isdir('locale'):
shutil.rmtree('locale')
shutil.move(os.path.join('tmppackages', 'locale'), 'locale')
##############################################################################
################### YOU SHOULD MODIFY ONLY WHAT IS BELOW #####################
##############################################################################
setup(
name='tmppackages',
version='0.1.0',
license='BSD',
author='Mathias Weber',
author_email='mathew.weber@gmail.com',
description='A template python directory for writing applications',
long_description='Add long description here.',
cmdclass={'build': InstallAndUpdateDataDirectory},
packages=find_packages('tmppackages'),
scripts=['bin/tmppackages_bin'],
data_files=(find_data('data', 'share/tmppackages') +
find_data('etc', '/etc') + find_data('locale', 'locale') +
find_data('doc', 'share/doc/tmppackages')),
)