<commit_before># Copyright (c) 2015 Ansible, Inc.
# All Rights Reserved

# Python
import pymongo
import sys
from optparse import make_option
import datetime
import json

# Django
from django.core.management.base import BaseCommand
from django.utils.timezone import now

# Mongoengine
import mongoengine

# awx
from awx.fact.models.fact import * # noqa
from awx.main.models import * # noqa

TEST_FACT_ANSIBLE = {
    "ansible_swapfree_mb" : 4092,
    "ansible_default_ipv6" : {
        
    },
    "ansible_distribution_release" : "trusty",
    "ansible_system_vendor" : "innotek GmbH",
    "ansible_os_family" : "Debian",
    "ansible_all_ipv4_addresses" : [
        "192.168.1.145"
    ],
    "ansible_lsb" : {
        "release" : "14.04",
        "major_release" : "14",
        "codename" : "trusty",
        "id" : "Ubuntu",
        "description" : "Ubuntu 14.04.2 LTS"
    },
}

TEST_FACT_PACKAGES = [
    {
        "name": "accountsservice",
        "architecture": "amd64",
        "source": "apt",
        "version": "0.6.35-0ubuntu7.1"
    },
    {
        "name": "acpid",
        "architecture": "amd64",
        "source": "apt",
        "version": "1:2.0.21-1ubuntu2"
    },
    {
        "name": "adduser",
        "architecture": "all",
        "source": "apt",
        "version": "3.113+nmu3ubuntu3"
    },
]

TEST_FACT_SERVICES = [
    {
        "source" : "upstart",
        "state" : "waiting",
        "name" : "ureadahead-other",
        "goal" : "stop"
    },
    {
        "source" : "upstart",
        "state" : "running",
        "name" : "apport",
        "goal" : "start"
    },
    {
        "source" : "upstart",
        "state" : "waiting",
        "name" : "console-setup",
        "goal" : "stop"
    },
]

FACT_FIXTURES = {
    'ansible': TEST_FACT_ANSIBLE,
    'packages': TEST_FACT_PACKAGES,
    'services': TEST_FACT_SERVICES,
    'files': TEST_FACT_ANSIBLE,
}

EXPERIMENT_DEFAULT = {
    "hosts": 10,
    "scan": {
        "duration" : int(525949), # 1 year
        "period": 1440 # 1 day
    },
    "modules": [
        "ansible",
        "packages",
        "services",
        "files"
    ]
}

# damn you python 2.6
def timedelta_total_seconds(timedelta):
    return (
        timedelta.microseconds + 0.0 +
        (timedelta.seconds + timedelta.days * 24 * 3600) * 10 ** 6) / 10 ** 6

class Experiment(object):
    def __init__(self, exp, fact_fixtures, raw_db, mongoengine_db):
        self.db = raw_db
        self.enginedb = mongoengine_db
<commit_msg>use file fact scan data for file fact scan module scans<commit_after># Copyright (c) 2015 Ansible, Inc.
# All Rights Reserved

# Python
import pymongo
import sys
from optparse import make_option
import datetime
import json

# Django
from django.core.management.base import BaseCommand
from django.utils.timezone import now

# Mongoengine
import mongoengine

# awx
from awx.fact.models.fact import * # noqa
from awx.main.models import * # noqa

TEST_FACT_ANSIBLE = {
    "ansible_swapfree_mb" : 4092,
    "ansible_default_ipv6" : {
        
    },
    "ansible_distribution_release" : "trusty",
    "ansible_system_vendor" : "innotek GmbH",
    "ansible_os_family" : "Debian",
    "ansible_all_ipv4_addresses" : [
        "192.168.1.145"
    ],
    "ansible_lsb" : {
        "release" : "14.04",
        "major_release" : "14",
        "codename" : "trusty",
        "id" : "Ubuntu",
        "description" : "Ubuntu 14.04.2 LTS"
    },
}

TEST_FACT_PACKAGES = [
    {
        "name": "accountsservice",
        "architecture": "amd64",
        "source": "apt",
        "version": "0.6.35-0ubuntu7.1"
    },
    {
        "name": "acpid",
        "architecture": "amd64",
        "source": "apt",
        "version": "1:2.0.21-1ubuntu2"
    },
    {
        "name": "adduser",
        "architecture": "all",
        "source": "apt",
        "version": "3.113+nmu3ubuntu3"
    },
]

TEST_FACT_SERVICES = [
    {
        "source" : "upstart",
        "state" : "waiting",
        "name" : "ureadahead-other",
        "goal" : "stop"
    },
    {
        "source" : "upstart",
        "state" : "running",
        "name" : "apport",
        "goal" : "start"
    },
    {
        "source" : "upstart",
        "state" : "waiting",
        "name" : "console-setup",
        "goal" : "stop"
    },
]

TEST_FACT_FILES = [
        {
            "uid": 0, 
            "woth": False, 
            "mtime": 1436810539.5895822, 
            "inode": 525214, 
            "isgid": False, 
            "size": 0, 
            "isuid": False, 
            "isreg": True, 
            "gid": 0, 
            "ischr": False, 
            "wusr": True, 
            "xoth": False, 
            "islnk": False, 
            "nlink": 1, 
            "issock": False, 
            "rgrp": True, 
            "path": "/test/1948", 
            "xusr": False, 
            "atime": 1436810539.5895822, 
            "isdir": False, 
            "ctime": 1436810539.5895822, 
            "isblk": False, 
            "wgrp": False, 
            "xgrp": False, 
            "dev": 64768, 
            "roth": True, 
            "isfifo": False, 
            "mode": "0644", 
            "rusr": True
        }, 
        {
            "uid": 0, 
            "woth": False, 
            "mtime": 1436810540.4955823, 
            "inode": 526295, 
            "isgid": False, 
            "size": 0, 
            "isuid": False, 
            "isreg": True, 
            "gid": 0, 
            "ischr": False, 
            "wusr": True, 
            "xoth": False, 
            "islnk": False, 
            "nlink": 1, 
            "issock": False, 
            "rgrp": True, 
            "path": "/test/3029", 
            "xusr": False, 
            "atime": 1436810540.4955823, 
            "isdir": False, 
            "ctime": 1436810540.4955823, 
            "isblk": False, 
            "wgrp": False, 
            "xgrp": False, 
            "dev": 64768, 
            "roth": True, 
            "isfifo": False, 
            "mode": "0644", 
            "rusr": True
        }, 
        {
            "uid": 0, 
            "woth": False, 
            "mtime": 1436810540.5825822, 
            "inode": 526401, 
            "isgid": False, 
            "size": 0, 
            "isuid": False, 
            "isreg": True, 
            "gid": 0, 
            "ischr": False, 
            "wusr": True, 
            "xoth": False, 
            "islnk": False, 
            "nlink": 1, 
            "issock": False, 
            "rgrp": True, 
            "path": "/test/3135", 
            "xusr": False, 
            "atime": 1436810540.5825822, 
            "isdir": False, 
            "ctime": 1436810540.5825822, 
            "isblk": False, 
            "wgrp": False, 
            "xgrp": False, 
            "dev": 64768, 
            "roth": True, 
            "isfifo": False, 
            "mode": "0644", 
            "rusr": True
        }, 
]

FACT_FIXTURES = {
    'ansible': TEST_FACT_ANSIBLE,
    'packages': TEST_FACT_PACKAGES,
    'services': TEST_FACT_SERVICES,
    'files': TEST_FACT_FILES,
}

EXPERIMENT_DEFAULT = {
    "hosts": 10,
    "scan": {
        "duration" : int(525949), # 1 year
        "period": 1440 # 1 day
    },
    "modules": [
        "ansible",
        "packages",
        "services",
        "files"
    ]
}

# damn you python 2.6
def timedelta_total_seconds(timedelta):
    return (
        timedelta.microseconds + 0.0 +
        (timedelta.seconds + timedelta.days * 24 * 3600) * 10 ** 6) / 10 ** 6

class Experiment(object):
    def __init__(self, exp, fact_fixtures, raw_db, mongoengine_db):
        self.db = raw_db
        self.enginedb = mongoengine_db

{'fraction_non_alphanumeric': 0.14861165428236214, 'fraction_numerical': 0.05110155129709295, 'mean_word_length': 1.6238030095759235, 'pattern_counts': {'":': 119, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 2, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7583443', 'n_tokens_mistral': 3029, 'n_tokens_neox': 2619, 'n_words': 533}