Skip to content
Newer
Older
100644 704 lines (603 sloc) 27.6 KB
36198b0 Currently working through making setup.py functional for generating r…
Alex Kesling authored
1 #!/usr/bin/env python
de439c9 @jmaas Remove leftover from subprocess import hack
jmaas authored
2
568f7db @jmaas PEP8 - setup.py
jmaas authored
3 import os
4 import sys
5 import time
1e8a5c9 Rework the glob() mechanism.
Michael Jansen authored
6 import glob as _glob
de439c9 @jmaas Remove leftover from subprocess import hack
jmaas authored
7
3d26436 @crobinso setup.py: Add stub 'test' command
crobinso authored
8 from distutils.core import setup, Command
c2f1ba5 @ciupicri make qa (pep8) fixes for setup.py
ciupicri authored
9 from distutils.command.build import build as _build
1222ac4 install: move chown code from Makefile to setup.py
Michael Jansen authored
10 from distutils.command.install import install as _install
86ca397 Reconfigured setup.py to now place config files and web ui content in…
Alex Kesling authored
11 from distutils.command.build_py import build_py as _build_py
1222ac4 install: move chown code from Makefile to setup.py
Michael Jansen authored
12 from distutils import log
1899be7 Implement a configuration build step.
Michael Jansen authored
13 from distutils import dep_util
14 from distutils.dist import Distribution as _Distribution
a0c4c59 @jmaas Convert /etc/cobbler/version from Yaml to ConfigParser filetype.
jmaas authored
15 from ConfigParser import ConfigParser
de439c9 @jmaas Remove leftover from subprocess import hack
jmaas authored
16
1899be7 Implement a configuration build step.
Michael Jansen authored
17 import codecs
3d26436 @crobinso setup.py: Add stub 'test' command
crobinso authored
18 import unittest
1222ac4 install: move chown code from Makefile to setup.py
Michael Jansen authored
19 import exceptions
20 import pwd
61dd1bc Move restorestate and savestate implementation to setup.py
Michael Jansen authored
21 import shutil
de439c9 @jmaas Remove leftover from subprocess import hack
jmaas authored
22 import subprocess
a81ca9a Added back in old-style version tracking... because api.py needs it.
Alex Kesling authored
23
3d26436 @crobinso setup.py: Add stub 'test' command
crobinso authored
24 try:
25 import coverage
26 except:
a8aef1c @jmaas Enable external YUM repo mirroring through a proxy server.
jmaas authored
27 pass
a81ca9a Added back in old-style version tracking... because api.py needs it.
Alex Kesling authored
28
ef0e9b5 @jmaas Next release from master will 3.0.0
jmaas authored
29 VERSION = "2.9.0"
a81ca9a Added back in old-style version tracking... because api.py needs it.
Alex Kesling authored
30 OUTPUT_DIR = "config"
9cd4ade Added more useful files to setup.py and MANIFEST.in as well as extra
Alex Kesling authored
31
32
33 #####################################################################
e383109 @berendt resolved PEP8 issue E265
berendt authored
34 # # Helper Functions #################################################
9cd4ade Added more useful files to setup.py and MANIFEST.in as well as extra
Alex Kesling authored
35 #####################################################################
36
1e8a5c9 Rework the glob() mechanism.
Michael Jansen authored
37 def glob(*args, **kwargs):
38 recursive = kwargs.get('recursive', False)
39 results = []
40 for arg in args:
41 for elem in _glob.glob(arg):
42 # Now check if we should handle/check those results.
43 if os.path.isdir(elem):
44 if os.path.islink(elem):
45 # We skip symlinks
46 pass
47 else:
48 # We only handle directories if recursive was specified
c2f1ba5 @ciupicri make qa (pep8) fixes for setup.py
ciupicri authored
49 if recursive:
1e8a5c9 Rework the glob() mechanism.
Michael Jansen authored
50 results.extend(
51 # Add the basename of arg (the pattern) to elem and continue
52 glob(
53 os.path.join(elem, os.path.basename(arg)),
54 recursive=True))
55 else:
56 # Always append normal files
57 results.append(elem)
58 return results
36198b0 Currently working through making setup.py functional for generating r…
Alex Kesling authored
59
9cd4ade Added more useful files to setup.py and MANIFEST.in as well as extra
Alex Kesling authored
60 #####################################################################
61
36198b0 Currently working through making setup.py functional for generating r…
Alex Kesling authored
62
9cd4ade Added more useful files to setup.py and MANIFEST.in as well as extra
Alex Kesling authored
63 #####################################################################
64
a81ca9a Added back in old-style version tracking... because api.py needs it.
Alex Kesling authored
65 def gen_build_version():
66 builddate = time.asctime()
c45e952 @jmaas Fix broken gitdate, gitstamp values in version file.
jmaas authored
67 cmd = subprocess.Popen(["/usr/bin/git", "log", "--format=%h%n%ad", "-1"], stdout=subprocess.PIPE)
68 data = cmd.communicate()[0].strip()
69 if cmd.returncode == 0:
70 gitstamp, gitdate = data.split("\n")
71 else:
72 gitdate = "?"
73 gitstamp = "?"
a0c4c59 @jmaas Convert /etc/cobbler/version from Yaml to ConfigParser filetype.
jmaas authored
74
75 fd = open(os.path.join(OUTPUT_DIR, "version"), "w+")
76 config = ConfigParser()
77 config.add_section("cobbler")
568f7db @jmaas PEP8 - setup.py
jmaas authored
78 config.set("cobbler", "gitdate", gitdate)
79 config.set("cobbler", "gitstamp", gitstamp)
80 config.set("cobbler", "builddate", builddate)
81 config.set("cobbler", "version", VERSION)
82 config.set("cobbler", "version_tuple", [int(x) for x in VERSION.split(".")])
a0c4c59 @jmaas Convert /etc/cobbler/version from Yaml to ConfigParser filetype.
jmaas authored
83 config.write(fd)
a81ca9a Added back in old-style version tracking... because api.py needs it.
Alex Kesling authored
84 fd.close()
85
86 #####################################################################
e383109 @berendt resolved PEP8 issue E265
berendt authored
87 # # Custom Distribution Class ########################################
1899be7 Implement a configuration build step.
Michael Jansen authored
88 #####################################################################
89
568f7db @jmaas PEP8 - setup.py
jmaas authored
90
1899be7 Implement a configuration build step.
Michael Jansen authored
91 class Distribution(_Distribution):
92 def __init__(self, *args, **kwargs):
93 self.configure_files = []
94 self.configure_values = {}
36855d1 Create a build_man command that builds the man pages only if necessary.
Michael Jansen authored
95 self.man_pages = []
1899be7 Implement a configuration build step.
Michael Jansen authored
96 _Distribution.__init__(self, *args, **kwargs)
97
86ca397 Reconfigured setup.py to now place config files and web ui content in…
Alex Kesling authored
98 #####################################################################
e383109 @berendt resolved PEP8 issue E265
berendt authored
99 # # Modify Build Stage ##############################################
86ca397 Reconfigured setup.py to now place config files and web ui content in…
Alex Kesling authored
100 #####################################################################
101
568f7db @jmaas PEP8 - setup.py
jmaas authored
102
86ca397 Reconfigured setup.py to now place config files and web ui content in…
Alex Kesling authored
103 class build_py(_build_py):
104 """Specialized Python source builder."""
27d7199 Fix some issues with clean installs of cobbler post build cleanup
Scott Henson authored
105
86ca397 Reconfigured setup.py to now place config files and web ui content in…
Alex Kesling authored
106 def run(self):
a81ca9a Added back in old-style version tracking... because api.py needs it.
Alex Kesling authored
107 gen_build_version()
86ca397 Reconfigured setup.py to now place config files and web ui content in…
Alex Kesling authored
108 _build_py.run(self)
109
3d26436 @crobinso setup.py: Add stub 'test' command
crobinso authored
110 #####################################################################
e383109 @berendt resolved PEP8 issue E265
berendt authored
111 # # Modify Build Stage ##############################################
1899be7 Implement a configuration build step.
Michael Jansen authored
112 #####################################################################
568f7db @jmaas PEP8 - setup.py
jmaas authored
113
114
1899be7 Implement a configuration build step.
Michael Jansen authored
115 class build(_build):
116 """Specialized Python source builder."""
117
118 def run(self):
119 _build.run(self)
120
121 #####################################################################
e383109 @berendt resolved PEP8 issue E265
berendt authored
122 # # Configure files ##################################################
1899be7 Implement a configuration build step.
Michael Jansen authored
123 #####################################################################
124
568f7db @jmaas PEP8 - setup.py
jmaas authored
125
1899be7 Implement a configuration build step.
Michael Jansen authored
126 class build_cfg(Command):
127
486fee8 Fix the build target.
Michael Jansen authored
128 description = "configure files (copy and substitute options)"
1899be7 Implement a configuration build step.
Michael Jansen authored
129
130 user_options = [
9eb1f39 Configure cobblerd, cobbler_web.conf and cobblerd.service
Michael Jansen authored
131 ('install-base=', None, "base installation directory"),
132 ('install-platbase=', None, "base installation directory for platform-specific files "),
133 ('install-purelib=', None, "installation directory for pure Python module distributions"),
134 ('install-platlib=', None, "installation directory for non-pure module distributions"),
135 ('install-lib=', None, "installation directory for all module distributions " +
136 "(overrides --install-purelib and --install-platlib)"),
137 ('install-headers=', None, "installation directory for C/C++ headers"),
138 ('install-scripts=', None, "installation directory for Python scripts"),
139 ('install-data=', None, "installation directory for data files"),
1899be7 Implement a configuration build step.
Michael Jansen authored
140 ('force', 'f', "forcibly build everything (ignore file timestamps")
141 ]
142
143 boolean_options = ['force']
144
145 def initialize_options(self):
146 self.build_dir = None
147 self.force = None
9eb1f39 Configure cobblerd, cobbler_web.conf and cobblerd.service
Michael Jansen authored
148 self.install_base = None
149 self.install_platbase = None
150 self.install_scripts = None
151 self.install_data = None
152 self.install_purelib = None
153 self.install_platlib = None
154 self.install_lib = None
155 self.install_headers = None
156 self.root = None
1899be7 Implement a configuration build step.
Michael Jansen authored
157
158 def finalize_options(self):
159 self.set_undefined_options(
160 'build',
161 ('build_base', 'build_dir'),
162 ('force', 'force')
163 )
9eb1f39 Configure cobblerd, cobbler_web.conf and cobblerd.service
Michael Jansen authored
164 self.set_undefined_options(
165 'install',
568f7db @jmaas PEP8 - setup.py
jmaas authored
166 ('install_base', 'install_base'),
9eb1f39 Configure cobblerd, cobbler_web.conf and cobblerd.service
Michael Jansen authored
167 ('install_platbase', 'install_platbase'),
568f7db @jmaas PEP8 - setup.py
jmaas authored
168 ('install_scripts', 'install_scripts'),
169 ('install_data', 'install_data'),
170 ('install_purelib', 'install_purelib'),
171 ('install_platlib', 'install_platlib'),
172 ('install_lib', 'install_lib'),
173 ('install_headers', 'install_headers'),
174 ('root', 'root')
9eb1f39 Configure cobblerd, cobbler_web.conf and cobblerd.service
Michael Jansen authored
175 )
f0634ce If no root is specified it makes no sense to unroot those directories.
Michael Jansen authored
176
177 if self.root:
178 # We need the unrooted versions of this values
568f7db @jmaas PEP8 - setup.py
jmaas authored
179 for name in ('lib', 'purelib', 'platlib', 'scripts', 'data', 'headers'):
f0634ce If no root is specified it makes no sense to unroot those directories.
Michael Jansen authored
180 attr = "install_" + name
568f7db @jmaas PEP8 - setup.py
jmaas authored
181 setattr(self, attr, '/' + os.path.relpath(getattr(self, attr), self.root))
9eb1f39 Configure cobblerd, cobbler_web.conf and cobblerd.service
Michael Jansen authored
182
167847d Support for virtualenv out of the box
Michael Jansen authored
183 # Check if we are running under a virtualenv
184 if hasattr(sys, 'real_prefix'):
185 virtualenv = sys.prefix
186 else:
187 virtualenv = ""
188
9eb1f39 Configure cobblerd, cobbler_web.conf and cobblerd.service
Michael Jansen authored
189 # The values to expand.
190 self.configure_values = {
191 'python_executable': sys.executable,
568f7db @jmaas PEP8 - setup.py
jmaas authored
192 'virtualenv': virtualenv,
193 'install_base': os.path.normpath(self.install_base),
194 'install_platbase': os.path.normpath(self.install_platbase),
195 'install_scripts': os.path.normpath(self.install_scripts),
196 'install_data': os.path.normpath(self.install_data),
197 'install_purelib': os.path.normpath(self.install_purelib),
198 'install_platlib': os.path.normpath(self.install_platlib),
199 'install_lib': os.path.normpath(self.install_lib),
200 'install_headers': os.path.normpath(self.install_headers),
9eb1f39 Configure cobblerd, cobbler_web.conf and cobblerd.service
Michael Jansen authored
201 }
202 self.configure_values.update(self.distribution.configure_values)
36855d1 Create a build_man command that builds the man pages only if necessary.
Michael Jansen authored
203
1899be7 Implement a configuration build step.
Michael Jansen authored
204 def run(self):
205 # On dry-run ignore missing source files.
206 if self.dry_run:
207 mode = 'newer'
208 else:
209 mode = 'error'
210 # Work on all files
211 for infile in self.distribution.configure_files:
212 # We copy the files to build/
213 outfile = os.path.join(self.build_dir, infile)
214 # check if the file is out of date
4321345 @jmaas Rebased development environment on EL7, new pyflakes & pep8 tools:
jmaas authored
215 if self.force or dep_util.newer_group([infile, 'setup.py'], outfile, mode):
1899be7 Implement a configuration build step.
Michael Jansen authored
216 # It is. Configure it
217 self.configure_one_file(infile, outfile)
218
219 def configure_one_file(self, infile, outfile):
220 self.announce("configuring %s" % (infile), log.INFO)
221 if not self.dry_run:
222 # Read the file
223 with codecs.open(infile, 'r', 'utf-8') as fh:
224 before = fh.read()
225 # Substitute the variables
226 # Create the output directory if necessary
227 outdir = os.path.dirname(outfile)
228 if not os.path.exists(outdir):
229 os.makedirs(outdir)
230 # Write it into build/
231 with codecs.open(outfile, 'w', 'utf-8') as fh:
4321345 @jmaas Rebased development environment on EL7, new pyflakes & pep8 tools:
jmaas authored
232 fh.write(self.substitute_values(before, self.configure_values))
cb8f58b Copy the mode (permissions) for configured files.
Michael Jansen authored
233 # The last step is to copy the permission bits
234 shutil.copymode(infile, outfile)
1899be7 Implement a configuration build step.
Michael Jansen authored
235
236 def substitute_values(self, string, values):
237 for name, val in values.iteritems():
238 # print("replacing @@%s@@ with %s" % (name, val))
239 string = string.replace("@@%s@@" % (name), val)
240 return string
241
242
243 def has_configure_files(build):
244 """Check if the distribution has configuration files to work on."""
245 return bool(build.distribution.configure_files)
246
568f7db @jmaas PEP8 - setup.py
jmaas authored
247
36855d1 Create a build_man command that builds the man pages only if necessary.
Michael Jansen authored
248 def has_man_pages(build):
249 """Check if the distribution has configuration files to work on."""
250 return bool(build.distribution.man_pages)
251
486fee8 Fix the build target.
Michael Jansen authored
252 build.sub_commands.extend((
253 ('build_man', has_man_pages),
1e21c46 Now its fixed. (TYPO)
Michael Jansen authored
254 ('build_cfg', has_configure_files)
486fee8 Fix the build target.
Michael Jansen authored
255 ))
36855d1 Create a build_man command that builds the man pages only if necessary.
Michael Jansen authored
256
257 #####################################################################
e383109 @berendt resolved PEP8 issue E265
berendt authored
258 # # Build man pages ##################################################
36855d1 Create a build_man command that builds the man pages only if necessary.
Michael Jansen authored
259 #####################################################################
260
568f7db @jmaas PEP8 - setup.py
jmaas authored
261
36855d1 Create a build_man command that builds the man pages only if necessary.
Michael Jansen authored
262 class build_man(Command):
263
264 decription = "build man pages"
265
266 user_options = [
267 ('force', 'f', "forcibly build everything (ignore file timestamps")
268 ]
269
270 boolean_options = ['force']
271
272 def initialize_options(self):
568f7db @jmaas PEP8 - setup.py
jmaas authored
273 self.build_dir = None
36855d1 Create a build_man command that builds the man pages only if necessary.
Michael Jansen authored
274 self.force = None
275
276 def finalize_options(self):
277 self.set_undefined_options(
278 'build',
279 ('build_base', 'build_dir'),
280 ('force', 'force')
281 )
282
283 def run(self):
284 """Generate the man pages... this is currently done through POD,
285 possible future version may do this through some Python mechanism
286 (maybe conversion from ReStructured Text (.rst))...
287 """
288 # On dry-run ignore missing source files.
289 if self.dry_run:
290 mode = 'newer'
291 else:
292 mode = 'error'
293 # Work on all files
294 for infile in self.distribution.man_pages:
295 # We copy the files to build/
296 outfile = os.path.join(self.build_dir, os.path.splitext(infile)[0] + '.gz')
297 # check if the file is out of date
4321345 @jmaas Rebased development environment on EL7, new pyflakes & pep8 tools:
jmaas authored
298 if self.force or dep_util.newer_group([infile], outfile, mode):
36855d1 Create a build_man command that builds the man pages only if necessary.
Michael Jansen authored
299 # It is. Configure it
300 self.build_one_file(infile, outfile)
301
302 _COMMAND = 'pod2man --center="%s" --release="" %s | gzip -c > %s'
303
304 def build_one_file(self, infile, outfile):
305 man = os.path.splitext(os.path.splitext(os.path.basename(infile))[0])[0]
306 self.announce("building %s manpage" % (man), log.INFO)
307 if not self.dry_run:
308 # Create the output directory if necessary
309 outdir = os.path.dirname(outfile)
310 if not os.path.exists(outdir):
311 os.makedirs(outdir)
312 # Now create the manpage
568f7db @jmaas PEP8 - setup.py
jmaas authored
313 cmd = build_man._COMMAND % ('man', infile, outfile)
36855d1 Create a build_man command that builds the man pages only if necessary.
Michael Jansen authored
314 if os.system(cmd):
ab74fa2 @alanoe Fix announce() call in setup.py
alanoe authored
315 self.announce("Creation of %s manpage failed." % man, log.ERROR)
36855d1 Create a build_man command that builds the man pages only if necessary.
Michael Jansen authored
316 exit(1)
317
318
1899be7 Implement a configuration build step.
Michael Jansen authored
319 #####################################################################
e383109 @berendt resolved PEP8 issue E265
berendt authored
320 # # Modify Install Stage ############################################
1222ac4 install: move chown code from Makefile to setup.py
Michael Jansen authored
321 #####################################################################
322
568f7db @jmaas PEP8 - setup.py
jmaas authored
323
1222ac4 install: move chown code from Makefile to setup.py
Michael Jansen authored
324 class install(_install):
325 """Specialised python package installer.
326
327 It does some required chown calls in addition to the usual stuff.
328 """
329
330 def __init__(self, *args):
331 _install.__init__(self, *args)
332
333 def change_owner(self, path, owner):
334 user = pwd.getpwnam(owner)
335 try:
336 log.info("changing mode of %s" % path)
337 if not self.dry_run:
338 # os.walk does not include the toplevel directory
339 os.lchown(path, user.pw_uid, -1)
340 # Now walk the directory and change them all
341 for root, dirs, files in os.walk(path):
342 for dirname in dirs:
343 os.lchown(os.path.join(root, dirname), user.pw_uid, -1)
344 for filename in files:
345 os.lchown(os.path.join(root, filename), user.pw_uid, -1)
346 except exceptions.OSError as e:
347 # We only check for errno = 1 (EPERM) here because its kinda
348 # expected when installing as a non root user.
349 if e.errno == 1:
350 self.warn("Could not change owner: You have insufficient permissions.")
351 else:
352 raise e
353
354 def run(self):
355 # Run the usual stuff.
356 _install.run(self)
357
3dfbb9f Undo split of cobbler-web from cobbler
Nishanth Aravamudan authored
358 # Hand over some directories to the webserver user
359 path = os.path.join(self.install_data, 'share/cobbler/web')
360 try:
361 self.change_owner(path, http_user)
362 except KeyError, e:
363 # building RPMs in a mock chroot, user 'apache' won't exist
364 log.warn("Error in 'chown apache %s': %s" % (path, e))
365 if not os.path.abspath(libpath):
366 # The next line only works for absolute libpath
367 raise Exception("libpath is not absolute.")
368 path = os.path.join(self.root + libpath, 'webui_sessions')
369 try:
370 self.change_owner(path, http_user)
371 except KeyError, e:
372 log.warn("Error in 'chown apache %s': %s" % (path, e))
373
374
1222ac4 install: move chown code from Makefile to setup.py
Michael Jansen authored
375 #####################################################################
e383109 @berendt resolved PEP8 issue E265
berendt authored
376 # # Test Command #####################################################
3d26436 @crobinso setup.py: Add stub 'test' command
crobinso authored
377 #####################################################################
378
568f7db @jmaas PEP8 - setup.py
jmaas authored
379
3d26436 @crobinso setup.py: Add stub 'test' command
crobinso authored
380 class test_command(Command):
381 user_options = []
382
383 def initialize_options(self):
384 pass
568f7db @jmaas PEP8 - setup.py
jmaas authored
385
3d26436 @crobinso setup.py: Add stub 'test' command
crobinso authored
386 def finalize_options(self):
387 pass
388
389 def run(self):
390 testfiles = []
02088aa @jmaas Split off Koan into a seperate repo and package.
jmaas authored
391 testdirs = []
3d26436 @crobinso setup.py: Add stub 'test' command
crobinso authored
392
393 for d in testdirs:
394 testdir = os.path.join(os.getcwd(), "tests", d)
395
1e8a5c9 Rework the glob() mechanism.
Michael Jansen authored
396 for t in _glob.glob(os.path.join(testdir, '*.py')):
3d26436 @crobinso setup.py: Add stub 'test' command
crobinso authored
397 if t.endswith('__init__.py'):
398 continue
399 testfile = '.'.join(['tests', d,
400 os.path.splitext(os.path.basename(t))[0]])
401 testfiles.append(testfile)
402
403 tests = unittest.TestLoader().loadTestsFromNames(testfiles)
568f7db @jmaas PEP8 - setup.py
jmaas authored
404 runner = unittest.TextTestRunner(verbosity=1)
3d26436 @crobinso setup.py: Add stub 'test' command
crobinso authored
405
406 if coverage:
407 coverage.erase()
408 coverage.start()
409
410 result = runner.run(tests)
411
412 if coverage:
413 coverage.stop()
414 sys.exit(int(bool(len(result.failures) > 0 or
415 len(result.errors) > 0)))
416
61dd1bc Move restorestate and savestate implementation to setup.py
Michael Jansen authored
417 #####################################################################
e383109 @berendt resolved PEP8 issue E265
berendt authored
418 # # state command base class #########################################
61dd1bc Move restorestate and savestate implementation to setup.py
Michael Jansen authored
419 #####################################################################
420
568f7db @jmaas PEP8 - setup.py
jmaas authored
421
61dd1bc Move restorestate and savestate implementation to setup.py
Michael Jansen authored
422 class statebase(Command):
423
424 user_options = [
425 ('statepath=', None, 'directory to backup configuration'),
568f7db @jmaas PEP8 - setup.py
jmaas authored
426 ('root=', None, 'install everything relative to this alternate root directory')
c2f1ba5 @ciupicri make qa (pep8) fixes for setup.py
ciupicri authored
427 ]
61dd1bc Move restorestate and savestate implementation to setup.py
Michael Jansen authored
428
429 def initialize_options(self):
430 self.statepath = statepath
431 self.root = None
432
433 def finalize_options(self):
434 pass
435
436 def _copy(self, frm, to):
437 if os.path.isdir(frm):
438 to = os.path.join(to, os.path.basename(frm))
439 self.announce("copying %s/ to %s/" % (frm, to), log.DEBUG)
440 if not self.dry_run:
441 if os.path.exists(to):
442 shutil.rmtree(to)
443 shutil.copytree(frm, to)
444 else:
445 self.announce("copying %s to %s" % (frm, os.path.join(to, os.path.basename(frm))), log.DEBUG)
446 if not self.dry_run:
447 shutil.copy2(frm, to)
448
449 #####################################################################
e383109 @berendt resolved PEP8 issue E265
berendt authored
450 # # restorestate command #############################################
61dd1bc Move restorestate and savestate implementation to setup.py
Michael Jansen authored
451 #####################################################################
452
568f7db @jmaas PEP8 - setup.py
jmaas authored
453
61dd1bc Move restorestate and savestate implementation to setup.py
Michael Jansen authored
454 class restorestate(statebase):
455
456 def _copy(self, frm, to):
457 if self.root:
458 to = self.root + to
459 statebase._copy(self, frm, to)
460
461 def run(self):
462 self.announce("restoring the current configuration from %s" % self.statepath, log.INFO)
463 if not os.path.exists(self.statepath):
464 self.warn("%s does not exist. Skipping" % self.statepath)
465 return
d85dd42 @alanoe Rename directory with serialized Cobbler objects from config to colle…
alanoe authored
466 self._copy(os.path.join(self.statepath, 'collections'), libpath)
3dfbb9f Undo split of cobbler-web from cobbler
Nishanth Aravamudan authored
467 self._copy(os.path.join(self.statepath, 'cobbler_web.conf'), webconfig)
61dd1bc Move restorestate and savestate implementation to setup.py
Michael Jansen authored
468 self._copy(os.path.join(self.statepath, 'cobbler.conf'), webconfig)
469 self._copy(os.path.join(self.statepath, 'modules.conf'), etcpath)
470 self._copy(os.path.join(self.statepath, 'settings'), etcpath)
471 self._copy(os.path.join(self.statepath, 'users.conf'), etcpath)
472 self._copy(os.path.join(self.statepath, 'users.digest'), etcpath)
473 self._copy(os.path.join(self.statepath, 'dhcp.template'), etcpath)
474 self._copy(os.path.join(self.statepath, 'rsync.template'), etcpath)
475
476 #####################################################################
e383109 @berendt resolved PEP8 issue E265
berendt authored
477 # # savestate command ################################################
61dd1bc Move restorestate and savestate implementation to setup.py
Michael Jansen authored
478 #####################################################################
479
568f7db @jmaas PEP8 - setup.py
jmaas authored
480
61dd1bc Move restorestate and savestate implementation to setup.py
Michael Jansen authored
481 class savestate(statebase):
482
483 description = "Backup the current configuration to /tmp/cobbler_settings."
484
485 def _copy(self, frm, to):
486 if self.root:
487 frm = self.root + frm
488 statebase._copy(self, frm, to)
489
490 def run(self):
568f7db @jmaas PEP8 - setup.py
jmaas authored
491 self.announce("backing up the current configuration to %s" % self.statepath, log.INFO)
61dd1bc Move restorestate and savestate implementation to setup.py
Michael Jansen authored
492 if os.path.exists(self.statepath):
493 self.announce("deleting existing %s" % self.statepath, log.DEBUG)
494 if not self.dry_run:
495 shutil.rmtree(self.statepath)
496 if not self.dry_run:
497 os.makedirs(self.statepath)
d85dd42 @alanoe Rename directory with serialized Cobbler objects from config to colle…
alanoe authored
498 self._copy(os.path.join(libpath, 'collections'), self.statepath)
3dfbb9f Undo split of cobbler-web from cobbler
Nishanth Aravamudan authored
499 self._copy(os.path.join(webconfig, 'cobbler_web.conf'), self.statepath)
61dd1bc Move restorestate and savestate implementation to setup.py
Michael Jansen authored
500 self._copy(os.path.join(webconfig, 'cobbler.conf'), self.statepath)
501 self._copy(os.path.join(etcpath, 'modules.conf'), self.statepath)
502 self._copy(os.path.join(etcpath, 'settings'), self.statepath)
503 self._copy(os.path.join(etcpath, 'users.conf'), self.statepath)
504 self._copy(os.path.join(etcpath, 'users.digest'), self.statepath)
505 self._copy(os.path.join(etcpath, 'dhcp.template'), self.statepath)
506 self._copy(os.path.join(etcpath, 'rsync.template'), self.statepath)
507
508
9cd4ade Added more useful files to setup.py and MANIFEST.in as well as extra
Alex Kesling authored
509 #####################################################################
e383109 @berendt resolved PEP8 issue E265
berendt authored
510 # # Actual Setup.py Script ###########################################
9cd4ade Added more useful files to setup.py and MANIFEST.in as well as extra
Alex Kesling authored
511 #####################################################################
230ff2e Massive overhaul of setup.py . Moved things around a little to clean up
Alex Kesling authored
512 if __name__ == "__main__":
e383109 @berendt resolved PEP8 issue E265
berendt authored
513 # # Configurable installation roots for various data files.
27d7199 Fix some issues with clean installs of cobbler post build cleanup
Scott Henson authored
514
86ca397 Reconfigured setup.py to now place config files and web ui content in…
Alex Kesling authored
515 # Trailing slashes on these vars is to allow for easy
516 # later configuration of relative paths if desired.
568f7db @jmaas PEP8 - setup.py
jmaas authored
517 docpath = "share/man/man1"
518 etcpath = "/etc/cobbler/"
519 initpath = "/etc/init.d/"
520 libpath = "/var/lib/cobbler/"
521 logpath = "/var/log/"
522 statepath = "/tmp/cobbler_settings/devinstall"
27d7199 Fix some issues with clean installs of cobbler post build cleanup
Scott Henson authored
523
b5f0bf3 @kscherer Update setup files to use proper apache configuration path
kscherer authored
524 if os.path.exists("/etc/SuSE-release"):
568f7db @jmaas PEP8 - setup.py
jmaas authored
525 webconfig = "/etc/apache2/conf.d"
526 webroot = "/srv/www/"
527 http_user = "wwwrun"
4e26342 @zultron Add source /etc/sysconfig/cobblerd to init script
zultron authored
528 defaultpath = "/etc/sysconfig/"
b5f0bf3 @kscherer Update setup files to use proper apache configuration path
kscherer authored
529 elif os.path.exists("/etc/debian_version"):
35817ae @jmaas Changed Apache configuration directory in Ubuntu 14.04 (#1208).
jmaas authored
530 if os.path.exists("/etc/apache2/conf-available"):
531 webconfig = "/etc/apache2/conf-available"
532 else:
533 webconfig = "/etc/apache2/conf.d"
568f7db @jmaas PEP8 - setup.py
jmaas authored
534 webroot = "/srv/www/"
535 http_user = "www-data"
4e26342 @zultron Add source /etc/sysconfig/cobblerd to init script
zultron authored
536 defaultpath = "/etc/default/"
b5f0bf3 @kscherer Update setup files to use proper apache configuration path
kscherer authored
537 else:
568f7db @jmaas PEP8 - setup.py
jmaas authored
538 webconfig = "/etc/httpd/conf.d"
539 webroot = "/var/www/"
540 http_user = "apache"
4e26342 @zultron Add source /etc/sysconfig/cobblerd to init script
zultron authored
541 defaultpath = "/etc/sysconfig/"
b5f0bf3 @kscherer Update setup files to use proper apache configuration path
kscherer authored
542
3dfbb9f Undo split of cobbler-web from cobbler
Nishanth Aravamudan authored
543 webcontent = webroot + "cobbler_webui_content/"
544 webimages = webcontent + "/images"
545
230ff2e Massive overhaul of setup.py . Moved things around a little to clean up
Alex Kesling authored
546 setup(
1899be7 Implement a configuration build step.
Michael Jansen authored
547 distclass=Distribution,
1222ac4 install: move chown code from Makefile to setup.py
Michael Jansen authored
548 cmdclass={
1899be7 Implement a configuration build step.
Michael Jansen authored
549 'build': build,
1222ac4 install: move chown code from Makefile to setup.py
Michael Jansen authored
550 'build_py': build_py,
551 'test': test_command,
61dd1bc Move restorestate and savestate implementation to setup.py
Michael Jansen authored
552 'install': install,
553 'savestate': savestate,
1899be7 Implement a configuration build step.
Michael Jansen authored
554 'restorestate': restorestate,
486fee8 Fix the build target.
Michael Jansen authored
555 'build_cfg': build_cfg,
36855d1 Create a build_man command that builds the man pages only if necessary.
Michael Jansen authored
556 'build_man': build_man
1222ac4 install: move chown code from Makefile to setup.py
Michael Jansen authored
557 },
568f7db @jmaas PEP8 - setup.py
jmaas authored
558 name="cobbler",
559 version=VERSION,
560 description="Network Boot and Update Server",
4cde33e @alanoe Rename 'kickstart' to 'automatic installation'
alanoe authored
561 long_description="Cobbler is a network install server. Cobbler supports PXE, virtualized installs, and reinstalling existing Linux machines. The last two modes use a helper tool, 'koan', that integrates with cobbler. There is also a web interface 'cobbler-web'. Cobbler's advanced features include importing distributions from DVDs and rsync mirrors, automatic OS installation templating, integrated yum mirroring, and built-in DHCP/DNS Management. Cobbler has a XMLRPC API for integration with other applications.",
568f7db @jmaas PEP8 - setup.py
jmaas authored
562 author="Team Cobbler",
563 author_email="cobbler@lists.fedorahosted.org",
1c68006 @jmaas Remove references to cobblerd.org.
jmaas authored
564 url="https://cobbler.github.io",
568f7db @jmaas PEP8 - setup.py
jmaas authored
565 license="GPLv2+",
566 requires=[
230ff2e Massive overhaul of setup.py . Moved things around a little to clean up
Alex Kesling authored
567 "mod_python",
568 "cobbler",
569 ],
568f7db @jmaas PEP8 - setup.py
jmaas authored
570 packages=[
230ff2e Massive overhaul of setup.py . Moved things around a little to clean up
Alex Kesling authored
571 "cobbler",
1e8a5c9 Rework the glob() mechanism.
Michael Jansen authored
572 "cobbler/modules",
3dfbb9f Undo split of cobbler-web from cobbler
Nishanth Aravamudan authored
573 "cobbler/web",
574 "cobbler/web/templatetags",
230ff2e Massive overhaul of setup.py . Moved things around a little to clean up
Alex Kesling authored
575 ],
568f7db @jmaas PEP8 - setup.py
jmaas authored
576 scripts=[
955568d @jimi-c FEATURE - adding ability to grab templated scripts
jimi-c authored
577 "bin/cobbler",
578 "bin/cobblerd",
579 "bin/cobbler-ext-nodes",
230ff2e Massive overhaul of setup.py . Moved things around a little to clean up
Alex Kesling authored
580 ],
568f7db @jmaas PEP8 - setup.py
jmaas authored
581 configure_values={
f550ad5 Replace the webroot in configuration files.
Michael Jansen authored
582 'webroot': os.path.normpath(webroot),
4e26342 @zultron Add source /etc/sysconfig/cobblerd to init script
zultron authored
583 'defaultpath': os.path.normpath(defaultpath),
f550ad5 Replace the webroot in configuration files.
Michael Jansen authored
584 },
568f7db @jmaas PEP8 - setup.py
jmaas authored
585 configure_files=[
2e4bf95 @alanoe Move Cobbler configuration files to a separate directory
alanoe authored
586 "config/cobbler/settings",
b953253 @alanoe Move Apache configuration files to a separate directory
alanoe authored
587 "config/apache/cobbler.conf",
3dfbb9f Undo split of cobbler-web from cobbler
Nishanth Aravamudan authored
588 "config/apache/cobbler_web.conf",
c697f7f @alanoe Move Cobbler's Linux service management configuration files to a sepa…
alanoe authored
589 "config/service/cobblerd.service",
590 "config/service/cobblerd"
f550ad5 Replace the webroot in configuration files.
Michael Jansen authored
591 ],
568f7db @jmaas PEP8 - setup.py
jmaas authored
592 man_pages=[
fbba878 @jmaas Move around some documentation
jmaas authored
593 'docs/man/cobbler.1.pod',
36855d1 Create a build_man command that builds the man pages only if necessary.
Michael Jansen authored
594 ],
568f7db @jmaas PEP8 - setup.py
jmaas authored
595 data_files=[
912481f A smart tftp server, and a module to manage it
Douglas Kilpatrick authored
596 # tftpd, hide in /usr/sbin
3f71a98 Make install path of tftpd.py relative
Michael Jansen authored
597 ("sbin", ["bin/tftpd.py"]),
b953253 @alanoe Move Apache configuration files to a separate directory
alanoe authored
598 ("%s" % webconfig, ["build/config/apache/cobbler.conf"]),
3dfbb9f Undo split of cobbler-web from cobbler
Nishanth Aravamudan authored
599 ("%s" % webconfig, ["build/config/apache/cobbler_web.conf"]),
c697f7f @alanoe Move Cobbler's Linux service management configuration files to a sepa…
alanoe authored
600 ("%s" % initpath, ["build/config/service/cobblerd"]),
568f7db @jmaas PEP8 - setup.py
jmaas authored
601 ("%s" % docpath, glob("build/docs/man/*.1.gz")),
cee040c @jmaas Fix paths for snippets, scripts and templates in /var/lib/cobbler.
jmaas authored
602 ("%s/templates" % libpath, glob("autoinstall_templates/*")),
603 ("%s/templates/install_profiles" % libpath, glob("autoinstall_templates/install_profiles/*")),
604 ("%s/snippets" % libpath, glob("autoinstall_snippets/*", recursive=True)),
605 ("%s/scripts" % libpath, glob("autoinstall_scripts/*")),
f634437 @jmaas Regression: fix to 'make install' (distro_signatures.json).
jmaas authored
606 ("%s" % libpath, ["config/cobbler/distro_signatures.json"]),
3dfbb9f Undo split of cobbler-web from cobbler
Nishanth Aravamudan authored
607 ("share/cobbler/web", glob("web/*.*")),
608 ("%s" % webcontent, glob("web/static/*")),
609 ("%s" % webimages, glob("web/static/images/*")),
610 ("share/cobbler/web/templates", glob("web/templates/*")),
611 ("%swebui_sessions" % libpath, []),
568f7db @jmaas PEP8 - setup.py
jmaas authored
612 ("%sloaders" % libpath, []),
613 ("%scobbler/aux" % webroot, glob("aux/*")),
aac0759 @jmaas Unbreak package building caused by #955
jmaas authored
614 # Configuration
b953253 @alanoe Move Apache configuration files to a separate directory
alanoe authored
615 ("%s" % etcpath, ["build/config/apache/cobbler.conf",
3dfbb9f Undo split of cobbler-web from cobbler
Nishanth Aravamudan authored
616 "build/config/apache/cobbler_web.conf",
c697f7f @alanoe Move Cobbler's Linux service management configuration files to a sepa…
alanoe authored
617 "build/config/service/cobblerd",
618 "build/config/service/cobblerd.service",
2e4bf95 @alanoe Move Cobbler configuration files to a separate directory
alanoe authored
619 "build/config/cobbler/settings"]),
620 ("%ssettings.d" % etcpath, glob("config/cobbler/settings.d/*")),
621 ("%s" % etcpath, ["config/bash/cobbler_bash",
622 "config/cobbler/auth.conf",
623 "config/cobbler/modules.conf",
624 "config/cobbler/mongodb.conf",
625 "config/cobbler/users.conf",
626 "config/cobbler/users.digest",
0786698 @alanoe Move Cheetah global methods file to a separate directory
alanoe authored
627 "config/cheetah/cheetah_macros",
7c6dcab @alanoe Move rotate configuration file to a separate directory
alanoe authored
628 "config/rotate/cobblerd_rotate",
2362504 @alanoe Move rsync configuration files to a separate directory
alanoe authored
629 "config/rsync/import_rsync_whitelist",
630 "config/rsync/rsync.exclude",
c2f1ba5 @ciupicri make qa (pep8) fixes for setup.py
ciupicri authored
631 "config/version"]),
3dfbb9f Undo split of cobbler-web from cobbler
Nishanth Aravamudan authored
632 ("%s" % etcpath, glob("templates/etc/*")),
633 ("%siso" % etcpath, glob("templates/iso/*")),
634 ("%sboot_loader_conf" % etcpath, glob("templates/boot_loader_conf/*")),
635 ("%sreporting" % etcpath, glob("templates/reporting/*")),
636 ("%spower" % etcpath, glob("templates/power/*")),
e383109 @berendt resolved PEP8 issue E265
berendt authored
637 # Build empty directories to hold triggers
568f7db @jmaas PEP8 - setup.py
jmaas authored
638 ("%striggers/add/distro/pre" % libpath, []),
639 ("%striggers/add/distro/post" % libpath, []),
640 ("%striggers/add/profile/pre" % libpath, []),
641 ("%striggers/add/profile/post" % libpath, []),
642 ("%striggers/add/system/pre" % libpath, []),
643 ("%striggers/add/system/post" % libpath, []),
644 ("%striggers/add/repo/pre" % libpath, []),
645 ("%striggers/add/repo/post" % libpath, []),
646 ("%striggers/add/mgmtclass/pre" % libpath, []),
647 ("%striggers/add/mgmtclass/post" % libpath, []),
648 ("%striggers/add/package/pre" % libpath, []),
649 ("%striggers/add/package/post" % libpath, []),
650 ("%striggers/add/file/pre" % libpath, []),
651 ("%striggers/add/file/post" % libpath, []),
652 ("%striggers/delete/distro/pre" % libpath, []),
653 ("%striggers/delete/distro/post" % libpath, []),
654 ("%striggers/delete/profile/pre" % libpath, []),
655 ("%striggers/delete/profile/post" % libpath, []),
656 ("%striggers/delete/system/pre" % libpath, []),
657 ("%striggers/delete/system/post" % libpath, []),
658 ("%striggers/delete/repo/pre" % libpath, []),
659 ("%striggers/delete/repo/post" % libpath, []),
87ec75c @kelseyhightower Updating setup.py and spec file.
kelseyhightower authored
660 ("%striggers/delete/mgmtclass/pre" % libpath, []),
568f7db @jmaas PEP8 - setup.py
jmaas authored
661 ("%striggers/delete/mgmtclass/post" % libpath, []),
662 ("%striggers/delete/package/pre" % libpath, []),
663 ("%striggers/delete/package/post" % libpath, []),
664 ("%striggers/delete/file/pre" % libpath, []),
665 ("%striggers/delete/file/post" % libpath, []),
666 ("%striggers/install/pre" % libpath, []),
667 ("%striggers/install/post" % libpath, []),
668 ("%striggers/install/firstboot" % libpath, []),
669 ("%striggers/sync/pre" % libpath, []),
670 ("%striggers/sync/post" % libpath, []),
671 ("%striggers/change" % libpath, []),
e383109 @berendt resolved PEP8 issue E265
berendt authored
672 # Build empty directories to hold the database
d85dd42 @alanoe Rename directory with serialized Cobbler objects from config to colle…
alanoe authored
673 ("%scollections" % libpath, []),
6a0ec52 @alanoe Drop .d in collections directories
alanoe authored
674 ("%scollections/distros" % libpath, []),
675 ("%scollections/images" % libpath, []),
676 ("%scollections/profiles" % libpath, []),
677 ("%scollections/repos" % libpath, []),
678 ("%scollections/systems" % libpath, []),
679 ("%scollections/mgmtclasses" % libpath, []),
680 ("%scollections/packages" % libpath, []),
681 ("%scollections/files" % libpath, []),
9cd4ade Added more useful files to setup.py and MANIFEST.in as well as extra
Alex Kesling authored
682 # logfiles
568f7db @jmaas PEP8 - setup.py
jmaas authored
683 ("%scobbler/kicklog" % logpath, []),
684 ("%scobbler/syslog" % logpath, []),
685 ("%shttpd/cobbler" % logpath, []),
686 ("%scobbler/anamon" % logpath, []),
687 ("%scobbler/tasks" % logpath, []),
9cd4ade Added more useful files to setup.py and MANIFEST.in as well as extra
Alex Kesling authored
688 # web page directories that we own
568f7db @jmaas PEP8 - setup.py
jmaas authored
689 ("%scobbler/localmirror" % webroot, []),
690 ("%scobbler/repo_mirror" % webroot, []),
d6888de @alanoe Rename ks_mirror directory
alanoe authored
691 ("%scobbler/distro_mirror" % webroot, []),
692 ("%scobbler/distro_mirror/config" % webroot, []),
568f7db @jmaas PEP8 - setup.py
jmaas authored
693 ("%scobbler/links" % webroot, []),
694 ("%scobbler/aux" % webroot, []),
695 ("%scobbler/pub" % webroot, []),
696 ("%scobbler/rendered" % webroot, []),
697 ("%scobbler/images" % webroot, []),
e383109 @berendt resolved PEP8 issue E265
berendt authored
698 # A script that isn't really data, wsgi script
568f7db @jmaas PEP8 - setup.py
jmaas authored
699 ("%scobbler/svc/" % webroot, ["bin/services.py"]),
9cd4ade Added more useful files to setup.py and MANIFEST.in as well as extra
Alex Kesling authored
700 # zone-specific templates directory
568f7db @jmaas PEP8 - setup.py
jmaas authored
701 ("%szone_templates" % etcpath, []),
1e8a5c9 Rework the glob() mechanism.
Michael Jansen authored
702 ],
230ff2e Massive overhaul of setup.py . Moved things around a little to clean up
Alex Kesling authored
703 )
Something went wrong with that request. Please try again.