1 # The contents of this file are subject to the Mozilla Public License Version
2 # 1.1 (the "License"); you may not use this file except in compliance with
3 # the License. You may obtain a copy of the License at
4 # http://www.mozilla.org/MPL/
6 # Software distributed under the License is distributed on an "AS IS" basis,
7 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8 # for the specific language governing rights and limitations under the
11 # The Original Code is Mozilla Corporation Code.
13 # The Initial Developer of the Original Code is
15 # Portions created by the Initial Developer are Copyright (C) 2007
16 # the Initial Developer. All Rights Reserved.
19 # Clint Talbert <ctalbert@mozilla.com>
21 # Alternatively, the contents of this file may be used under the terms of
22 # either the GNU General Public License Version 2 or later (the "GPL"), or
23 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
24 # in which case the provisions of the GPL or the LGPL are applicable instead
25 # of those above. If you wish to allow use of your version of this file only
26 # under the terms of either the GPL or the LGPL, and not to allow others to
27 # use your version of this file under the terms of the MPL, indicate your
28 # decision by deleting the provisions above and replace them with the notice
29 # and other provisions required by the GPL or the LGPL. If you do not delete
30 # the provisions above, a recipient may use your version of this file under
31 # the terms of any one of the MPL, the GPL or the LGPL.
33 # ***** END LICENSE BLOCK *****
35 from optparse
import OptionParser
37 from checkBookmarks
import bookmarkParser
38 from logAppender
import LogAppender
, stderrCatcher
48 def main(left
, right
, log
):
49 # Instantiate the log writer
52 sys
.stderr
= stderrCatcher(lw
)
54 # Parse the left hand file
55 leftParser
= bookmarkParser(isDebug
=DIFFBKMK_DBG
)
56 leftParser
.parseFile(left
)
58 # Parse the right hand file
59 rightParser
= bookmarkParser(isDebug
=DIFFBKMK_DBG
)
60 rightParser
.parseFile(right
)
62 # Now we compare the lists generated from the parsing and they should be
63 # identical, and they are sorted by <folder> and then by <link title>
64 leftList
= leftParser
.getList()
65 rightList
= rightParser
.getList()
67 # Handle the case where we are missing a file
68 if len(leftList
) == 0:
69 lw
.writeLog("**** BOOKMARKS REFERENCE FILE IS MISSING ****")
70 raise SystemExit("**** BOOKMARKS REFERENCE FILE IS MISSING ****")
71 elif len(rightList
) == 0:
72 lw
.writeLog("**** BOOKMARKS DATA FOR BUILD UNDER TEST IS MISSING ****")
73 raise SystemExit("**** BOOKMARKS DATA FOR BUILD UNDER TEST IS MISSING ****")
76 for lentry
in leftList
:
77 leftlines
.append(lentry
[0] + lentry
[1] + lentry
[2] + lentry
[3] + lentry
[4] + "\n")
80 for rentry
in rightList
:
81 rightlines
.append(rentry
[0] + rentry
[1] + rentry
[2] + rentry
[3] + rentry
[4] + "\n")
83 # Create the diff. Here's how it works. These are flattened sorted lists of
84 # bookmarks. For ease of viewing, in their diffs, they look like this:
85 # folder=<bookmark folder> title=<link title> url=<link href> feedurl=<feedurl (if present)> icon=<icon>
86 # The diff takes the two sets of lines and does a unified diff on them.
87 diff
= difflib
.unified_diff(leftlines
, rightlines
)
90 if __name__
== "__main__":
91 parser
= OptionParser()
92 parser
.add_option("-l", "--leftFile", dest
="left",
93 help="Bookmarks HTML file 1", metavar
="LEFT_FILE")
94 parser
.add_option("-r", "--rightFile", dest
="right",
95 help="Bookmarks HTML file 2", metavar
="RIGHT_FILE")
96 parser
.add_option("-f", "--LogFile", dest
="log",
97 help="The file where the log output should go",
99 parser
.add_option("-d", "--Debug", dest
="isDebug", default
=False,
100 help="Turn on debug output by specifying -d true")
102 (options
, args
) = parser
.parse_args()
108 main(options
.left
, options
.right
, options
.log
)