1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 '''A generic script to add entries to a file
6 if the entry does not already exist.
8 Usage: buildlist.py <filename> <entry> [<entry> ...]
10 from __future__
import print_function
14 from utils
import lockFile
16 def addEntriesToListFile(listFile
, entries
):
17 """Given a file |listFile| containing one entry per line,
18 add each entry in |entries| to the file, unless it is already
20 lock
= lockFile(listFile
+ ".lck")
22 if os
.path
.exists(listFile
):
24 existing
= set(x
.strip() for x
in f
.readlines())
28 f
= open(listFile
, 'a')
31 f
.write("{0}\n".format(e
))
37 if __name__
== '__main__':
39 print("Usage: buildlist.py <list file> <entry> [<entry> ...]",
42 addEntriesToListFile(sys
.argv
[1], sys
.argv
[2:])