Beispiel #1
0
    def checkEnvFile(cls, target, otherPaths=None):
        """Doc..."""
        pathSep = OsUtils.getPerOsValue(';', ':')
        additions = cls._getSourcePaths(otherPaths=otherPaths)

        with open(target, 'r') as f:
            contents = f.read()

        result = cls._PYTHON_PATH_PATTERN.search(contents)
        if not result:
            return False

        paths = result.groupdict()['paths'].split(pathSep)
        for addition in additions:
            found = False
            for p in paths:
                p = FileUtils.cleanupPath(p, noTail=True)
                if p == FileUtils.cleanupPath(addition.folderPath,
                                              noTail=True):
                    found = True
                    break
            if not found:
                return False

        return True
Beispiel #2
0
    def __init__(self, containerPath, isRemoteDeploy =False, sourceRootFolder ='src', **kwargs):
        """Creates a new instance of Site."""
        super(Site, self).__init__()

        self.errorCount     = 0
        self.warningCount   = 0
        self._staticPaths   = []

        self._logger = ArgsUtils.getLogger(self, kwargs)
        self._sourceRootFolderName = sourceRootFolder

        # NGinx root path in which all files reside
        self._containerPath = FileUtils.cleanupPath(containerPath, isDir=True)

        # Location of the source files used to create the website
        self._sourceWebRootPath = FileUtils.createPath(containerPath, sourceRootFolder, isDir=True)

        # Locations where files should be deployed. If the target root path is None, which is the
        # default value, the local web root path is used in its place.

        if isRemoteDeploy:
            self._targetWebRootPath = FileUtils.cleanupPath(
                tempfile.mkdtemp(prefix='staticFlow_'), isDir=True)
        else:
            self._targetWebRootPath = None

        self._localWebRootPath  = FileUtils.createPath(
            containerPath, ArgsUtils.get('localRootFolder', 'root', kwargs), isDir=True)

        path = FileUtils.createPath(self.sourceWebRootPath, '__site__.def', isFile=True)
        try:
            self._data.data = JSON.fromFile(path, throwError=True)
        except Exception, err:
            self.writeLogError(u'Unable to load site definition file: "%s"' % path, error=err)
            pass
Beispiel #3
0
    def _copyWalker(self, walkData):
        staticFolder = False
        for folder in self._staticPaths:
            path = FileUtils.cleanupPath(walkData.folder, isDir=True)
            folder = FileUtils.cleanupPath(folder, isDir=True)
            if path == folder or FileUtils.isInFolder(path, folder):
                staticFolder = True
                break

        copiedNames = []
        for item in walkData.names:
            if not staticFolder and not StringUtils.ends(item, self._FILE_COPY_TYPES):
                continue

            sourcePath = FileUtils.createPath(walkData.folder, item)
            if os.path.isdir(sourcePath):
                continue

            destPath = FileUtils.changePathRoot(
                sourcePath, self.sourceWebRootPath, self.targetWebRootPath)

            try:
                FileUtils.getDirectoryOf(destPath, createIfMissing=True)
                shutil.copy(sourcePath, destPath)

                lastModified = FileUtils.getUTCModifiedDatetime(sourcePath)
                SiteProcessUtils.createHeaderFile(destPath, lastModified)
                SiteProcessUtils.copyToCdnFolder(destPath, self, lastModified)
                copiedNames.append(item)
            except Exception, err:
                self.writeLogError(u'Unable to copy file', error=err, extras={
                    'SOURCE':sourcePath,
                    'TARGET':destPath })
                return
Beispiel #4
0
    def __init__(self, localRootPath, sourceWebRootPath, forceHtml =False, forceAll =False, **kwargs):
        """Creates a new instance of S3SiteDeployer."""
        self._logger            = ArgsUtils.getLogger(self, kwargs)
        self._localRootPath     = FileUtils.cleanupPath(localRootPath, isDir=True)
        self._sourceWebRootPath = FileUtils.cleanupPath(sourceWebRootPath, isDir=True)
        self._forceHtml         = forceHtml
        self._forceAll          = forceAll
        self._cdnRootPath       = None

        try:
            siteData = JSON.fromFile(FileUtils.createPath(
                sourceWebRootPath, '__site__.def', isFile=True), throwError=True)
        except Exception, err:
            self._logger.writeError(
                u'Failed to read __site__.def file. Check to make sure JSON is valid.', err)
            siteData = {}
Beispiel #5
0
 def path(self):
     if not self._path:
         return None
     if not StringUtils.ends(self._path, '.csv'):
         if not FileUtils.getFileExtension(self._path):
             self._path += '.csv'
     return FileUtils.cleanupPath(self._path, isFile=True)
Beispiel #6
0
    def locateMayaEnvFiles(cls):
        """ Finds the location of all Maya.env files located in the default location on the host
            and return them as a list. If no such env files exist, the method returns an empty
            list. """

        home = FileUtils.cleanupPath(OsUtils.getHomePath(), isDir=True)
        if not os.path.exists(home):
            return []

        if OsUtils.isWindows():
            root = FileUtils.createPath(OsUtils.getDocumentsPath(),
                                        'maya',
                                        isDir=True)
            if not os.path.exists(root):
                return []
        elif OsUtils.isMac():
            root = FileUtils.createPath(home,
                                        'Library',
                                        'Preferences',
                                        'Autodesk',
                                        'maya',
                                        isDir=True)
            if not os.path.exists(root):
                return []
        else:
            return []

        out = []
        FileUtils.walkPath(root, cls._handleFindEnvFiles, out)
        return out
Beispiel #7
0
    def initializeFromInternalPath(cls, referencePath, force =False):
        """ Used to explicitly initialiize the pyglass environment when running inside the source
            code respository with a standard structure where the repository root has a src and
            a resources folder. """

        if cls.isInitialized and not force:
            return True

        path = FileUtils.cleanupPath(referencePath, noTail=True)
        if os.path.isfile(path):
            path = FileUtils.getDirectoryOf(referencePath, noTail=True)

        rootPath = None
        while path:
            srcPath = FileUtils.makeFolderPath(path, 'src', isDir=True)
            resPath = FileUtils.makeFolderPath(path, 'resources', isDir=True)
            if os.path.exists(srcPath) and os.path.exists(resPath):
                rootPath = path
                break
            path = FileUtils.getDirectoryOf(path, noTail=True)

        if not rootPath:
            return False

        cls._rootResourcePath       = FileUtils.makeFolderPath(rootPath, 'resources')
        cls._rootLocalResourcePath  = FileUtils.makeFolderPath(rootPath, 'resources', 'local')
        return True
    def _handleLocatePath(self):
        self.refreshGui()
        path = QtGui.QFileDialog.getExistingDirectory(
            self, caption=u'Specify Root NGinx Path', dir=self.rootPath)

        if path:
            path = FileUtils.cleanupPath(path)
            self._pathLineEdit.setText(path)
    def browseForDirectory(cls, parent, caption =None, defaultPath =None):
        out = QtGui.QFileDialog.getExistingDirectory(
            parent,
            caption=caption if caption else u'Select a Directory',
            dir=defaultPath if defaultPath else os.path.expanduser('~'))

        if not out:
            return out
        return FileUtils.cleanupPath(out, isDir=True)
    def browseForFileOpen(cls, parent, caption =None, defaultPath =None):
        out = QtGui.QFileDialog.getOpenFileName(
            parent,
            caption=caption if caption else u'Select a File',
            dir=defaultPath if defaultPath else os.path.expanduser('~'))

        if not out or not out[0]:
            return out
        return FileUtils.cleanupPath(out[0], isFile=True)
Beispiel #11
0
    def toFile(self, path):
        path = FileUtils.cleanupPath(path, isFile=True)

        try:
            f = open(path, 'wb')
            f.write(self._data)
            f.close()
        except Exception:
            print('FAILED: Write ByteChunk to file')
            raise
    def browseForFileOpen(cls, parent, caption =None, defaultPath =None, allowMultiple =False, filterDefs =None):
        QFD = QtGui.QFileDialog
        f = QFD.getOpenFileNames if allowMultiple else QFD.getOpenFileName
        out = f(
            parent,
            caption=caption if caption else 'Select a File',
            dir=defaultPath if defaultPath else os.path.expanduser('~'),
            filter=cls.getFileFilterString(filterDefs))

        if not out or not out[0]:
            return None

        if not allowMultiple:
            return FileUtils.cleanupPath(out[0], isFile=True)

        items = []
        for item in out[0]:
            items.append(FileUtils.cleanupPath(item, isFile=True))
        return items
Beispiel #13
0
    def toFile(self, path):
        path = FileUtils.cleanupPath(path, isFile=True)

        try:
            f = open(path, 'wb')
            f.write(self._data)
            f.close()
        except Exception:
            print('FAILED: Write ByteChunk to file')
            raise
    def browseForFileSave(cls, parent, caption =None, defaultPath =None, filterDefs =None):
        out = QtGui.QFileDialog.getSaveFileName(
            parent,
            caption=caption if caption else 'Specify File',
            dir=defaultPath if defaultPath else os.path.expanduser('~'),
            options=QtGui.QFileDialog.AnyFile,
            filter=cls.getFileFilterString(filterDefs))

        if not out or not out[0]:
            return None
        return FileUtils.cleanupPath(out[0], isFile=True)
Beispiel #15
0
    def _handleLocatePath(self):
        self.refreshGui()
        path = QtGui.QFileDialog.getExistingDirectory(
            self,
            caption=u'Specify Root NGinx Path',
            dir=self.rootPath
        )

        if path:
            path = FileUtils.cleanupPath(path)
            self._pathLineEdit.setText(path)
Beispiel #16
0
    def loggingPath(self, value):
        self._logPath = FileUtils.cleanupPath(value)

        logFolder = self.getLogFolder()
        if logFolder:
            name = self._name
            extension = self.logFileExtension
            if self.timestampFileSuffix:
                name += '_' + self._timeCode
            self._logFile = FileUtils.createPath(logFolder, name + '.' + extension)
            if self.removeIfExists:
                self.resetLogFile()
        else:
            self._logFile = None
Beispiel #17
0
    def _handleBrowseFolders(self):

        path = QtGui.QFileDialog.getExistingDirectory(
            self,
            'Select Project Folder',
            self.appConfig.get(self._LAST_PROJECT_PATH, u''))

        if not path:
            return

        path = FileUtils.cleanupPath(path, isDir=True)
        self.appConfig.set(self._LAST_PROJECT_PATH, path)
        self.pathLine.setText(path)
        self.openBtn.setEnabled(True)
Beispiel #18
0
    def __init__(self, rootPath =None, recursive =True, **kwargs):
        """Creates a new instance of WidgetUiCompiler."""
        self._log        = Logger(self)
        self._verbose    = ArgsUtils.get('verbose', False, kwargs)
        self._recursive  = recursive
        self._pythonPath = os.path.normpath(sys.exec_prefix)

        if rootPath and os.path.isabs(rootPath):
            self._rootPath = FileUtils.cleanupPath(rootPath, isDir=True)
        elif rootPath:
            parts = rootPath.split(os.sep if rootPath.find(os.sep) != -1 else '/')
            self._rootPath = PyGlassEnvironment.getRootResourcePath(*parts, isDir=True)
        else:
            self._rootPath = PyGlassEnvironment.getRootResourcePath()
Beispiel #19
0
    def createIcon(cls, iconsPath):
        """ Creates a window icon from a path, adding the standard icon sizes for multiple
            operating systems. """

        if not os.path.exists(iconsPath):
            return None

        iconsPath = FileUtils.cleanupPath(iconsPath, isDir=True)
        icon      = QtGui.QIcon()
        sizes     = [512, 256, 180, 128, 96, 72, 64, 48, 32, 24, 16]
        for size in sizes:
            path = FileUtils.createPath(iconsPath, str(size) + '.png', isFile=True)
            if os.path.exists(path):
                icon.addFile(path)
        return icon
Beispiel #20
0
    def checkEnvFile(cls, target, otherPaths =None):
        """Doc..."""
        pathSep   = OsUtils.getPerOsValue(';', ':')
        additions = cls._getSourcePaths(otherPaths=otherPaths)

        with open(target, 'r') as f:
            contents = f.read()

        result = cls._PYTHON_PATH_PATTERN.search(contents)
        if not result:
            return False

        paths = result.groupdict()['paths'].split(pathSep)
        for addition in additions:
            found = False
            for p in paths:
                p = FileUtils.cleanupPath(p, noTail=True)
                if p == FileUtils.cleanupPath(addition.folderPath, noTail=True):
                    found = True
                    break
            if not found:
                return False

        return True
Beispiel #21
0
    def loggingPath(self, value):
        self._logPath = FileUtils.cleanupPath(value)

        logFolder = self.getLogFolder()
        if logFolder:
            name = self._name
            extension = self.logFileExtension
            if self.timestampFileSuffix:
                name += '_' + self._timeCode
            self._logFile = FileUtils.createPath(logFolder,
                                                 name + '.' + extension)
            if self.removeIfExists:
                self.resetLogFile()
        else:
            self._logFile = None
    def _getIconPath(self):
        path = self.iconPath
        if not path:
            return ''

        if isinstance(path, basestring):
            if os.path.isabs(path) and os.path.exists(path):
                return FileUtils.cleanupPath(path)
            else:
                path = path.replace('\\', '/').strip('/').split('/')

        path.append('icons' if OsUtils.isWindows() else 'icons.iconset')
        out = PyGlassEnvironment.getRootResourcePath(*path, isDir=True)
        if os.path.exists(out):
            return out
        return ''
Beispiel #23
0
    def deploy(self):
        """Doc..."""
        if not os.path.exists(self._localRootPath):
            return False

        # Find the CDN root path if it exists
        self._cdnRootPath = None
        for item in os.listdir(self._localRootPath):
            itemPath = FileUtils.createPath(self._localRootPath, item)
            if item.startswith(StaticFlowEnvironment.CDN_ROOT_PREFIX) and os.path.isdir(itemPath):
                self._cdnRootPath = FileUtils.cleanupPath(itemPath)
                break

        # Deploy CDN files first so they are available when the non-cdn files are deployed
        if self._cdnRootPath:
            os.path.walk(self._cdnRootPath, self._deployWalker, {'cdn':True})

        # Walk the rest of the files not on the CDN root path
        os.path.walk(self._localRootPath, self._deployWalker, {'cdn':False})
        return True
Beispiel #24
0
    def __init__(self, name=None, **kwargs):
        """Initializes settings."""
        self.headerless  = kwargs.get('headerless', False)
        self._time       = self._getTime()
        self._timeCode   = self._time.strftime('%y-%U')
        self._timestamp  = self._time.strftime('%Y|%m|%d|%H|%M|%S')

        self._logPath    = kwargs.get('logFolder', None)
        if self._logPath:
            self._logPath = FileUtils.cleanupPath(self._logPath)

        self._htmlEscape    = kwargs.get('htmlEscape', False)
        self._storageBuffer = [] if kwargs.get('useStorageBuffer', False) else None

        writeCallbacks = kwargs.get('writeCallbacks', None)
        if writeCallbacks:
            cbs = writeCallbacks
            self._writeCallbacks = cbs if isinstance(cbs, list) else [cbs]
        else:
            self._writeCallbacks = []

        printCallbacks = kwargs.get('printCallbacks', None)
        if printCallbacks:
            cbs = printCallbacks
            self._printCallbacks = cbs if isinstance(cbs, list) else [cbs]
        else:
            self._printCallbacks = []

        self._locationPrefix = kwargs.get('locationPrefix', False)
        self._traceLogs      = kwargs.get('printOut', False)
        self._buffer         = []
        self._hasError       = False

        if isinstance(name, basestring) and len(name) > 0:
            self._name = name
        elif hasattr(name, '__class__'):
            try:
                self._name = name.__class__.__name__
            except Exception, err:
                self._name = 'UnknownObject'
Beispiel #25
0
    def locateMayaEnvFiles(cls):
        """ Finds the location of all Maya.env files located in the default location on the host
            and return them as a list. If no such env files exist, the method returns an empty
            list. """

        home = FileUtils.cleanupPath(OsUtils.getHomePath(), isDir=True)
        if not os.path.exists(home):
            return []

        if OsUtils.isWindows():
            root = FileUtils.createPath(OsUtils.getDocumentsPath(), 'maya', isDir=True)
            if not os.path.exists(root):
                return []
        elif OsUtils.isMac():
            root = FileUtils.createPath(
                home, 'Library', 'Preferences', 'Autodesk', 'maya', isDir=True)
            if not os.path.exists(root):
                return []
        else:
            return []

        out = []
        FileUtils.walkPath(root, cls._handleFindEnvFiles, out)
        return out
Beispiel #26
0
    def compileCoffeescript(cls, site, path):
        csPath  = FileUtils.cleanupPath(path, isFile=True)
        outPath = FileUtils.changePathRoot(
            csPath[:-6] + 'js', site.sourceWebRootPath, site.targetWebRootPath)
        FileUtils.getDirectoryOf(outPath, createIfMissing=True)

        outDir = os.path.dirname(outPath)
        result = cls.compileCoffeescriptFile(csPath, outDir, minify=not site.isLocal)
        if result['code']:
            site.writeLogError(u'Failed to compile: "%s"' % unicode(path))
            print result
            return False
        else:
            site.writeLogSuccess(u'COMPILED', unicode(path))

        lastModified = FileUtils.getUTCModifiedDatetime(csPath)
        SiteProcessUtils.createHeaderFile(outPath, lastModified)
        if site.isLocal:
            return True

        cls.copyToCdnFolder(outPath, site, lastModified)
        site.writeLogSuccess(u'COMPRESSED', unicode(outPath))

        return True
 def setResourceRootPath(cls, path):
     cls._resourceRootOverridePath = FileUtils.cleanupPath(path, isDir=True)
Beispiel #28
0
 def rootPath(self, value):
     self._pathLineEdit.setText(FileUtils.cleanupPath(value))
Beispiel #29
0
    def modifyEnvFile(cls, target, install=True, test=False, otherPaths=None):
        """Doc..."""
        pathSep = OsUtils.getPerOsValue(';', ':')
        removals = []
        entries = cls._getSourcePaths(otherPaths=otherPaths)
        additions = entries + []

        with open(target, 'r') as f:
            contents = f.read().strip()

        result = cls._PYTHON_PATH_PATTERN.search(contents)
        if not result:
            if install and not test:
                with open(target, 'w') as f:
                    f.write((contents + '\n' if contents else '') +
                            'PYTHONPATH=' + cls._joinPathEntries(additions))
            return cls.MAYA_ENV_MODIFIED_RESULT_NT(
                additions if install else [], removals)

        paths = result.groupdict()['paths'].strip()
        paths = paths.split(pathSep) if paths else []
        if not paths and not install:
            return cls.MAYA_ENV_MODIFIED_RESULT_NT([], [])

        index = 0
        while index < len(paths):
            # Stop if no more additions remain
            if not additions:
                break

            p = FileUtils.cleanupPath(paths[index], noTail=True)

            # If path already exists don't add it again
            pathMatch = cls._hasPath(p, additions)
            if pathMatch:
                additions.remove(pathMatch)

                # If uninstalling add to removals
                if not install:
                    removals.append(pathMatch)
                    paths.remove(p)
                else:
                    index += 1
                continue
            elif not install:
                index += 1
                continue

            for entry in entries:
                testPath = FileUtils.createPath(p, entry.rootName, noTail=True)
                if os.path.exists(testPath):
                    paths.remove(p)

            index += 1

        for entry in additions:
            paths.append(entry.folderPath)

        insertion = ('PYTHONPATH=' + pathSep.join(paths) +
                     '\n') if paths else ''
        contents = contents[:result.start()] + insertion + contents[result.end(
        ):]

        result = cls.MAYA_ENV_MODIFIED_RESULT_NT(additions if install else [],
                                                 removals)
        if test:
            return result

        with open(target, 'w') as f:
            f.write(contents)

        return result
 def sslCertificatePath(self):
     """ The path to the folder containing the SSL security certificate, key, and authority
         files """
     return FileUtils.cleanupPath(self._certPath, isDir=True) if self._certPath else None
Beispiel #31
0
 def projectPath(self):
     return FileUtils.cleanupPath(self._projectPath)
Beispiel #32
0
from pyaid.json.JSON import JSON
from pyaid.system.SystemUtils import SystemUtils

FOLDER_NAME = 'Statistical-Results'

#---------------------------------------------------------------------------------------------------

rootPath = FileUtils.getDirectoryOf(__file__)
localAnalysisPath = FileUtils.makeFolderPath(rootPath, '..', 'resources', 'local', 'analysis')
analysisConfigPath = FileUtils.makeFilePath(localAnalysisPath, 'analysis.json')

config = JSON.fromFile(analysisConfigPath)

if 'OUTPUT_PATH' not in config:
    rootTargetPath = localAnalysisPath
else:
    rootTargetPath = FileUtils.cleanupPath(config['OUTPUT_PATH'], isDir=True)

targetPath = FileUtils.makeFolderPath(rootTargetPath, FOLDER_NAME)

if os.path.exists(targetPath):
    SystemUtils.remove(targetPath)

outputPath = FileUtils.makeFolderPath(rootPath, 'output')

if not SystemUtils.copy(outputPath, targetPath, echo=True):
    print('[FAILED]: Deployment')
    sys.exit(1)

print('Deployment Complete')
Beispiel #33
0
 def fromRootPath(cls, path):
     """Doc..."""
     parts = path.rsplit(os.sep, 1)
     return MayaEnvEntry(parts[-1],
                         FileUtils.cleanupPath(parts[0], noTail=True))
Beispiel #34
0
 def initializeExplicitAppSettings(cls, rootResourcePath, rootLocalResourcePath):
     cls._rootResourcePath = FileUtils.cleanupPath(rootResourcePath, isDir=True)
     cls._rootLocalResourcePath = FileUtils.cleanupPath(rootLocalResourcePath, isDir=True)
Beispiel #35
0
 def rootPath(self, value):
     self._pathLineEdit.setText(FileUtils.cleanupPath(value))
Beispiel #36
0
 def fromRootPath(cls, path):
     """Doc..."""
     parts = path.rsplit(os.sep, 1)
     return MayaEnvEntry(parts[-1], FileUtils.cleanupPath(parts[0], noTail=True))
Beispiel #37
0
    def modifyEnvFile(cls, target, install =True, test =False, otherPaths =None):
        """Doc..."""
        pathSep   = OsUtils.getPerOsValue(';', ':')
        removals  = []
        entries   = cls._getSourcePaths(otherPaths=otherPaths)
        additions = entries + []

        with open(target, 'r') as f:
            contents = f.read().strip()

        result = cls._PYTHON_PATH_PATTERN.search(contents)
        if not result:
            if install and not test:
                with open(target, 'w') as f:
                    f.write(
                        (contents + '\n' if contents else '') + 'PYTHONPATH='
                        + cls._joinPathEntries(additions) )
            return cls.MAYA_ENV_MODIFIED_RESULT_NT(additions if install else [], removals)

        paths = result.groupdict()['paths'].strip()
        paths = paths.split(pathSep) if paths else []
        if not paths and not install:
            return cls.MAYA_ENV_MODIFIED_RESULT_NT([], [])

        index = 0
        while index < len(paths):
            # Stop if no more additions remain
            if not additions:
                break

            p = FileUtils.cleanupPath(paths[index], noTail=True)

            # If path already exists don't add it again
            pathMatch = cls._hasPath(p, additions)
            if pathMatch:
                additions.remove(pathMatch)

                # If uninstalling add to removals
                if not install:
                    removals.append(pathMatch)
                    paths.remove(p)
                else:
                    index += 1
                continue
            elif not install:
                index += 1
                continue

            for entry in entries:
                testPath = FileUtils.createPath(p, entry.rootName, noTail=True)
                if os.path.exists(testPath):
                    paths.remove(p)

            index += 1

        for entry in additions:
            paths.append(entry.folderPath)

        insertion = ('PYTHONPATH=' + pathSep.join(paths) + '\n') if paths else ''
        contents  = contents[:result.start()] + insertion + contents[result.end():]

        result = cls.MAYA_ENV_MODIFIED_RESULT_NT(additions if install else [], removals)
        if test:
            return result

        with open(target, 'w') as f:
            f.write(contents)

        return result
 def rootPath(self):
     path = self._pathLineEdit.text()
     if path:
         return FileUtils.cleanupPath(path)
     return u''