#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import print_function

import BaseHTTPServer
import json
import time

import psutil

HOST_NAME = '0.0.0.0'
PORT_NUMBER = 8222


class ProcessListHandler(BaseHTTPServer.BaseHTTPRequestHandler):
    def do_GET(s):
        s.send_response(200)
        s.send_header("Content-type", "application/json")
        s.end_headers()

        options = []
        for proc in psutil.process_iter():
            try:
                options.append(dict(key=proc.name(), value=proc.pid))
            except psutil.NoSuchProcess:
                pass

        s.wfile.write(json.dumps(dict(options=sorted(options, key=lambda p: p['value'], reverse=True))))


if __name__ == '__main__':
    server_class = BaseHTTPServer.HTTPServer
    httpd = server_class((HOST_NAME, PORT_NUMBER), ProcessListHandler)
    print(time.asctime(), "Server Starts - %s:%s" % (HOST_NAME, PORT_NUMBER))
    try:
        httpd.serve_forever()
    except KeyboardInterrupt:
        pass
    httpd.server_close()
    print(time.asctime(), "Server Stops - %s:%s" % (HOST_NAME, PORT_NUMBER))

@@ -39,16 +39,301 @@
 f-8 -*-%0A
+%22%22%22%0AScript for demonstrating possibilities of web-populated select Teamcity plugin.%0A%0AThe scripts runs simple web server and returns list of processes in format,%0Asuitable for the plugin. Two methods are supported: GET and POST.%0AGET method requires basic authorisation, POST doesn't.%0A%22%22%22
 %0Afrom __
@@ -386,16 +386,30 @@
 PServer%0A
+import base64%0A
 import j
@@ -423,16 +423,70 @@
 ort time
+%0Afrom SimpleHTTPServer import SimpleHTTPRequestHandler
 %0A%0Aimport
@@ -540,73 +540,928 @@
 22%0A%0A
-%0Aclass ProcessListHandler(BaseHTTPServer.BaseHTTPRequestHandler):
+key = base64.b64encode('username:password')%0A%0A%0Aclass ProcessListHandler(SimpleHTTPRequestHandler):%0A    def do_HEAD(self):%0A        self.send_response(200)%0A        self.send_header('Content-type', 'text/html')%0A        self.end_headers()%0A%0A    def do_AUTHHEAD(self):%0A        self.send_response(401)%0A        self.send_header('WWW-Authenticate', 'Basic realm=%5C%22Test%5C%22')%0A        self.send_header('Content-type', 'text/html')%0A        self.end_headers()%0A%0A    def do_GET(self):%0A        if self.headers.getheader('Authorization') is None:%0A            self.do_AUTHHEAD()%0A            self.wfile.write('no auth header received')%0A            pass%0A        elif self.headers.getheader('Authorization') == 'Basic ' + key:%0A            self._list_processes()%0A        else:%0A            self.do_AUTHHEAD()%0A            self.wfile.write(self.headers.getheader('Authorization'))%0A            self.wfile.write('not authenticated')%0A            pass%0A
 %0A   
@@ -1468,21 +1468,25 @@
  def do_
-GET(s
+POST(self
 ):%0A     
@@ -1485,24 +1485,90 @@
 ):%0A        s
+elf._list_processes()%0A%0A    def _list_processes(self):%0A        self
 .send_respon
@@ -1584,16 +1584,19 @@
        s
+elf
 .send_he
@@ -1645,16 +1645,19 @@
        s
+elf
 .end_hea
@@ -1887,16 +1887,19 @@
        s
+elf
 .wfile.w
@@ -1987,17 +1987,16 @@
 ue))))%0A%0A
-%0A
 if __nam

Update demo web-server with different methods and support of basic authorisation.