~facundo/magicicada-server/incorporate-venv-client

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
# Copyright 2008-2015 Canonical
# Copyright 2015-2018 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
ENV = $(CURDIR)/.env
PYTHON = $(ENV)/bin/python
SRC_DIR = $(CURDIR)/magicicada
LIB_DIR = $(CURDIR)/lib
PATH := $(ENV)/bin:$(PATH)
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
SUPERVISOR_CTL = $(ENV)/bin/supervisorctl

export PATH
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

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
	touch $(SOURCEDEPS_TAG)

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

build-clientdefs:
	@echo "Building client clientdefs.py"
	@cd $(TARGET_SOURCECODE_DIR)/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

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
	$(MAKE) $(ENV)
	$(MAKE) sourcedeps build-clientdefs
	mkdir -p tmp

docker-bootstrap: clean
	cat dependencies.txt | xargs apt-get install -y --no-install-recommends
	cat dependencies-devel.txt | xargs apt-get install -y --no-install-recommends
	$(MAKE) $(ENV)
	$(MAKE) sourcedeps build-clientdefs
	mkdir -p tmp

$(ENV): $(ENV)/bin/activate

# only runs when requirements.txt or requirements-devel.txt changes
$(ENV)/bin/activate: requirements.txt requirements-devel.txt
	test -d $(ENV) || virtualenv $(ENV)
	$(ENV)/bin/pip install -Ur requirements.txt
	$(ENV)/bin/pip install -Ur requirements-devel.txt
	$(ENV)/bin/pip install ubuntuone-storageprotocol --no-deps -t "$(TARGET_SOURCECODE_DIR)/magicicada-protocol"
	touch $(ENV)/bin/activate

raw-test:
	$(PYTHON) test $(TESTFLAGS)

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

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

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

check-readme:
	$(ENV)/bin/rst2html5 README.rst  --exit-status=warning > /dev/null && echo "README.rst OK"|| ( echo "ERROR: README.rst format is incorrect!!!!!" && exit 1)

lint: $(ENV) check-readme
	$(ENV)/bin/flake8 --filename='*.py' --exclude='migrations' $(SRC_DIR)

start: $(ENV) start-base start-filesync-server-group publish-api-port

resume: start-base start-filesync-server-group

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

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

stop: 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:
	$(SUPERVISOR_CTL) -c $(CURDIR)/tmp/supervisor-dev.conf shutdown

start-%-group:
	$(SUPERVISOR_CTL) -c $(CURDIR)/tmp/supervisor-dev.conf start $*:

stop-%-group:
	$(SUPERVISOR_CTL) -c $(CURDIR)/tmp/supervisor-dev.conf stop $*:

start-%:
	$(SUPERVISOR_CTL) -c $(CURDIR)/tmp/supervisor-dev.conf start $*

stop-%:
	$(SUPERVISOR_CTL) -c $(CURDIR)/tmp/supervisor-dev.conf stop $*

publish-api-port:
	$(PYTHON) -c 'from magicicada import settings; print >> file("tmp/filesyncserver.port", "w"), settings.TCP_PORT'
	$(PYTHON) -c 'from magicicada import settings; print >> file("tmp/filesyncserver.port.ssl", "w"), settings.SSL_PORT'
	$(PYTHON) -c 'from magicicada import settings; print >> file("tmp/filesyncserver-status.port", "w"), settings.API_STATUS_PORT'

shell:
	$(DJANGO_MANAGE) shell

manage:
	$(DJANGO_MANAGE) $(ARGS)

admin:
	$(DJANGO_ADMIN) $(ARGS)

.PHONY: sourcedeps link-sourcedeps clean lint test ci-test clean-sourcedeps \
	start stop publish-api-port start-supervisor stop-supervisor \
	start-dbus stop-dbus start-heapy check-readme