Skip to content

klen/dealer

Repository files navigation

logo Dealer

Dealer — SCM revision helper in your projects. Just add SCM revision to your static paths and get automatic control at client browser caches:

Somewhere in templates:

<script src='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/main.js?{{ request.revision }}'

On clientside:

<script src='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/main.js?34jhfd45hd8'

Supported Git, Mercurial and simple revision parse by file.

Note

You should install Mercurial for hg support.

Note

For Django<2 please use Dealer<2

Build Status Coverals Version Downloads Donate
  • python 2.7, 3.5+

Note

For Django<2 please use Dealer<2

Dealer should be installed using pip:

pip install dealer
from dealer.git import git

print git.revision

print git.tag
# Auto parse repository type
from dealer.auto import auto
print auto.revision

print auto.tag

path — path to SCM repository (current dir by default)

from dealer.mercurial import Backend

hg = Backend('/path/to/hg/repo')

DEALER_TYPE — Type of SCM repository ('auto', 'git', 'mercurial', 'simple', 'env', 'null'). By default 'auto';

DEALER_PATH — Path to SCM. By default current dir;

DEALER_SILENT — Disable log warnings;

DEALER_BACKENDS — Backends for auto search by default ('git', 'mercurial', 'simple', 'env', 'null');

Append to your context processors:

...
context_processors = ['dealer.contrib.django.context_processor']

And use the REVISION and TAG variables in your templates:

<link href="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/test.css?{{ REVISION }}" rel="stylesheet" type="text/css" media="screen" />
<script src="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/test.js?{{ REVISION }}"></script>

Append to your settings:

MIDDLEWARE = ['dealer.contrib.django.Middleware']

And use in your views:

def view(request):
    return request.revision

Or in your templates by request.revision var.

DEALER_TYPE — Type of SCM repository ('auto', 'git', 'mercurial', 'simple', 'env', 'null'). By default 'auto' DEALER_PARAMS — Params for backend

In views:

from flask import Flask, g
from dealer.contrib.flask import Dealer

app = Flask('test')
Dealer(app)
assert app.revision

@app.route('/')
def usage_in_view():
    return g.revision

In templates:

<link href="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/test.css?{{ REVISION }}" rel="stylesheet" type="text/css" media="screen" />
config.include('dealer.contrib.pyramid')
def myview(request):
    revision = request.registry.dealer.revision
    tag = request.registry.dealer.tag

In templates

Revision: {{DEALER_REVISION}}
Tag: {{DEALER_TAG}}

DEALER_TYPE = 'env' DEALER_PARAMS:

revision_env_keyname - Variable name for revision (default: DEALER_REVISION)
tag_env_keyname - Variable name for tag (default: DEALER_TAG)

Setup your revision and tag value in envirement variables. For example in Heroku.com:

heroku config:set DEALER_REVISION='3ffb6b6'
heroku config:set DEALER_TAG=v1_1

After that use dealer as described above.

If you have any suggestions, bug reports or annoyances please report them to the issue tracker at https://github.com/klen/Dealer/issues

Development of dealer happens at github: https://github.com/klen/dealer

  • klen (Kirill Klenov)

Licensed under a BSD license.