def _handleStartServer(self):
        if not NGinxSetupOps.commandExists():
            self.mainWindow.updateStatusBar(
                u'ERROR: No NGinx command available')
            print 'NO COMMAND'
            return

        if NGinxRunOps.isRunning():
            self.mainWindow.updateStatusBar(
                u'ERROR: An NGinx process is already active')
            print 'ALREADY RUNNING'
            return

        path = self.rootPath
        self.mainWindow.appConfig.set(AppConfigEnum.ROOT_PATH, path)
        recentPaths = self.mainWindow.appConfig.get(AppConfigEnum.RECENT_PATHS,
                                                    [])
        ListUtils.addIfMissing(path,
                               recentPaths,
                               reorder=True,
                               frontOrdering=True)
        self.mainWindow.appConfig.set(AppConfigEnum.RECENT_PATHS, recentPaths)

        thread = NGinxRemoteThread(self, rootPath=path)
        self._serverThread = thread
        thread.start()
        self.mainWindow.updateStatusBar(u'NGinx server now active')
        self._updateDisplay()
    def initializeEnvironment(cls, path):
        """ CREATE MISSING FILES AND FOLDERS
            Due to the limited file creation privileges while running NGinx as a normal user,
            certain files and folders must exist prior to starting the server.
        """

        for folderParts in cls._NGINX_FOLDERS:
            p = FileUtils.createPath(path, *folderParts, isDir=True)
            if not os.path.exists(p):
                os.makedirs(p)

        for fileParts in cls._NGINX_FILES:
            p = FileUtils.createPath(path, *fileParts, isFile=True)
            if not os.path.exists(p):
                f = open(p, 'w+')
                f.close()

        #-------------------------------------------------------------------------------------------
        # COPY CONF FILES
        #       NGinx requires a number of conf files to be present and comes with a default set of
        #       files, which must be cloned to the target location if they do not already exist.
        nginxExeConfFolder = FileUtils.createPath(NGinxSetupOps.getExePath(), 'conf', isDir=True)
        for item in os.listdir(nginxExeConfFolder):
            itemPath = FileUtils.createPath(nginxExeConfFolder, item)
            if not os.path.isfile(itemPath):
                continue
            targetPath = FileUtils.createPath(path, 'conf', item, isFile=True)
            if os.path.exists(targetPath):
                continue
            shutil.copy(itemPath, targetPath)
    def initializeEnvironment(cls, path):
        """ CREATE MISSING FILES AND FOLDERS
            Due to the limited file creation privileges while running NGinx as a normal user,
            certain files and folders must exist prior to starting the server.
        """

        for folderParts in cls._NGINX_FOLDERS:
            p = FileUtils.createPath(path, *folderParts, isDir=True)
            if not os.path.exists(p):
                os.makedirs(p)

        for fileParts in cls._NGINX_FILES:
            p = FileUtils.createPath(path, *fileParts, isFile=True)
            if not os.path.exists(p):
                f = open(p, 'w+')
                f.close()

        #-------------------------------------------------------------------------------------------
        # COPY CONF FILES
        #       NGinx requires a number of conf files to be present and comes with a default set of
        #       files, which must be cloned to the target location if they do not already exist.
        nginxExeConfFolder = FileUtils.createPath(NGinxSetupOps.getExePath(),
                                                  'conf',
                                                  isDir=True)
        for item in os.listdir(nginxExeConfFolder):
            itemPath = FileUtils.createPath(nginxExeConfFolder, item)
            if not os.path.isfile(itemPath):
                continue
            targetPath = FileUtils.createPath(path, 'conf', item, isFile=True)
            if os.path.exists(targetPath):
                continue
            shutil.copy(itemPath, targetPath)
    def _handleStartServer(self):
        if not NGinxSetupOps.commandExists():
            self.mainWindow.updateStatusBar(u'ERROR: No NGinx command available')
            print 'NO COMMAND'
            return

        if NGinxRunOps.isRunning():
            self.mainWindow.updateStatusBar(u'ERROR: An NGinx process is already active')
            print 'ALREADY RUNNING'
            return

        path = self.rootPath
        self.mainWindow.appConfig.set(AppConfigEnum.ROOT_PATH, path)
        recentPaths = self.mainWindow.appConfig.get(
            AppConfigEnum.RECENT_PATHS, []
        )
        ListUtils.addIfMissing(path, recentPaths, reorder=True, frontOrdering=True)
        self.mainWindow.appConfig.set(AppConfigEnum.RECENT_PATHS, recentPaths)

        thread = NGinxRemoteThread(self, rootPath=path)
        self._serverThread = thread
        thread.start()
        self.mainWindow.updateStatusBar(u'NGinx server now active')
        self._updateDisplay()
    def __init__(self, parent, **kwargs):
        """Creates a new instance of NwmHomeWidget."""
        super(NwmHomeWidget, self).__init__(parent,
                                            widgetFile=False,
                                            id='home',
                                            **kwargs)

        mainLayout = self._getLayout(self, QtGui.QVBoxLayout)
        mainLayout.setContentsMargins(6, 6, 6, 6)

        rootPath = self.mainWindow.appConfig.get(AppConfigEnum.ROOT_PATH,
                                                 NGinxSetupOps.getExePath())

        label = QtGui.QLabel(self)
        label.setText(u'Server Container Path:')
        label.setStyleSheet(self._HEADER_STYLE)
        mainLayout.addWidget(label)

        label = QtGui.QLabel(self)
        label.setText(
            u'The absolute path the location NGinx will use as its root source'
        )
        label.setStyleSheet(self._INFO_STYLE)
        mainLayout.addWidget(label)
        mainLayout.addSpacing(3)

        textWidget, textLayout = self._createWidget(self, QtGui.QHBoxLayout,
                                                    True)

        text = QtGui.QLineEdit(textWidget)
        text.setText(rootPath)
        textLayout.addWidget(text)
        self._pathLineEdit = text

        recent = PyGlassPushButton(textWidget,
                                   icon=IconSheetMap.DOWN,
                                   size=SizeEnum.SMALL)
        recent.setSizePolicy(QtGui.QSizePolicy.Maximum,
                             QtGui.QSizePolicy.Preferred)
        recent.clicked.connect(self._handleRecentLocations)
        textLayout.addWidget(recent)
        self._recentBtn = recent

        browse = PyGlassPushButton(textWidget,
                                   icon=IconSheetMap.FOLDER,
                                   size=SizeEnum.SMALL)
        browse.setSizePolicy(QtGui.QSizePolicy.Maximum,
                             QtGui.QSizePolicy.Preferred)
        browse.clicked.connect(self._handleLocatePath)
        textLayout.addWidget(browse)
        self._browseBtn = browse

        mainLayout.addSpacing(20)

        label = QtGui.QLabel(self)
        label.setText(u'Server Management:')
        label.setStyleSheet(self._HEADER_STYLE)
        mainLayout.addWidget(label)

        label = QtGui.QLabel(self)
        label.setText(u'Modify the state of your NGinx server')
        label.setStyleSheet(self._INFO_STYLE)
        mainLayout.addWidget(label)
        mainLayout.addSpacing(3)

        buttonBox, boxLayout = self._createWidget(self, QtGui.QHBoxLayout,
                                                  True)

        btn = PyGlassPushButton(buttonBox,
                                text='Start',
                                icon=IconSheetMap.FORWARD)
        btn.clicked.connect(self._handleStartServer)
        boxLayout.addWidget(btn)
        self._startBtn = btn

        btn = PyGlassPushButton(buttonBox, text='Stop', icon=IconSheetMap.X)
        btn.clicked.connect(self._handleStopServer)
        boxLayout.addWidget(btn)
        self._stopBtn = btn

        btn = PyGlassPushButton(buttonBox,
                                text='Reload',
                                icon=IconSheetMap.ROTATE)
        btn.clicked.connect(self._handleReloadServer)
        boxLayout.addWidget(btn)
        self._reloadBtn = btn

        boxLayout.addStretch()

        mainLayout.addStretch()

        self._updateDisplay()
 def rootPath(self):
     path = self._pathLineEdit.text()
     if path:
         return path
     return NGinxSetupOps.getExePath()
 def __init__(self, parent, **kwargs):
     super(NGinxRemoteThread, self).__init__(parent, **kwargs)
     self._path = ArgsUtils.get('rootPath', None, kwargs)
     if not self._path:
         self._path = NGinxSetupOps.getExePath()
    def __init__(self, parent, **kwargs):
        """Creates a new instance of NwmHomeWidget."""
        super(NwmHomeWidget, self).__init__(parent, widgetFile=False, id='home', **kwargs)

        mainLayout = self._getLayout(self, QtGui.QVBoxLayout)
        mainLayout.setContentsMargins(6, 6, 6, 6)

        rootPath = self.mainWindow.appConfig.get(
            AppConfigEnum.ROOT_PATH, NGinxSetupOps.getExePath()
        )

        label = QtGui.QLabel(self)
        label.setText(u'Server Container Path:')
        label.setStyleSheet(self._HEADER_STYLE)
        mainLayout.addWidget(label)

        label = QtGui.QLabel(self)
        label.setText(u'The absolute path the location NGinx will use as its root source')
        label.setStyleSheet(self._INFO_STYLE)
        mainLayout.addWidget(label)
        mainLayout.addSpacing(3)

        textWidget, textLayout = self._createWidget(self, QtGui.QHBoxLayout, True)

        text = QtGui.QLineEdit(textWidget)
        text.setText(rootPath)
        textLayout.addWidget(text)
        self._pathLineEdit = text

        recent = PyGlassPushButton(textWidget, icon=IconSheetMap.DOWN, size=SizeEnum.SMALL)
        recent.setSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Preferred)
        recent.clicked.connect(self._handleRecentLocations)
        textLayout.addWidget(recent)
        self._recentBtn = recent

        browse = PyGlassPushButton(textWidget, icon=IconSheetMap.FOLDER, size=SizeEnum.SMALL)
        browse.setSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Preferred)
        browse.clicked.connect(self._handleLocatePath)
        textLayout.addWidget(browse)
        self._browseBtn = browse

        mainLayout.addSpacing(20)

        label = QtGui.QLabel(self)
        label.setText(u'Server Management:')
        label.setStyleSheet(self._HEADER_STYLE)
        mainLayout.addWidget(label)

        label = QtGui.QLabel(self)
        label.setText(u'Modify the state of your NGinx server')
        label.setStyleSheet(self._INFO_STYLE)
        mainLayout.addWidget(label)
        mainLayout.addSpacing(3)

        buttonBox, boxLayout = self._createWidget(self, QtGui.QHBoxLayout, True)

        btn = PyGlassPushButton(buttonBox, text='Start', icon=IconSheetMap.FORWARD)
        btn.clicked.connect(self._handleStartServer)
        boxLayout.addWidget(btn)
        self._startBtn = btn

        btn = PyGlassPushButton(buttonBox, text='Stop', icon=IconSheetMap.X)
        btn.clicked.connect(self._handleStopServer)
        boxLayout.addWidget(btn)
        self._stopBtn = btn

        btn = PyGlassPushButton(buttonBox, text='Reload', icon=IconSheetMap.ROTATE)
        btn.clicked.connect(self._handleReloadServer)
        boxLayout.addWidget(btn)
        self._reloadBtn = btn

        boxLayout.addStretch()

        mainLayout.addStretch()

        self._updateDisplay()
 def rootPath(self):
     path = self._pathLineEdit.text()
     if path:
         return path
     return NGinxSetupOps.getExePath()