~facundo/magicicada-server/publicfiles

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
# Copyright 2008-2015 Canonical
# Copyright 2015-2016 Chicharreros (https://launchpad.net/~chicharreros)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# For further info, check  http://launchpad.net/magicicada-server

DJANGO_SETTINGS_MODULE ?= magicicada.settings
FLAKE8 = flake8
PYTHON = python
SRC_DIR = $(CURDIR)/magicicada
LIB_DIR = $(CURDIR)/lib
ENV = $(CURDIR)/env
PYTHONPATH := $(SRC_DIR):$(LIB_DIR):$(CURDIR):$(PYTHONPATH)
DJANGO_ADMIN = $(LIB_DIR)/django/bin/django-admin.py
DJANGO_MANAGE = $(PYTHON) manage.py

MAKEFLAGS:=$(MAKEFLAGS) --no-print-directory
# use protobuf cpp
PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp
PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION_VERSION=2

START_SUPERVISORD = lib/ubuntuone/supervisor/start-supervisord.py

export PYTHONPATH
export DJANGO_SETTINGS_MODULE
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION_VERSION
export ROOTDIR ?= $(CURDIR)

SOURCEDEPS_TAG = .sourcecode/sourcedeps-tag
SOURCEDEPS_DIR ?= ../sourcedeps
SOURCEDEPS_SOURCECODE_DIR = $(SOURCEDEPS_DIR)/sourcecode
TARGET_SOURCECODE_DIR = $(CURDIR)/.sourcecode

BUILD_DEPLOY_SOURCEDEPS=magicicada-protocol

TESTFLAGS=

TAR_EXTRA = --exclude 'tmp/*' --exclude tags

ifneq ($(strip $(STRIP_BZR)),)
TAR_EXTRA += --exclude .bzr
endif

include Makefile.db

sourcedeps: $(SOURCEDEPS_TAG)

clean-sourcedeps:
	rm -rf .sourcecode/*

$(SOURCEDEPS_TAG):
ifndef EXPORT_FROM_BZR
	$(MAKE) link-sourcedeps
endif
	$(MAKE) build-sourcedeps
	touch $(SOURCEDEPS_TAG)

build: link-sourcedeps build-sourcedeps version

link-sourcedeps:
	@echo "Checking out external source dependencies..."
	dev-scripts/link-external-sourcecode -p $(SOURCEDEPS_SOURCECODE_DIR)/ \
		-t $(TARGET_SOURCECODE_DIR) -c config-manager.txt

# no need to link sourcedeps before building them, as rollout process
# handles config-manager.txt automatically
build-for-deployment: build-deploy-sourcedeps version

build-sourcedeps: build-deploy-sourcedeps
	@echo "Building client clientdefs.py"
	@cd .sourcecode/magicicada-client/ubuntuone/ && sed \
		-e 's|\@localedir\@|/usr/local/share/locale|g' \
		-e 's|\@libexecdir\@|/usr/local/libexec|g' \
		-e 's|\@GETTEXT_PACKAGE\@|ubuntuone-client|g' \
		-e 's|\@VERSION\@|0.0.0|g' < clientdefs.py.in > clientdefs.py

build-deploy-sourcedeps:
	@echo "Building Python extensions"

	@for sourcedep in $(BUILD_DEPLOY_SOURCEDEPS) ; do \
            d=".sourcecode/$$sourcedep" ; \
            if test -e "$$d/setup.py" ; then \
	        (cd "$$d" && $(PYTHON) \
	        setup.py build build_ext --inplace > /dev/null) ; \
            fi ; \
	done

	@echo "Generating twistd plugin cache"
	@$(PYTHON) -c "from twisted.plugin import IPlugin, getPlugins; list(getPlugins(IPlugin));"

tarball: build-for-deployment
	tar czf ../filesync-server.tgz $(TAR_EXTRA) .

bootstrap:
	cat dependencies.txt | sudo xargs apt-get install -y --no-install-recommends
	cat dependencies-devel.txt | sudo xargs apt-get install -y --no-install-recommends

raw-test:
	./test $(TESTFLAGS)

test: lint sourcedeps clean version start-db start-base start-dbus raw-test stop

ci-test:
	$(MAKE) test TESTFLAGS="-1 $(TESTFLAGS)"

clean:
	rm -rf tmp/* _trial_temp $(ENV)

lint:
	virtualenv $(ENV)
	$(ENV)/bin/pip install flake8 rst2html5
	$(ENV)/bin/flake8 --filename='*.py' --exclude='migrations' $(SRC_DIR)
	dev-scripts/check_readme.sh

version:
	bzr version-info --format=python > lib/versioninfo.py || true

start: build start-base start-filesync-dummy-group publish-api-port

start-oauth: build start-base start-filesync-oauth-group publish-api-port

start-oauth-heapy:
	USE_HEAPY=1 $(MAKE) start-oauth

start-base:
	$(MAKE) start-supervisor && $(MAKE) start-dbus || ( $(MAKE) stop ; exit 1 )

stop: stop-filesync-dummy-group stop-supervisor stop-dbus

start-dbus:
	dev-scripts/start-dbus.sh

stop-dbus:
	dev-scripts/stop-dbus.sh

start-supervisor:
	@python dev-scripts/supervisor-config-dev.py
	-@$(START_SUPERVISORD) dev-scripts/supervisor-dev.conf.tpl

stop-supervisor:
	-@dev-scripts/supervisorctl-dev shutdown

start-%-group:
	-@dev-scripts/supervisorctl-dev start $*:

stop-%-group:
	-@dev-scripts/supervisorctl-dev stop $*:

start-%:
	-@dev-scripts/supervisorctl-dev start $*

stop-%:
	-@dev-scripts/supervisorctl-dev stop $*

publish-api-port:
	python -c 'from magicicada import settings; print >> file("tmp/filesyncserver.port", "w"), settings.api_server.TCP_PORT'
	python -c 'from magicicada import settings; print >> file("tmp/filesyncserver.port.ssl", "w"), settings.ssl_proxy.PORT'
	python -c 'from magicicada import settings; print >> file("tmp/filesyncserver-status.port", "w"), settings.api_server.STATUS_PORT'

shell:
	$(DJANGO_MANAGE) shell

manage:
	$(DJANGO_MANAGE) $(ARGS)

admin:
	$(DJANGO_ADMIN) $(ARGS)

.PHONY: sourcedeps link-sourcedeps build-sourcedeps build-deploy-sourcedeps \
	build clean version lint test ci-test build-for-deployment \
	clean-sourcedeps tarball start stop publish-api-port start-supervisor \
	stop-supervisor start-dbus stop-dbus start-oauth start-oauth-heapy