Ejemplo n.º 1
0
def get_version(ctx, fname, kind='pkg'):
    """Return the version number for fname.
    """
    fname = Path(fname)
    if kind == "pkg":
        return ctx.pkg.version
    elif kind == "hash":
        md5 = fname.dirname() / '.md5'
        if md5.exists():
            return md5.open().read()
        return hashlib.md5(open(fname).read()).hexdigest()
    # elif kind == "svn":
    #     ver = get_svn_version(source)
    return ""
Ejemplo n.º 2
0
def publish_prod_version(c):
    """Publish a production version of dkdj (the .js part).
    """
    fnames = glob.glob(r'dkdj\static\dkdj\js\dkdj.*.min.js')
    print("deleting old versions:", fnames)
    if fnames:
        c.run('rm dkdj/static/dkdj/js/dkdj.*.min.js')

    # upversion_and_add_to_checkin
    v = upversion.upversion(c)
    c.run('git add docs/conf.py package.json setup.py src/version.js')

    # build production/web version
    os.environ['DKBUILD_TYPE'] = 'PRODUCTION'
    c.run('webpack')

    # git add the django include-scripts template
    c.run('git add dkdj/templates/dkdj/include-scripts.html')

    # git commit and push new version
    c.run('git commit -m "upversion"')

    # git tag and push new tagged version
    c.run('git tag -a v{v} -m "Version {v}"'.format(v=v))
    c.run('git push --tags')

    # report which files were built
    fnames = glob.glob(r'dkdj\static\dkdj\js\dkdj.*.min.js')
    print("created new version:", fnames)
    assert len(fnames) == 1
    fname = fnames[0]

    # [bp] collectstatic could include way too much...
    # admin = SRV / 'www' / 'admin_datakortet'
    # with admin.cd():
    #     c.run('python manage.py collectstatic --noinput')

    # 'manual' collectstatic
    SRV = Path(os.environ['SRV'])
    static_dkdj = SRV / 'data' / 'static' / 'dkdj' / 'js'
    # -> copy all newly created files to static-root
    c.run('cp {src} {dst}'.format(src=fname, dst=static_dkdj))

    # -> add and check in all newly copied files in static-root
    with static_dkdj.cd():
        basename = os.path.basename(fname)
        c.run('svn add {}'.format(basename))
        c.run('svn ci {} -m "collectstatic"'.format(basename))

    # remember AWS...
    bfp = SRV / 'www' / 'batforerregisteret'
    with bfp.cd():
        os.environ['USE_AWS_STATIC'] = '1'
        c.run('python manage.py collectstatic --noinput')

    # now get local back to dev-mode..
    c.run('rm {}'.format(fname))
    del os.environ['DKBUILD_TYPE']
    del os.environ['USE_AWS_STATIC']
    c.run('webpack')
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
def init_cmd(argv, args):
    site_ini = Path('site.ini')
    if site_ini.exists() and not args.force:
        print(textwrap.dedent("""
            ERROR: site.ini exists, writing to site.ini.new
        """),  file=sys.stderr)
        site_ini = Path('site.ini.new')

    site_ini.write(SITE_INI_TEMPLATE.read())
    if args.verbose or True:
        print(SITE_INI_TEMPLATE.read())
Ejemplo n.º 5
0
    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
Ejemplo n.º 6
0
from invoke import Collection

from dktasklib import docs as doctools
from dktasklib import jstools
from dktasklib import lessc
from dktasklib import version, upversion
from dktasklib.manage import collectstatic
from dktasklib.package import Package, package
from dktasklib.watch import Watcher
# from dktasklib.publish import publish

# from http://plantuml.com
PLANTUML_JAR = r'c:\bin\plantuml.jar'

#: where tasks.py is located (root of package)
DIRNAME = Path(os.path.dirname(__file__))

# collectstatic
# --------------
# Specify which settings file should be used when running
# `python manage.py collectstatic` (must be on the path or package root
# directory).
DJANGO_SETTINGS_MODULE = ''

# .less
# ------
# there should be a mypkg/mypkg/less/mypkg.less file that imports any other
# needed sources

# .jsx (es6 source)
# ------------------
Ejemplo n.º 7
0
def find_server_ini(argv, args):
    site_ini = Path(args.site)
    for pth in site_ini.parents:
        if args.server in pth.listdir():
            return pth / args.server
    raise NoServerIniError("%s not found." % args.server)
Ejemplo n.º 8
0
# -*- coding: utf-8 -*-
from __future__ import print_function
import os
import sys
import textwrap
from dkfileutils.path import Path

FILE = Path(__file__)
DIRNAME = FILE.dirname


def transitions_to_dot(transitions, states):
    def fillcolor(c, fc=None):
        return {'style': 'filled', 'fillcolor': c, 'fontcolor': fc or 'white'}

    sdata = {s[0]: s[2] for s in states}
    rules = []
    for cur, nexts in transitions.iteritems():
        for nxt in nexts:
            rule = '        "%s" -> "%s"' % (cur, nxt)
            if 'comm' in sdata[nxt]:
                rule += ' [label="step-%d"]' % sdata[nxt]['comm']
                del sdata[nxt]['comm']
                sdata[nxt].update(fillcolor('blue'))
            rules.append(rule + ';')

    nodes = []

    for node, attrs in sdata.iteritems():
        if node.endswith('-err'):
            attrs.update(fillcolor('red'))
Ejemplo n.º 9
0
# -*- coding: utf-8 -*-
from __future__ import print_function
import sys
import textwrap

from dkfileutils.path import Path
from jinja2 import Template

from dkbuild_apacheconf.context import Context

DIRNAME = Path(__file__).dirname()
APACHECONF_TEMPLATE = DIRNAME / 'apache.conf.jinja'
SITE_INI_TEMPLATE = DIRNAME / 'site.ini'


def init_cmd(argv, args):
    site_ini = Path('site.ini')
    if site_ini.exists() and not args.force:
        print(textwrap.dedent("""
            ERROR: site.ini exists, writing to site.ini.new
        """),  file=sys.stderr)
        site_ini = Path('site.ini.new')

    site_ini.write(SITE_INI_TEMPLATE.read())
    if args.verbose or True:
        print(SITE_INI_TEMPLATE.read())


def run_cmd(argv, args):
    """Create a new apache.conf file from site.ini and server.ini
    """