travis2docker 7.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,54 @@
1
+ FROM {{ image }}
2
+
3
+ ARG HOME=/home/odoo
4
+
5
+ # rm -rf /home/odoo/.ssh
6
+
7
+ {%- for src, dest in copies or [] %}
8
+ COPY {{ src }} {{ dest }}
9
+ {% endfor -%}
10
+
11
+ {% if copies -%}
12
+ RUN {% for src, dest in copies or [] -%} chown -R {{ user }}:{{ user }} {{dest}};
13
+ {%- endfor -%}
14
+ {%- endif %}
15
+
16
+ ENV ODOORC_DB_NAME=odoo ODOORC_PIDFILE=/home/odoo/.odoo.pid ODOORC_DATA_DIR=/home/odoo/data_dir PROFILE_FILE=/etc/bash.bashrc MAIN_REPO_FULL_PATH=/home/odoo/instance/$MAIN_REPO_PATH DEB_PYTHON_INSTALL_LAYOUT=deb
17
+ ENV COVERAGE_RCFILE=$HOME/.coveragerc
18
+ ENV COVERAGE_HOME=$MAIN_REPO_FULL_PATH
19
+
20
+ {% for build_env_arg in build_env_args %}
21
+ ENV {{ build_env_arg }}=TRUE
22
+ {% endfor %}
23
+
24
+ # Create cluster with odoo as owner and use environment variables instead of odoo cfg to connect
25
+ RUN . /home/odoo/build.sh && \
26
+ set_odoo_ids && \
27
+ install_dev_tools && \
28
+ service_postgres_without_sudo odoo odoo && \
29
+ install_pgcli_venv && \
30
+ custom_alias && \
31
+ odoo_conf && \
32
+ git_set_remote && \
33
+ bash_colorized && \
34
+ setup_coverage && \
35
+ local_bin_path && \
36
+ configure_vim && \
37
+ configure_zsh && \
38
+ chown_all && \
39
+ [ -e /entrypoint_image ] && mv /entrypoint_image /deployv_entrypoint_image ; \
40
+ [ -e /entry_point.py ] && mv /entry_point.py /deployv_entry_point.py ; \
41
+ [ -e /entrypoint ] && mv /entrypoint /deployv_entrypoint ; \
42
+ mkdir -p /run/sshd
43
+
44
+ {% for step in build_extra_steps %}
45
+ RUN {{ step }}
46
+ {% endfor %}
47
+
48
+ USER {{ user }}
49
+
50
+ # TODO: Use .profile as bash profiler by default
51
+
52
+ ENTRYPOINT /entrypoint.sh
53
+
54
+ WORKDIR $MAIN_REPO_FULL_PATH
@@ -0,0 +1,364 @@
1
+ #!/usr/bin/env bash
2
+
3
+ service_postgres_without_sudo(){
4
+ USER="${1}"
5
+ PASSWORD="${2}"
6
+ VERSIONS=$(pg_lsclusters | sed '1d' | awk '{print $1}' )
7
+ for version in $VERSIONS; do
8
+ pg_dropcluster --stop $version main
9
+ done
10
+ adduser ${USER} postgres
11
+ chown -R ${USER}:postgres /var/run/postgresql
12
+ for version in $VERSIONS; do
13
+ pg_createcluster -u ${USER} -g postgres -s /var/run/postgresql -p 15432 --lc-collate=${LC_COLLATE} --start-conf auto --start $version main
14
+ echo "include = '/etc/postgresql-common/common-vauxoo.conf'" >> /etc/postgresql/$version/main/postgresql.conf
15
+ su - ${USER} -c "psql -p 15432 -d postgres -c \"ALTER ROLE ${USER} WITH PASSWORD '${PASSWORD}';\""
16
+ su - ${USER} -c "psql -p 15432 -d postgres -c \"CREATE ROLE postgres LOGIN SUPERUSER INHERIT CREATEDB CREATEROLE;\""
17
+ /etc/init.d/postgresql stop $version
18
+ sed -i "s/port = 15432/port = 5432/g" /etc/postgresql/$version/main/postgresql.conf
19
+ done
20
+ }
21
+
22
+ install_pgcli_venv(){
23
+ # pgcli==3.1.0 change psycopg2 version
24
+ virtualenv /venev-pgcli
25
+ . /venev-pgcli/bin/activate
26
+ pip install pgcli
27
+ echo 'alias pgcli2="source /venev-pgcli/bin/activate && pgcli -l"' >> $PROFILE_FILE
28
+ }
29
+
30
+ odoo_conf(){
31
+ if [ -f "/home/odoo/.odoorc" ]; then
32
+ export ODOO_CONF="/home/odoo/.odoorc"
33
+ elif [ -f "/home/odoo/.openerp_serverrc" ]; then
34
+ export ODOO_CONF="/home/odoo/.openerp_serverrc"
35
+ else
36
+ echo "❌ Odoo configuration file not found."
37
+ exit 1
38
+ fi
39
+ if [ -x "/entrypoint" ]; then
40
+ export ENTRYPOINT="/entrypoint"
41
+ elif [ -x "/entry_point.py" ]; then
42
+ export ENTRYPOINT="/entry_point.py"
43
+ else
44
+ echo "❌ Orchest entrypoint not found"
45
+ exit 1
46
+ fi
47
+ $ENTRYPOINT run true
48
+ sed -i '/db_host\|db_password\|db_user\|workers\|list_db/d' $ODOO_CONF
49
+ sed -i 's/\(with_demo\s*=\s*\)False/\1True/' $ODOO_CONF
50
+ su odoo -c "mkdir -p $ODOORC_DATA_DIR"
51
+ }
52
+
53
+ custom_alias(){
54
+ cat >> /etc/bash.bashrc << EOF
55
+ alias psql_logs_enable="export PGOPTIONS=\" -c client_min_messages=notice -c log_min_messages=warning -c log_min_error_statement=error -c log_min_duration_statement=0 -c log_connections=on -c log_disconnections=on -c log_duration=off -c log_error_verbosity=verbose -c log_lock_waits=on -c log_statement=none -c log_temp_files=0\""
56
+ alias psql_logs_disable="unset PGOPTIONS"
57
+ alias tail2="multitail -cS odoo"
58
+ alias rgrep="rgrep -n"
59
+ git_fetch_pr() {
60
+ REMOTE=$1
61
+ shift 1
62
+ git fetch -p $REMOTE +refs/pull/*/head:refs/pull/$REMOTE/*
63
+ }
64
+ git_fetch_mr() {
65
+ REMOTE=$1
66
+ shift 1
67
+ # git fetch -p $REMOTE +refs/merge_requests/*/head:refs/pull/$REMOTE/*
68
+ git fetch -p $REMOTE +refs/merge-requests/*/head:refs/pull/$REMOTE/*
69
+ }
70
+ EOF
71
+ # alias odoo
72
+ }
73
+
74
+ # You can add new packages here
75
+ install_dev_tools(){
76
+ apt update -qq
77
+ # TODO: Download a versioned public file?
78
+ apt install -y \
79
+ sudo \
80
+ tree \
81
+ iputils-ping \
82
+ expect-dev \
83
+ tcl8.6 \
84
+ less \
85
+ openssh-server \
86
+ pgbadger \
87
+ p7zip-full mosh bpython \
88
+ rsync \
89
+ gettext \
90
+ net-tools \
91
+ libecpg-dev \
92
+ iproute2
93
+ # aspell aspell-en aspell-es \
94
+ # emacs \
95
+ # byobu \
96
+ # multitail # Set the terminal with red letters build the docker
97
+ sudo -E pip install -q \
98
+ ipython \
99
+ py-spy \
100
+ virtualenv \
101
+ ipdb \
102
+ pre-commit-vauxoo \
103
+ pg-activity \
104
+ nodeenv \
105
+ pdbpp \
106
+ codebase-memory-deployv
107
+
108
+ # Symlinks used by vscode and possibly other tools.
109
+ PCV_DIR="$(python3 -c "import pre_commit_vauxoo as pcv; print(pcv.__path__[0])")/cfg"
110
+ ln -sf "${PCV_DIR}/.pylintrc" "${HOME}/.pylintrc"
111
+ ln -sf "${PCV_DIR}/.flake8" "${HOME}/.flake8"
112
+ ln -sf "${PCV_DIR}/.isort.cfg" "${HOME}/.isort.cfg"
113
+ ln -sf "${PCV_DIR}/.eslintrc.json" "${HOME}/.eslintrc.json"
114
+
115
+ # pre install pre-commit-vauxoo?
116
+ # sudo su odoo -c "git init /tmp/test && cd /tmp/test && pre-commit-vauxoo -f"
117
+ touch /home/odoo/full_test-requirements.txt
118
+ sudo -E pip install -r /home/odoo/full_test-requirements.txt
119
+
120
+ # Install git-delta from .deb since not all Ubuntu versions ship the package
121
+ GIT_DELTA_VERSION=0.18.2
122
+ wget -q https://github.com/dandavison/delta/releases/download/${GIT_DELTA_VERSION}/git-delta_${GIT_DELTA_VERSION}_$(dpkg --print-architecture).deb -O /tmp/git-delta.deb && \
123
+ apt install -qqq -y /tmp/git-delta.deb || true
124
+
125
+ # Keep alive the ssh server
126
+ # 60 seconds * 360 = 21600 seconds = 6 hours
127
+ # https://www.bjornjohansen.no/ssh-timeout
128
+ echo "ClientAliveInterval 60" >> /etc/ssh/sshd_config
129
+ echo "ClientAliveCountMax 360" >> /etc/ssh/sshd_config
130
+
131
+ # Install ngrok
132
+ wget -O /tmp/ngrok.tgz https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-linux-amd64.tgz && \
133
+ tar xvzf /tmp/ngrok.tgz -C /usr/local/bin || true
134
+
135
+ # Configure color for git diff if git-delta is already installed
136
+ if command -v delta >/dev/null 2>&1; then
137
+ git config --system core.pager delta
138
+ git config --system interactive.diffFilter "delta --color-only"
139
+
140
+ git config --system delta.navigate true
141
+ git config --system delta.line-numbers true
142
+ git config --system delta.syntax-theme DarkNeon
143
+ git config --system delta.keep-plus-minus-markers true
144
+ fi
145
+ cat >> /etc/multitail.conf << EOF
146
+ # Odoo log
147
+ colorscheme:odoo
148
+ cs_re:blue:^[0-9]*-[0-9]*-[0-9]* [0-9]*:[0-9]*:[0-9]*,[0-9]*
149
+ cs_re_s:blue,,bold:^[^ ]* *[^,]*,[^ ]* *[0-9]* *(DEBUG) *[^ ]* [^ ]* *(.*)$
150
+ cs_re_s:green:^[^ ]* *[^,]*,[0-9]* *[0-9]* *(INFO) *[^ ]* [^ ]* *(.*)$
151
+ cs_re_s:yellow:^[^ ]* *[^,]*,[0-9]* *[0-9]* *(WARNING) *[^ ]* [^ ]* *(.*)$
152
+ cs_re_s:red:^[^ ]* *[^,]*,[0-9]* *[0-9]* *(ERROR) *[^ ]* [^ ]* *(.*)$
153
+ cs_re_s:red,,bold:^[^ ]* *[^,]*,[0-9]* *[0-9]* *(CRITICAL) *[^ ]* [^ ]* *(.*)$
154
+ EOF
155
+
156
+ # Configure emacs for odoo user
157
+ git clone --depth 1 -b master https://github.com/Vauxoo/emacs.d.git /home/odoo/.emacs.d
158
+
159
+ # Install pgvector for "ai" odoo-18.4+ module
160
+ VERSIONS=$(pg_lsclusters | sed '1d' | awk '{print $1}' )
161
+ for version in $VERSIONS; do
162
+ apt install -y postgresql-$version-pgvector
163
+ done
164
+ }
165
+
166
+ setup_coverage() {
167
+ echo "export MODULES2TEST=$(cd ${MAIN_REPO_FULL_PATH} && find * -name "__manifest__.py" -printf "/%h,")" >> ${HOME}/.bashrc
168
+ echo "export MODULES2INSTALL=$(cd ${MAIN_REPO_FULL_PATH} && find * -name "__manifest__.py" -printf "%h,")" >> ${HOME}/.bashrc
169
+ }
170
+
171
+ local_bin_path(){
172
+ # Add ~/.local/bin to PATH at shell startup if it exists and is not already there
173
+ cat >> ${HOME}/.bashrc << 'EOF'
174
+ if [ -d "$HOME/.local/bin" ] && [[ ":$PATH:" != *":$HOME/.local/bin:"* ]]; then
175
+ export PATH="$HOME/.local/bin:$PATH"
176
+ fi
177
+ EOF
178
+ }
179
+
180
+
181
+ bash_colorized(){
182
+ cat >> ~/.bashrc << 'EOF'
183
+ Purple="\[\033[0;35m\]"
184
+ BIPurple="\[\033[1;95m\]"
185
+ Color_Off="\[\033[0m\]"
186
+ PathShort="\w"
187
+ UserMachine="$BIPurple[\u@$Purple\h]"
188
+ GREEN_WOE="\001\033[0;32m\002"
189
+ RED_WOE="\001\033[0;91m\002"
190
+ git_ps1_style(){
191
+ local git_branch="$(__git_ps1 2>/dev/null)";
192
+ local git_ps1_style="";
193
+ if [ -n "$git_branch" ]; then
194
+ if [ -n "$GIT_STATUS" ]; then
195
+ (git diff --quiet --ignore-submodules HEAD 2>/dev/null)
196
+ local git_changed=$?
197
+ if [ "$git_changed" == 0 ]; then
198
+ git_ps1_style=$GREEN_WOE;
199
+ else
200
+ git_ps1_style=$RED_WOE;
201
+ fi
202
+ fi
203
+ git_ps1_style=$git_ps1_style$git_branch
204
+ fi
205
+ echo -e "$git_ps1_style"
206
+ }
207
+ PS1=$UserMachine$Color_Off$PathShort\$\\n"\$(git_ps1_style)"$Color_Off\$" "
208
+ EOF
209
+ }
210
+
211
+ git_set_remote(){
212
+ (su odoo -c "cd /home/odoo/build && python3 -c \"import build;build.git_set_remote()\"")
213
+ }
214
+
215
+ chown_all(){
216
+ find /home/odoo -maxdepth 1 -user root -exec chown odoo:odoo -R {} \;
217
+ chown -R odoo:odoo /etc/postgresql-common/common-vauxoo.conf
218
+ }
219
+
220
+ set_odoo_ids(){
221
+ # OrchestSH images (ORCHESTSH=True) use UID/GID 5410 for the odoo user;
222
+ # older images use 1000/1001. A mismatch causes permission issues when
223
+ # sharing files across containers, so align both to 5410 when they differ.
224
+ CURRENT_UID=$(id -u odoo)
225
+ CURRENT_GID=$(id -g odoo)
226
+ NEW_ID=5410
227
+ if [ "${CURRENT_GID}" != "${NEW_ID}" ]; then
228
+ echo "Changing odoo GID from ${CURRENT_GID} to ${NEW_ID}"
229
+ groupmod -g "${NEW_ID}" odoo
230
+ # groupmod does not re-chown any file
231
+ find / -xdev -gid "${CURRENT_GID}" -exec chown -h ":${NEW_ID}" {} + 2>/dev/null || true
232
+ fi
233
+ if [ "${CURRENT_UID}" != "${NEW_ID}" ]; then
234
+ echo "Changing odoo UID from ${CURRENT_UID} to ${NEW_ID}"
235
+ usermod -u "${NEW_ID}" odoo
236
+ # usermod only re-chowns files inside the home directory
237
+ find / -xdev -uid "${CURRENT_UID}" -exec chown -h "${NEW_ID}" {} + 2>/dev/null || true
238
+ fi
239
+ }
240
+
241
+ configure_vim(){
242
+ git_clone_copy(){
243
+ URL="${1}"
244
+ BRANCH="${2}"
245
+ WHAT="${3}"
246
+ WHERE="${4}"
247
+ TEMPDIR="$( mktemp -d )"
248
+ echo "Cloning ${URL} ..."
249
+ mkdir -p $( dirname "${WHERE}" )
250
+ git clone ${URL} --depth 1 -b ${BRANCH} -q --single-branch --recursive ${TEMPDIR}
251
+ rsync -aqz "${TEMPDIR}/${WHAT}" "${WHERE}"
252
+ rm -rf ${TEMPDIR}
253
+ }
254
+
255
+ if [ -z ${VIM_INSTALL+x} ];
256
+ then
257
+ echo "VIM_INSTALL was not defined. Skipping spf13-vim plugins. Use t2d parameter --build-env-args=VIM_INSTALL to be autoconfigured."
258
+ return 0;
259
+ fi
260
+ # Upgrade & configure vim
261
+ apt install vim --only-upgrade
262
+ apt install exuberant-ctags -y
263
+ # Get vim version
264
+ VIM_VERSION=$(dpkg -s vim | grep Version | sed -n 's/.*\([0-9]\+\.[0-9]\+\)\..*/\1/p' | sed -r 's/\.//g')
265
+
266
+ wget -q -O /usr/share/vim/vim${VIM_VERSION}/spell/es.utf-8.spl https://ftp.nluug.nl/pub/vim/runtime/spell/es.utf-8.spl
267
+ wget -O - https://raw.githubusercontent.com/spf13/spf13-vim/3.0/bootstrap.sh | sh
268
+ git_clone_copy "https://github.com/vauxoo/vim-openerp.git" "master" "vim/" "${HOME}/.vim/bundle/vim-openerp"
269
+ git_clone_copy "https://github.com/davidhalter/jedi-vim.git" "master" "." "${HOME}/.vim/bundle/jedi-vim"
270
+
271
+ sed -i 's/ set mouse\=a/\"set mouse\=a/g' ${HOME}/.vimrc
272
+ sed -i "s/let g:neocomplete#enable_at_startup = 1/let g:neocomplete#enable_at_startup = 0/g" ${HOME}/.vimrc
273
+
274
+ # Disable virtualenv in Pymode
275
+ cat >> ${HOME}/.vimrc << EOF
276
+ " Disable virtualenv in Pymode
277
+ let g:pymode_virtualenv = 0
278
+ " Disable pymode init and lint because of https://github.com/python-mode/python-mode/issues/897
279
+ let g:pymode_init = 0
280
+ let g:pymode_lint = 0
281
+ " Disable modelines: https://github.com/numirias/security/blob/master/doc/2019-06-04_ace-vim-neovim.md
282
+ set modelines=0
283
+ set nomodeline
284
+ EOF
285
+
286
+ # Disable vim-signify
287
+ cat >> ${HOME}/.vimrc << EOF
288
+ " Disable vim-signify
289
+ let g:signify_disable_by_default = 1
290
+ EOF
291
+
292
+ # Install WakaTime
293
+ git_clone_copy "https://github.com/wakatime/vim-wakatime.git" "master" "." "${HOME}/.vim/bundle/vim-wakatime"
294
+ cat >> ${HOME}/.vimrc << EOF
295
+ colorscheme heliotrope
296
+ set colorcolumn=119
297
+ set spelllang=en,es
298
+ EOF
299
+
300
+ # Configure pylint_odoo plugin and the .conf file
301
+ # to enable python pylint_odoo checks and eslint checks into the vim editor.
302
+ cat >> ${HOME}/.vimrc << EOF
303
+ :filetype on
304
+ let g:syntastic_aggregate_errors = 1
305
+ let g:syntastic_python_checkers = ['pylint', 'flake8']
306
+ let g:syntastic_auto_loc_list = 1
307
+ let g:syntastic_python_pylint_args =
308
+ \ '--rcfile=${HOME}/.pylintrc'
309
+ let g:syntastic_python_flake8_args =
310
+ \ '--config=${HOME}/.flake8'
311
+ let g:syntastic_javascript_checkers = ['eslint']
312
+ let g:syntastic_javascript_eslint_args =
313
+ \ '--config ${HOME}/.eslintrc.json'
314
+ " make YCM compatible with UltiSnips (using supertab) more info http://stackoverflow.com/a/22253548/3753497
315
+ let g:ycm_key_list_select_completion = ['<C-n>', '<Down>']
316
+ let g:ycm_key_list_previous_completion = ['<C-p>', '<Up>']
317
+ let g:SuperTabDefaultCompletionType = '<C-n>'
318
+ " better key bindings for Snippets Expand Trigger
319
+ let g:UltiSnipsExpandTrigger = "<tab>"
320
+ let g:UltiSnipsJumpForwardTrigger = "<tab>"
321
+ let g:UltiSnipsJumpBackwardTrigger = "<s-tab>"
322
+ " Convert all files to unix format on open
323
+ au BufRead,BufNewFile * set ff=unix
324
+ EOF
325
+
326
+ cat >> ${HOME}/.vimrc.bundles.local << EOF
327
+ " Odoo snippets {
328
+ if count(g:spf13_bundle_groups, 'odoovim')
329
+ Bundle 'vim-openerp'
330
+ endif
331
+ " }
332
+ " wakatime bundle {
333
+ if filereadable(expand("~/.wakatime.cfg")) && count(g:spf13_bundle_groups, 'wakatime')
334
+ Bundle 'vim-wakatime'
335
+ endif
336
+ " }
337
+ EOF
338
+
339
+ cat >> ${HOME}/.vimrc.before.local << EOF
340
+ let g:spf13_bundle_groups = ['general', 'writing', 'odoovim', 'wakatime',
341
+ \ 'programming', 'youcompleteme', 'php', 'ruby',
342
+ \ 'python', 'javascript', 'html',
343
+ \ 'misc']
344
+ EOF
345
+ }
346
+
347
+ configure_zsh(){
348
+ if [ -z ${ZSH_INSTALL+x} ];
349
+ then
350
+ echo "ZSH_INSTALL is not defined. Skipping zsh installation."
351
+ return 0;
352
+ fi
353
+ apt update && apt install -y zsh
354
+ wget -O /tmp/install_zsh.sh https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
355
+ ZSH=${HOME}
356
+ sh /tmp/install_zsh.sh "" --unattended
357
+ wget -O /home/odoo/.oh-my-zsh/themes/odoo-shippable.zsh-theme https://gist.githubusercontent.com/schminitz/9931af23bbb59e772eec/raw/cb524246fc93df242696bc3f502cababb03472ec/schminitz.zsh-theme
358
+ sed -i 's/root/home\/odoo/g' /home/odoo/.zshrc
359
+ sed -i 's/robbyrussell/odoo-shippable/g' /home/odoo/.zshrc
360
+ sed -i 's/^plugins=(/plugins=(\n virtualenv\n/' /home/odoo/.zshrc
361
+ # default using bash
362
+ usermod -s /bin/bash root
363
+ usermod -s /bin/bash odoo
364
+ }
@@ -0,0 +1,125 @@
1
+ #!/usr/bin/env python
2
+
3
+ from __future__ import print_function
4
+
5
+ import os
6
+ import subprocess
7
+ import time
8
+ import pwd
9
+
10
+
11
+ def start_psql():
12
+ # Start postgresql service
13
+ if not str2bool(os.environ.get("START_PSQL", True)):
14
+ return
15
+ cmd = "/etc/init.d/postgresql start "
16
+ subprocess.Popen(
17
+ cmd, shell=True, env=os.environ, stdin=None, stdout=None, stderr=None
18
+ )
19
+ print("Waiting to start psql service", end="")
20
+ count = 0
21
+ max_count = 250
22
+ while True:
23
+ print(".", end="")
24
+ psql_subprocess = subprocess.Popen(
25
+ ["psql", "-XtA", "-l"], stdout=subprocess.PIPE, stderr=subprocess.PIPE
26
+ )
27
+ psql_subprocess.wait()
28
+ psql_out = psql_subprocess.stderr.read()
29
+ if b"rol" in psql_out and b"does not exist" in psql_out:
30
+ psql_error = False
31
+ elif psql_out:
32
+ psql_error = True
33
+ else:
34
+ psql_error = False
35
+ if not psql_error or count > max_count:
36
+ break
37
+ time.sleep(4)
38
+ count += 1
39
+ if not psql_error:
40
+ print("...psql service started.")
41
+ else:
42
+ raise RuntimeError("PSQL %s not started." % os.environ.get("PSQL_VERSION", ""))
43
+
44
+ # Fix flaky error when run instance to connect more info:
45
+ # https://www.odoo.com/es_ES/forum/ayuda-1/question/internal-error-index-10107 # noqa
46
+ cmd = [
47
+ "psql",
48
+ os.environ["ODOORC_DB_NAME"],
49
+ "-XtAc",
50
+ "REINDEX INDEX ir_translation_src_hash_idx;",
51
+ ]
52
+ try:
53
+ popen = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
54
+ if popen.wait() == 0:
55
+ print("Reindex created: ", cmd)
56
+ except BaseException:
57
+ pass
58
+ return True
59
+
60
+
61
+ def list_modules(modules_path):
62
+ main_repo_path = os.environ["MAIN_REPO_FULL_PATH"]
63
+ list_modules = []
64
+ excluded_modules = set([module.strip() for module in os.environ.get("EXCLUDE", "").split(",") if module.strip()])
65
+ for i in os.listdir(main_repo_path):
66
+ if i in excluded_modules:
67
+ continue
68
+ manifest = os.path.join(main_repo_path, i, "__manifest__.py")
69
+ if os.path.isfile(manifest):
70
+ manifest_data = eval(open(manifest).read())
71
+ if not manifest_data.get("installable", True):
72
+ continue
73
+ list_modules.append(i)
74
+ return list_modules
75
+
76
+
77
+ def is_root():
78
+ return pwd.getpwuid(os.getuid())[0] == "root"
79
+
80
+
81
+ def str2bool(string):
82
+ return str(string or "").lower() in ["1", "true", "yes"]
83
+
84
+
85
+ def start_odoo():
86
+ if not str2bool(os.environ.get("START_ODOO", True)):
87
+ return
88
+ modules = list_modules(os.environ["MAIN_REPO_FULL_PATH"])
89
+ test_enable = str2bool(os.environ.get("TEST_ENABLE", True))
90
+ cmd = ["/home/odoo/instance/odoo/odoo-bin"]
91
+ psql_cmd = [
92
+ "psql",
93
+ os.environ["ODOORC_DB_NAME"],
94
+ "-XtAc",
95
+ "SELECT 1 FROM res_users LIMIT 1;",
96
+ ]
97
+ if is_root():
98
+ cmd = ["sudo", "-u", "odoo"] + cmd
99
+ psql_cmd = ["sudo", "-u", "postgres"] + psql_cmd
100
+
101
+ try:
102
+ subprocess.check_output(psql_cmd)
103
+ database_created = True
104
+ except subprocess.CalledProcessError:
105
+ database_created = False
106
+
107
+ if not database_created:
108
+ cmd.extend(["-i", ",".join(modules), "--workers=0", "--stop-after-init"])
109
+ if test_enable:
110
+ # TODO: Generate coveragerc
111
+ # cmd.insert(["coverage", "run"])
112
+ cmd.extend(["--test-enable", "--test-tags=/%s" % ",/".join(modules)])
113
+ print(' '.join(cmd))
114
+ subprocess.call(cmd)
115
+
116
+
117
+ def start_ssh():
118
+ if str2bool(os.environ.get("START_SSH")) and is_root():
119
+ subprocess.call("/etc/init.d/ssh start", shell=True)
120
+
121
+
122
+ if __name__ == "__main__":
123
+ start_ssh()
124
+ start_psql()
125
+ start_odoo()