Exemple #1
0
def copyfile(
    sourcePath,
    destPath,
):
    """Copy a file, changing the destination ownership.

    Parameters
    ----------
    sourcePath : string
        Full path of the source file
    destPath : string
        Full path of the destination file


    Notes
    -----
    The destination file will have it's owner, group and rights set from the
    config.
    """
    logg.debug('Copying files (%s => %s)' % (
        sourcePath,
        destPath,
    ), )
    writeDestinationFile(
        destPath,
        readSourceFile(sourcePath),
    )
Exemple #2
0
def virtualenv(sourceDir,
               outputDir,
               pythonBin,
               ):
    """Reproduce a virtualenv found in sourceDir into outputDir.

    Parameters
    ----------
    sourceDir : str
        The path to the source environment. The script will look for
        path/bin/pip.
    outputDir : str
        The path to the copy environment.
    pythonBin : str
        Path to the python binary to use in the copied virtualenv.


    Notes
    -----
    The copied environment is not a 1:1 copy of the source; it merely reproduces
    the list of installed packages.
    """
    _createVirtualEnvironment(outputDir, pythonBin)
    requirements = _getRequirements(sourceDir)
    installed_requirements = _get_installed_requirements(outputDir)
    if requirements == installed_requirements:
        return
    writeDestinationFile(join(outputDir,
                              'requirements.txt',
                              ),
                         requirements)
    _installRequirements(outputDir)
Exemple #3
0
def jsProcess(source, dest):
    """Process a css file into a minified css file"""
    writeDestinationFile(dest,
                         _jsProcessFromSource(source),
                         )
Exemple #4
0
def copyFile(sourcepath,
             destinationpath):
    writeDestinationFile(destinationpath,
                         readSourceFile(sourcepath))
Exemple #5
0
def lessProcess(source, dest, includeDirs):
    """Process a less file into a css file"""
    writeDestinationFile(
        dest,
        _lessProcessFromSource(source, includeDirs),
    )
Exemple #6
0
def imgProcess(source, dest):
    """Process an image file into a minified image file"""
    writeDestinationFile(
        dest,
        _imgProcessFromSource(source),
    )
Exemple #7
0
def makepages(sourceDir, targetDir, headerNames, footerNames, pagesList):
    """Create files by merging headers, body and footers.

    Parameters
    ----------
    sourceDir : string
        The path to all the files to merge together. Relative to ROOT
    targetDir : string
        The path to put created files into. Relative to PREFIX
    headerNames : list(string)
        List of headers to prepend to bodies (in order). The names listed here
        will get the '.html' suffix appended to them, and the script will look
        for them in sourceDir.
    footerNames : list(string)
        List of footers. Same rules as headerNames.
    pagesList : list(tuple(string,string)
        List of pages to generate. The tuples contain the title of the page, and
        the name of the file to use as the body. Same rules applies as for
        headerNames.


    Notes
    -----
    The title will be used anywhere the '%TITLE%' string is used (header, body,
    footer).
    """
    header = u''
    decoratorTime = 0
    if headerNames:
        logg.info('Reading headers for file merging')
        for headerName in headerNames:
            logg.debug('Reading header: %s' % headerName)
            headerPath = join(sourceDir, '%s.html' % headerName)
            content = readSourceFile(headerPath)
            thisHeaderTime = getSourceMTime(headerPath)
            header += content.decode()
            decoratorTime = max(decoratorTime, thisHeaderTime)
    footer = u''
    if footerNames:
        logg.info('Reading footers for file merging')
        for footerName in footerNames:
            logg.debug('Reading footer: %s' % footerName)
            footerPath = join(sourceDir, '%s.html' % footerName)
            content = readSourceFile(footerPath)
            thisFooterTime = getSourceMTime(footerPath)
            footer += content.decode()
            decoratorTime = max(decoratorTime, thisFooterTime)

    logg.info('Generating merged files')
    for title, bodyFile in pagesList:
        logg.debug('Merging file %s' % bodyFile)
        sourcePath = join(sourceDir, '%s.html' % bodyFile)
        targetPath = join(targetDir, '%s.html' % bodyFile)

        content = readSourceFile(sourcePath).decode()
        bodyTime = getSourceMTime(sourcePath)
        sourceTime = max(bodyTime, decoratorTime)
        targetTime = getDestinationMTime(targetPath)

        if sourceTime <= targetTime:
            continue
        fullContent = u'%s%s%s' % (
            header,
            content,
            footer,
        )
        fullContent = fullContent.replace(u'%TITLE%', title)
        writeDestinationFile(targetPath, fullContent.encode())