Browse Source

copy files to /etc and bash completion when installing

tags/v1.0.0
Robin Thoni 7 years ago
parent
commit
2ed367f169
1 changed files with 28 additions and 2 deletions
  1. 28
    2
      setup.py

+ 28
- 2
setup.py View File

1
 #! /usr/bin/env python
1
 #! /usr/bin/env python
2
 from os import path
2
 from os import path
3
 import os
3
 import os
4
+
5
+import shutil
6
+import subprocess
7
+
4
 from setuptools import setup, find_packages
8
 from setuptools import setup, find_packages
9
+from setuptools.command.install import install
5
 
10
 
6
 install_requires = [
11
 install_requires = [
7
     'argcomplete'
12
     'argcomplete'
10
 here = path.abspath(path.dirname(__file__))
15
 here = path.abspath(path.dirname(__file__))
11
 
16
 
12
 
17
 
18
+class InstallCommand(install):
19
+    def run(self):
20
+        install.run(self)
21
+        try:
22
+            if path.isdir('/etc/bash_completion.d/'):
23
+                shutil.copy('extra/bash/sitegen', '/etc/bash_completion.d/')
24
+        except Exception as e:
25
+            print(e)
26
+        try:
27
+            if not path.isdir('/etc/sitegen/'):
28
+                shutil.copytree('extra/sitegen/', '/etc/sitegen/')
29
+                os.mkdir('/etc/sitegen/hooks-enabled/')
30
+                for hook_type in ['site', 'cert']:
31
+                    os.mkdir('/etc/sitegen/hooks-enabled/%1s' % hook_type)
32
+                    for file in os.listdir('/etc/sitegen/hooks-available/%1s/' % hook_type):
33
+                        os.symlink('../../hooks-available/%1s/%2s' % (hook_type, file),
34
+                                   '/etc/sitegen/hooks-enabled/%1s/%2s' % (hook_type, file))
35
+        except Exception as e:
36
+            print(e)
37
+
38
+
13
 def package_files(directory):
39
 def package_files(directory):
14
     paths = []
40
     paths = []
15
     for (path, directories, filenames) in os.walk(directory):
41
     for (path, directories, filenames) in os.walk(directory):
68
     },
94
     },
69
 
95
 
70
     data_files=[
96
     data_files=[
71
-        ('/etc/bash_completion.d/', ['extra/bash/sitegen']),
97
+        ('share/sitegen/bash_completion.d/', ['extra/bash/sitegen']),
72
         ('share/sitegen/', ['extra/apache/sitegen.conf']),
98
         ('share/sitegen/', ['extra/apache/sitegen.conf']),
73
         ('etc/sitegen/', ['extra/sitegen/sitegen.json']),
99
         ('etc/sitegen/', ['extra/sitegen/sitegen.json']),
74
         ('etc/sitegen/hooks-available/cert/', package_files('extra/sitegen/hooks-available/cert/')),
100
         ('etc/sitegen/hooks-available/cert/', package_files('extra/sitegen/hooks-available/cert/')),
83
     },
109
     },
84
 
110
 
85
     cmdclass={
111
     cmdclass={
86
-        # 'install': PostInstallCommand,
112
+        'install': InstallCommand,
87
     }
113
     }
88
 )
114
 )

Loading…
Cancel
Save