[publish] use a persistent header for generated apt.conf (closes #119789)

authorDavid Douard <david.douard@logilab.fr>
changeset8be74904cd12
branchdefault
phasepublic
hiddenno
parent revision#ebc3c8d71b2c Added tag debinstall-debian-version-2.6.0-1 for changeset b0bb779aac60
child revision#d1fba946ca68 fix typo
files modified by this revision
debrepo.py
# HG changeset patch
# User David Douard <david.douard@logilab.fr>
# Date 1359708928 -3600
# Fri Feb 01 09:55:28 2013 +0100
# Node ID 8be74904cd122a668950d0d9e4eae52380ac95a1
# Parent ebc3c8d71b2c7194ff7d04a30b5f185a5f9e2bc1
[publish] use a persistent header for generated apt.conf (closes #119789)

diff --git a/debrepo.py b/debrepo.py
@@ -85,11 +85,14 @@
1                  return num
2              if num is _SEPARATOR:
3                  separator_found = True
4          return None
5 
6 -APTDEFAULT_APTCONF = '''// Generated file, do not modify !!
7 +APTDEFAULT_APTCONF = '''// This header is used to generate the apt.conf file
8 +// you may modify it to configure your repository, eg. you can add headers in
9 +// APT::FTPArchive::Release, etc.
10 +// MODIFY BELOW THIS LINE
11 
12  APT {
13    FTPArchive {
14      Release {
15          Origin "%(origin)s";
@@ -153,13 +156,24 @@
16                               distrib, dereferenced)
17          return distribdir
18 
19      def generate_aptconf(self, origin='Logilab'):
20          """write a configuration file for use by apt-ftparchive"""
21 +        header_file = self.aptconf_file+".in"
22 +        if not osp.isfile(header_file):
23 +            with open(header_file, "w") as stream:
24 +                stream.write(APTDEFAULT_APTCONF % { 'origin': origin,
25 +                                                    'archivedir': self.dists_directory,
26 +                                                    })
27          stream = open(self.aptconf_file, "w")
28 -        stream.write(APTDEFAULT_APTCONF % {
29 -            'origin': origin, 'archivedir': self.dists_directory})
30 +        stream.write('// Generated by ldi; DO NOT EDIT\n')
31 +        stream.write('// You may edit the apt.conf.in file to customize it\n')
32 +        header = [line.rstrip() for line open(header_file)]
33 +        marker = "// MODIFY BELOW THIS LINE"
34 +        if marker in header:
35 +            header = header[header.index(marker) + 1:]
36 +        stream.write('\n'.join(header))
37          for distrib in glob(osp.join(self.dists_directory, '*')):
38              if osp.isdir(distrib) and not osp.islink(distrib):
39                  distrib = osp.basename(distrib)
40                  stream.write(BINDIRECTORY_APTCONF % {'distribution': distrib})
41          stream.close()