<commit_before>use clap::{ArgMatches};
use std::path::Path;
use db;
use std::fs::File;
use std::io::Read;
use rustc_serialize;
use rustc_serialize::{Encodable};
use rustc_serialize::json::{self, Encoder};
use rustc_serialize::json::Json;
use std::collections::BTreeMap;
use std::collections::HashMap;
use std::result::Result;
use rusqlite::Connection;
use rusqlite::Error;

use dbFsFile;
use std::result;
use json_loader_elephant::json_loader_elephant;
use elephant;

#[derive(Debug)]
struct Person {
    id: i32,
    name: String,
    data: Option<Vec<u8>>
}




pub fn listy(direcory: &str) {
    let path = Path::new(direcory);
    for entry in path.read_dir().expect("read_dir call failed") {
        if let Ok(entry) = entry {
            println!("aaaa{:?}", entry.path());
        }
    }
}


pub fn job_files_list(direcory: &str)  {
    let path = Path::new(direcory);
    for entry in path.read_dir().expect("read_dir call failed") {
        if let Ok(entry) = entry {
            println!("job_files_list{:?}", entry.path());
        }
    }
}



pub fn deligate(conn: &Connection, matches : ArgMatches) {
    if let Some(in_v) = matches.values_of("dir-scripts") {
        let str_shell_files_list = String::from("shell_files");
        let pk_directory_type_shell = elephant::elephant_directory_type(&conn, &str_shell_files_list);
        for in_file in in_v {
            let filename = in_file.to_string();
            db::insert_fs_dir(&conn, pk_directory_type_shell, filename);
            listy(&in_file);

        }
    }
        // If we specified the multiple() setting we can get all the values
    if let Some(in_v) = matches.values_of("env") {
        for in_file in in_v {
            //println!("An input file: {}", in_file);
            job_files_list(&in_file);
        }
    }

    if let Some(in_v) = matches.values_of("dir-jobs") {
        let str_job_files_list = String::from("job_files");
        let pk_directory_type_jobs = elephant::elephant_directory_type(&conn, &str_job_files_list);
        for in_file in in_v {
            let filename = in_file.to_string();
            db::insert_fs_dir(&conn, pk_directory_type_jobs, filename);
        }
    }
}



#[cfg(test)]
mod tests {
    #[test]
    fn list_provider() {
        use db;
        let conn = db::connect();
        db::create_tables(&conn);
        for filename in db::list_provider(&conn) {
            println!("list_provider:{:?}", filename);
        }

    }

    #[test]
    fn list_job_depend() {
        use db;
        let conn = db::connect();
        db::create_tables(&conn);
        for filename in db::list_job_depend(&conn) {
            println!("list_job_depend:{:?}", filename);<commit_msg>Add enviroment method to loader<commit_after>use clap::{ArgMatches};
use std::path::Path;
use db;
use std::fs::File;
use std::io::Read;
use rustc_serialize;
use rustc_serialize::{Encodable};
use rustc_serialize::json::{self, Encoder};
use rustc_serialize::json::Json;
use std::collections::BTreeMap;
use std::collections::HashMap;
use std::result::Result;
use rusqlite::Connection;
use rusqlite::Error;

use dbFsFile;
use std::result;
use json_loader_elephant::json_loader_elephant;
use elephant;

#[derive(Debug)]
struct Person {
    id: i32,
    name: String,
    data: Option<Vec<u8>>
}




pub fn listy(direcory: &str) {
    let path = Path::new(direcory);
    for entry in path.read_dir().expect("read_dir call failed") {
        if let Ok(entry) = entry {
            println!("aaaa{:?}", entry.path());
        }
    }
}


pub fn job_files_list(direcory: &str)  {
    let path = Path::new(direcory);
    for entry in path.read_dir().expect("read_dir call failed") {
        if let Ok(entry) = entry {
            println!("job_files_list{:?}", entry.path());
        }
    }
}



pub fn deligate(conn: &Connection, matches : ArgMatches) {
    if let Some(in_v) = matches.values_of("dir-scripts") {
        let str_shell_files_list = String::from("shell_files");
        let pk_directory_type_shell = elephant::elephant_directory_type(&conn, &str_shell_files_list);
        for in_file in in_v {
            let filename = in_file.to_string();
            db::insert_fs_dir(&conn, pk_directory_type_shell, filename);
        }
    }
    if let Some(in_v) = matches.values_of("dir-jobs") {
        let str_job_files_list = String::from("job_files");
        let pk_directory_type_jobs = elephant::elephant_directory_type(&conn, &str_job_files_list);
        for in_file in in_v {
            let filename = in_file.to_string();
            db::insert_fs_dir(&conn, pk_directory_type_jobs, filename);
        }
    }
}


pub fn enviroment(conn: &Connection, pk_session : i32, matches : ArgMatches) {
    if let Some(in_v) = matches.values_of("env") {
        for in_file in in_v {
            let filename = in_file.to_string();
            let mut text = "".to_string();
            let pk_variable_name = elephant::elephant_variable_pk(&conn, &filename);
            let session = elephant::elephant_enviroment(&conn, &pk_session, &pk_variable_name);
        }
    }
}



#[cfg(test)]
mod tests {
    #[test]
    fn list_provider() {
        use db;
        let conn = db::connect();
        db::create_tables(&conn);
        for filename in db::list_provider(&conn) {
            println!("list_provider:{:?}", filename);
        }

    }

    #[test]
    fn list_job_depend() {
        use db;
        let conn = db::connect();
        db::create_tables(&conn);
        for filename in db::list_job_depend(&conn) {
            println!("list_job_depend:{:?}", filename);
{'fraction_non_alphanumeric': 0.14009315657470442, 'fraction_numerical': 0.0014331780723754925, 'mean_word_length': 3.0310469314079422, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1721287', 'n_tokens_mistral': 1875, 'n_tokens_neox': 1867, 'n_words': 391}