WebFaction
Community site: login faq

I have my django app at webfaction and need to insert a short version tag into some templates so I have created a custom template tag for this (see below).

It works great in my local development environment but not when deployed in production at webfaction and it needs to have to do with where django process is running on webfaction and how to from there reference the git repository that I am using on webfaction.

What I would like to do is from within the django production process run: 'git log --pretty=format:'%h %ai' --abbrev-commit --date=short -1'

Currently when using this in production the tag generates:

fatal: Not a git repository (or any of the parent directories): .git

So question is -- what would be the correct command to from within django in production run this git command?

The template tag is as below:

try:
    head = subprocess.Popen("git log --pretty=format:'%h %ai' --abbrev-commit --date=short -1",
                            shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    GIT_SHORT = head.stdout.readline().strip()
except:
    GIT_SHORT = u'unknown'

@register.simple_tag()
def git_short_version():
    """
    Use in template by doing {% git_short_version %}

    Will insert a git log formatted as 'edfeed7 2013-01-17 21:51:23 +0100' or branch + author date ISO8601 format.
    """
    return GIT_SHORT

asked 19 Jan '13, 04:57

jenlu
112
accept rate: 0%

Forgot, for reference the path to my app where git is;

/home/XXX/webapps/shoot_django/shootscore

can run command from shell here

(19 Jan '13, 05:08) jenlu

How about adding 'cd /home/XXX/webapps/shoot_django/shootscore;' in front of that subprocess.Popen() command?

(19 Jan '13, 06:08) BenAtWide

As simple as that.

For anyone else - inserted GIT_ROOT in my settings file (have different for deployment and development) and updated tags code to something like this;

try:

    cmd = 'cd ' + settings.GIT_ROOT + ';'
    cmd += "git log --pretty=format:'%h %ai' --abbrev-commit --date=short -1" + ';'
    cmd += 'cd -'

    head = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    GIT_SHORT = head.stdout.readline().strip()

except:

    GIT_SHORT = u'unknown'
permanent link

answered 19 Jan '13, 07:35

jenlu
112
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×909
×111
×21
×15
×1

question asked: 19 Jan '13, 04:57

question was seen: 4,440 times

last updated: 19 Jan '13, 07:35

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM