module intended to be imported in most AIKIF utils
    to manage folder paths, user settings, etc.
    Modify the parameters at the top of this file to suit
337129
def show_config():
    
    res = ''
    res += '\n---------- Folder Locations ---------\n'
    for k,v in fldrs.items():
        res += str(k) + ' = ' + str(v) + '\n'
    
    res += '\n---------- Logfiles ---------\n'
    for k,v in logs.items():
        res += str(k) + ' = ' + str(v) + '\n'
        
    res += '\n---------- Parameters ---------\n'
    for k,v in params.items():
        res += str(k) + ' = ' + str(v) + '\n'
    print("\nusage from other programs - returns " + fldr_root())
    return res
218432
def scan_django_settings(values, imports):
    '''
    '''
    if isinstance(values, (str, bytes)):
        if utils.is_import_str(values):
            imports.add(values)
    elif isinstance(values, dict):
        for k, v in values.items():
            scan_django_settings(k, imports)
            scan_django_settings(v, imports)
    elif hasattr(values, '__file__') and getattr(values, '__file__'):
        imp, _ = utils.import_path_from_file(getattr(values, '__file__'))
        imports.add(imp)
    elif hasattr(values, '__iter__'):
        for item in values:
            scan_django_settings(item, imports)
298470
def main():
    
    print('Initialising AIKIF Project...')
    name = 'AIKIF'
    type = 'Software'
    desc = """
     Artificial Intelligence Knowledge Information Framework - Project Overview
       
     This document was autogenerated via aikif/examples/AIKIF_project.py  
"""
    desc += '\n     Last updated ' + mod_dt.TodayAsString()	

        
    fldr = os.getcwd() # 'T:\\user\\dev\\src\\python\\AIKIF\\aikif\\examples\\AIKIF_project'
    report_file_base = fldr + os.sep + 'aikif_report'
    p = mod_prj.Project(name, type, desc, fldr)
    project_setup(p)


    requirements = mod_dt.DataTable('requirements.csv', ',', col_names=['id', 'dep_id', 'name', 'details'])
    p.log_table(requirements)
    p.record(requirements, '', ['a', '', 'process data', 'automatically process source files to tables based on rules'])
    p.record(requirements, '', ['b', '', 'define structures', 'use mappings and ontology to specify what to do'])
    p.record(requirements, '', ['c', '', 'log intent', 'log key events'])
    p.record(requirements, '', ['d', '', 'methods toolbox', 'implement a set of programs that can be used generically'])
    p.record(requirements, '', ['e', '', 'Command Line Interface', 'CLI to query and update datasets and control processes'])
    p.record(requirements, '', ['a01', 'a', 'download CSV', 'download CSV file from website'])
    p.record(requirements, '', ['a02', 'a', 'load CSV to table', 'import CSV file to Database table'])
    p.record(requirements, '', ['a03', 'a', 'find blank rows in CSV', 'read CSV file and count DQ issues'])
    p.record(requirements, '', ['a04', 'a', 'aggregate table', 'summarise Database table by col(n)'])
    p.record(requirements, '', ['e01', 'e', 'CLI commands', 'CLI to manage commands and modes of operation'])
    p.record(requirements, '', ['e02', 'e', 'CLI query', 'query functions of datasets in AIKIF using basic fixed commands'])
    p.record(requirements, '', ['e03', 'e', 'CLI NLP', 'integrate NLP to allow english questions and data addition in add/query mode'])
    p.record(requirements, '', ['e04', 'e', 'CLI add', 'allows user to add data to general or specific datasets'])
    p.record(requirements, '', ['e05', 'e', 'CLI process', 'allows managing of all processes in AIKIF'])

    progress = mod_dt.DataTable('progress.csv', ',', col_names=['program', 'percent', 'details'])
    p.log_table(progress)
    p.record(progress, '', ['knowledge', '1%',  'class to manage raw data to information'])
    p.record(progress, '', ['mapper', '20%', 'mapping columns to data structures, with business rules'])
    p.record(progress, '', ['sql_code_generator', '90%', 'generates SQL to transform data external to AIKIF'])
    
    issues = mod_dt.DataTable('issues.csv', ',', col_names=['id', 'name', 'details'])
    p.log_table(issues)
    p.record(issues, '', ['01', 'In Progress', 'implement AIKIF project logging'])
    p.record(issues, '', ['02', 'todo', 'implement Knowledge mapping'])
    p.record(issues, '', ['03', 'Testing', 'data mapping of columns'])
    
    
  #  p.build_report(report_file_base + '.md', type='md')
    p.build_report(report_file_base + '.rst', type='rst')
    print('Done...')
764667
def init_current_directory():
    """"""
    settings_directory=project_path+'/.dry'
    settings_file=settings_directory+'/config.py'
    if os.path.isdir(settings_directory):
	# already initialized
	print("directory already initialized.")
	return
    # init
    os.makedirs(settings_directory)
    f = open(settings_file,'w')
    print(sample_config_file, file=f)
    f.close()
1340604
def _update_init_all(module_path, r):
    """"""
    module_dir_path = os.path.split(module_path)[0]
    module_list = []
    for item_name in os.listdir(module_dir_path):
        item_path = os.path.join(module_dir_path, item_name)
        if os.path.isfile(item_path) and item_name in ('__init__.py', 'setup.py'):
            continue
        if os.path.isfile(item_path) and not item_name.endswith('.py'):
            continue
        # if os.path.isdir(item_path) and not os.path.isfile(
        #     os.path.join(item_path, '__init__.py')
        # ):
        #   continue
        if os.path.isdir(item_path):
            continue
        module_list.append(re.sub(r'.py$', '', item_name).encode('utf-8'))
    module_literal_str = str(sorted(module_list))

    assignment_node_list = r('AssignmentNode', recursive=False)
    for n in assignment_node_list:
        if n.type == 'assignment' and n.target.value == '__all__':
            n.value = module_literal_str
            break
    else:
        r.node_list.append(
            redbaron.RedBaron('__all__ = {}\n'.format(module_literal_str))
        )
    return r
1217336
def _manage(target, extra='', proj_settings=PROJ_SETTINGS):
    """"""
    local("export PYTHONPATH='' && "
          "export DJANGO_SETTINGS_MODULE='%s' && "
          "django-admin.py %s %s" %
          (proj_settings, target, extra),
          capture=False)
854298
private void adjustModuleConfig() {

        Locale l = CmsLocaleManager.getLocale("en");
        try {
            CmsResource config = m_cms.readResource(m_config.getValue());
            CmsFile configFile = m_cms.readFile(config);
            CmsXmlContent xmlContent = CmsXmlContentFactory.unmarshal(m_cms, configFile);
            int number = xmlContent.getIndexCount(XMLPath.CONFIG_RESOURCETYPE, l) + 1;
            createParentXmlElements(
                xmlContent,
                XMLPath.CONFIG_RESOURCETYPE + XMLPath.num(number) + XMLPath.CONFIG_RESOURCETYPE_TYPENAME,
                l);
            I_CmsXmlContentValue v = xmlContent.getValue(
                XMLPath.CONFIG_RESOURCETYPE + XMLPath.num(number) + XMLPath.CONFIG_RESOURCETYPE_TYPENAME,
                l);
            v.setStringValue(m_cms, m_typeShortName.getValue());
            v = xmlContent.addValue(
                m_cms,
                XMLPath.CONFIG_RESOURCETYPE + XMLPath.num(number) + XMLPath.CONFIG_RESOURCETYPE_NAMEPATTERN,
                l,
                CmsXmlUtils.getXpathIndexInt(
                    XMLPath.CONFIG_RESOURCETYPE + XMLPath.num(number) + XMLPath.CONFIG_RESOURCETYPE_NAMEPATTERN) - 1);
            v.setStringValue(m_cms, getNamePattern());
            configFile.setContents(xmlContent.marshal());

            CmsLockUtil.ensureLock(m_cms, configFile);
            m_cms.writeFile(configFile);
            CmsLockUtil.tryUnlock(m_cms, configFile);
        } catch (CmsException e) {
            LOG.error("Can't read module config resource", e);
        }
    }
737212
def options(self, context, module_options):
        '''
            
        '''

        self.user = None
        self.userfile = None

        if 'USER' in module_options and 'USERFILE' in module_options:
            context.log.error('USER and USERFILE options are mutually exclusive!')
            sys.exit(1)

        if 'USER' in module_options:
            self.user = module_options['USER']

        elif 'USERFILE' in module_options:
            path = os.path.expanduser(module_options['USERFILE'])

            if not os.path.exists(path):
                context.log.error('Path to USERFILE invalid!')
                sys.exit(1)

            self.userfile = path

        self.ps_script = obfs_ps_script('powersploit/Exfiltration/Invoke-TokenManipulation.ps1')
1191387
function (options, callback) {
        options = extend({}, MODULE_LOADER_DEFAULTS, options)
        var modulesFolder = options.uri

        iterateFiles(modulesFolder, loadModule, callback, isJsFile)

        function loadModule(fileName) {
            if (options.skip && options.skip.test(fileName)) {
                return
            }
            var module = require(fileName)
            var name = path.relative(options.uri, fileName)
            options.core.add(name, module)
        }
    }
93368
function _importDirectoryOptionsParser(options={}) {
  const _options = Object.assign({
    imports: {},
    onload: options.callback,
    extension: makeArray(options.extensions || settings.get('extensions')),
    useSyncRequire: settings.get('useSyncRequire'),
    merge: settings.get('mergeImports'),
    rescursive: false
  }, options, {
    squashErrors: !!options.retry
  });

  if (_options.extensions) delete _options.extensions;

  if (options.callback) console.warn(`The options.callback method is deprecated, please use options.onload() instead. This being used in ${getCallingFileName()}`);

  return _options;
}
416240
function internalRewire(parentModulePath, targetPath) {
    var targetModule,
        prelude,
        appendix,
        src;

    // Checking params
    if (typeof targetPath !== "string") {
        throw new TypeError("Filename must be a string");
    }

    // Resolve full filename relative to the parent module
    targetPath = Module._resolveFilename(targetPath, parentModulePath);

    // Create testModule as it would be created by require()
    targetModule = new Module(targetPath, parentModulePath);

    // We prepend a list of all globals declared with var so they can be overridden (without changing original globals)
    prelude = getImportGlobalsSrc();

    // Wrap module src inside IIFE so that function declarations do not clash with global variables
    // @see https://github.com/jhnns/rewire/issues/56
    prelude += "(function () { ";

    // We append our special setter and getter.
    appendix = "\n" + getDefinePropertySrc();

    // End of IIFE
    appendix += "})();";

    // Check if the module uses the strict mode.
    // If so we must ensure that "use strict"; stays at the beginning of the module.
    src = fs.readFileSync(targetPath, "utf8");
    if (detectStrictMode(src) === true) {
        prelude = ' "use strict"; ' + prelude;
    }

    moduleEnv.inject(prelude, appendix);
    moduleEnv.load(targetModule);

    return targetModule.exports;
}
541588
def init_app(module, BASE_DIR, **kwargs):
    
    global app

    def init_config():
        """
        Load settings module and attach values to the application
        config dictionary
        """
        if 'FLASK_PHILO_SETTINGS_MODULE' not in os.environ:
            raise ConfigurationError('No settings has been defined')

        app.config['BASE_DIR'] = BASE_DIR

        # default settings
        for v in dir(default_settings):
            if not v.startswith('_'):
                app.config[v] = getattr(default_settings, v)

        app.debug = app.config['DEBUG']

        # app settings
        settings = importlib.import_module(
            os.environ['FLASK_PHILO_SETTINGS_MODULE'])
        for v in dir(settings):
            if not v.startswith('_'):
                app.config[v] = getattr(settings, v)

        def init_urls():
            # Reads urls definition from URLs file and bind routes and views
            urls_module = importlib.import_module(app.config['URLS'])
            for route in urls_module.URLS:
                app.add_url_rule(
                    route[0], view_func=route[1].as_view(route[2]))

        def init_logging():
            """
            initialize logger for the app
            """

            hndlr = logging.StreamHandler()
            formatter = logging.Formatter(
                '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
            hndlr.setFormatter(formatter)
            app.logger.addHandler(hndlr)
            log_level = app.config['LOG_LEVEL']
            app.logger.setLevel(getattr(logging, log_level))

        def init_flask_oauthlib():
            """
            http://flask-oauthlib.readthedocs.io/en/latest/oauth2.html
            """
            oauth.init_app(app)

        def init_cors(app):
            """
            Initializes cors protection if config
            """

            if 'CORS' in app.config:
                CORS(
                    app,
                    resources=app.config['CORS'],
                    supports_credentials=app.config.get(
                        "CORS_SUPPORT_CREDENTIALS",
                        False
                    ),
                    allow_headers=app.config.get(
                        "CORS_ALLOW_HEADERS",
                        "Content-Type,Authorization,accept-language,accept"
                    )
                )

        init_db(g, app)
        init_logging()
        init_urls()
        init_flask_oauthlib()
        init_jinja2(g, app)
        init_cors(app)
    app = Flask(module)
    init_config()
    return app
910802
def run(self, tool, args, new_import_path=''):
        
        if new_import_path != '':
            #print('APPENDING PATH = ', new_import_path)
            sys.path.append(new_import_path)
        
        #if silent == 'N':
        print('main called ' + tool['file'] + '->' + tool['function'] + ' with ', args, ' = ', tool['return'])
        mod = __import__( os.path.basename(tool['file']).split('.')[0]) # for absolute folder names
        # mod = __import__( tool['file'][:-2]) # for aikif folders (doesnt work)
        func = getattr(mod, tool['function'])
        tool['return'] = func(args)
        return tool['return']
490594
def _load_custom(self, settings_name='localsettings.py'):
        '''
        

        '''
        if settings_name[-3:] == '.py':
            settings_name = settings_name[:-3]

        new_settings = {}
        try:
            settings = importlib.import_module(settings_name)
            new_settings = self._convert_to_dict(settings)
        except ImportError:
            log.info("No override settings found")

        for key in new_settings:
            if key in self.my_settings:
                item = new_settings[key]
                if isinstance(item, dict) and \
                        isinstance(self.my_settings[key], dict):
                    for key2 in item:
                        self.my_settings[key][key2] = item[key2]
                else:
                    self.my_settings[key] = item
            else:
                self.my_settings[key] = new_settings[key]
1315002
def set_paths(self, base_dir, script_path):
        """"""
        # Make absolute paths #
        if 'change_dir' in self.kwargs:
            self.kwargs['change_dir'] = DirectoryPath(os.path.abspath(self.kwargs['change_dir']))
        if 'out_file' in self.kwargs:
            self.kwargs['out_file']   = FilePath(os.path.abspath(self.kwargs['out_file']))
        # In case there is a base directory #
        if base_dir is not None:
            self.base_dir             = DirectoryPath(os.path.abspath(base_dir))
            self.script_path          = FilePath(base_dir + "run." + self.extensions[self.language])
            self.kwargs['change_dir'] = base_dir
            self.kwargs['out_file']   = FilePath(base_dir + "run.out")
        # Other cases #
        if base_dir is None and script_path is None: self.script_path = FilePath(new_temp_path())
        if script_path is not None: self.script_path = FilePath(os.path.abspath(script_path))
15876
def set_api_from_config_path(self) -> None:
        """"""
        config = ConfigParser(allow_no_value=False)
        # TODO: Remove this after this issue https://github.com/python/mypy/issues/2427 is closed
        config.optionxform = str  # type:ignore
        config.read(self.config_path, "utf-8")
        if config.has_option("defaults", "dynamic_loading"):
            dynamic_loading = config.get("defaults", "dynamic_loading")
        else:
            dynamic_loading = "infura"
        self._set_rpc(dynamic_loading)
351555
def admin(module):
    """"""
    # add module into admin site
    app = os.getcwd().split('/')[-1]
    if app != 'app':
        logger.warning('''\033[31m{Warning}\033[0m
==> your current path is \033[32m%s\033[0m\n
==> please add your sql module under app folder!''' % os.getcwd())
        exit(1)

    admin_path = os.path.join(os.getcwd(), 'admin')
    os.chdir(admin_path)
    with open('views.py', 'r+') as f:
        prev = pos = 0
        while f.readline():
            prev, pos = pos, f.tell()
        f.seek(prev)
        f.write(
            '\nfrom app.models import %s\nadmin.add_view(ModelView(%s, db.session))'
            % (module, module)
        )

    logger.info('''\033[33m{Info}\033[0m: add module done!''')