Ejemplo n.º 1
0
def handle(c):
    if c == "" or c[0] == "#": return
    c = c.strip()
    head = c.lower().split(" ")[0]
    args = " ".join(c.split(" ")[1:])
    try:
        # Yeah, we don't have switch case in python...
        if not Cli.general_commands(head, args, module_help):
            if head in [
                    "database", "debug", "dev", "verbose", "reload", "refresh",
                    "list", "show", "resource", "os", "use", "exec", "search",
                    "info", "previous", "sessions", "jobs", "eval", "report"
            ]:
                exec("Cli.command_{}(args)".format(head))
                Settings.update_history(c)
            else:
                handler = globals()["command_{}".format(head)]
                handler(args)
                Settings.update_history(c)
    except Exception as e:
        if Settings.debug:
            print("Exception -> " + str(e))
            print("    Input -> " + str(c))
            print("Trackback -> ")
            traceback.print_exc()
        error(head + " is not recognized as an internal command !")
        #To check for the wanted command on typos
        wanted = utils.grab_wanted(head, module_keywords)
        if len(wanted) > 0:
            status("Maybe you meant : " + wanted)
        status("Type help or ? to learn more..")
Ejemplo n.º 2
0
def test_settings(email, password, zip_code, languages, categories, save,
                  file_name):
    with mock.patch("builtins.input",
                    side_effect=[email, zip_code, languages, categories,
                                 save]):
        with mock.patch("getpass.getpass", return_value=password):
            settings_path = f"test_tmp/{file_name}"
            settings = Settings(settings_path)
            assert settings.email == email
            assert settings.password == password
            assert settings.zip_code == zip_code
            assert settings.languages == [] if languages is None else languages
            assert settings.categories == [] if categories is None else categories

            if save.upper() == "Y":
                yaml = YAML()
                with open(settings_path) as f:
                    settings = yaml.load(f)
                    assert settings["udemy"]["email"] == email
                    assert settings["udemy"]["password"] == password
                    assert settings["udemy"]["zipcode"] == zip_code
                    assert (settings["udemy"]["languages"] == []
                            if languages is None else ",".join(languages))
                    assert (settings["udemy"]["categories"] == []
                            if categories is None else categories)
                # Load settings just created
                Settings(settings_path)
            else:
                assert os.path.isdir(settings_path) is False
Ejemplo n.º 3
0
def command_handler(c):
    #parsing a command and pass to its function
    if c == "" or c[0] == "#": return
    command = c.lower().split()[0]
    args = " ".join(c.split()[1:])
    try:
        handler = globals()["command_{}".format(command)]
        handler(args)
        Settings.update_history(
            c
        )  # Log the important commands and the ones that doesn't gave error :D
    except Exception as e:
        if command not in all_keywords:
            error(command + " is not recognized as an internal command !")
            #To check for the wanted command on typos
            wanted = utils.grab_wanted(command, all_keywords)
            if len(wanted) > 0:
                status("Maybe you meant : " + wanted)
        else:
            error("Error in executing command " + command)
        status("Type help or ? to learn more..")

        if Settings.debug:
            print("Exception -> " + str(e))
            print("    Input -> " + str(c))
            print("  Modules -> " + "  ".join(modules))
            print("Trackback -> ")
            traceback.print_exc()
Ejemplo n.º 4
0
def handle(c):
	if c=="" or c[0]=="#":return
	c = c.strip()
	head = c.lower().split(" ")[0]
	args = " ".join(c.split(" ")[1:])
	try:
		# Yeah, we don't have switch case in python...
		if not Cli.general_commands(head, args, module_help):
			if head in ["database","debug","dev","verbose","reload","refresh","list","show","resource","os","use","exec",
							"search","info","previous","sessions","jobs","eval","report"]:
				exec("Cli.command_{}(args)".format(head))
				Settings.update_history(c)
			else:
				handler = globals()["command_{}".format(head)]
				handler(args)
				Settings.update_history(c)
	except Exception as e:
		if Settings.debug:
			print("Exception -> "+str(e))
			print("    Input -> "+str(c))
			print("Trackback -> ")
			traceback.print_exc()
		error( head + " is not recognized as an internal command !")
		#To check for the wanted command on typos
		wanted = utils.grab_wanted(head,module_keywords)
		if len(wanted)>0:
			status( "Maybe you meant : " + wanted )
		status( "Type help or ? to learn more..")
Ejemplo n.º 5
0
def Exec(all_keywords):
    global global_options, module_keywords, cli_keywords
    module_keywords += all_keywords
    cli_keywords = all_keywords
    mod = importlib.import_module(
        utils.pythonize("core.modules." + Settings.running_module))
    global_options = getattr(mod, 'execution').module_type.options
    if os.name != "nt":
        utils.Input_completer(module_keywords + modules)
    Settings.add_module(Settings.running_module)
Ejemplo n.º 6
0
def Exec(all_keywords):
	global global_options, module_keywords, cli_keywords
	module_keywords += all_keywords
	cli_keywords = all_keywords
	mod            = importlib.import_module(utils.pythonize("core.modules."+Settings.running_module))
	if Settings.development:
		mod            = utils.reload(mod)
	global_options = getattr(mod, 'execution').module_type.options
	if os.name !="nt":
		utils.Input_completer(module_keywords+modules)
	Settings.add_module(Settings.running_module)
Ejemplo n.º 7
0
def command_use(p=False):
    p = p.lower()
    if not p:
        error("You must enter a module to use !")
        return
    else:
        if p in modules:
            if Settings.running_module:
                Settings.update_previous()
            Settings.running_module = p
            module.Exec(all_keywords)
            return
        else:
            error(p + " module not found!")
Ejemplo n.º 8
0
def test_load_existing_settings(email, password, zip_code, languages,
                                categories, save, file_name):
    with mock.patch("builtins.input",
                    side_effect=[email, zip_code, languages, categories,
                                 save]):
        with mock.patch("getpass.getpass", return_value=password):
            settings_path = f"test_tmp/{file_name}"
            Settings(settings_path)

    # Load existing settings
    settings = Settings(settings_path)
    assert settings.email == email
    assert settings.password == password
    assert settings.zip_code == zip_code
    assert settings.languages == [] if languages is None else languages
    assert settings.categories == [] if categories is None else categories
Ejemplo n.º 9
0
    def __init__(self):
        """
        Initialize
        """
        super(QtCore.QObject, self).__init__()

        self.central_state_monitor = CentralStateMonitor()

        # News
        self.news = News()

        # settings
        self.central_settings = Settings()
        self.signals = Signals()

        # path to modules directory
        self.path_modules = os.path.normpath(
            os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../",
                         "modules"))

        # dictionary to keep track of the instantiated modules
        self._instantiated_modules = {}

        # create window, show it
        self.window = HQWindow(self)
        self.window.show()

        # connect signals: signal_stop_all_modules, which can be called from the modules to stop all other modules
        self.signal_stop_all_modules.connect(self.stop_modules)
        self.signals.write_signal("stop_all_modules",
                                  self.signal_stop_all_modules)
Ejemplo n.º 10
0
class Window(QMainWindow):
    conf = Settings.getInstance()

    def __init__(self, MainQtApp=None, *args, **kwargs):
        super(Window, self).__init__(MainQtApp, *args, **kwargs)
        self.setWindowTitle("Oceana Navigation Data Package")
        self.status = self.statusBar()
        self.mdiArea = QMdiArea(self)
        self.mdiArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
        self.mdiArea.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
        self.mdiArea.subWindowActivated.connect(self.updateMenus)
        self.windowMapper = QSignalMapper(self)
        self.windowMapper.mapped[QWidget].connect(self.setActiveSubWindow)

        self.setCentralWidget(self.mdiArea)

    def setActiveSubWindow(self, window):
        if window:
            self.mdiArea.setActiveSubWindow(window)

    def updateMenus(self):
        hasMdiChild = (self.activeMdiChild() is not None)

    def activeMdiChild(self):
        activeSubWindow = self.mdiArea.activeSubWindow()
        if activeSubWindow:
            return activeSubWindow.widget()

        return None
Ejemplo n.º 11
0
def command_use(p=False):
    p = p.lower()
    if not p:
        error("You must enter a module to use !")
        return
    else:
        if p in modules:
            if Settings.running_module:
                Settings.update_previous()
            Settings.running_module = p
            module.Exec(all_keywords)
            return
        else:
            if Settings.debug:
                print("Module -> " + p)
                print("Loaded modules ->" + "\t".join(modules))
            error(p + " module not found!")
Ejemplo n.º 12
0
def test_load_ci_settings(_, monkeypatch, is_ci_run, email, password):
    monkeypatch.setenv("CI_TEST", str(is_ci_run))
    monkeypatch.setenv("UDEMY_EMAIL", email)
    monkeypatch.setenv("UDEMY_PASSWORD", password)
    settings = Settings("")
    if is_ci_run:
        assert settings.email == email
        assert settings.password == password
Ejemplo n.º 13
0
    def set_from_current_settings(self, settings_singleton: Settings):
        """
        Set the base settings
        :param settings_singleton:
        :return:
        """
        if self.all_conditions:
            raise RuntimeError(
                "The base settings of an experiment can only be modified when no conditions exist."
            )

        for module in self.modules_included:
            self.base_settings[module] = copy.deepcopy(
                settings_singleton.get_settings(module).as_dict()[str(
                    module)])  # not sure if .as_dict() is a good idea
def run(
    browser: str,
    max_pages: Union[int, None],
    cache_hit_limit: int,
    driver: WebDriver = None,
):
    """
    Run the udemy enroller script

    :param str browser: Name of the browser we want to create a driver for
    :param int or None max_pages: Max number of pages to scrape from tutorialbar.com
    :param int cache_hit_limit: If we hit the cache this many times in a row we exit the script
    :param WebDriver driver:
    :return:
    """
    settings = Settings()
    if driver is None:
        dm = DriverManager(browser=browser, is_ci_build=settings.is_ci_build)
        driver = dm.driver
    redeem_courses(driver, settings, max_pages, cache_hit_limit)
Ejemplo n.º 15
0
def command_back(text=False):
	Settings.update_previous()
	Settings.running_module = False
	Settings.reset_name()
	if os.name!="nt":
		utils.Input_completer(cli_keywords+modules )
# Install all the requirements by running requirements.py in IDLE or follow the alternate instructions at
# https://github.com/aapatre/Automatic-Udemy-Course-Enroller-GET-PAID-UDEMY-COURSES-for-FREE/ Make sure you have
# cleared all saved payment details on your Udemy account & the browser! For firefox you need to manually install the
# driver on Arch Linux (sudo pacman -S geckodriver). Untested on other platforms.
from selenium import webdriver

from core import Settings
from core.utils import redeem_courses

settings = Settings()

driver = webdriver.Firefox()

# Maximizes the browser window since Udemy has a responsive design and the code only works
driver.maximize_window()

# in the maximized layout

try:
    redeem_courses(driver, settings)
except KeyboardInterrupt:
    print("Exiting the script")
except Exception as e:
    print("Error: {}".format(e))
finally:
    print("Closing browser")
    driver.quit()
Ejemplo n.º 17
0
 def settingsMenu(self):
     if self.engine.advSettings:
         self.settingsMenuObject = Settings.SettingsMenu(self.engine)
     else:
         self.settingsMenuObject = Settings.BasicSettingsMenu(self.engine)
     return self.settingsMenuObject
Ejemplo n.º 18
0
import os
import sys
from PyQt5.Qt import QApplication
from PyQt5 import QtGui
from core.ui import Window
from core import Settings

if __name__ == "__main__":
    appconf = {}
    conf = Settings.getInstance()
    QApp = QApplication(sys.argv)
    QApp.setObjectName("Oceana")
    mainWindow = Window()
    if not QApp.objectName() in conf:
        conf[QApp.objectName()] = {}
        appconf = conf[QApp.objectName()]
        appconf["x"] = mainWindow.pos().x()
        appconf["y"] = mainWindow.pos().y()
        appconf["width"] = mainWindow.width()
        appconf["height"] = mainWindow.height()
        appconf["lookandfeel"] = "native"

    appconf = conf[QApp.objectName()]
    mainWindow.setMinimumSize(appconf.as_int("width"),
                              appconf.as_int("height"))
    mainWindow.show()
    conf.write()
    sys.exit(QApp.exec_())
Ejemplo n.º 19
0
def command_back(text=False):
    Settings.update_previous()
    Settings.running_module = False
    Settings.reset_name()
    if os.name != "nt":
        utils.Input_completer(cli_keywords + modules)