<commit_before>import ast
import docker
import json
import os

from vent.api.plugins import Plugin
from vent.api.templates import Template
from vent.helpers.meta import Version

class Action:
   """ Handle actions in menu """
   def __init__(self, **kargs):
       self.plugin = Plugin(**kargs)
       self.d_client = docker.from_env()
       self.vent_config = os.path.join(self.plugin.path_dirs.meta_dir, "vent.cfg")

   def add(self, repo, tools=None, overrides=None, version="HEAD",
           branch="master", build=True, user=None, pw=None, groups=None,
           version_alias=None, wild=None, remove_old=True, disable_old=True):
       """ Add a new set of tool(s) """
       status = (True, None)
       status = self.plugin.add(repo,
                                tools=tools,
                                overrides=overrides,
                                version=version,
                                branch=branch,
                                build=build,
                                user=user,
                                pw=pw,
                                groups=groups,
                                version_alias=version_alias,
                                wild=wild,
                                remove_old=remove_old,
                                disable_old=disable_old)
       return status

   @staticmethod
   def remove():
       return

   def start(self,
             repo=None,
             name=None,
             groups=None,
             enabled="yes",
             branch="master",
             version="HEAD"):
       """
       Start a set of tools that match the parameters given, if no parameters
       are given, start all installed tools on the master branch at verison
       HEAD that are enabled
       """
       args = locals()
       options = ['name',
                  'namespace',
                  'built',
                  'groups',
                  'path',
                  'image_name',
                  'branch',
                  'version']
       # !! TODO needs to be an array of statuses
       status = (True, None)
       vent_config = Template(template=self.vent_config)
       files = vent_config.option('main', 'files')
       sections, template = self.plugin.constraint_options(args, options)
       tool_dict = {}
       for section in sections:
           # ensure tools are built before starting them
           if not sections[section]['built'] == 'yes':
               # try and build the tool first
               # !! TODO make this an optional flag (it'll make it easier for testing without merging later
               status = self.build(name=sections[section]['name'],
                                   groups=groups,
                                   enabled=enabled,
                                   branch=branch,
                                   version=version)

           # initialize needed vars
           template_path = os.path.join(sections[section]['path'], 'vent.template')
           container_name = sections[section]['image_name'].replace(':','-')
           image_name = sections[section]['image_name']

           # checkout the right version and branch of the repo
           self.plugin.branch = branch
           self.plugin.version = version
           cwd = os.getcwd()
           os.chdir(os.path.join(sections[section]['path']))
           status = self.plugin.checkout()
           os.chdir(cwd)

           # set docker settings for container<commit_msg>checkout the repo before building on start<commit_after>import ast
import docker
import json
import os

from vent.api.plugins import Plugin
from vent.api.templates import Template
from vent.helpers.meta import Version

class Action:
   """ Handle actions in menu """
   def __init__(self, **kargs):
       self.plugin = Plugin(**kargs)
       self.d_client = docker.from_env()
       self.vent_config = os.path.join(self.plugin.path_dirs.meta_dir, "vent.cfg")

   def add(self, repo, tools=None, overrides=None, version="HEAD",
           branch="master", build=True, user=None, pw=None, groups=None,
           version_alias=None, wild=None, remove_old=True, disable_old=True):
       """ Add a new set of tool(s) """
       status = (True, None)
       status = self.plugin.add(repo,
                                tools=tools,
                                overrides=overrides,
                                version=version,
                                branch=branch,
                                build=build,
                                user=user,
                                pw=pw,
                                groups=groups,
                                version_alias=version_alias,
                                wild=wild,
                                remove_old=remove_old,
                                disable_old=disable_old)
       return status

   @staticmethod
   def remove():
       return

   def start(self,
             repo=None,
             name=None,
             groups=None,
             enabled="yes",
             branch="master",
             version="HEAD"):
       """
       Start a set of tools that match the parameters given, if no parameters
       are given, start all installed tools on the master branch at verison
       HEAD that are enabled
       """
       args = locals()
       options = ['name',
                  'namespace',
                  'built',
                  'groups',
                  'path',
                  'image_name',
                  'branch',
                  'version']
       # !! TODO needs to be an array of statuses
       status = (True, None)
       vent_config = Template(template=self.vent_config)
       files = vent_config.option('main', 'files')
       sections, template = self.plugin.constraint_options(args, options)
       tool_dict = {}
       for section in sections:
           # initialize needed vars
           template_path = os.path.join(sections[section]['path'], 'vent.template')
           container_name = sections[section]['image_name'].replace(':','-')
           image_name = sections[section]['image_name']

           # checkout the right version and branch of the repo
           self.plugin.branch = branch
           self.plugin.version = version
           cwd = os.getcwd()
           os.chdir(os.path.join(sections[section]['path']))
           status = self.plugin.checkout()
           os.chdir(cwd)

           # ensure tools are built before starting them
           if not sections[section]['built'] == 'yes':
               # try and build the tool first
               # !! TODO make this an optional flag (it'll make it easier for testing without merging later
               status = self.build(name=sections[section]['name'],
                                   groups=groups,
                                   enabled=enabled,
                                   branch=branch,
                                   version=version)

           # set docker settings for container
{'fraction_non_alphanumeric': 0.09182658137882019, 'fraction_numerical': 0.0, 'mean_word_length': 1.455846422338569, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7179114', 'n_tokens_mistral': 1728, 'n_tokens_neox': 1655, 'n_words': 455}