コード例 #1
0
ファイル: version.py プロジェクト: datakortet/dk-tasklib
def copy_to_version(ctx, source, outputdir=None, kind="pkg", force=False):
    """Copy source with version number to `outputdir`.

       The version type is specified by the ``kind`` parameter and can be
       either "pkg" (package version), "svn" (current subversion revision
       number), or "hash" (the md5 hash of the file's contents).

       Returns:
           (str) output file name
    """
    # where to place the versioned file..
    # print "LOCALS:", locals()
    source = Path(source)
    outputdir = Path(outputdir) if outputdir else source.dirname()
    outputdir.makedirs()
    dst_fname = source.basename()
    if '{version}' not in str(dst_fname):
        dst_fname = versioned_name(dst_fname)
    dst = outputdir / dst_fname.format(version=get_version(ctx, source, kind))

    if force or not os.path.exists(dst):
        copy(ctx, source, dst, force=force)

    elif open(source).read() != open(dst).read():
        print """
        Filename already exists, add --force or call upversion: {}
        """.format(dst)

    return dst
コード例 #2
0
ファイル: lessc.py プロジェクト: datakortet/dk-tasklib
    def __call__(self,
                 src='{pkg.sourcedir}/less/{pkg.name}.less',
                 dst='{pkg.sourcedir}/static/{pkg.name}/css/{pkg.name}-{version}.min.css',
                 version='pkg',
                 bootstrap=True,
                 force=False,
                 **kw):
        c = env(self.ctx)
        source = Path(fmt(src, c))
        dest = Path(fmt(dst, c))

        for fname in source.dirname().glob("*.inline"):
            urlinliner.inline(self.ctx, fname)

        if not force and not Directory(source.dirname()).changed(glob='**/*.less'):
            print "No changes: {input_dir}/{glob}, add --force to build.".format(
                input_dir=source.dirname(), glob='**/*.less')
            return

        path = kw.pop('path', [])
        if bootstrap:
            path.append(self.bootstrap_src)

        cssname = dest.relpath().format(version=get_version(self.ctx, source, version))
        lessc(
            self.ctx,
            src=source.relpath(),
            dst=cssname,
            include_path=path,
            strict_imports=True,
            inline_urls=False,
            autoprefix="last 4 versions",
            clean_css="-b --s0 --advanced",
        )

        copy(  # create a copy without version number too..
            self.ctx,
            cssname,
            Path(cssname).dirname() / switch_extension(source.basename(), '.css'),
            force=True
        )
        return cssname