# -*- coding: utf-8 -*-
import os
import sys
import json
import urllib.parse
import urllib.request
from optparse import OptionParser

def publish_project(project, tag):
    print(project_name, project_tag)
    PUBLISH_URL = "http://10.10.3.16:5012/publisttest"
    post_data = {
        'project' : project,
        'tag' : tag,
    }
    post_data = urllib.parse.urlencode(post_data).encode('ascii')
    req = urllib.request.Request(PUBLISH_URL)
    data = urllib.request.urlopen(req, post_data).read()
    print(data)

parser = OptionParser(usage="%prog [options]")
parser.add_option("-p",
                  "--projects",
                  action = "store",
                  type = "string",
                  dest = "projects",
                  help = "publish projects")
(options, args) = parser.parse_args()
if options.projects:
    for project in options.projects.split(','):
        project_name, project_tag = project.split('@')
        publish_project(project_name, project_tag)
