Added a basic task to pull and build docs.

rtd2
Eric Holscher 2010-08-14 02:43:28 -05:00
parent 6f882aaea7
commit 3cb28e6129
2 changed files with 49 additions and 0 deletions

36
projects/tasks.py Normal file
View File

@ -0,0 +1,36 @@
import os
import fnmatch
from celery.decorators import task
from projects.models import Project
from projects.utils import get_project_path, find_file
#@task
def update_docs(slug, type='git'):
project = Project.objects.get(slug=slug)
path = get_project_path(project)
if not os.path.exists(path):
os.makedirs(path)
os.chdir(path)
if os.path.exists(os.path.join(path, project.slug)):
os.chdir(project.slug)
if type is 'git':
command = 'git reset --hard origin/master'
print command
os.system(command)
else:
if type is 'git':
command = 'git clone %s.git %s' % (project.github_repo, project.slug)
print command
os.system(command)
elif type is 'hg':
os.system('hg clone ')
build_docs(path)
def build_docs(path):
os.chdir(path)
matches = find_file('Makefile')
if len(matches) == 1:
make_dir = matches[0].replace('/Makefile', '')
os.chdir(make_dir)
os.system('make html')

13
projects/utils.py Normal file
View File

@ -0,0 +1,13 @@
import os
from django.conf import settings
import subprocess
def get_project_path(project):
return os.path.join(settings.DOCROOT, project.user.username, project.slug)
def find_file(file):
matches = []
for root, dirnames, filenames in os.walk('.'):
for filename in fnmatch.filter(filenames, file):
matches.append(os.path.join(root, filename))
return matches