You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@manifoldcf.apache.org by kw...@apache.org on 2014/01/25 21:47:07 UTC
svn commit: r1561399 - in /manifoldcf/release-scripts: create-site-branch.py
create_site_branch.py
Author: kwright
Date: Sat Jan 25 20:47:07 2014
New Revision: 1561399
URL: http://svn.apache.org/r1561399
Log:
Work on debugging the code
Added:
manifoldcf/release-scripts/create_site_branch.py
- copied, changed from r1561048, manifoldcf/release-scripts/create-site-branch.py
Removed:
manifoldcf/release-scripts/create-site-branch.py
Copied: manifoldcf/release-scripts/create_site_branch.py (from r1561048, manifoldcf/release-scripts/create-site-branch.py)
URL: http://svn.apache.org/viewvc/manifoldcf/release-scripts/create_site_branch.py?p2=manifoldcf/release-scripts/create_site_branch.py&p1=manifoldcf/release-scripts/create-site-branch.py&r1=1561048&r2=1561399&rev=1561399&view=diff
==============================================================================
--- manifoldcf/release-scripts/create-site-branch.py (original)
+++ manifoldcf/release-scripts/create_site_branch.py Sat Jan 25 20:47:07 2014
@@ -91,20 +91,297 @@ def add_change_file_new_dev_row(change_f
# Remove old file and rename temp file
os.unlink(change_file_path)
os.rename(temp_file, change_file_path)
+
+IN_BODY = 0
+IN_PREAMBLE = 1
+IN_COMMENT = 2
+IN_TAG_NAME = 3
+IN_TAG_BODY = 4
+IN_END_TAG_NAME = 5
+IN_BODY_SEEN_LEFTANGLE = 6
+IN_BODY_SEEN_LEFTANGLE_BANG = 7
+IN_BODY_SEEN_LEFTANGLE_BANG_DASH = 9
+IN_COMMENT_SEEN_DASH = 11
+IN_COMMENT_SEEN_DASH_DASH = 12
+IN_PREAMBLE_SEEN_QUESTION = 13
+IN_TAG_BODY_SEEN_SLASH = 14
+IN_TAG_SEEN_SLASH = 15
+
+class TagScanner:
+
+ def __init__( self, action_object ):
+ self.state = IN_BODY
+ self.tag_name = None
+ self.action_object = action_object
+ self.body_accumulator = u''
+
+ def end( self ):
+ if self.state != IN_BODY:
+ raise Exception("At end, in unknown state %d" % self.state)
+ self.action_object.write(self.action_object.map_body(self.body_accumulator))
+
+ def accept_character( self, char ):
+ uchar = unicode(char)
+ print uchar
+ if self.state == IN_BODY:
+ if uchar == u'<':
+ self.state = IN_BODY_SEEN_LEFTANGLE
+ else:
+ self.body_accumulator += uchar
+
+ elif self.state == IN_PREAMBLE:
+ if uchar == u'?':
+ self.state = IN_PREAMBLE_SEEN_QUESTION
+ else:
+ self.action_object.write(uchar)
+
+ elif self.state == IN_COMMENT:
+ if uchar == u'-':
+ self.state = IN_COMMENT_SEEN_DASH
+ else:
+ self.action_object.write(uchar)
+
+ elif self.state == IN_TAG_NAME:
+ if uchar <= u' ':
+ self.action_object.found_tag(self.tag_name)
+ self.action_object.write(uchar)
+ self.state = IN_TAG_BODY
+ elif uchar == u'>':
+ self.action_object.found_tag(self.tag_name)
+ self.action_object.write(uchar)
+ self.state = IN_BODY
+ elif uchar == u'/':
+ self.action_object.found_tag(self.tag_name)
+ self.action_object.write(uchar)
+ self.state = IN_TAG_SEEN_SLASH
+ else:
+ self.tag_name += uchar
+ self.action_object.write(uchar)
+
+ elif self.state == IN_TAG_SEEN_SLASH:
+ if uchar == u'>':
+ self.action_object.found_end_tag(self.tag_name)
+ self.action_object.write(uchar)
+ self.state = IN_BODY
+ self.tag_name = None
+ elif uchar == u'/':
+ self.action_object.write(uchar)
+ else:
+ self.action_object.write(uchar)
+ self.state = IN_TAG_BODY
+
+ elif self.state == IN_TAG_BODY:
+ if uchar == u'/':
+ self.state = IN_TAG_BODY_SEEN_SLASH
+ self.action_object.write(uchar)
+ elif uchar == u'>':
+ self.state = IN_BODY
+ self.action_object.write(uchar)
+ else:
+ self.action_object.write(uchar)
+
+ elif self.state == IN_TAG_BODY_SEEN_SLASH:
+ if uchar == u'>':
+ self.action_object.found_end_tag(self.tag_name)
+ self.action_object.write(uchar)
+ self.state = IN_BODY
+ self.tag_name = None
+ elif uchar == u'/':
+ self.action_object.write(uchar)
+ else:
+ self.action_object.write(uchar)
+ self.state = IN_TAG_BODY
+
+ elif self.state == IN_END_TAG_NAME:
+ if uchar == u'>':
+ self.state = IN_BODY
+ self.action_object.found_end_tag(self.tag_name)
+ self.action_object.write(uchar)
+ self.tag_name = None
+ else:
+ self.action_object.write(uchar)
+ self.tag_name += uchar
+
+ elif self.state == IN_BODY_SEEN_LEFTANGLE:
+ if uchar == u'!':
+ self.state = IN_BODY_SEEN_LEFTANGLE_BANG
+ elif uchar == u'?':
+ self.action_object.write(self.action_object.map_body(self.body_accumulator))
+ self.body_accumulator = u""
+ self.action_object.write(u'<')
+ self.action_object.write(u'?')
+ self.body_accumulator = u""
+ self.state = IN_PREAMBLE
+ elif uchar == u'/':
+ self.state = IN_END_TAG_NAME
+ self.action_object.write(self.action_object.map_body(self.body_accumulator))
+ self.body_accumulator = u""
+ self.action_object.write(u'<')
+ self.action_object.write(u'/')
+ self.tag_name = u""
+ elif uchar == u'<':
+ self.body_accumulator += u'<'
+ else:
+ self.action_object.write(self.action_object.map_body(self.body_accumulator))
+ self.body_accumulator = u""
+ self.action_object.write(u'<')
+ self.action_object.write(uchar)
+ self.tag_name = u"" + uchar
+ self.state = IN_TAG_NAME
+
+ elif self.state == IN_BODY_SEEN_LEFTANGLE_BANG:
+ if uchar == u'-':
+ self.state = IN_BODY_SEEN_LEFTANGLE_BANG_DASH
+ else:
+ self.body_accumulator += u'<'
+ self.body_accumulator += u'!'
+ self.body_accumulator += uchar
+
+ elif self.state == IN_BODY_SEEN_LEFTANGLE_BANG_DASH:
+ if uchar == u'-':
+ self.state = IN_COMMENT
+ self.action_object.write(self.action_object.map_body(self.body_accumulator))
+ self.body_accumulator = u""
+ self.action_object.write(u"<!--")
+ else:
+ self.state = IN_BODY
+ self.body_accumulator += u"<!-"
+ self.body_accumulator += uchar
+
+ elif self.state == IN_COMMENT_SEEN_DASH:
+ if uchar == u'-':
+ self.state = IN_COMMENT_SEEN_DASH_DASH
+ self.action_object.write(uchar)
+ else:
+ self.action_object.write(uchar)
+ self.state = IN_COMMENT
+
+ elif self.state == IN_COMMENT_SEEN_DASH_DASH:
+ if uchar == u'>':
+ self.state = IN_BODY
+ self.action_object.write(uchar)
+ elif uchar == u'-':
+ self.action_object.write(uchar)
+ else:
+ self.state = IN_COMMENT
+ self.action_object.write(uchar)
+
+ elif self.state == IN_PREAMBLE_SEEN_QUESTION:
+ if uchar == u'>':
+ self.state = IN_BODY
+ self.action_object.write(uchar)
+ elif uchar == u'?':
+ self.action_object.write(uchar)
+ else:
+ self.action_object.write(uchar)
+ self.state = IN_PREAMBLE
+
+ else:
+ raise Exception("Unknown state %d" % self.state)
+
+
+class ActionBase:
+ def __init__( self, output_stream ):
+ self.output_stream = output_stream
+
+ def write( self, chars ):
+ self.output_stream.write( chars )
+
+ def map_body( self, body_text ):
+ return body_text
+
+ def found_end_tag( self, tag_name ):
+ pass
+
+ def found_tag( self, tag_name ):
+ pass
+
+
+class HierarchicalAction(ActionBase):
+ def __init__( self, output_stream ):
+ ActionBase.__init__( self, output_stream )
+ self.tag_hierarchy = [ ]
+
+ def found_tag( self, tag_name ):
+ self.tag_hierarchy += [ tag_name ]
+ self.enter_tag( self.make_tag_string( ) )
+
+ def found_end_tag( self, tag_name ):
+ if len(self.tag_hierarchy) == 0 or self.tag_hierarchy[len(self.tag_hierarchy)-1] != tag_name:
+ raise Exception("Unmatched end tag '%s'" % tag_name)
+ self.exit_tag( self.make_tag_string( ) )
+ del self.tag_hierarchy[len(self.tag_hierarchy)-1]
-def fix_pom_xml(pom_file_path, pom_version):
+ def make_tag_string( self ):
+ tag_string = u""
+ for tag in self.tag_hierarchy:
+ tag_string += u"/" + tag
+ return tag_string
+
+ def enter_tag( self, hierarchy_string ):
+ pass
+
+ def exit_tag( self, hierarchy_string ):
+ pass
+
+class PomAction(HierarchicalAction):
+ def __init__( self, output_stream, new_version, root_parent ):
+ HierarchicalAction.__init__( self, output_stream )
+ self.accumulator = None
+ self.modules = [ ]
+ self.new_version = new_version
+ self.replace = False
+ self.root_parent = root_parent
+
+ def enter_tag( self, hierarchy_string ):
+ if hierarchy_string == u"/project/modules/module":
+ self.accumulator = u""
+ elif hierarchy_string == u"/project/version":
+ self.replace = True
+ elif hierarchy_string == u"/project/parent/version" and not self.root_parent:
+ self.replace = True
+
+ def exit_tag( self, hierarchy_string ):
+ if hierarchy_string == u"/project/modules/module":
+ self.modules += [ self.accumulator ]
+ self.accumulator = None
+ elif hierarchy_string == u"/project/version":
+ self.replace = False
+ elif hierarchy_string == u"/project/parent/version" and not self.root_parent:
+ self.replace = False
+
+ def map_body( self, body_text ):
+ if self.replace:
+ return self.new_version
+ return body_text
+
+def fix_pom_xml(pom_file_path, pom_version, root_parent):
"""
Fix primary versions in a pom file to become the specified pom_version.
Returns an array of child project names (NOT paths).
"""
- # MHL
- return [ ]
+ temp_file = "%s.tmp" % pom_file_path
+ fd = codecs.open(pom_file_path, "r", "utf-8")
+ try:
+ out_fd = codecs.open(temp_file, "w", "utf-8")
+ try:
+ action_object = PomAction(out_fd, pom_version, root_parent)
+ ts = TagScanner(action_object)
+ for line in fd:
+ for char in line:
+ ts.accept_character(char)
+ ts.end()
+ return action_object.modules
+ finally:
+ out_fd.close()
+ finally:
+ fd.close()
-def update_poms(root_directory, pom_version):
+def update_poms(root_directory, pom_version, root_parent=True):
""" Update all poms in a project """
- dirs = fix_pom_xml( "%s/pom.xml" % root_directory, pom_version )
+ dirs = fix_pom_xml( "%s/pom.xml" % root_directory, pom_version, root_parent )
for dir in dirs:
- update_poms( "%s/%s" % (root_directory, dir), pom_version )
+ update_poms( "%s/%s" % (root_directory, dir), pom_version, root_parent=False )
def convert_build_xml_line(line, build_version):
"""