<commit_before>#!/usr/bin/python

#      Copyright 2015, <NAME> BV
#
#      Licensed to the Apache Software Foundation (ASF) under one
#      or more contributor license agreements.  See the NOTICE file
#      distributed with this work for additional information
#      regarding copyright ownership.  The ASF licenses this file
#      to you under the Apache License, Version 2.0 (the
#      "License"); you may not use this file except in compliance
#      with the License.  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#      Unless required by applicable law or agreed to in writing,
#      software distributed under the License is distributed on an
#      "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
#      KIND, either express or implied.  See the License for the
#      specific language governing permissions and limitations
#      under the License.

#      Script to deploy VMs locally on Qemu/KVM
#      Written by <NAME>, <NAME>
#      <EMAIL>

import libvirt
import xml.etree.ElementTree as ET
import sys
import getopt
import os.path
import ConfigParser
import shutil
from jinja2 import Template
import subprocess

# Colored terminals
try:
    from clint.textui import colored
except:
    print "Error: Please install clint library to support color in the terminal:"
    print "       pip install clint"
    sys.exit(1)

# Handle the arguments
def handleArguments(argv):
    global DEBUG
    DEBUG = 0
    global DRYRUN
    DRYRUN = 1
    global deploy_role
    deploy_role = ''
    global deploy_cloud
    deploy_cloud = ''
    global digit
    digit = ''
    global display_state 
    display_state = False

    # Usage message
    help = "Usage: ./" + os.path.basename(__file__) + ' [options]' + \
        '\n  --deploy-role -r \t\tDeploy VM with this role' + \
        '\n  --deploy-cloud -c \t\tDeploy group of VMs to build a cloud' + \
        '\n  --digit -d \t\tDigit to append to the role-name instead of the next available' + \
        '\n  --status -s \t\t\tDisplay status of your VMs' + \
        '\n  --debug\t\t\tEnable debug mode'

    try:
        opts, args = getopt.getopt(
            argv, "hr:c:d:s", [
                "deploy-role=", "deploy-cloud=", "digit=", "status", "debug"])
    except getopt.GetoptError as e:
        print "Error: " + str(e)
        print help
        sys.exit(2)

    if len(opts) == 0:
        print help
        sys.exit(2)

    for opt, arg in opts:
        print "processing option " + opt + " arg " + arg
        if opt == '-h':
            print help
            sys.exit()
        elif opt in ("-r", "--deploy-role"):
            deploy_role = arg
        elif opt in ("-c", "--deploy-cloud"):
            deploy_cloud = arg
        elif opt in ("-d", "--digit"):
            digit = arg
        elif opt in ("-s", "--status"):
            display_state = True 
        elif opt in ("--debug"):
            DEBUG = 1

# Parse arguments
if __name__ == "__main__":
    handleArguments(sys.argv[1:])

# Deploy local KVM class
class kvm_local_deploy:
    
    # Init function
    def __init__(self, debug=0, dryrun=0, force=0):
        self.DEBUG = debug
        self.DRYRUN = dryrun
        self.FORCE = force
        self.check_root()
        self.configfile = os.getcwd() + '/config'
        self.config_data = {}
        try:
            self.conn = libvirt.open('qemu:///system')
        except Exception, e:
            print "ERROR: Could not connect to Qemu!"
            sys.exit(1)

        self.print_welcome()
        self.read_config_file(self.configfile)

    # Check for root permissions
    def check_root(self):
        if not os.geteuid() == 0:
            print "ERROR: Script must be run as root'"
            sys.exit(1)

    # Read our own config file for settings
    def read_config_file(self, configfile):<commit_msg>comment out the is-root check for now<commit_after>#!/usr/bin/python

#      Copyright 2015, <NAME>
#
#      Licensed to the Apache Software Foundation (ASF) under one
#      or more contributor license agreements.  See the NOTICE file
#      distributed with this work for additional information
#      regarding copyright ownership.  The ASF licenses this file
#      to you under the Apache License, Version 2.0 (the
#      "License"); you may not use this file except in compliance
#      with the License.  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#      Unless required by applicable law or agreed to in writing,
#      software distributed under the License is distributed on an
#      "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
#      KIND, either express or implied.  See the License for the
#      specific language governing permissions and limitations
#      under the License.

#      Script to deploy VMs locally on Qemu/KVM
#      Written by <NAME>, <NAME>
#      <EMAIL>

import libvirt
import xml.etree.ElementTree as ET
import sys
import getopt
import os.path
import ConfigParser
import shutil
from jinja2 import Template
import subprocess

# Colored terminals
try:
    from clint.textui import colored
except:
    print "Error: Please install clint library to support color in the terminal:"
    print "       pip install clint"
    sys.exit(1)

# Handle the arguments
def handleArguments(argv):
    global DEBUG
    DEBUG = 0
    global DRYRUN
    DRYRUN = 1
    global deploy_role
    deploy_role = ''
    global deploy_cloud
    deploy_cloud = ''
    global digit
    digit = ''
    global display_state 
    display_state = False

    # Usage message
    help = "Usage: ./" + os.path.basename(__file__) + ' [options]' + \
        '\n  --deploy-role -r \t\tDeploy VM with this role' + \
        '\n  --deploy-cloud -c \t\tDeploy group of VMs to build a cloud' + \
        '\n  --digit -d \t\tDigit to append to the role-name instead of the next available' + \
        '\n  --status -s \t\t\tDisplay status of your VMs' + \
        '\n  --debug\t\t\tEnable debug mode'

    try:
        opts, args = getopt.getopt(
            argv, "hr:c:d:s", [
                "deploy-role=", "deploy-cloud=", "digit=", "status", "debug"])
    except getopt.GetoptError as e:
        print "Error: " + str(e)
        print help
        sys.exit(2)

    if len(opts) == 0:
        print help
        sys.exit(2)

    for opt, arg in opts:
        print "processing option " + opt + " arg " + arg
        if opt == '-h':
            print help
            sys.exit()
        elif opt in ("-r", "--deploy-role"):
            deploy_role = arg
        elif opt in ("-c", "--deploy-cloud"):
            deploy_cloud = arg
        elif opt in ("-d", "--digit"):
            digit = arg
        elif opt in ("-s", "--status"):
            display_state = True 
        elif opt in ("--debug"):
            DEBUG = 1

# Parse arguments
if __name__ == "__main__":
    handleArguments(sys.argv[1:])

# Deploy local KVM class
class kvm_local_deploy:
    
    # Init function
    def __init__(self, debug=0, dryrun=0, force=0):
        self.DEBUG = debug
        self.DRYRUN = dryrun
        self.FORCE = force
        # we can run as a user in the libvirt group
        #self.check_root()
        self.configfile = os.getcwd() + '/config'
        self.config_data = {}
        try:
            self.conn = libvirt.open('qemu:///system')
        except Exception, e:
            print "ERROR: Could not connect to Qemu!"
            sys.exit(1)

        self.print_welcome()
        self.read_config_file(self.configfile)

    # Check for root permissions
    def check_root(self):
        if not os.geteuid() == 0:
            print "ERROR: Script must be run as root'"
            sys.exit(1)

    # Read our own config file for settings
    def read_config_file(self, configfile):
{'fraction_non_alphanumeric': 0.10176651305683564, 'fraction_numerical': 0.005888376856118792, 'mean_word_length': 2.1127490039840637, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '5293759', 'n_tokens_mistral': 2346, 'n_tokens_neox': 2290, 'n_words': 826}