<commit_before>#!/usr/bin/python3

import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
import sys
import errno
import modules.sdnpwn_common as com
import importlib.machinery

def main():
  if(len(sys.argv) == 1):
    try:
      loader = importlib.machinery.SourceFileLoader("help", "modules/help.py")
      mod = loader.load_module()
      params = sys.argv.pop(0)
      filter(None, params)
      mod.run(params)
      del mod
    except IOError:
      com.message("Error importing " + modName + " as a module.", com.ERROR)
  elif(len(sys.argv) > 1):
    modName = sys.argv[1]
    modName = modName.replace("-", "_")
    params = sys.argv
    filter(None, params)
    params.pop(0)
    try:
      loader = importlib.machinery.SourceFileLoader(modName, "modules/" + modName + ".py")
      mod = loader.load_module()
      mod.run(params)
      del sys.modules[modName]
    except IOError as e:
      if(e == errno.EPERM):
        com.message("Run as root!", com.ERROR)
    except ImportError as e:
        com.message("Error importing " + modName + " as a module.", com.ERROR)
        print(e)
    #except Exception as e:
      #com.message("Something went wrong!", com.ERROR)
      #print(e)
      
if __name__=='__main__':
  main()<commit_msg>Changed module loading for new structure<commit_after>#!/usr/bin/python3

import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
import sys
import errno
import modules.sdnpwn.sdnpwn_common as com
import importlib.machinery
import os

def main():
  if(len(sys.argv) == 1):
    try:
      loader = importlib.machinery.SourceFileLoader("help", "modules/sdnpwn/help.py")
      mod = loader.load_module()
      params = sys.argv.pop(0)
      filter(None, params)
      mod.run(params)
      del mod
    except IOError:
      com.message("Error importing " + modName + " as a module.", com.ERROR)
  elif(len(sys.argv) > 1):
    modName = sys.argv[1]
    modName = modName.replace("-", "_")
    params = sys.argv
    filter(None, params)
    params.pop(0)
    try:
      moduleLocation = ""
      for direc, direcs, filenames in os.walk('modules/'):
        for filename in filenames:
          if(filename == (modName + ".py")):
            moduleLocation = direc + "/" + (modName + ".py")
            break
      loader = importlib.machinery.SourceFileLoader(modName, moduleLocation)
      mod = loader.load_module()
      mod.run(params)
      del sys.modules[modName]
    except IOError as e:
      if(e == errno.EPERM):
        com.message("Run as root!", com.ERROR)
    except ImportError as e:
        com.message("Error importing " + modName + " as a module.", com.ERROR)
        print(e)
    #except Exception as e:
      #com.message("Something went wrong!", com.ERROR)
      #print(e)
      
if __name__=='__main__':
  main()
{'fraction_non_alphanumeric': 0.1364120781527531, 'fraction_numerical': 0.004262877442273535, 'mean_word_length': 2.7900403768506057, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4454074', 'n_tokens_mistral': 930, 'n_tokens_neox': 917, 'n_words': 215}