[build] Rewrite ginsh related sed scripts in python.