Esempio n. 1
0
    def runScript(self, script):
        if exists(script):
            self.out.indent('Running script: %s' % script)
            self.system.runCommand([script], self.getUserHomeDir())
            self.out.unIndent()

    def getOsHash(self):
        installedProfiles = self.getInstalledProfiles()
        osHash = '|'.join(sorted(installedProfiles))
        self.out.put('hashed current OS profile to hash key: %s' % osHash, self.out.LOG_LEVEL_DEBUG)
        return osHash

    def getInstalledProfiles(self):
        try:
            fileList = listdir(self.config['installedOsProfilesFolder'])
        except:
            # probably in debug environment - directory doesn't exist
            fileList = []
        return sorted(fileList)

if __name__ == '__main__':
    from py_base.Job import runMockJob
    def fakeProfiles():
        # MUST return sorted to match real behavior
        return ['base', 'workstation']
    CustomLogin.getInstalledProfiles = fakeProfiles
    runMockJob(CustomLogin,
               config={'loginScriptFolder': '/home/luke/Reference/Config/profiles'})

Esempio n. 2
0
    def getTargetFileName(self, fileInfo):
        if self.arguments["strip"]:
            # always strip time as well as date (not doing so may lead to huge headaches)
            fileName = "%s.%s" % (fileInfo["title"], fileInfo["extension"])
        elif self.arguments["time"]:
            fileName = FILE_FORMAT_DATETIME % (
                fileInfo["year"],
                fileInfo["month"],
                fileInfo["day"],
                fileInfo["hour"],
                fileInfo["minute"],
                fileInfo["title"],
                fileInfo["extension"],
            )
        else:
            fileName = FILE_FORMAT_DATE % (
                fileInfo["year"],
                fileInfo["month"],
                fileInfo["day"],
                fileInfo["title"],
                fileInfo["extension"],
            )
        return fileName


if __name__ == "__main__":
    from py_base.Job import runMockJob

    runMockJob(ImageDateStamper, arguments={"path": getTestFilePaths() + ["bad/path.JPG"]})  # 'time': True,
Esempio n. 3
0
    def getDebFileFullPath(self, package):
        return "%s/%s.deb" % (self.config["debsDir"], package)

    def removeWorkingDir(self):
        self.out.put("cleaning up working directory")
        command = ["rm", "-rf", self.getWorkingDirFullPath()]
        self.system.runCommand(command)

    def refreshAptRepository(self):
        if len(self.packageList) == 0:
            self.out.put("Not rebuilding APT repository metadata (no packages updated)")
        else:
            self.out.put("rebuilding APT repository metadata")
            packageInfoFilename = self.getPackageInfoUncompressedFilename()
            command = ["dpkg-scanpackages", "./", "/dev/null"]
            # 'None' signals PySystem to throw away stderr.
            packageInfo = self.system.runCommand(command, self.config["debsDir"], err=None, stripNewlines=False)
            self.system.writeFile(packageInfoFilename, packageInfo)
            command = ["gzip", "--best", "--force", packageInfoFilename]
            self.system.runCommand(command)

    def getPackageInfoUncompressedFilename(self):
        return self.config["debsDir"] + "/" + self.APT_PACKAGES_BASE_FILENAME


if __name__ == "__main__":
    from py_base.Job import runMockJob

    runMockJob(Builder)
Esempio n. 4
0
    def getAllStarsFullPaths(self, path):
        self.out.put("Looking for all stars path in %s" % (path), self.out.LOG_LEVEL_VERBOSE)
        result = []

        # list the subfolder contents of path
        # I'm using sorted() here so that there is consistency
        # in the order of preference when multiple folders exist
        for filename in sorted(listdir(path)):
            # does this name match the regex?
            if not self.isAllStarFolder(filename):
                self.out.put("- filename %s failed all star regex" % filename, self.out.LOG_LEVEL_DEBUG)
                continue

            self.out.put("- all star filename %s found! (not a confirmed directory yet)" % filename, self.out.LOG_LEVEL_DEBUG)

            # is the matching name a folder?
            allStarsFullPath = "%s/%s" % (path, filename)
            if isdir(allStarsFullPath):
                # we've found what we are looking for
                self.out.put("- full path %s is a confirmed directory! Adding to result list." % allStarsFullPath, self.out.LOG_LEVEL_DEBUG)
                result.append(allStarsFullPath)
        return result

    def isAllStarFolder(self, filename):
        return match(REGEX_ALL_STARS_FOLDER, filename)

if __name__ == "__main__":
    from py_base.Job import runMockJob
    runMockJob(AllStarCopier, arguments={'path': getTestFilePaths()})
#!/usr/bin/python
from image_tools.ImageScaler import ImageScaler
from image_tools_gui.ImageToolsSharedGui import ImageFileInfoToolGui

class ImageScalerGui(ImageScaler):

    def doRunSteps(self):
        imageTool = ImageFileInfoToolGui(self.out, self.system)
        super(ImageScalerGui, self).doRunSteps(imageTool)

if __name__ == "__main__":
    from py_base.Job import runMockJob
    from image_tools.ImageToolsShared import getTestFilePaths
    runMockJob(ImageScalerGui, arguments={'path':getTestFilePaths()})
Esempio n. 6
0
        if self.inDebugMode():
            # if we're running in mock mode, then we shouldn't be changing anything on the filesystem.
            self.out.put("DEBUG: Not writing image file because we're in mock mode")
        else:
            self.out.put("writing image file...", self.out.LOG_LEVEL_DEBUG)
            sourceImage.save(targetFileName)

    def getTargetFileName(self, sourceFileName):
        self.out.put("Setting target filename...", self.out.LOG_LEVEL_VERBOSE)
        (base, ext) = splitext(sourceFileName)
        targetFileName = base + FILENAME_SCALED_SUFFIX + ext.lower()
        self.out.put("source path: %s" % sourceFileName, self.out.LOG_LEVEL_VERBOSE)
        self.out.put("target path: %s" % targetFileName, self.out.LOG_LEVEL_VERBOSE)
        return targetFileName

    def inDebugMode(self):
        return self.system.__class__ == PySystemMock

if __name__ == "__main__":
    from py_base.Job import runMockJob

    # clean out old runs
    from subprocess import Popen
    Popen(['rm', '-f', '%s/test/*.scaled.jpg' % dirname(__file__)])

    runMockJob(ImageScaler,
               arguments={'limit_size': 100,
                          'greyscale': True,
                          'path': getTestFilePaths()})