Git Product home page Git Product logo

dealer's Introduction

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

On clientside: :

<script src='/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

Requirements

  • python 2.7, 3.5+

Note

For Django<2 please use Dealer<2

Installation

Dealer should be installed using pip: :

pip install dealer

Usage

Basic usage

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

Manually create backend ----------------------

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

from dealer.mercurial import Backend

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

Django support

Settings

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');

Context-processor

Append to your context processors: :

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

And use the REVISION and TAG variables in your templates: :

<link href="/test.css?{{ REVISION }}" rel="stylesheet" type="text/css" media="screen" />
<script src="/test.js?{{ REVISION }}"></script>

Middleware

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.

Flask support

Settings

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

Usage

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

Pyramid support

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}}

Heroku support -------------

Settings

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)

Usage

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.

Bug tracker

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

Contributing

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

Contributors

  • klen (Kirill Klenov)

License

Licensed under a BSD license.

dealer's People

Contributors

klen avatar klinkin avatar remcogerlich avatar sinanm89 avatar singingwolfboy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

dealer's Issues

Dealer template context processor returns null in Django with git backend

Interestingly, Dealer works with no configuration (other than adding the template context processor) on my Django project when running off the development server. However, {{ REVISION }} prints null on the same project when running in production via Apache + WSGI. Explicitly setting DEALER_PATH does not help.

Dealer Not Working on Production Deploy with Git, Gunicorn

I'm using dealer on a django project (1.5) and it works great with my development install.

On production, I get Null for {{ REVISION }} in my templates. I am running on Ubuntu 12.04 and using supervisor to start my gunicorn process via shell script within my django project.

What is the proper way to get dealer working for my configuration? Thanks.

TypeError at /: b"fatal: bad default revision 'HEAD'"

This only happens once after server start, after that there is no error, but no git version either.

TypeError at /

b"fatal: bad default revision 'HEAD'"
Environment:

Request Method: GET
Request URL: http://example.com/384/ # changed

Django Version: 1.9
Python Version: 3.4.3
Installed Applications:

('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'PROJECT', # changed
 'jquery',
 'mod_wsgi.server')

Installed Middleware:

('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware',
 'dealer.contrib.django.Middleware',
 'luckydonaldUtils.djangos.middleware.access.AllowFromIPMiddleware',
 'luckydonaldUtils.djangos.middleware.headers.EastereggHeadersMiddleware')

Traceback:

File "/var/www-django/project/venv-3.4/lib/python3.4/site-packages/dealer/git.py" in init_repo
  71.             self._revision = self.repo.git('log -1 --format=%h')

File "/var/www-django/project/venv-3.4/lib/python3.4/site-packages/dealer/git.py" in git
  54.             raise GitException(stderr)

During handling of the above exception (b"fatal: bad default revision 'HEAD'"), another exception occurred:

File "/var/www-django/project/venv-3.4/lib/python3.4/site-packages/django/core/handlers/base.py" in get_response
  123.                 response = middleware_method(request)

File "/var/www-django/project/venv-3.4/lib/python3.4/site-packages/dealer/contrib/django/staff.py" in process_request
  22.         request.revision = BACKEND.revision

File "/var/www-django/project/venv-3.4/lib/python3.4/site-packages/dealer/base.py" in revision
  52.         return self.repo and _to_str(self._revision)

File "/var/www-django/project/venv-3.4/lib/python3.4/site-packages/dealer/base.py" in repo
  44.         return self._repo or self.init_repo()

File "/var/www-django/project/venv-3.4/lib/python3.4/site-packages/dealer/git.py" in init_repo
  79.             raise TypeError(e)

Exception Type: TypeError at /
Exception Value: b"fatal: bad default revision 'HEAD'"

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/29044164-typeerror-at-b-fatal-bad-default-revision-head?utm_campaign=plugin&utm_content=tracker%2F387713&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F387713&utm_medium=issues&utm_source=github).

_to_str() won't work on a None object

When a None item is passed to the _to_str() function it fails because None has no attribute decode.

This happens, for instance, when there is no tag set and it tries to return the tag value (which is None instead of an empty string).

Adding a simple check on if it is None and thus returning an empty string would probably solve this.

You misspelled your docs

While explaining how to use and set-up dealer on django you wrote;

MIDDLEWARE_CLASSES += 'dealer.contrib.django.staff.middleware',

it should be

MIDDLEWARE_CLASSES += 'dealer.contrib.django.staff.Middleware',

The 'm' should be uppercase

git.revision, git.tag show the same thing

With dealer version 2.0.5, python 3.5:

from dealer.git import git
print(git.revision)
print(git.tag)

both print statements display the latest commit ID, while I was expecting the second one to display the latest tag. Same with the provided template tags -- {{REVISION}} AND {{TAG}} both display the latest revision.

I do have tags in my repo - can I expose them with dealer? Thanks.

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Issues with Middleware and Django 1.10

Hi, is this addon ready for Django 1.10?

I don't find a MIDDLEWARE_CLASSES variable in my settings file, i only see a MIDDLEWARE variable.

I think both variables are equivalents, but when i add the 'dealer.contrib.django.Middleware', class to MIDDLEWARE list like this:

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'corsheaders.middleware.CorsMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'simple_history.middleware.HistoryRequestMiddleware',
    'dealer.contrib.django.Middleware',
]

I get this error:

jango version 1.10.5, using settings 'backend.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Unhandled exception in thread started by <function wrapper at 0x1023cc2a8>
Traceback (most recent call last):
  File "/Users/hugoruscitti/proyectos/enjambre/origami-backend/venv/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/Users/hugoruscitti/proyectos/enjambre/origami-backend/venv/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 142, in inner_run
    handler = self.get_handler(*args, **options)
  File "/Users/hugoruscitti/proyectos/enjambre/origami-backend/venv/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/runserver.py", line 27, in get_handler
    handler = super(Command, self).get_handler(*args, **options)
  File "/Users/hugoruscitti/proyectos/enjambre/origami-backend/venv/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 64, in get_handler
    return get_internal_wsgi_application()
  File "/Users/hugoruscitti/proyectos/enjambre/origami-backend/venv/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 49, in get_internal_wsgi_application
    return import_string(app_path)
  File "/Users/hugoruscitti/proyectos/enjambre/origami-backend/venv/lib/python2.7/site-packages/django/utils/module_loading.py", line 20, in import_string
    module = import_module(module_path)
  File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/Users/hugoruscitti/proyectos/enjambre/origami-backend/backend/wsgi.py", line 16, in <module>
    application = get_wsgi_application()
  File "/Users/hugoruscitti/proyectos/enjambre/origami-backend/venv/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
    return WSGIHandler()
  File "/Users/hugoruscitti/proyectos/enjambre/origami-backend/venv/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 153, in __init__
    self.load_middleware()
  File "/Users/hugoruscitti/proyectos/enjambre/origami-backend/venv/lib/python2.7/site-packages/django/core/handlers/base.py", line 82, in load_middleware
    mw_instance = middleware(handler)
TypeError: object() takes no parameters

git backend setting to define the revision format

There are several ways to format the revsion string:
https://git-scm.com/docs/pretty-formats

Provide a backend settings to configure what is returned on the following line (or perhaps adding a self._custom = ... ):
https://github.com/klen/dealer/blob/develop/dealer/git.py#L71

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/37125108-git-backend-setting-to-define-the-revision-format?utm_campaign=plugin&utm_content=tracker%2F387713&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F387713&utm_medium=issues&utm_source=github).

Always get null when using detached work tree

Using 1.1.1 with django/gunicorn.

When I use manage.py shell and:

from dealer.contrib.django import context_processor
context_processor({})

returns valid looking values.

However, in production it only returns "null".

I've set the DEALER_PATH to no avail.

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

QUESTION

Is there a way to capture data from Annotated Tags? Like date, tagger, author

Example :
$ git show v1.4
tag v1.4
Tagger: Ben Straub [email protected]
Date: Sat May 3 20:19:12 2014 -0700

my version 1.4

commit ca82a6dff817ec66f44342007202690a93763949
Author: Scott Chacon [email protected]
Date: Mon Mar 17 21:52:11 2008 -0700

changed the version number
--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/40755859-question?utm_campaign=plugin&utm_content=tracker%2F387713&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F387713&utm_medium=issues&utm_source=github).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.