~fabricematrat/charmworld/redirect-charm

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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# Makefile debugging hack: uncomment the two lines below and make will tell you
# more about what is happening.  The output generated is of the form
# "FILE:LINE [TARGET (DEPENDENCIES) (NEWER)]" where DEPENDENCIES are all the
# things TARGET depends on and NEWER are all the files that are newer than
# TARGET.  DEPENDENCIES will be colored green and NEWER will be blue.
#OLD_SHELL := $(SHELL)
#SHELL = $(warning [$@ ($^) ($?) ])$(OLD_SHELL)

WD := $(shell pwd)
CACHE := download-cache/dist
CSS_PATH := charmworld/static/css
PSERVE := bin/pserve
SYSTEM_DEPS := \
	build-essential bzr libyaml-dev python-dev python-virtualenv\
	subversion nodejs npm


# Default ini file to use for all scripted commands. Can be overridden by
# specifying  INI=development.ini
INI = charmworld.ini

# INI is the default ini file used for all work. By default we want to copy a
# sample.ini and generate a single charmworld.ini used.

ifeq ($(wildcard custom.ini), )
	CONFIG_DEPS = default.ini
else
	CONFIG_DEPS = default.ini custom.ini
endif


$(INI): $(CONFIG_DEPS)
	scripts/config $(INI) $(CONFIG_DEPS)

test.ini: default.ini test-setup.ini
	scripts/config test.ini default.ini test-setup.ini

# ###############
# INSTALL targets
# ###############

bin/pip:
	virtualenv .

bin/python:
	virtualenv .

# We use a "canary" file to tell us if the charmworld package has been
# installed in "develop" mode.
DEVELOP_CANARY := lib/__develop_canary
develop: $(DEVELOP_CANARY)
$(DEVELOP_CANARY): | bin/python
	bin/python setup.py develop
	touch $(DEVELOP_CANARY)

install: deps bin/python bin/pip $(INI) develop css bin/test

bin/es-update: bin/python
	bin/python setup.py develop

clean_venv:
	rm -rf bin include lib local

sysdeps:
	sudo apt-get update
	sudo apt-get install --yes python-software-properties
	sudo add-apt-repository -y ppa:juju/pkgs
	sudo add-apt-repository -y ppa:ce-orange-squad/experimental
	sudo apt-get update
	sudo apt-get install -y $(SYSTEM_DEPS) mongodb-server \
	    elasticsearch-java;
	# On quantal need to provide node bin for deps to work.
	if test ! -e /usr/bin/node; \
	    then sudo ln -s /usr/bin/nodejs /usr/bin/node; \
	fi

deploy_sysdeps:
	sudo apt-get install -y $(SYSTEM_DEPS) mongodb-clients;

# We use a "canary" file to tell us if the Python packages have been installed.
PYTHON_PACKAGE_CANARY := lib/python2.7/site-packages/___canary
python-deps: $(PYTHON_PACKAGE_CANARY)
$(PYTHON_PACKAGE_CANARY): requirements.txt | bin/pip
	if test -d download-cache; \
	    then bzr up download-cache; \
	    else bzr checkout lp:~juju-jitsu/charmworld/download-cache; \
	fi
	bin/pip install --no-index --no-dependencies --find-links \
	    file:///$(WD)/$(CACHE) -r requirements.txt
	touch $(PYTHON_PACKAGE_CANARY)

# We use a "canary" file to tell us if the Node packages have been installed.
NODE_CANARY := node_modules/___canary
node-deps: $(NODE_CANARY)
$(NODE_CANARY):
	npm install download-cache/npm/ycssmin.tar.gz
	npm install download-cache/npm/less.tar.gz
	rm -rf build
	rm -rf share
	touch $(NODE_CANARY)

deps: python-deps node-deps


# ###################
# Development helpers
# ###################

bin/nosetests: python-deps

bin/test: | test.ini $(INI) bin/nosetests
	ln scripts/test bin/test

test: install bin/test
	bin/test

testid: install bin/test
	# Run specific nose id tests.
	# To set up the index you must run `make testid` once to completion to
	# setup the index.  Then you can run a group of tests like:
	# Call with `ID="3 5" make testid`
	bin/test -v -s -x --with-id $(ID) charmworld

testdebug: bin/test
	bin/test --pdb --pdb-failures charmworld

check: clear_ini clean sysdeps install lint testid

lint: sources = setup.py charmworld
lint: install
	@find $(sources) -name '*.py' \
	    -! -path 'charmworld/teams.py' ! -print0 | xargs -r0 \
		bin/flake8 --ignore=E125,E127

# Generate ctags for the code in the project.
tags:
	ctags --tag-relative --python-kinds=-iv -Rf tags --sort=yes --exclude=.bzr --languages=python

doc: bin/sphinx-build
	bin/sphinx-build docs docs/_build/html

doc-open: doc
	xdg-open docs/_build/html/index.html

doc-upload: doc
	scp -r docs/_build/html/* people.canonical.com:/home/rharding/public_html/charmworld

run: $(INI) bin/es-update
	bin/es-update
	$(PSERVE) --reload --monitor-restart $(INI)

start_supervisor:
	bin/supervisord -c charmworld/jobs/supervisord.conf

stop_supervisor:
	if test -f ./supervisord.pid; \
		then  cat ./supervisord.pid | xargs kill -HUP; \
		else echo "No pidfile for supervisor; is the process running?"; \
	fi

start_worker:
	bin/supervisorctl -c charmworld/jobs/supervisord.conf start ingest

stop_worker:
	bin/supervisorctl -c charmworld/jobs/supervisord.conf stop ingest

worker_status:
	bin/supervisorctl -c charmworld/jobs/supervisord.conf status ingest

clean:
	find . -type f -name '*.py[co]' -print0 | xargs -r0 rm -rf
	find . -type f -name '*~' -print0 | xargs -r0 rm -rf
	rm -rf node_modules

clear_ini:
	rm -f charmworld.ini

distclean: clean clean_venv
	rm -rf tags TAGS .installed.cfg lib



#
# Phony stuff.
#
define phony
  check
  css
  clean_venv
  clean
  deps
  develop
  distclean
  doc
  doc-open
  install
  lint
  run
  tags
  test
  testid
  start_worker
  stop_worker
  worker_status
endef

phony := $(sort $(strip $(phony)))

.PHONY: $(phony)

.DEFAULT_GOAL := install