<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Registry handles service registration and images transmission.
#
# <NAME> @ Computer Lab, Cambridge University
# 2015.06.15


import os
import sys

from service import *
from config import conf, logger
from docker import Client


class Registry():

    def __init__(self, cli):
        self._cli = cli
        self._services = {}
        self.init_service_list()
        pass


    def init_service_list(self):
        """Init the service list."""
        images = self._cli.images()
        for image in images:
            self._services[image['Id']] = image

            # liang: dump the images, need to move to cache abstraction in the future.
            logger.info('dumping %s' % image['Id'])
            if image['Id'] == u'3d3b49d80014e2df3434f282586b3bb2cff0f7b5f58a3e63d9229c48085a53a8':
                continue
            raw = self._cli.get_image(image['Id'])
            tar = open(conf['image_dir']+image['Id']+'.tar', 'w')
            tar.write(raw.data)
            tar.close()
        pass


    def register_service(self):
        pass


    def unregister_service(self):
        pass


    def get_registry_list(self):
        pass


    def start_service(self):
        pass


    def stop_service(self):
        pass


    def retrieve_service_image(self):
        pass


    def delete_service_image(self):
        pass

    pass


def test():
    cli = Client(conf['base_url'])
    reg = Registry(cli)
    pass


if __name__=="__main__":
    test()

    sys.exit(0)<commit_msg>coding ...<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Registry handles service registration and images transmission.
#
# <NAME> @ Computer Lab, Cambridge University
# 2015.06.15


import os
import sys

from service import *
from config import conf, logger
from docker import Client


class Registry():

    def __init__(self, cli):
        self._cli = cli
        self._services = {}
        self.init_service_list()
        pass


    def init_service_list(self):
        """Init the service list."""
        images = self._cli.images()
        for image in images:
            self._services[image['Id']] = image

            # liang: dump the images, need to move to cache abstraction in the future.
            if image['Id'] == u'3d3b49d80014e2df3434f282586b3bb2cff0f7b5f58a3e63d9229c48085a53a8':
                continue
            if not os.path.exists(conf['image_dir']+image['Id']+'.tar'):
                logger.info('dumping %s' % image['Id'])
                raw = self._cli.get_image(image['Id'])
                tar = open(conf['image_dir']+image['Id']+'.tar', 'w')
                tar.write(raw.data)
                tar.close()
        pass


    def register_service(self):
        pass


    def unregister_service(self):
        pass


    def get_registry_list(self):
        pass


    def start_service(self, sid, cmd):
        #self._cli.create_container(image=sid, command=cmd)
        container = self._cli.create_container(image='busybox:latest', command=cmd)
        print container
        self._cli.start(sid)
        pass


    def stop_service(self):
        pass


    def retrieve_service_image(self):
        pass


    def delete_service_image(self):
        pass

    pass


def test():
    cli = Client(conf['base_url'])
    reg = Registry(cli)
    #reg.start_service(u'8c2e06607696bd4afb3d03b687e361cc43cf8ec1a4a725bc96e39f05ba97dd55', '/bin/sleep 30')
    pass


if __name__=="__main__":
    test()

    sys.exit(0)
{'fraction_non_alphanumeric': 0.11427765237020317, 'fraction_numerical': 0.040632054176072234, 'mean_word_length': 2.2946096654275094, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2912120', 'n_tokens_mistral': 1230, 'n_tokens_neox': 1090, 'n_words': 252}