Ejemplo n.º 1
0
    def test_storeConfigInFile_createsNewFileIfNotExists(self):
        PathsManager.CONFIG_PATH = os.path.join(self.myTestFolder, "newConfig.json")
        self.assertFalse(os.path.exists(PathsManager.CONFIG_PATH))

        Config.store_config_in_file()

        self.assertTrue(os.path.exists(PathsManager.CONFIG_PATH))
Ejemplo n.º 2
0
    def test_readConfigFile_ConfigNotChangedIfCorruptedFile(self):
        PathsManager.CONFIG_PATH = os.path.join(self.myTestFolder, "testConfigCorrupted.json")

        Config.read_config_file()

        for k, v in Config.get_config_values().items():
            self.assertEqual(self.originalConfigDict[k], v)
Ejemplo n.º 3
0
    def test_readConfigFile_catchesErrorIfCorruptedFile(self):
        PathsManager.CONFIG_PATH = os.path.join(self.myTestFolder, "testConfigCorrupted.json")

        try:
            Config.read_config_file()
        except:
            self.fail("Exception not catched")
Ejemplo n.º 4
0
 def __init__(self, config: Config):
     self.GLOBAL_PORT = config.getInteger('queen_port', 4040)
     self.GLOBAL_CHUNK_SIZE = config.getInteger('chunk_size', 1024)
     start_ip = config.get('nodes_start_ip', '192.168.0.0')
     end_ip = config.get('nodes_end_ip', '192.168.5.255')
     self.GLOBAL_CONFIG = config
     # scan all up hosts and validate kdfs node
     self.scanNodes(start_ip, end_ip)
Ejemplo n.º 5
0
    def test_storeConfigInFile_overWriteFileIfExist(self):
        PathsManager.CONFIG_PATH = os.path.join(self.myTestFolder, "newConfig.json")
        with open(PathsManager.CONFIG_PATH, "w") as f:
            f.write("Testing")

        Config.store_config_in_file()

        with open(PathsManager.CONFIG_PATH) as f:
            self.assertNotEqual(f.read(), "Testing")
Ejemplo n.º 6
0
    def test_storeConfigInFile_createsAJsonWithAllConfigValues(self):
        PathsManager.CONFIG_PATH = os.path.join(self.myTestFolder, "newConfig.json")

        Config.store_config_in_file()

        with open(PathsManager.CONFIG_PATH) as f:
            obj = json.load(f)

        for k, v in self.originalConfigDict.items():
            self.assertEqual(obj[k], v)
Ejemplo n.º 7
0
 def set_values(self, config_dic):
     config_values = Config.get_config_values()
     if "libraries_path" in config_dic:
         libraries_path = config_dic.pop("libraries_path")
         self.set_libraries_path(libraries_path)
     for k in config_values.keys():
         if k in config_dic:
             Config.__dict__[k] = config_dic[k]
     if Config.proxy is not None:
         utils.set_proxy(dict(http=Config.proxy, https=Config.proxy))
     Config.store_config_in_file()
     return True
Ejemplo n.º 8
0
 def set_values(self, config_dic):
     config_values = Config.get_config_values()
     if "libraries_path" in config_dic:
         libraries_path = config_dic.pop("libraries_path")
         self.set_libraries_path(libraries_path)
     for k in config_values.keys():
         if k in config_dic:
             Config.__dict__[k] = config_dic[k]
     if Config.proxy is not None:
         utils.set_proxy(dict(http=Config.proxy, https=Config.proxy))
     Config.store_config_in_file()
     return True
Ejemplo n.º 9
0
 def __init__(self, config: Config):
     self.HOST_NAME = '0.0.0.0'
     self.SERVER_PORT = config.getInteger('queen_port', 4040)
     self.CLIENT_PORT = config.getInteger('client_port', 4041)
     self.KDFS_CONFIG = config
     self.KDFS_START_IP = config.get('nodes_start_ip', '192.168.0.0')
     self.KDFS_END_IP = config.get('nodes_end_ip', '192.168.5.255')
     self.CHUNK_SIZE = config.getInteger('chunk_size', 1024)
     self.MAX_TIMEOUT = config.getInteger('max_timeout', 60)
     # get client ip address
     self.CLIENT_IP = self.KDFS_CONFIG.get('client_ip', '127.0.0.1')
     # check if this node server is queen
     if config.getBoolean('is_queen', False):
         from server.KDFSQueen import KDFSQueen
         self.IS_QUEEN = True
         self.QUEEN = KDFSQueen(config)
         self.MAX_LISTEN = config.getInteger('queen_max_nodes', 1)
     # check for ports is already use
     if ServerUtils.checkPortInUse(
             self.CLIENT_PORT,
             self.CLIENT_IP) or ServerUtils.checkPortInUse(
                 self.SERVER_PORT, self.HOST_NAME):
         KDFSProtocol.echo(
             "One of \"{}:{}\" or \"{}:{}\" ports are already use!".format(
                 self.HOST_NAME, self.SERVER_PORT, self.CLIENT_IP,
                 self.CLIENT_PORT),
             is_err=True)
         return
     # run local socket client in another thread!
     # self.LOCALSERVERTHREAD = threading.Thread(target=self._runLocalServer)
     self.LOCALSERVERTHREAD = multiprocessing.Process(
         target=self._runLocalServer)
     self.LOCALSERVERTHREAD.start()
     # run global socket server
     self._runGlobalServer()
Ejemplo n.º 10
0
 def __log_environment():
     Version.log_data()
     log.debug("Enviromental data:")
     try:
         log.debug(json.dumps(os.environ.data, indent=4, encoding=sys.getfilesystemencoding()))
     except:
         log.exception("unable to log environmental data")
     try:
         PathsManager.log_relevant_environmental_paths()
     except:
         log.exception("Unable to log Paths")
     try:
         Config.log_values()
     except:
         log.exception("Unable to log Config")
Ejemplo n.º 11
0
        def run(self,argvs):
                # read kdfs config file
                KDFSConfig = Config(ServerUtils.CONFIG_PATH)
                cprint("\r\nKDFS SERVER (version {})".format(KDFSConfig.get('version','unknown')),'green',attrs=['bold'])
                # get kdfs server info
                (info,err) = MinimalCommands().identifyCommand()
                print("MAC Address is {} on {}({})".format(info['macaddr'],info['os'],info['arch']))
                # check if server is queen
                if KDFSConfig.getBoolean('is_queen',False):
                        cprint("*** THIS SERVER RUN AS QUEEN ***",'yellow')
                print("\n")

                # print(minimalUitls.searchTextByRegex("home","%.md"))
                # print(MinimalCommands().findCommand({'type':'rec','path':'/','mode':'name','regex':'Until'}))
                
                server = KDFSServer(KDFSConfig)
Ejemplo n.º 12
0
 def __log_environment():
     Version.log_data()
     log.debug("Enviromental data:")
     try:
         log.debug(
             json.dumps(os.environ.data,
                        indent=4,
                        encoding=sys.getfilesystemencoding()))
     except:
         log.exception("unable to log environmental data")
     try:
         PathsManager.log_relevant_environmental_paths()
     except:
         log.exception("Unable to log Paths")
     try:
         Config.log_values()
     except:
         log.exception("Unable to log Config")
Ejemplo n.º 13
0
 def test_connection(self):
     import socket
     time.sleep(2)
     sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     result = sock.connect_ex((Config.get_client_ws_ip(), Config.web_socket_port))
     if result == 0:
         log.debug("Port is open")
     else:
         log.error("Port: {} could not be opened, check antivirus configuration".format(Config.web_socket_port))
Ejemplo n.º 14
0
 def test_connection(self):
     import socket
     time.sleep(2)
     sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     result = sock.connect_ex(
         (Config.get_client_ws_ip(), Config.web_socket_port))
     if result == 0:
         log.debug("Port is open")
     else:
         log.error(
             "Port: {} could not be opened, check antivirus configuration".
             format(Config.web_socket_port))
Ejemplo n.º 15
0
 def sendAndReceiveServerIdentify(config: Config, ip: str):
     socketi = ServerUtils.socketConnect(
         ip, config.getInteger('queen_port', 4040), 2)
     try:
         # send identify command
         chunk_size = config.getInteger('chunk_size', 1024)
         KDFSProtocol.sendMessage(
             socketi, chunk_size,
             KDFSProtocol.sendCommandFormatter('identify', {},
                                               send_queen=True))
         # get response of command, if exist!
         response = KDFSProtocol.receiveMessage(socketi, chunk_size)['data']
         # print('(debug) node identify:',response)
         return response
     except Exception as e:
         return None
         # raise
     finally:
         # close socket
         if socketi is not None:
             socketi.close()
     return None
Ejemplo n.º 16
0
def commandOutput(widget, pid, output):
    global g_configGuiPid

    if pid == g_configGuiPid:
        config = Config()
        # Check whether config was changed or not
        try:
            configChanged = config.getboolean("main", "config_changed")
            config.remove_option("main", "config_changed")
        except:
            configChanged = False

        config.close()

        if configChanged:
            karamba.reloadTheme(widget)
            return
        else:
            g_configGuiPid = None
Ejemplo n.º 17
0
def commandOutput(widget, pid, output):
    global g_configGuiPid

    if pid == g_configGuiPid:
        config = Config()
        # Check whether config was changed or not
        try:
            configChanged = config.getboolean("main", "config_changed")
            config.remove_option("main", "config_changed")
        except:
            configChanged = False

        config.close()

        if configChanged:
            karamba.reloadTheme(widget)
            return
        else:
            g_configGuiPid = None
Ejemplo n.º 18
0
 def setUp(self):
     self.myTestFolder = os.path.join(PathsManager.TEST_SETTINGS_PATH, "Config")
     self.originalConfigDict = Config.get_config_values()
     restore_test_resources()
Ejemplo n.º 19
0
 def get_config(self):
     config = deepcopy(Config.get_config_values())
     config.update(dict(libraries_path=self.get_libraries_path()))
     return config
Ejemplo n.º 20
0
__author__ = "Xose Pérez"
__contact__ = "*****@*****.**"
__copyright__ = "Copyright (C) 2016 Xose Pérez"
__license__ = 'GPL v3'

import sys

from libs.Config import Config
from libs.Mosquitto import Mosquitto
from libs.Manager import Manager

from libs.services.TheThingsIO import TheThingsIO

if __name__ == "__main__":

    config = Config('config/mqtt2thethingsio.yaml')

    manager = Manager(config.get('daemon', 'pidfile', '/tmp/mqtt2cloud.pid'))
    manager.stdout = config.get('daemon', 'stdout', '/dev/null')
    manager.stderr = config.get('daemon', 'stderr', '/dev/null')
    manager.debug = config.get('daemon', 'debug', False)

    mqtt = Mosquitto(config.get('mqtt', 'client_id'))
    mqtt.host = config.get('mqtt', 'host')
    mqtt.port = config.get('mqtt', 'port')
    mqtt.keepalive = config.get('mqtt', 'keepalive')
    mqtt.clean_session = config.get('mqtt', 'clean_session')
    mqtt.qos = config.get('mqtt', 'qos', 0)
    mqtt.retain = config.get('mqtt', 'retain', True)
    mqtt.status_topic = config.get('mqtt', 'status_topic')
    mqtt.set_will = config.get('mqtt', 'set_will')
Ejemplo n.º 21
0
 def _getConfig(self):
     # read kdfs config file
     if self._KDFSConfig is None:
         self._KDFSConfig = Config(ServerUtils.CONFIG_PATH)
     return self._KDFSConfig
Ejemplo n.º 22
0
 def __init__(self):
     Version.read_version_values()
     Config.read_config_file()
     self.w2b_server = None
     self.consoleHandler = ConsoleHandler()
Ejemplo n.º 23
0
 def set_proxy(self, proxy_url):
     Config.proxy = proxy_url
     Config.store_config_in_file()
Ejemplo n.º 24
0
from libs.Config import Config
from libs.Version import Version

print os.getcwd()
sys.path.append(os.getcwd())

from libs.Packagers.Packager import Packager
from libs.LoggingUtils import init_logging

architectureInt = 64
offline = "offline" in sys.argv
if "32" in sys.argv:
    architectureInt = int(sys.argv[1])

subprocess.call(["python", modulePath + os.sep + "ConstructRes.py"])
Version.read_version_values()
Config.read_config_file()

architecture = Packager.ARCH_32 if architectureInt == 32 else Packager.ARCH_64
packager = Packager.construct_current_platform_packager(
    architecture=architecture)
packager.prepare_res_folder_for_executable()

log = init_logging(__name__)
log.info("packaging for architecture: {}".format(architecture))
if offline:
    log.info("packaging for OFFLINE")
    packager.create_package_for_offline()
else:
    log.info("packaging")
    packager.create_package()
Ejemplo n.º 25
0
 def set_web_socket_info(self, IP, port):
     Config.web_socket_ip = IP
     Config.web_socket_port = port
     Config.store_config_in_file()
Ejemplo n.º 26
0
    def run(self):
        """
        Entry point, initiates components and loops forever...
        """
        self.log("[INFO] Starting " + __app__ + " v" + __version__)
        self.mqtt_connect()
        self.prepare()

        while True:
            self.mqtt.loop()
            if time.time() > self.next_event_time:
                self.push_message()

if __name__ == "__main__":

    config = Config('rentalito.yaml')

    manager = Rentalito(config.get('general', 'pidfile', '/tmp/rentalito.pid'))
    manager.stdout = config.get('general', 'stdout', '/dev/null')
    manager.stderr = config.get('general', 'stderr', '/dev/null')
    manager.debug = config.get('general', 'debug', False)
    manager.publish_to = config.get('general', 'publish_to', '/client/rentalito')
    manager.minimum_time = config.get('general', 'minimum_time', 5)
    manager.time_length_ratio = config.get('general', 'time_length_ratio', 0.5)
    manager.topics = config.get('topics', None, {});

    mqtt = Mosquitto(config.get('mqtt', 'client_id'))
    mqtt.host = config.get('mqtt', 'host')
    mqtt.port = config.get('mqtt', 'port')
    mqtt.keepalive = config.get('mqtt', 'keepalive')
    mqtt.clean_session = config.get('mqtt', 'clean_session')
Ejemplo n.º 27
0
def initWidget(widget):
    global g_nextCacheRefresh, g_showList, g_showIds, g_cacheExpiration, g_pastDays, g_linesMin, g_linesMax

    # Pass the widget reference
    Applet.widget = widget

    # Init splash
    splash = Applet().Splash()
    splash.show()

    # Create dir structure
    splash.setText("Checking config dirs...")
    createConfigDirs()

    # Read config
    splash.setText("Reading config...")
    config = Config()

    # Check whether we want DEBUG messages enabled or not
    if config.getboolean("main", "debug") == False:
        tools.msgDebug("Disabling debug messages !", __name__)
        Globals.DEBUG = False

    # Copy GUI files (if necessary)
    if Globals().versions['nextShows'] != config.get("main", "version") \
    or not "launchGUI" in os.listdir( Globals().nsCGuiBaseDir ):
        # Init dir structures and copy files
        splash.setText("Setup GUI...")
        copyThemeFilesToConfigDir(widget)
        config.set("main", "version", Globals().versions['nextShows'])

    # Get other useful infos from config
    splash.setText("Reading config...")
    displayType = config.get("display", "type")
    if displayType == "Fixed":
        g_linesMax = config.getint("display", "lines_fixed")
        g_linesMin = g_linesMax
    else:
        g_linesMin = config.getint("display", "lines_min")
        g_linesMax = config.getint("display", "lines_max")
    g_cacheExpiration          = config.getint("misc",    "cache_expiration")
    g_pastDays                 = config.getint("display", "past_days")
    applet.colorList           = config.getColors()
    applet.episodeFormatString = config.get(   "display", "format")
    applet.browser             = config.get(   "misc",    "browser")
    applet.dateFormat          = config.get(   "display", "date_format")
    applet.whenFormat          = config.getint("misc",    "when_format")

    # Getting the show list
    splash.setText("Getting show list....")
    g_showList = config.getShows()

    # Extract IDs
    g_showIds = [ show['id'] for show in g_showList ]

    # Init cache
    cache.setExpiration( g_cacheExpiration )
    cache.showIds = g_showIds

    # Refresh cache if necessary
    staledList = cache.getStaledCacheFiles()
    for id in staledList:
        for show in g_showList:
            if show['id'] == id:
                showName = show['name']
        splash.setText("Updating cache: '%s'..." % showName)
        cache.cacheEpisodeList( id )

    # Fetch data to display
    splash.setText("Filtering episodes...")
    data = Data()
    episodeList  = data.getEpisodeList( g_showIds, g_pastDays, g_linesMax )
    applet.episodeList = episodeList

    # Close the splash
    splash.setText("Done!")
    splash.hide()

    # Init widget
    # Fallback (for compatibility reasons)
    # "[display] theme=" was moved to "[misc] theme="
    try:
        applet.themeName = config.get("misc", "theme")
    except:
        applet.themeName = Globals().defaultThemeName
    numReturnedEpisode = len( episodeList )
    if numReturnedEpisode < g_linesMin:
        themeLines = g_linesMin
    elif numReturnedEpisode > g_linesMax:
        themeLines = g_linesMax
    else:
        themeLines = numReturnedEpisode
    applet.themeLines = themeLines
    applet.drawBackground()
    applet.printEpisodeList()

    # Store next cache refresh
    g_nextCacheRefresh = cache.getNextRefreshTS()

    # Setup menu entry for config GUI
    karamba.addMenuConfigOption(widget, "config_gui", "Configure...")
    karamba.setMenuConfigOption(widget, "config_gui", 0)
Ejemplo n.º 28
0
 def storeNewWhenFormat(dummy):
     config = Config()
     config.set( "misc", "when_format", str( applet.whenFormat ) )
     config.close()
Ejemplo n.º 29
0
    def test_readConfigFile_changesConfigParameters(self):
        PathsManager.CONFIG_PATH = os.path.join(self.myTestFolder, "testConfig.json")
        Config.read_config_file()

        self.assertEqual(Config.log_level, logging.DEBUG)
Ejemplo n.º 30
0
__author__ = "Xose Pérez"
__contact__ = "*****@*****.**"
__copyright__ = "Copyright (C) 2013 Xose Pérez"
__license__ = 'GPL v3'

import sys

from libs.Config import Config
from libs.Mosquitto import Mosquitto
from libs.Manager import Manager

from libs.services.Sense import Sense

if __name__ == "__main__":

    config = Config('config/mqtt2sense.yaml')

    manager = Manager(config.get('daemon', 'pidfile', '/tmp/mqtt2sense.pid'))
    manager.stdout = config.get('daemon', 'stdout', '/dev/null')
    manager.stderr = config.get('daemon', 'stderr', '/dev/null')
    manager.debug = config.get('daemon', 'debug', False)

    mqtt = Mosquitto(config.get('mqtt', 'client_id'))
    mqtt.host = config.get('mqtt', 'host')
    mqtt.port = config.get('mqtt', 'port')
    mqtt.keepalive = config.get('mqtt', 'keepalive')
    mqtt.clean_session = config.get('mqtt', 'clean_session')
    mqtt.qos = config.get('mqtt', 'qos', 0)
    mqtt.retain = config.get('mqtt', 'retain', True)
    mqtt.status_topic = config.get('mqtt', 'status_topic')
    mqtt.set_will = config.get('mqtt', 'set_will')
Ejemplo n.º 31
0
 def destination_path(self):
     return Config.get_platformio_lib_dir()
Ejemplo n.º 32
0
 def get_libraries_path(self):
     return Config.get_platformio_lib_dir()
__author__ = "Xose Pérez"
__contact__ = "*****@*****.**"
__copyright__ = "Copyright (C) 2016 Xose Pérez"
__license__ = 'GPL v3'

import sys

from libs.Config import Config
from libs.Mosquitto import Mosquitto
from libs.Manager import Manager

from libs.services.TheThingsIO import TheThingsIO

if __name__ == "__main__":

    config = Config('config/mqtt2thethingsio.yaml')

    manager = Manager(config.get('daemon', 'pidfile', '/tmp/mqtt2cloud.pid'))
    manager.stdout = config.get('daemon', 'stdout', '/dev/null')
    manager.stderr = config.get('daemon', 'stderr', '/dev/null')
    manager.debug = config.get('daemon', 'debug', False)

    mqtt = Mosquitto(config.get('mqtt', 'client_id'))
    mqtt.host = config.get('mqtt', 'host')
    mqtt.port = config.get('mqtt', 'port')
    mqtt.keepalive = config.get('mqtt', 'keepalive')
    mqtt.clean_session = config.get('mqtt', 'clean_session')
    mqtt.qos = config.get('mqtt', 'qos', 0)
    mqtt.retain = config.get('mqtt', 'retain', True)
    mqtt.status_topic = config.get('mqtt', 'status_topic')
    mqtt.set_will = config.get('mqtt', 'set_will')
Ejemplo n.º 34
0
    def saveConfig(self):
        self.saveRequired( False )  # Reset save button state

        # Disable quit button
        self.ui.btnQuit.setEnabled( False )

        # Save button icon & text
        s_btnIcon = self.ui.btnSave.icon()
        s_btnText = self.ui.btnSave.text()
        self.ui.btnSave.setText(u"Saving...")
        self.ui.btnSave.setIcon(QIcon())
        self.repaint()
        qApp.processEvents()

        tools.msgDebug(u"Saving configuration...", __name__)

        config = Config()

        # Save Data
        config.setShows( self.myShows )
        config.setColors( self.myColors )

        if self.ui.radioDispFixedLines.isChecked():
            value = "Fixed"
        else:
            value = "Automatic"
        config.set( "display", "type", value )

        config.set( "display", "past_days",     str( self.ui.spinNumPastDays.value()     ) )
        config.set( "display", "lines_fixed",   str( self.ui.spinFixedDispLines.value()  ) )
        config.set( "display", "lines_min",     str( self.ui.spinMinDispLines.value()    ) )
        config.set( "display", "lines_max",     str( self.ui.spinMaxDispLines.value()    ) )
        config.set( "display", "format",        str( self.ui.leditFormat.text()          ) )
        sep  = self.ui.leditDateSeparator.text()
        list = self.ui.comboDateFormat.itemData( self.ui.comboDateFormat.currentIndex() ).toStringList()
        dateFormat = list.join(sep)
        config.set( "display", "date_separator",str( sep                                 ) )
        config.set( "display", "date_format",   str( dateFormat                          ) )

        config.set( "misc", "cache_expiration", str( self.ui.spinCacheExpiration.value() ) )
        config.set( "misc", "browser",          str( self.ui.leditBrowser.text()         ) )
        config.set( "misc", "theme",            str( self.ui.comboTheme.currentText()    ) )

        # Set this so that the widget knows something changed
        config.set( "main", "config_changed", "True" )

        tools.msgDebug(u"Saving done!", __name__)

        config.close()  # Destroy Config()

        # Restore buttons
        self.ui.btnSave.setIcon( s_btnIcon )
        self.ui.btnSave.setText( s_btnText )
        self.ui.btnQuit.setEnabled( True )
Ejemplo n.º 35
0
 def get_libraries_path(self):
     return Config.get_platformio_lib_dir()
Ejemplo n.º 36
0
 def __init__(self):
     Version.read_version_values()
     Config.read_config_file()
     self.w2b_server = None
     self.consoleHandler = ConsoleHandler()
Ejemplo n.º 37
0
 def set_libraries_path(self, lib_dir):
     Config.set_platformio_lib_dir(lib_dir)
     PathsManager.clean_pio_envs()
Ejemplo n.º 38
0
    def initForm(self):
        # 1st tab labels
        self.ui.lblResultsDisplayed.setText( u"Displayed results: 0/0" )
        self.ui.lblTrackedShows.setText( u"Tracked shows: 0" )

        # Format Sample
        fmtSample = u"<u><b>Sample:</b></u> <b>show:</b> %s, <b>title:</b> %s, <b>season</b>: %d, <b>episode</b>: %d" % (
                      Globals().sampleEpisode['show'],
                      Globals().sampleEpisode['title'],
                      Globals().sampleEpisode['season'],
                      Globals().sampleEpisode['episode'] )
        self.ui.lblFormatSample.setText( fmtSample )

        #### Versions
        version = Globals().versions
        # nextShows Footer Release
        labelContent=str(self.ui.lblFooterRelease.text())
        self.ui.lblFooterRelease.setText(labelContent % version['nextShows'])
        # nextShows Release (About tab)
        labelContent=str(self.ui.lblNextShowsVersion.text())
        self.ui.lblNextShowsVersion.setText(labelContent % version['nextShows'])
        # Libs releases (About tab)
        # Python version
        a,b,c,d,e = sys.version_info
        pythonVersion = "%d.%d.%d" % (a, b, c)
        #
        labelContent=str(self.ui.lblLibsVersion.text())
        self.ui.lblLibsVersion.setText(labelContent % (
            pythonVersion,
            QT_VERSION_STR,
            PYQT_VERSION_STR,
            version["KDE"]) )


        #### Default values
        self.ui.spinNumPastDays.setMinimum(0)
        self.ui.spinNumPastDays.setMaximum(99)
        #self.ui.spinNumPastDays.setValue(1)
        self.ui.spinFixedDispLines.setMinimum(1)
        self.ui.spinFixedDispLines.setMaximum(50)
        #self.ui.spinFixedDispLines.setValue(10)
        self.ui.spinMinDispLines.setMinimum(1)
        self.ui.spinMinDispLines.setMaximum(49)
        #self.ui.spinMinDispLines.setValue(1)
        self.ui.spinMaxDispLines.setMinimum(2)
        self.ui.spinMaxDispLines.setMaximum(50)
        #self.ui.spinMaxDispLines.setValue(10)
        #
        self.ui.spinColorsSingleDay.setMinimum(-99)
        self.ui.spinColorsSingleDay.setMaximum(99)
        self.ui.spinColorsSingleDay.setValue(0)
        self.ui.spinColorsFrom.setMinimum(-99)
        self.ui.spinColorsFrom.setMaximum(98)
        self.ui.spinColorsFrom.setValue(0)
        self.ui.spinColorsTo.setMinimum(-98)
        self.ui.spinColorsTo.setMaximum(99)
        self.ui.spinColorsTo.setValue(10)

        # default color for "Select color"
        self.ui.lblSelectColor.setPixmap( self.drawPreviewColor( self.lastColorUsed, 36, 36 ) )

        # Theme combo
        self.ui.comboTheme.addItems( Globals().availableThemes )


        ####
        #### Read config
        ####
        tools.msgDebug(u"Reading config...", __name__)
        config = Config()

        # Enable/Disable DEBUG
        if config.getboolean("main", "debug") == False:
            tools.msgDebug("Disabling debug messages !", __name__)
            Globals.DEBUG = False

        # Get Data
        self.myShows  = config.getShows()
        self.displayMyShows()
        self.myColors = config.getColors()
        self.ui.lblDefaultColor.setPixmap( self.drawPreviewColor( self.myColors['default'], 36, 36 ) )
        self.displayMyColors()

        if config.get("display", "type") == "Fixed":
            self.ui.radioDispFixedLines.setChecked( True )
        else:
            self.ui.radioDispAutoResize.setChecked( True )

        self.ui.spinNumPastDays.setValue(    int( config.get( "display", "past_days"   ) ) )
        self.ui.spinFixedDispLines.setValue( int( config.get( "display", "lines_fixed" ) ) )
        self.ui.spinMinDispLines.setValue(   int( config.get( "display", "lines_min"   ) ) )
        self.ui.spinMaxDispLines.setValue(   int( config.get( "display", "lines_max"   ) ) )
        self.ui.leditFormat.setText( config.get( "display", "format" ) )
        self.refreshFormatPreview( str(self.ui.leditFormat.text()) )

        self.ui.spinCacheExpiration.setValue( int( config.get( "misc", "cache_expiration" ) ) )
        self.ui.leditBrowser.setText( config.get( "misc", "browser" ) )

        # Fallback code since the "theme" key was located in the [display] section
        # in versions < 2.1.0
        try:
            idx = int( Globals().availableThemes.index( config.get( "misc", "theme" ) ) )
        except:
            idx = 0
        self.ui.comboTheme.setCurrentIndex( idx )

        # Date Separator
        # Fallback code since the "date_separator" key doesn't exist in version < 2.1.0
        try:
            sep = config.get( "display", "date_separator" )
        except:
            sep = "/"
        self.ui.leditDateSeparator.setText( sep )

        # Date Format
        dateFormat = config.get( "display", "date_format" )
        data       = [ "%"+a for a in dateFormat.split( sep ) ]
        idx        = self.ui.comboDateFormat.findData( QVariant( data ) )
        if idx==-1: idx = 0
        self.ui.comboDateFormat.setCurrentIndex( idx )

        config.close()

        # Reset "Save" button state
        self.saveRequired(False)

        tools.msgDebug(u"Done!", __name__)
Ejemplo n.º 39
0
 def set_web_socket_info(self, IP, port):
     Config.web_socket_ip = IP
     Config.web_socket_port = port
     Config.store_config_in_file()
Ejemplo n.º 40
0
class MinimalCommands:
    def __init__(self):
        # get kdfs config
        self.config = Config(ServerUtils.CONFIG_PATH)
        self.storage_path = self.config.get('storage', './')

    # ------------------------------------------------
    def _getAbsPath(self, pathi: str):
        return os.path.abspath("{}/{}".format(self.storage_path, pathi))

    # ------------------------------------------------
    def listCommand(self, params: dict):
        response = []
        # create absolute path with storage path
        absPath = self._getAbsPath(params['path'])
        # check for exist directory
        if not os.path.exists(absPath) or not os.path.isdir(absPath):
            return ('', "no such directory to retrive")
        # get list of files and dirs
        files = os.listdir(absPath)
        # iterate all files
        for filei in files:
            newPath = os.path.join(absPath, filei)
            sizei = os.stat(newPath).st_size
            # translate size humanly
            size = minimalUitls.convertBytesToHumanly(sizei)
            # append to response
            response.append({
                'name': filei,
                'size': size,
                'type': 'dir' if os.path.isdir(newPath) else 'file',
                'path': os.path.join(params['path'], filei)
            })

        return (response, '')

    # ------------------------------------------------
    def findCommand(self, params: dict):
        response = []
        # print("minimal:",params)
        # create absolute path with storage path
        absPath = self._getAbsPath(params['path'])
        # check for exist directory
        if not os.path.exists(absPath) or not os.path.isdir(absPath):
            return ('', "no such directory to retrive")
        # get list of files and dirs (can recursion)
        files = minimalUitls.getAllFilesList(
            absPath,
            is_recursion=(params['type'] == 'rec'),
            just_files=(params['type'] == 'file'))
        # get max items
        maxItems = self.config.getInteger('list_limit', 10)
        # print('final files:',files)
        # iterate all files
        for filei in files:
            # print('file to find:',filei)
            # get abs path
            newPath = os.path.join(absPath, filei)
            findCount = 0
            # if search in filename
            if params['mode'] == 'name':
                # search regex on filename
                findCount = len(
                    minimalUitls.searchTextByRegex(filei, params['regex']))
            elif params['mode'] == 'content':
                # check if directory
                if os.path.isdir(newPath): continue
                # check if file is binary
                if minimalUitls.checkIsBinaryFile(newPath): continue
                # open file and read line by line
                try:
                    with open(newPath, 'r', encoding='utf-8') as f:
                        for line in f:
                            # search regex on every line
                            findCount += len(
                                minimalUitls.searchTextByRegex(
                                    line, params['regex']))
                except:
                    pass

            # append to response
            if findCount > 0 and len(response) <= maxItems:
                response.append({
                    'name': filei,
                    'count': findCount,
                    'type': 'dir' if os.path.isdir(newPath) else 'file',
                    'path': os.path.join(params['path'], filei)
                })

        # print('response_minimal:',params,response)

        return (response, '')

    # ------------------------------------------------
    def existCommand(self, params: dict):
        # create absolute path with storage path
        absPath = self._getAbsPath(params['path'])
        # check for exist path
        if os.path.exists(absPath):
            return ("true", '')
        else:
            return ('false', '')

    # ------------------------------------------------
    def statCommand(self, params: dict):
        response = {}
        # create absolute path with storage path
        absPath = self._getAbsPath(params['path'])
        # check for exist directory or file
        if not os.path.exists(absPath):
            return ('', "no such file or directory to retrive")
        # get stat of absolute path
        (mode, ino, dev, nlink, uid, gid, sizei, atime, mtime,
         ctime) = os.stat(absPath)
        # fileStat = os.stat(newPath)
        # translate size humanly
        size = minimalUitls.convertBytesToHumanly(sizei)

        # append to response
        response = {
            'name': os.path.basename(absPath),
            'size': size,
            'type': 'dir' if os.path.isdir(absPath) else 'file',
            'kdfs_path': params['path'],
            'local_path': absPath,
            'last_access': time.ctime(atime),
            'last_modify': time.ctime(mtime),
            'owner': pwd.getpwuid(uid).pw_name
        }

        return (response, '')

    # ------------------------------------------------
    def identifyCommand(self, params: dict = {}):
        res: dict = {
            'macaddr':
            ServerUtils.getMacAddress(),
            'version':
            self.config.getInteger('version', 0),
            'os':
            platform.system(),
            'arch':
            platform.machine(),
            'hostname':
            platform.node(),
            'node_type':
            'queen' if self.config.getBoolean('is_queen', False) else 'node'
        }
        return (res, '')

    # ------------------------------------------------
    def upgradeCommand(self, params: dict):
        # if packet number is 1,then just return 'yes' or 'no'
        if params['packnumber'] == 1:
            # check if server can accept upgrades or not
            if self.config.getBoolean('accept_upgrades', True):
                KDFSProtocol.echo(
                    "Accept kdfs version {} upgrading...".format(
                        params['version']), 'upgrade')
                # check if upgrades folder is not exsit
                if not os.path.exists(ServerUtils.UPGRADE_PATH):
                    os.makedirs(ServerUtils.UPGRADE_PATH)
                # resturn accept response
                return ('yes', '')
            else:
                KDFSProtocol.echo("Refuse any upgrading", 'upgrade')
                # return refuse response
                return ('no', '')
        # if get file in next packet number, save it
        else:
            try:
                # save to file
                with open(ServerUtils.UPGRADE_ZIP_PATH.format(
                        params['version']),
                          mode='wb') as f:
                    f.write(bytearray(params['data']))
                # extract to min source
                with tarfile.open(
                        ServerUtils.UPGRADE_ZIP_PATH.format(params['version']),
                        'r:gz') as kdfsTar:
                    kdfsTar.extractall("./")
                # update kdfs version number
                self.config.updateItem('version', params['version'])
                KDFSProtocol.echo(
                    "saved kdfs version {} upgraded file in local".format(
                        params['version']), 'upgrade')
                # if os is linux, then run bash script
                if ServerUtils.detectOS() == 'linux':
                    os.system("sh ./upgrade.sh &")
                else:
                    pass
                    # TODO:

                return ('success', '')

            except Exception as e:
                return (e, '')

    # ------------------------------------------------
    def notifyCommand(self, params: dict):
        response = Notification(self.config.get('app_name', 'KDFS'),
                                params['text'], 30).send()
        if response:
            return ('success', '')
        else:
            return ('failed', '')

    # ------------------------------------------------
    def copyCommand(self, params: dict):
        # create absolute path with storage path
        absPath = self._getAbsPath(params['path'])
        # print('abspath:',absPath)
        # if type of copy is 'src'
        if params['mode'] == 'src':
            # check for exist directory or file
            if not os.path.exists(absPath):
                return ('', "no such file or directory to retrive")
            # if path is for file
            if os.path.isfile(absPath):
                content = KDFSProtocol.fileCompress(absPath)
                return (content, '')
            # if path is for directory
            elif os.path.isdir(absPath):
                content = KDFSProtocol.directoryCompress(absPath)
                return (content, '')
            else:
                return ('', "undefined path")

        # if type of copy is 'dest'
        elif params['mode'] == 'dest':
            if params['packnumber'] == 1:
                # check for exist parent directory of dest path
                if not os.path.exists(os.path.dirname(absPath)):
                    return ('', "no such parent directory to retrive")
                return ('success', '')
            else:

                # print("data file (copy):",params['data'])
                # save to file
                filename = KDFSProtocol.saveTempCompressedFile(params['data'])
                # extract to min source
                with tarfile.open(filename, 'r:gz') as kdfsTar:
                    kdfsTar.extractall(absPath)

                return ('success', '')
Ejemplo n.º 41
0
 def destination_path(self):
     return Config.get_platformio_lib_dir()
Ejemplo n.º 42
0
 def __init__(self):
     # get kdfs config
     self.config = Config(ServerUtils.CONFIG_PATH)
     self.storage_path = self.config.get('storage', './')
Ejemplo n.º 43
0
    def initForm(self):
        # 1st tab labels
        self.ui.lblResultsDisplayed.setText(u"Displayed results: 0/0")
        self.ui.lblTrackedShows.setText(u"Tracked shows: 0")

        # Format Sample
        fmtSample = u"<u><b>Sample:</b></u> <b>show:</b> %s, <b>title:</b> %s, <b>season</b>: %d, <b>episode</b>: %d" % (
            Globals().sampleEpisode['show'], Globals().sampleEpisode['title'],
            Globals().sampleEpisode['season'],
            Globals().sampleEpisode['episode'])
        self.ui.lblFormatSample.setText(fmtSample)

        #### Versions
        version = Globals().versions
        # nextShows Footer Release
        labelContent = str(self.ui.lblFooterRelease.text())
        self.ui.lblFooterRelease.setText(labelContent % version['nextShows'])
        # nextShows Release (About tab)
        labelContent = str(self.ui.lblNextShowsVersion.text())
        self.ui.lblNextShowsVersion.setText(labelContent %
                                            version['nextShows'])
        # Libs releases (About tab)
        # Python version
        a, b, c, d, e = sys.version_info
        pythonVersion = "%d.%d.%d" % (a, b, c)
        #
        labelContent = str(self.ui.lblLibsVersion.text())
        self.ui.lblLibsVersion.setText(
            labelContent %
            (pythonVersion, QT_VERSION_STR, PYQT_VERSION_STR, version["KDE"]))

        #### Default values
        self.ui.spinNumPastDays.setMinimum(0)
        self.ui.spinNumPastDays.setMaximum(99)
        #self.ui.spinNumPastDays.setValue(1)
        self.ui.spinFixedDispLines.setMinimum(1)
        self.ui.spinFixedDispLines.setMaximum(50)
        #self.ui.spinFixedDispLines.setValue(10)
        self.ui.spinMinDispLines.setMinimum(1)
        self.ui.spinMinDispLines.setMaximum(49)
        #self.ui.spinMinDispLines.setValue(1)
        self.ui.spinMaxDispLines.setMinimum(2)
        self.ui.spinMaxDispLines.setMaximum(50)
        #self.ui.spinMaxDispLines.setValue(10)
        #
        self.ui.spinColorsSingleDay.setMinimum(-99)
        self.ui.spinColorsSingleDay.setMaximum(99)
        self.ui.spinColorsSingleDay.setValue(0)
        self.ui.spinColorsFrom.setMinimum(-99)
        self.ui.spinColorsFrom.setMaximum(98)
        self.ui.spinColorsFrom.setValue(0)
        self.ui.spinColorsTo.setMinimum(-98)
        self.ui.spinColorsTo.setMaximum(99)
        self.ui.spinColorsTo.setValue(10)

        # default color for "Select color"
        self.ui.lblSelectColor.setPixmap(
            self.drawPreviewColor(self.lastColorUsed, 36, 36))

        # Theme combo
        self.ui.comboTheme.addItems(Globals().availableThemes)

        ####
        #### Read config
        ####
        tools.msgDebug(u"Reading config...", __name__)
        config = Config()

        # Enable/Disable DEBUG
        if config.getboolean("main", "debug") == False:
            tools.msgDebug("Disabling debug messages !", __name__)
            Globals.DEBUG = False

        # Get Data
        self.myShows = config.getShows()
        self.displayMyShows()
        self.myColors = config.getColors()
        self.ui.lblDefaultColor.setPixmap(
            self.drawPreviewColor(self.myColors['default'], 36, 36))
        self.displayMyColors()

        if config.get("display", "type") == "Fixed":
            self.ui.radioDispFixedLines.setChecked(True)
        else:
            self.ui.radioDispAutoResize.setChecked(True)

        self.ui.spinNumPastDays.setValue(
            int(config.get("display", "past_days")))
        self.ui.spinFixedDispLines.setValue(
            int(config.get("display", "lines_fixed")))
        self.ui.spinMinDispLines.setValue(
            int(config.get("display", "lines_min")))
        self.ui.spinMaxDispLines.setValue(
            int(config.get("display", "lines_max")))
        self.ui.leditFormat.setText(config.get("display", "format"))
        self.refreshFormatPreview(str(self.ui.leditFormat.text()))

        self.ui.spinCacheExpiration.setValue(
            int(config.get("misc", "cache_expiration")))
        self.ui.leditBrowser.setText(config.get("misc", "browser"))

        # Fallback code since the "theme" key was located in the [display] section
        # in versions < 2.1.0
        try:
            idx = int(Globals().availableThemes.index(
                config.get("misc", "theme")))
        except:
            idx = 0
        self.ui.comboTheme.setCurrentIndex(idx)

        # Date Separator
        # Fallback code since the "date_separator" key doesn't exist in version < 2.1.0
        try:
            sep = config.get("display", "date_separator")
        except:
            sep = "/"
        self.ui.leditDateSeparator.setText(sep)

        # Date Format
        dateFormat = config.get("display", "date_format")
        data = ["%" + a for a in dateFormat.split(sep)]
        idx = self.ui.comboDateFormat.findData(QVariant(data))
        if idx == -1: idx = 0
        self.ui.comboDateFormat.setCurrentIndex(idx)

        config.close()

        # Reset "Save" button state
        self.saveRequired(False)

        tools.msgDebug(u"Done!", __name__)
Ejemplo n.º 44
0
from libs.Version import Version

print os.getcwd()
sys.path.append(os.getcwd())

from libs.Packagers.Packager import Packager
from libs.LoggingUtils import init_logging

architectureInt = 64
offline = "offline" in sys.argv
if "32" in sys.argv:
    architectureInt = int(sys.argv[1])


subprocess.call(["python", modulePath + os.sep + "ConstructRes.py"])
Version.read_version_values()
Config.read_config_file()


architecture = Packager.ARCH_32 if architectureInt == 32 else Packager.ARCH_64
packager = Packager.construct_current_platform_packager(architecture=architecture)
packager.prepare_res_folder_for_executable()

log = init_logging(__name__)
log.info("packaging for architecture: {}".format(architecture))
if offline:
    log.info("packaging for OFFLINE")
    packager.create_package_for_offline()
else:
    log.info("packaging")
    packager.create_package()
Ejemplo n.º 45
0
 def set_libraries_path(self, lib_dir):
     Config.set_platformio_lib_dir(lib_dir)
     PathsManager.clean_pio_envs()
Ejemplo n.º 46
0
    def saveConfig(self):
        self.saveRequired(False)  # Reset save button state

        # Disable quit button
        self.ui.btnQuit.setEnabled(False)

        # Save button icon & text
        s_btnIcon = self.ui.btnSave.icon()
        s_btnText = self.ui.btnSave.text()
        self.ui.btnSave.setText(u"Saving...")
        self.ui.btnSave.setIcon(QIcon())
        self.repaint()
        qApp.processEvents()

        tools.msgDebug(u"Saving configuration...", __name__)

        config = Config()

        # Save Data
        config.setShows(self.myShows)
        config.setColors(self.myColors)

        if self.ui.radioDispFixedLines.isChecked():
            value = "Fixed"
        else:
            value = "Automatic"
        config.set("display", "type", value)

        config.set("display", "past_days",
                   str(self.ui.spinNumPastDays.value()))
        config.set("display", "lines_fixed",
                   str(self.ui.spinFixedDispLines.value()))
        config.set("display", "lines_min",
                   str(self.ui.spinMinDispLines.value()))
        config.set("display", "lines_max",
                   str(self.ui.spinMaxDispLines.value()))
        config.set("display", "format", str(self.ui.leditFormat.text()))
        sep = self.ui.leditDateSeparator.text()
        list = self.ui.comboDateFormat.itemData(
            self.ui.comboDateFormat.currentIndex()).toStringList()
        dateFormat = list.join(sep)
        config.set("display", "date_separator", str(sep))
        config.set("display", "date_format", str(dateFormat))

        config.set("misc", "cache_expiration",
                   str(self.ui.spinCacheExpiration.value()))
        config.set("misc", "browser", str(self.ui.leditBrowser.text()))
        config.set("misc", "theme", str(self.ui.comboTheme.currentText()))

        # Set this so that the widget knows something changed
        config.set("main", "config_changed", "True")

        tools.msgDebug(u"Saving done!", __name__)

        config.close()  # Destroy Config()

        # Restore buttons
        self.ui.btnSave.setIcon(s_btnIcon)
        self.ui.btnSave.setText(s_btnText)
        self.ui.btnQuit.setEnabled(True)
Ejemplo n.º 47
0
 def set_proxy(self, proxy_url):
     Config.proxy = proxy_url
     Config.store_config_in_file()
Ejemplo n.º 48
0
 def get_config(self):
     config = deepcopy(Config.get_config_values())
     config.update(dict(libraries_path=self.get_libraries_path()))
     return config