def commit(self):
		with open(os.path.join(self.config['IMAGE_HOME'], "gui", "lib", "Frontend", "conf", "unveillance.secrets.json"), 'rb') as u:
			frontend_config = json.loads(u.read())
		
		# add remaining frontend templates
		# write .git_as.sh and .ssh_as.sh
		ssh_cmd = ['exec ssh -i %(ssh_key_priv)s -o PubkeyAuthentication=yes -o IdentitiesOnly=yes "$@"' % frontend_config]
		git_cmd = ['GIT_SSH=%s/.ssh_as.sh exec git "$@"' % self.config['IMAGE_HOME']]

		for c in [("git_as", git_cmd), ("ssh_as", ssh_cmd)]:
			with open(os.path.join(self.config['IMAGE_HOME'], ".%s.sh" % c[0]), 'wb+') as g:
				g.write("#! /bin/bash")
				g.write("\n")
				g.write("\n".join(c[1]))

		# say hello to annex
		# git remote add docker image
		routine = [
			"chmod +x %(IMAGE_HOME)s/.git_as.sh %(IMAGE_HOME)s/.ssh_as.sh" % self.config,
			"sleep 5",
			"ssh -f -p %(annex_remote_port)d -o IdentitiesOnly=yes -o PubkeyAuthentication=yes -i %(ssh_key_priv)s %(server_user)s@%(server_host)s 'echo \"\"'" % frontend_config,
			"cd %(IMAGE_HOME)s/annex" % self.config,
			"git config alias.unveillance \\!\"%(IMAGE_HOME)s/.git_as.sh\"" % self.config,
			"git remote add origin ssh://%(server_user)s@%(server_host)s:%(annex_remote_port)d/~/unveillance" % frontend_config
		]

		return build_routine(routine, dst=self.config['IMAGE_HOME'])
	def attach(self):
		with open(os.path.join(self.config['IMAGE_HOME'], "gui", "lib", "Frontend", "conf", "unveillance.secrets.json"), 'rb') as u:
			frontend_config = json.loads(u.read())

		routine = [
			"ssh -p %(annex_remote_port)d -o IdentitiesOnly=yes -o PubkeyAuthentication=yes -i %(ssh_key_priv)s %(server_user)s@%(server_host)s" % frontend_config
		]

		return build_routine(routine, dst=self.config['IMAGE_HOME'])
	def update(self):
		with open(os.path.join(self.config['IMAGE_HOME'], "gui", "lib", "Frontend", "conf", "unveillance.secrets.json"), 'rb') as u:
			frontend_config = json.loads(u.read())

		routine = [
			"ssh -f -p %(annex_remote_port)d -o IdentitiesOnly=yes -o PubkeyAuthentication=yes -i %(ssh_key_priv)s %(server_user)s@%(server_host)s 'source ~/.bash_profile && cd ~/unveillance && git reset --hard HEAD && ./unveillance.sh update'" % frontend_config
		]

		return build_routine(routine, dst=self.config['IMAGE_HOME'])
	def stop(self):
		with open(os.path.join(self.config['IMAGE_HOME'], "gui", "lib", "Frontend", "conf", "unveillance.secrets.json"), 'rb') as u:
			frontend_config = json.loads(u.read())

		routine = [
			"ssh -f -p %(annex_remote_port)d -o IdentitiesOnly=yes -o PubkeyAuthentication=yes -i %(ssh_key_priv)s %(server_user)s@%(server_host)s 'source ~/.bash_profile && cd ~/unveillance/lib/Annex && ./shutdown.sh'&" % frontend_config,
			"sleep 3",
			"%(DOCKER_EXE)s stop %(PROJECT_NAME)s" % self.config
		]

		return build_routine(routine, dst=self.config['IMAGE_HOME'])
Exemple #5
0
    def attach(self):
        with open(
                os.path.join(self.config['IMAGE_HOME'], "gui", "lib",
                             "Frontend", "conf", "unveillance.secrets.json"),
                'rb') as u:
            frontend_config = json.loads(u.read())

        routine = [
            "ssh -p %(annex_remote_port)d -o IdentitiesOnly=yes -o PubkeyAuthentication=yes -i %(ssh_key_priv)s %(server_user)s@%(server_host)s"
            % frontend_config
        ]

        return build_routine(routine, dst=self.config['IMAGE_HOME'])
Exemple #6
0
    def update(self):
        with open(
                os.path.join(self.config['IMAGE_HOME'], "gui", "lib",
                             "Frontend", "conf", "unveillance.secrets.json"),
                'rb') as u:
            frontend_config = json.loads(u.read())

        routine = [
            "ssh -f -p %(annex_remote_port)d -o IdentitiesOnly=yes -o PubkeyAuthentication=yes -i %(ssh_key_priv)s %(server_user)s@%(server_host)s 'source ~/.bash_profile && cd ~/unveillance && git reset --hard HEAD && ./unveillance.sh update'"
            % frontend_config
        ]

        return build_routine(routine, dst=self.config['IMAGE_HOME'])
	def remove(self):
		with open(os.path.join(self.config['IMAGE_HOME'], "gui", "lib", "Frontend", "conf", "unveillance.secrets.json"), 'rb') as u:
			frontend_config = json.loads(u.read())

		routine = [
			"rm %(ssh_key_priv)s %(ssh_key_priv)s.pub" % frontend_config,
			"%(DOCKER_EXE)s stop %(PROJECT_NAME)s",
			"%(DOCKER_EXE)s rm %(PROJECT_NAME)s",
			"%(DOCKER_EXE)s rmi %(IMAGE_NAME)s:%(PROJECT_NAME)s",
			"cd ../",
			"rm -rf %(IMAGE_HOME)s"
		]

		return build_routine([r % self.config for r in routine], dst=self.config['IMAGE_HOME'])
Exemple #8
0
    def stop(self):
        with open(
                os.path.join(self.config['IMAGE_HOME'], "gui", "lib",
                             "Frontend", "conf", "unveillance.secrets.json"),
                'rb') as u:
            frontend_config = json.loads(u.read())

        routine = [
            "ssh -f -p %(annex_remote_port)d -o IdentitiesOnly=yes -o PubkeyAuthentication=yes -i %(ssh_key_priv)s %(server_user)s@%(server_host)s 'source ~/.bash_profile && cd ~/unveillance/lib/Annex && ./shutdown.sh'&"
            % frontend_config, "sleep 3",
            "%(DOCKER_EXE)s stop %(PROJECT_NAME)s" % self.config
        ]

        return build_routine(routine, dst=self.config['IMAGE_HOME'])
	def model(self, *args):
		new_model = self.__parse_asset(args[0]) if type(args) is list else {}
		new_model['root'] = os.path.join(self.config['IMAGE_HOME'], "annex", "Models")

		if "name" not in new_model.keys():
			new_model['name'] = prompt("New model name: ")

		if not self.__tr(new_model['name']):
			return False

		new_model['path'] = os.path.join(new_model['root'], "%s.py" % new_model['name'])

		routine = [
			"sed 's/NAME_OF_MODEL/%(name)s/g' $UNVEILLANCE_BUILD_HOME/tmpl/annex.model.py > %(path)s"
		]

		return build_routine([r % new_model for r in routine], dst=self.config['IMAGE_HOME'])
Exemple #10
0
    def remove(self):
        with open(
                os.path.join(self.config['IMAGE_HOME'], "gui", "lib",
                             "Frontend", "conf", "unveillance.secrets.json"),
                'rb') as u:
            frontend_config = json.loads(u.read())

        routine = [
            "rm %(ssh_key_priv)s %(ssh_key_priv)s.pub" % frontend_config,
            "%(DOCKER_EXE)s stop %(PROJECT_NAME)s",
            "%(DOCKER_EXE)s rm %(PROJECT_NAME)s",
            "%(DOCKER_EXE)s rmi %(IMAGE_NAME)s:%(PROJECT_NAME)s", "cd ../",
            "rm -rf %(IMAGE_HOME)s"
        ]

        return build_routine([r % self.config for r in routine],
                             dst=self.config['IMAGE_HOME'])
Exemple #11
0
    def model(self, *args):
        new_model = self.__parse_asset(args[0]) if type(args) is list else {}
        new_model['root'] = os.path.join(self.config['IMAGE_HOME'], "annex",
                                         "Models")

        if "name" not in new_model.keys():
            new_model['name'] = prompt("New model name: ")

        if not self.__tr(new_model['name']):
            return False

        new_model['path'] = os.path.join(new_model['root'],
                                         "%s.py" % new_model['name'])

        routine = [
            "sed 's/NAME_OF_MODEL/%(name)s/g' $UNVEILLANCE_BUILD_HOME/tmpl/annex.model.py > %(path)s"
        ]

        return build_routine([r % new_model for r in routine],
                             dst=self.config['IMAGE_HOME'])
Exemple #12
0
    def commit(self):
        with open(
                os.path.join(self.config['IMAGE_HOME'], "gui", "lib",
                             "Frontend", "conf", "unveillance.secrets.json"),
                'rb') as u:
            frontend_config = json.loads(u.read())

        # add remaining frontend templates
        # write .git_as.sh and .ssh_as.sh
        ssh_cmd = [
            'exec ssh -i %(ssh_key_priv)s -o PubkeyAuthentication=yes -o IdentitiesOnly=yes "$@"'
            % frontend_config
        ]
        git_cmd = [
            'GIT_SSH=%s/.ssh_as.sh exec git "$@"' % self.config['IMAGE_HOME']
        ]

        for c in [("git_as", git_cmd), ("ssh_as", ssh_cmd)]:
            with open(os.path.join(self.config['IMAGE_HOME'], ".%s.sh" % c[0]),
                      'wb+') as g:
                g.write("#! /bin/bash")
                g.write("\n")
                g.write("\n".join(c[1]))

        # say hello to annex
        # git remote add docker image
        routine = [
            "chmod +x %(IMAGE_HOME)s/.git_as.sh %(IMAGE_HOME)s/.ssh_as.sh" %
            self.config, "sleep 5",
            "ssh -f -p %(annex_remote_port)d -o IdentitiesOnly=yes -o PubkeyAuthentication=yes -i %(ssh_key_priv)s %(server_user)s@%(server_host)s 'echo \"\"'"
            % frontend_config,
            "cd %(IMAGE_HOME)s/annex" % self.config,
            "git config alias.unveillance \\!\"%(IMAGE_HOME)s/.git_as.sh\"" %
            self.config,
            "git remote add origin ssh://%(server_user)s@%(server_host)s:%(annex_remote_port)d/~/unveillance"
            % frontend_config
        ]

        return build_routine(routine, dst=self.config['IMAGE_HOME'])
	def task(self, *args):
		new_task = self.__parse_asset(args[0]) if type(args) is list else {}
		new_task['root'] = os.path.join(self.config['IMAGE_HOME'], "annex", "Tasks")

		if "name" not in new_task.keys():
			new_task['name'] = prompt("New task name: ")
		
		if not self.__tr(new_task['name']):
			return False
		
		if "dir" not in new_task.keys():
			print "Which group should this task belong to? "
			for _, d, _ in os.walk(new_task['root']):
				if len(d) > 0:
					print "Choose one from these groups:"
					print ", ".join(d)
					print "or create a new one here."
				else:
					print "No groups yet! Create one here."

				break
			
			new_task['dir'] = prompt("Task group: ")

		if not self.__tr(new_task['dir']):
			return False

		new_task['dir'] = new_task['dir'].capitalize()
		
		with open(os.path.join(self.config['IMAGE_HOME'], "annex", "vars.json"), 'rb') as M:
			annex_vars = json.loads(M.read())

		if "apply" not in new_task.keys():
			new_task['apply'] = False

			if prompt("Apply mime-type to this task? Y|n: ") not in ["n", "N"]:
				new_task['apply'] = "mime_type"
			else:
				if prompt("Run task at project start? Y|n: ") not in ["n", "N"]:
					new_task['apply'] = "init"

		if new_task['apply'] == "mime_type":
			for m in ["MIME_TYPES", "MIME_TYPE_MAP", "MIME_TYPE_TASKS"]:
				if m not in annex_vars.keys():
					annex_vars[m] = {}

			if "mime_type" not in new_task.keys():
				if len(annex_vars['MIME_TYPES'].keys()) > 0:
					print "Choose from one of these mime types"
					print ", ".join(annex_vars['MIME_TYPES'].keys())
					print "or create a new one here."
				else:
					print "No mime types yes! Create on here."

				new_task['mime_type'] = prompt("Mime type: ")
			
			if not self.__tr(new_task['mime_type']):
				return False

			if new_task['mime_type'] not in annex_vars['MIME_TYPES'].keys():
				if "short_code" not in new_task.keys():
					new_task['short_code'] = prompt("Short code for new mime type %s (i.e. \"my_json\"): " \
						% new_task['mime_type'])

				if not self.__tr(new_task['short_code']):
					return False

				annex_vars['MIME_TYPES'].update({ new_task['mime_type'] : new_task['short_code'] })
				annex_vars['MIME_TYPE_MAP'].update({ new_task['short_code'] : new_task['mime_type'] })

			if new_task['mime_type'] not in annex_vars['MIME_TYPE_TASKS'].keys():
				annex_vars['MIME_TYPE_TASKS'][new_task['mime_type']] = []

			annex_vars['MIME_TYPE_TASKS'][new_task['mime_type']].append("%(dir)s.%(name)s.%(name)s" % new_task)

		elif new_task['apply'] == "init":
				if "INITIAL_TASKS" not in annex_vars.keys():
					annex_vars['INITIAL_TASKS'] = []

				annex_vars['INITIAL_TASKS'].append("%(dir)s.%(name)s.%(name)s" % new_task)		

		if "TASK_POOL" not in annex_vars.keys():
			annex_vars['TASK_POOL'] = []

		annex_vars['TASK_POOL'].append("%(dir)s.%(name)s.%(name)s" % new_task)

		new_task['dir'] = os.path.join(new_task['root'], new_task['dir'])
		new_task['path'] = os.path.join(new_task['dir'], "%s.py" % new_task['name'])

		with open(os.path.join(self.config['IMAGE_HOME'], "annex", "vars.json"), 'wb+') as M:
			M.write(json.dumps(annex_vars, indent=4))

		routine = [
			"mkdir -p %(dir)s" ,
			"if [ ! -f %(dir)s/__init__.py ]; then touch %(dir)s/__init__.py; fi",
			"sed 's/NAME_OF_TASK/%(name)s/g' $UNVEILLANCE_BUILD_HOME/tmpl/annex.task.py > %(path)s"
		]

		return build_routine([r % new_task for r in routine], dst=self.config['IMAGE_HOME'])
Exemple #14
0
    def task(self, *args):
        new_task = self.__parse_asset(args[0]) if type(args) is list else {}
        new_task['root'] = os.path.join(self.config['IMAGE_HOME'], "annex",
                                        "Tasks")

        if "name" not in new_task.keys():
            new_task['name'] = prompt("New task name: ")

        if not self.__tr(new_task['name']):
            return False

        if "dir" not in new_task.keys():
            print "Which group should this task belong to? "
            for _, d, _ in os.walk(new_task['root']):
                if len(d) > 0:
                    print "Choose one from these groups:"
                    print ", ".join(d)
                    print "or create a new one here."
                else:
                    print "No groups yet! Create one here."

                break

            new_task['dir'] = prompt("Task group: ")

        if not self.__tr(new_task['dir']):
            return False

        new_task['dir'] = new_task['dir'].capitalize()

        with open(
                os.path.join(self.config['IMAGE_HOME'], "annex", "vars.json"),
                'rb') as M:
            annex_vars = json.loads(M.read())

        if "apply" not in new_task.keys():
            new_task['apply'] = False

            if prompt("Apply mime-type to this task? Y|n: ") not in ["n", "N"]:
                new_task['apply'] = "mime_type"
            else:
                if prompt("Run task at project start? Y|n: ") not in [
                        "n", "N"
                ]:
                    new_task['apply'] = "init"

        if new_task['apply'] == "mime_type":
            for m in ["MIME_TYPES", "MIME_TYPE_MAP", "MIME_TYPE_TASKS"]:
                if m not in annex_vars.keys():
                    annex_vars[m] = {}

            if "mime_type" not in new_task.keys():
                if len(annex_vars['MIME_TYPES'].keys()) > 0:
                    print "Choose from one of these mime types"
                    print ", ".join(annex_vars['MIME_TYPES'].keys())
                    print "or create a new one here."
                else:
                    print "No mime types yes! Create on here."

                new_task['mime_type'] = prompt("Mime type: ")

            if not self.__tr(new_task['mime_type']):
                return False

            if new_task['mime_type'] not in annex_vars['MIME_TYPES'].keys():
                if "short_code" not in new_task.keys():
                    new_task['short_code'] = prompt("Short code for new mime type %s (i.e. \"my_json\"): " \
                     % new_task['mime_type'])

                if not self.__tr(new_task['short_code']):
                    return False

                annex_vars['MIME_TYPES'].update(
                    {new_task['mime_type']: new_task['short_code']})
                annex_vars['MIME_TYPE_MAP'].update(
                    {new_task['short_code']: new_task['mime_type']})

            if new_task['mime_type'] not in annex_vars['MIME_TYPE_TASKS'].keys(
            ):
                annex_vars['MIME_TYPE_TASKS'][new_task['mime_type']] = []

            annex_vars['MIME_TYPE_TASKS'][new_task['mime_type']].append(
                "%(dir)s.%(name)s.%(name)s" % new_task)

        elif new_task['apply'] == "init":
            if "INITIAL_TASKS" not in annex_vars.keys():
                annex_vars['INITIAL_TASKS'] = []

            annex_vars['INITIAL_TASKS'].append("%(dir)s.%(name)s.%(name)s" %
                                               new_task)

        if "TASK_POOL" not in annex_vars.keys():
            annex_vars['TASK_POOL'] = []

        annex_vars['TASK_POOL'].append("%(dir)s.%(name)s.%(name)s" % new_task)

        new_task['dir'] = os.path.join(new_task['root'], new_task['dir'])
        new_task['path'] = os.path.join(new_task['dir'],
                                        "%s.py" % new_task['name'])

        with open(
                os.path.join(self.config['IMAGE_HOME'], "annex", "vars.json"),
                'wb+') as M:
            M.write(json.dumps(annex_vars, indent=4))

        routine = [
            "mkdir -p %(dir)s",
            "if [ ! -f %(dir)s/__init__.py ]; then touch %(dir)s/__init__.py; fi",
            "sed 's/NAME_OF_TASK/%(name)s/g' $UNVEILLANCE_BUILD_HOME/tmpl/annex.task.py > %(path)s"
        ]

        return build_routine([r % new_task for r in routine],
                             dst=self.config['IMAGE_HOME'])