Github user kaknikhil commented on a diff in the pull request: https://github.com/apache/madlib/pull/318#discussion_r217842978 --- Diff: src/madpack/create_changelist.py --- @@ -0,0 +1,239 @@ +#!/usr/bin/python +# ------------------------------------------------------------------------------ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ------------------------------------------------------------------------------ + +# Create changelist for any two branches/tags + +# Prequisites: +# The old version has to be installed in the "madlib_old_vers" schema +# The new version has to be installed in the "madlib" (default) schema +# Two branches/tags must exist locally (run 'git fetch' to ensure you have the latest version) +# The current branch does not matter + +# Usage (must be executed in the src/madpack directory): +# python create_changelist.py <database name> <old version branch> <new version branch> <changelist filename> +# If you are using the master branch, plase make sure to edit the branch/tag in the output file + +# Example (should be equivalent to changelist_1.13_1.14.yaml): +# python create_changelist.py madlib rel/v1.13 rel/v1.14 chtest1.yaml + +import sys +import os + +database = sys.argv[1] +old_vers = sys.argv[2] +new_vers = sys.argv[3] +ch_filename = sys.argv[4] + +if os.path.exists(ch_filename): + print "{0} already exists".format(ch_filename) + raise SystemExit + +err1 = os.system("""psql {0} -l > /dev/null""".format(database)) +if err1 != 0: + print "Database {0} does not exist".format(database) + raise SystemExit + +err1 = os.system("""psql {0} -c "select madlib_old_vers.version()" > /dev/null + """.format(database)) +if err1 != 0: + print "MADlib is not installed in the madlib_old_vers schema. Please refer to the Prequisites." + raise SystemExit + +err1 = os.system("""psql {0} -c "select madlib.version()" > /dev/null + """.format(database)) +if err1 != 0: + print "MADlib is not installed in the madlib schema. Please refer to the Prequisites." + raise SystemExit + +print "Creating changelist {0}".format(ch_filename) +os.system("rm -f /tmp/madlib_tmp_nm.txt /tmp/madlib_tmp_udf.txt /tmp/madlib_tmp_udt.txt") +try: + # Find the new modules using the git diff + err1 = os.system("git diff {old_vers} {new_vers} --name-only --diff-filter=A > /tmp/madlib_tmp_nm.txt".format(**locals())) + if err1 != 0: + print "Git diff failed. Please ensure that branches/tags are fetched." + raise SystemExit + + f = open("/tmp/madlib_tmp_cl.yaml", "w") + f.write( +"""# ------------------------------------------------------------------------------ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ------------------------------------------------------------------------------ +""") + + f.write( + """ +# Changelist for MADlib version {old_vers} to {new_vers} + +# This file contains all changes that were introduced in a new version of +# MADlib. This changelist is used by the upgrade script to detect what objects +# should be upgraded (while retaining all other objects from the previous version) + +# New modules (actually .sql_in files) added in upgrade version +# For these files the sql_in code is retained as is with the functions in the +# file installed on the upgrade version. All other files (that don't have +# updates), are cleaned up to remove object replacements +""".format(**locals())) + + # Find the new .sql_in files that are not in test folders + f.write("new module:\n") + with open('/tmp/madlib_tmp_nm.txt') as fp: + for line in fp: + if 'sql_in' in line and '/test/' not in line: + f.write(' ' + line.split('/')[5].split('.')[0]+':\n') + + # Find the changed types and keep a list for future use + os.system("psql {0} -f diff_udt.sql > /tmp/madlib_tmp_udt.txt".format(database)) + + f.write("\n# Changes in the types (UDT) including removal and modification\n") + f.write("udt:\n") + udt_list=[] + with open('/tmp/madlib_tmp_udt.txt') as fp: + for line in fp: + if 'UDT' in line and '[]' not in line: + ch_type = line.split('|')[1].strip() + udt_list.append(ch_type) + f.write(' ' + ch_type +":\n") + + # Find the list of UDFs and UDAs + # There are two main sources for these lists. + # 1. The functions that actually got changed + # 2. The functions that depend on a changed type + + # We will keep two lists (for UDF and UDA) and fill them as we parse the + # output of diff functions + + udf_list=[] + uda_list=[] + current_list = udf_list --- End diff -- Do we really need the current_list variable? The code will look a bit simpler if we just append to the right list whenever necessary.
---