forked from tobami/codespeed
-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathcreate_trunks.py
More file actions
56 lines (43 loc) · 1.68 KB
/
create_trunks.py
File metadata and controls
56 lines (43 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# -*- coding: utf-8 -*-
"""
Create the default branch for all existing projects
Starting v 0.8.0 that is mandatory.
Note: This file is assumed to be in the same directory
as the project settings.py. Otherwise you have to set the
shell environment DJANGO_SETTINGS_MODULE
"""
import sys
import os
## Setup to import models from Django app ##
def import_from_string(name):
"""helper to import module from a given string"""
components = name.split('.')[1:]
return reduce(lambda mod, y: getattr(mod, y), components, __import__(name))
sys.path.append(os.path.abspath('..'))
if 'DJANGO_SETTINGS_MODULE' in os.environ:
settings = import_from_string(os.environ['DJANGO_SETTINGS_MODULE'])
else:
try:
import settings # Assumed to be in the same directory.
except ImportError:
import sys
sys.stderr.write(
"Error: Can't find the file 'settings.py' in the directory "
"containing %r. It appears you've customized things.\nYou'll have "
"to run django-admin.py, passing it your settings module.\n(If the"
" file settings.py does indeed exist, it's causing an ImportError "
"somehow.)\n" % __file__)
sys.exit(1)
from django.core.management import setup_environ
setup_environ(settings)
from codespeed.models import Branch, Project
def main():
"""Add Branch default to projects if not there"""
projects = Project.objects.all()
for proj in projects:
if not proj.branches.filter(name='default'):
trunk = Branch(name='default', project=proj)
trunk.save()
print "Created branch 'default' for project {0}".format(proj)
if __name__ == '__main__':
main()