├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── .gitignore ├── .gitlab-ci.yml ├── .gitlab └── issue_templates │ ├── Bug.md │ └── Feature.md ├── .simplecov ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── bin ├── odoo-helper ├── odoo-helper-addons ├── odoo-helper-addons-update ├── odoo-helper-db ├── odoo-helper-fetch ├── odoo-helper-link ├── odoo-helper-log ├── odoo-helper-restart ├── odoo-helper-server ├── odoo-helper-test └── odoo-install ├── defaults └── odoo-helper.conf ├── docs ├── README.md ├── frequently-used-commands.md ├── index.md ├── installation.md ├── odoo-helper-configuration.md ├── odoo-requirements-txt.md ├── project-directory-structure.md └── quick-start-guide.md ├── install-system.bash ├── install-user.bash ├── lib ├── addons.bash ├── ci.bash ├── common.bash ├── config.bash ├── db.bash ├── default_config │ ├── coverage.cfg │ ├── flake8.cfg │ ├── pylint_odoo.cfg │ ├── pylint_odoo_strict.cfg │ ├── stylelint-default-less.json │ ├── stylelint-default-scss.json │ └── stylelint-default.json ├── doc-utils.bash ├── fetch.bash ├── git.bash ├── install.bash ├── link.bash ├── lint.bash ├── main.bash ├── odoo.bash ├── postgres.bash ├── pylib │ ├── bash_unwrap.py │ ├── ci_fix_version.py │ ├── ci_fw_postfixes.py │ ├── jinja-cli.py │ ├── parse_deb_deps.py │ └── py_utils.py ├── recursion.bash ├── scaffold.bash ├── server.bash ├── system.bash ├── templates │ └── scaffold │ │ ├── addon │ │ ├── __init__.py │ │ └── models │ │ │ └── __init__.py │ │ ├── addon__README.rst.tmpl │ │ ├── addon__manifest__.py.tmpl │ │ └── gitignore.tmpl ├── test.bash ├── tr.bash ├── utils.bash └── version.bash ├── mkdocs.yml ├── scripts ├── README.md ├── build_docs.bash ├── build_packages.bash ├── prepare_docs.bash ├── run_docker_test.bash └── serve_docs.bash └── tests ├── ci.bash ├── docker └── Dockerfile └── test.bash /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | 5 | --- 6 | 7 | **Describe the bug** 8 | A clear and concise description of what the bug is. 9 | 10 | **To Reproduce** 11 | Steps to reproduce the behavior: 12 | 13 | **Expected behavior** 14 | A clear and concise description of what you expected to happen. 15 | 16 | **Additional context** 17 | Add any other context about the problem here. 18 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | 5 | --- 6 | 7 | **Is your feature request related to a problem? Please describe.** 8 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 9 | 10 | **Describe the solution you'd like** 11 | A clear and concise description of what you want to happen. 12 | 13 | **Additional context** 14 | Add any other context or screenshots about the feature request here. 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | *.swp 3 | *.swn 4 | *.swo 5 | *.swm 6 | *.pyc 7 | /coverage/ 8 | /venv/ 9 | /site/ 10 | /public/ 11 | /build/ 12 | /docs/release-notes.md 13 | /docs/contributing.md 14 | /docs/command-reference.md 15 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | image: ubuntu:20.04 2 | 3 | variables: 4 | GIT_SUBMODULE_STRATEGY: recursive 5 | CI_RUN: '1' 6 | ODOO_HELPER_INSTALL_PATH: "$CI_PROJECT_DIR" 7 | TEST_TMP_DIR: "/tmp/odoo-helper-tests" 8 | DEBIAN_FRONTEND: 'noninteractive' 9 | ALWAYS_ANSWER_YES: '1' 10 | LANG: 'C.UTF-8' 11 | LC_ALL: 'C.UTF-8' 12 | LANGUAGE: 'C.UTF-8' 13 | PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache" 14 | APT_DIR: "$CI_PROJECT_DIR/.apt-cache" 15 | APT_STATE_LISTS: "$APT_DIR/lists" 16 | APT_CACHE_ARCHIVES: "$APT_DIR/archives" 17 | PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/odoo-helper-scripts" 18 | 19 | cache: 20 | key: ${CI_JOB_NAME} 21 | paths: 22 | - .cache 23 | stages: 24 | - lint 25 | - test 26 | - build 27 | - release 28 | - deploy 29 | 30 | shellcheck: 31 | image: koalaman/shellcheck-alpine:stable 32 | stage: lint 33 | before_script: 34 | - shellcheck --version 35 | script: 36 | - shellcheck -s bash -x -a --color -e "SC1090,SC1091,SC2034" ./bin/* ./lib/*.bash 37 | rules: 38 | - if: $CI_PIPELINE_SOURCE == "merge_request_event" 39 | - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS 40 | when: never 41 | - if: $CI_COMMIT_BRANCH 42 | - if: $CI_COMMIT_TAG !~ /^v\d.*/ 43 | 44 | flake8: 45 | image: python:3 46 | stage: lint 47 | before_script: 48 | - pip install flake8 49 | script: 50 | - flake8 ./lib/pylib/ 51 | rules: 52 | - if: $CI_PIPELINE_SOURCE == "merge_request_event" 53 | - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS 54 | when: never 55 | - if: $CI_COMMIT_BRANCH 56 | - if: $CI_COMMIT_TAG !~ /^v\d.*/ 57 | 58 | 59 | .test:definition: &tests-definition 60 | stage: test 61 | before_script: 62 | # Setup PIP Cache 63 | - mkdir -p .cache && chmod a+rwx -R .cache 64 | 65 | # Install deps 66 | - apt-get update -qq && apt-get install -yqq adduser sudo locales ruby git 67 | - update-locale LANG=C.UTF-8 && update-locale LC_ALL=C.UTF-8 && update-locale LANGUAGE=C.UTF-8 68 | - gem install bashcov -v 1.8.2 69 | - gem install codecov simplecov-console 70 | 71 | # Configure Odoo user 72 | - adduser -q odoo 73 | - echo ' odoo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers 74 | - sudo -u odoo -HE git config --global user.email "test-oh@test.test" 75 | - sudo -u odoo -HE git config --global user.name "test-oh" 76 | script: 77 | - bash install-system.bash 78 | - sudo -u odoo -HE bashcov tests/test.bash 79 | coverage: '/COVERAGE:.*\s+(\d{1,3}\.\d{2}\%)/' 80 | artifacts: 81 | paths: 82 | - coverage 83 | expire_in: 3 day 84 | when: always 85 | rules: 86 | - if: $CI_PIPELINE_SOURCE == "merge_request_event" 87 | - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS 88 | when: never 89 | - if: $CI_COMMIT_BRANCH 90 | 91 | 92 | tests:ubuntu:20.04: 93 | image: ubuntu:20.04 94 | <<: *tests-definition 95 | 96 | tests:ubuntu:22.04: 97 | image: ubuntu:22.04 98 | <<: *tests-definition 99 | 100 | .build:package:base:definition: &build-package-base-def 101 | image: ubuntu:22.04 102 | stage: build 103 | variables: 104 | ODOO_HELPER_ROOT: $CI_PROJECT_DIR 105 | ODOO_HELPER_BIN: $CI_PROJECT_DIR/bin 106 | ODOO_HELPER_LIB: $CI_PROJECT_DIR/lib 107 | before_script: 108 | - apt-get update -qq && apt-get install -qqy ruby ruby-dev make gcc curl 109 | - gem install fpm 110 | 111 | build:package:tag: 112 | <<: *build-package-base-def 113 | script: 114 | - bash scripts/build_packages.bash 115 | after_script: 116 | - 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file "build/odoo-helper-scripts.deb" "${PACKAGE_REGISTRY_URL}/${CI_COMMIT_TAG#v}/odoo-helper-scripts_${CI_COMMIT_TAG#v}.deb"' 117 | rules: 118 | - if: $CI_COMMIT_TAG =~ /^v\d.*/ 119 | 120 | build:package:branch:dev: 121 | <<: *build-package-base-def 122 | script: 123 | - bash scripts/build_packages.bash "${CI_COMMIT_REF_NAME}" 124 | after_script: 125 | - 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file "build/odoo-helper-scripts.deb" "${PACKAGE_REGISTRY_URL}/${CI_COMMIT_REF_NAME}/odoo-helper-scripts_${CI_COMMIT_REF_NAME}.deb"' 126 | when: manual 127 | rules: 128 | - if: $CI_PIPELINE_SOURCE == "merge_request_event" 129 | 130 | build:package:branch:master: 131 | <<: *build-package-base-def 132 | script: 133 | - bash scripts/build_packages.bash "${CI_COMMIT_REF_NAME}" 134 | after_script: 135 | - 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file "build/odoo-helper-scripts.deb" "${PACKAGE_REGISTRY_URL}/${CI_COMMIT_REF_NAME}/odoo-helper-scripts_${CI_COMMIT_REF_NAME}.deb"' 136 | rules: 137 | - if: $CI_COMMIT_BRANCH == "master" 138 | 139 | do_release:tag: 140 | stage: release 141 | image: registry.gitlab.com/gitlab-org/release-cli:latest 142 | rules: 143 | # Run this job when a tag is created manually 144 | - if: $CI_COMMIT_TAG =~ /^v\d.*/ 145 | before_script: 146 | - apk add coreutils 147 | script: 148 | - echo "Preparing release $CI_COMMIT_TAG." 149 | - csplit --prefix=CHANGELOG. --suffix=%02d.md CHANGELOG.md '/---/' 150 | release: 151 | tag_name: $CI_COMMIT_TAG 152 | name: "${CI_COMMIT_TAG}" 153 | description: "./CHANGELOG.00.md" 154 | assets: 155 | links: 156 | - name: "odoo-helper-scripts_${CI_COMMIT_TAG}.deb" 157 | url: "$PACKAGE_REGISTRY_URL/${CI_COMMIT_TAG#v}/odoo-helper-scripts_${CI_COMMIT_TAG#v}.deb" 158 | link_type: "package" 159 | 160 | pages: 161 | image: ubuntu:20.04 162 | stage: deploy 163 | before_script: 164 | - apt-get update 165 | - apt-get install -y python3-pip 166 | - bash install-system.bash 167 | - python3 -m pip install mkdocs mkdocs-cinder==0.14.0 168 | script: 169 | - bash scripts/build_docs.bash 170 | artifacts: 171 | paths: 172 | - public 173 | rules: 174 | - if: $CI_COMMIT_BRANCH == "master" 175 | -------------------------------------------------------------------------------- /.gitlab/issue_templates/Bug.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | 5 | --- 6 | 7 | **Describe the bug** 8 | A clear and concise description of what the bug is. 9 | 10 | **To Reproduce** 11 | Steps to reproduce the behavior: 12 | 13 | **Expected behavior** 14 | A clear and concise description of what you expected to happen. 15 | 16 | **Additional context** 17 | Add any other context about the problem here. 18 | -------------------------------------------------------------------------------- /.gitlab/issue_templates/Feature.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | 5 | --- 6 | 7 | **Is your feature request related to a problem? Please describe.** 8 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 9 | 10 | **Describe the solution you'd like** 11 | A clear and concise description of what you want to happen. 12 | 13 | **Additional context** 14 | Add any other context or screenshots about the feature request here. 15 | -------------------------------------------------------------------------------- /.simplecov: -------------------------------------------------------------------------------- 1 | require 'simplecov' 2 | require 'simplecov-console' 3 | 4 | SimpleCov.start do 5 | SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([ 6 | SimpleCov::Formatter::HTMLFormatter, 7 | SimpleCov::Formatter::Console 8 | ]) 9 | add_filter ".git/" 10 | add_filter "/tmp/odoo-helper-tests/" 11 | add_filter "run_docker_test.bash" 12 | add_filter "scripts/" 13 | add_filter "tests/ci.bash" 14 | add_filter "tools/virtualenv" 15 | end 16 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to odoo-helper-scripts 2 | 3 | Thank you for your interest in contributing to odoo-helper-scripts! 4 | 5 | ## Contributing to this project 6 | 7 | 1. Fork the repository on [GitHub](https://github.com/katyukha/odoo-helper-scripts) or [GitLab](https://gitlab.com/katyukha/odoo-helper-scripts/) 8 | 2. Create a new branch, e.g., `git checkout -b bug-12345` based on `dev` branch 9 | 3. Fix the bug or add the feature 10 | 4. Add or modify related help message (if necessary) 11 | 5. Add or modify documentation (if necessary) for your change 12 | 6. Add changelog entry for your change in *Unreleased* section 13 | 7. Commit and push it to your fork 14 | 8. Create Merge Request or Pull Request 15 | 16 | ## How to build documentation 17 | 18 | Install [MkDocs](https://www.mkdocs.org/) 19 | 20 | ```bash 21 | pip install mkdocs 22 | ``` 23 | 24 | Run `build_docs` script in repository root. 25 | 26 | ```bash 27 | ./scripts/build_docs.sh 28 | ``` 29 | 30 | Run MkDocs built-in dev server with following command in repository root. 31 | 32 | ```bash 33 | mkdocs serve 34 | ``` 35 | 36 | Generated documentation will be available at `http://127.0.0.1:8000/`. 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Odoo helper scripts collection 2 | 3 | | Master | [![pipeline status](https://gitlab.com/katyukha/odoo-helper-scripts/badges/master/pipeline.svg)](https://gitlab.com/katyukha/odoo-helper-scripts/commits/master) | [![coverage report](https://gitlab.com/katyukha/odoo-helper-scripts/badges/master/coverage.svg)](https://gitlab.com/katyukha/odoo-helper-scripts/commits/master)| [![CHANGELOG](https://img.shields.io/badge/CHANGELOG-master-brightgreen.svg)](https://gitlab.com/katyukha/odoo-helper-scripts/blob/master/CHANGELOG.md) | 4 | | ------------- |:---------------|:--------------|:------------| 5 | | Dev | [![pipeline status](https://gitlab.com/katyukha/odoo-helper-scripts/badges/dev/pipeline.svg)](https://gitlab.com/katyukha/odoo-helper-scripts/commits/dev) | [![coverage report](https://gitlab.com/katyukha/odoo-helper-scripts/badges/dev/coverage.svg)](https://gitlab.com/katyukha/odoo-helper-scripts/commits/dev) | [![CHANGELOG](https://img.shields.io/badge/CHANGELOG-dev-yellow.svg)](https://gitlab.com/katyukha/odoo-helper-scripts/blob/dev/CHANGELOG.md) | 6 | 7 | ## Overview 8 | 9 | This project aims to simplify development process of Odoo addons as much as possible. 10 | 11 | odoo-helper-scripts will do all routine operations for you: 12 | - install odoo with ALL dependencies (even those not mentioned in odoo's requirements.txt like [python-slugify](https://pypi.org/project/python-slugify/)) 13 | - manage local development databases 14 | - install custom addons 15 | - check if versions of modules are updated before pushing changes. 16 | - generate / regenerate translations 17 | - run tests 18 | - and a lot more 19 | 20 | If you have any routine operation that you would like to automate with odoo-helper-scripts, 21 | just fill an issue or do pull request, and may be that feature will be available in one of next releases. 22 | 23 | ***WARNING***: If you want to deploy production-ready odoo server, 24 | please, read carefully [Usage notes](#usage-note) section. 25 | 26 | ## The War in Ukraine 27 | 28 | 2022-02-24 Russia invaded Ukraine... 29 | 30 | If you want to help or support Ukraine to stand against russian inavasion, 31 | please, visit [the official site of Ukraine](https://war.ukraine.ua/) 32 | and find the best way to do it. 33 | 34 | Thanks. 35 | 36 | ## Canonical source 37 | 38 | The canonical source of odoo-helper-scripts is hosted on [GitLab](https://gitlab.com/katyukha/odoo-helper-scripts). 39 | 40 | ## Features 41 | 42 | - Easily manage multiple instances of Odoo that ran on same machine 43 | - Wide usage of [virtualenv](https://virtualenv.pypa.io/en/stable/) for isolation purpose 44 | - Use [nodeenv](https://pypi.python.org/pypi/nodeenv) to install [node.js](https://nodejs.org/en/), [phantom.js](http://phantomjs.org/), etc in isolated [virtualenv](https://virtualenv.pypa.io/en/stable/) 45 | - The easiest way to install Odoo for development purposes (but not limited to development) 46 | - single command to install odoo 47 | - ability to build custom python for odoo 48 | - Powerful testing capabilities, including support for: 49 | - *python* and *js* code check via [pylint\_odoo](https://pypi.python.org/pypi/pylint-odoo) (which uses [ESLint](https://eslint.org/) to check JS files) 50 | - *python* code check via [flake8](https://pypi.python.org/pypi/flake8) 51 | - styles (*.css*, *.scss*, *.less* files) check via [stylelint](https://stylelint.io/) 52 | - compute test code coverage via [coverage.py](https://coverage.readthedocs.io) 53 | - Test web tours via [phantom.js](http://phantomjs.org/) or *chromium browser* (Odoo 12.0+) 54 | - Easy addons installation 55 | - Automatiacly resolve and fetch dependencies 56 | - oca\_dependencies.txt ([sample](https://github.com/OCA/maintainer-quality-tools/blob/master/sample_files/oca_dependencies.txt), [mqt tool code](https://github.com/OCA/maintainer-quality-tools/blob/master/sample_files/oca_dependencies.txt)) 57 | - [requirements.txt](https://pip.readthedocs.io/en/stable/user_guide/#requirements-files) 58 | - Own file format to track addon dependencies: [odoo\_requirements.txt](https://katyukha.gitlab.io/odoo-helper-scripts/odoo-requirements-txt/) 59 | - installation directly from [Odoo Market](https://apps.odoo.com/apps) (**experimental**) 60 | - Only free addons 61 | - Including dependencies 62 | - Semi-automatic upgrade when new version released 63 | - installation from *git* repositories 64 | - installation of python dependencies from [PyPI](pypi.python.org/pypi) or any [vcs supported by setuptools](https://setuptools.readthedocs.io/en/latest/setuptools.html?highlight=develop%20mode#dependencies-that-aren-t-in-pypi) 65 | - automatically processing of [requirements.txt](https://pip.pypa.io/en/stable/user_guide/#requirements-files) files located inside repository root and addon directories. 66 | - shortcuts that simplifies fetching addons from [OCA](https://github.com/OCA) or [github](https://github.com) 67 | - works good with long recursive dependencies. 68 | One of the reasons for this script collection development was, 69 | ability to automaticaly install more that 50 addons, 70 | that depend on each other, and where each addon have it's own git repo. 71 | - Easy database management 72 | - easily create / drop / backup / rename / copy databases 73 | - Continious Integration related features 74 | - ensure addon version changed 75 | - ensure repository version changed 76 | - ensure each addon have icon 77 | - ensure all changed addon has correct versions 78 | - simplify forward-port process (move changes from older serie to newer (for example from 11.0 to 12.0)) 79 | - Translation management from command line 80 | - import / export translations by command from shell 81 | - test translation rate for specified language 82 | - regenerate translations for specified language 83 | - generate *.pot* files for modules 84 | - load language (for one db or for old databases) 85 | - Supported odoo versions: 86 | - *8.0* 87 | - *9.0* 88 | - *10.0* 89 | - *11.0* 90 | - *12.0* 91 | - *13.0* 92 | - *14.0* 93 | - *15.0* 94 | - *16.0* 95 | - *17.0* 96 | - *18.0* (**Experimental**) 97 | - OS support: 98 | - On *Ubuntu* should work nice (auto tested on *Ubuntu 20.04, 22.04*) 99 | - Also should work on *Debian* based systems, but some troubles may happen with installation of system dependencies. 100 | - Other linux systems - in most cases should work, but system dependecies must be installed manualy. 101 | - Missed feature? [Fill an issue](https://gitlab.com/katyukha/odoo-helper-scripts/issues/new) 102 | 103 | 104 | ## Documentation 105 | 106 | ***Note*** Documentaion in this readme, or in other sources, may not be up to date!!! 107 | So use ``--help`` option, which is available for most of commands. 108 | 109 | - [Documentation](https://katyukha.gitlab.io/odoo-helper-scripts/) 110 | - [Installation](https://katyukha.gitlab.io/odoo-helper-scripts/installation/) 111 | - [Frequently used commands](https://katyukha.gitlab.io/odoo-helper-scripts/frequently-used-commands/) 112 | - [Command Reference](https://katyukha.gitlab.io/odoo-helper-scripts/command-reference/) 113 | 114 | 115 | ## Usage note 116 | 117 | This script collection is designed to simplify life of addons developer. 118 | This project ***is not designed, to install and configure production ready Odoo instances***, unless you know what you do! 119 | 120 | For **production-ready** installations take a look at [crnd-deploy](http://github.com/crnd-inc/crnd-deploy) project - just a single command allows you to get production-ready odoo instance with configured [PostgreSQL](https://www.postgresql.org/) and [Nginx](https://nginx.org/). 121 | 122 | Also take a look at [Yodoo Cockpit](https://crnd.pro/yodoo-cockpit) project, and discover the easiest way to manage your production Odoo installations with automated billing and support of custom addons. 123 | 124 | [![Yodoo Cockpit](https://crnd.pro/web/image/18846/banner_2_4_gif_animation_cut.gif)](https://crnd.pro/yodoo-cockpit) 125 | 126 | Just short notes about [Yodoo Cockpit](https://crnd.pro/yodoo-cockpit): 127 | - start new production-ready odoo instance in 1-2 minutes. 128 | - add custom addons to your odoo instances in 5-10 minutes. 129 | - out-of-the-box email configuration: just press button and add some records to your DNS, and get a working email 130 | - make your odoo instance available to external world (internet) in 30 seconds (just add single record in your DNS) 131 | 132 | 133 | ## Level up your service quality 134 | 135 | Level up your service quality with [Helpdesk](https://crnd.pro/solutions/helpdesk) / [Service Desk](https://crnd.pro/solutions/service-desk) / [ITSM](https://crnd.pro/itsm) solution by [CR&D](https://crnd.pro/). 136 | 137 | Just test it at [yodoo.systems](https://yodoo.systems/saas/templates): choose template you like, and start working. 138 | 139 | Test all available features of [Bureaucrat ITSM](https://crnd.pro/itsm) with [this template](https://yodoo.systems/saas/template/bureaucrat-itsm-demo-data-95). 140 | 141 | 142 | ## Installation 143 | 144 | For full list of installation options look at [installation documentation](https://katyukha.gitlab.io/odoo-helper-scripts/installation/) 145 | 146 | Basically, odoo-helper could be installed in two way: 147 | - Traditional installation via shell script 148 | - Installation via deb package (still experimental) 149 | 150 | ### Traditional installation 151 | 152 | To install *odoo-helper-scripts* system-wide (the recommended way) do folowing: 153 | 154 | ```bash 155 | # Install odoo-helper-scripts 156 | wget -O - https://gitlab.com/katyukha/odoo-helper-scripts/raw/master/install-system.bash | sudo bash -s 157 | 158 | # Install system dependencies required for odoo-helper-scripts 159 | # NOTE: Works only on debian-based systems 160 | odoo-helper install pre-requirements 161 | ``` 162 | 163 | or more explicit way: 164 | 165 | ```bash 166 | # Download installation script 167 | wget -O /tmp/odoo-helper-install.bash https://gitlab.com/katyukha/odoo-helper-scripts/raw/master/install-system.bash; 168 | 169 | # Install odoo-helper-scripts 170 | sudo bash /tmp/odoo-helper-install.bash; 171 | 172 | # Intall system pre-requirements for odoo-helper-scripts 173 | # NOTE: Works only on debian-based systems 174 | odoo-helper install pre-requirements 175 | ``` 176 | 177 | ### Installation as deb package 178 | 179 | Also, you can install *odoo-helper-scripts* as debian package. See [releases](https://gitlab.com/katyukha/odoo-helper-scripts/-/releases) page. 180 | To install the latest **stable** version just download and install following deb package: [odoo-helper-scripts_master.deb](https://gitlab.com/api/v4/projects/6823247/packages/generic/odoo-helper-scripts/master/odoo-helper-scripts_master.deb) 181 | 182 | 183 | ## Test your OS support 184 | 185 | It is possible to run basic tests via docker. 186 | For this task, odoo-helper-scripts repo contains script `scripts/run_docker_test.bash`. 187 | Run `bash scripts/run_docker_test.bash --help` to see all available options for that script. 188 | 189 | For example to test, how odoo-helper-scripts will work on debian:stretch, do following: 190 | 191 | ```bash 192 | cd $ODOO_HELPER_ROOT 193 | bash scripts/run_docker_test.bash --docker-ti --docker-image debian:stretch 194 | ``` 195 | 196 | Note, running tests may take more then 1:30 hours. 197 | 198 | 199 | ## Usage 200 | 201 | And after install you will have available folowing scripts in your path: 202 | 203 | - odoo-install 204 | - odoo-helper 205 | 206 | Each script have `-h` or `--help` option which display most relevant information 207 | about script and all possible options and subcommands of script 208 | 209 | Also there are some aliases for common commands: 210 | 211 | - odoo-helper-addons 212 | - odoo-helper-db 213 | - odoo-helper-fetch 214 | - odoo-helper-log 215 | - odoo-helper-restart 216 | - odoo-helper-server 217 | - odoo-helper-test 218 | 219 | For more info look at [documentation](https://katyukha.gitlab.io/odoo-helper-scripts/). (currently documentation status is *work-in-progress*). 220 | Also look at [Frequently used commands](https://katyukha.gitlab.io/odoo-helper-scripts/frequently-used-commands/) and [Command reference](https://katyukha.gitlab.io/odoo-helper-scripts/command-reference/) 221 | 222 | Also look at [odoo-helper-scripts tests](./tests/test.bash) to get complete usage example (look for *Start test* comment). 223 | 224 | ## Support 225 | 226 | Have you any quetions? Just [fill an issue](https://gitlab.com/katyukha/odoo-helper-scripts/issues/new) or [send email](mailto:incoming+katyukha/odoo-helper-scripts@incoming.gitlab.com) 227 | -------------------------------------------------------------------------------- /bin/odoo-helper: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright © 2015-2018 Dmytro Katyukha 4 | 5 | ####################################################################### 6 | # This Source Code Form is subject to the terms of the Mozilla Public # 7 | # License, v. 2.0. If a copy of the MPL was not distributed with this # 8 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. # 9 | ####################################################################### 10 | 11 | 12 | # Use odoo-helper --help for a documentation 13 | 14 | 15 | SCRIPT=$0; 16 | SCRIPT_NAME=$(basename "$SCRIPT"); 17 | WORKDIR=$(pwd); 18 | 19 | # load basic conf 20 | if [ -f "/etc/odoo-helper.conf" ]; then 21 | source "/etc/odoo-helper.conf"; 22 | fi 23 | if [ -f "$HOME/odoo-helper.conf" ]; then 24 | source "$HOME/odoo-helper.conf"; 25 | fi 26 | # ----------- 27 | 28 | set -e; # Fail on errors 29 | 30 | 31 | if [ -z "$ODOO_HELPER_LIB" ]; then 32 | echo "Odoo-helper-scripts seems not been installed correctly."; 33 | echo "Reinstall it (see Readme on https://gitlab.com/katyukha/odoo-helper-scripts/)"; 34 | exit 1; 35 | fi 36 | 37 | if [ -z "$ODOO_HELPER_COMMON_IMPORTED" ]; then 38 | source "$ODOO_HELPER_LIB/common.bash"; 39 | fi 40 | 41 | ohelper_require "main"; 42 | 43 | # Run odoo-helper main 44 | odoo_helper_main "$@"; 45 | -------------------------------------------------------------------------------- /bin/odoo-helper-addons: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright © 2016-2018 Dmytro Katyukha 4 | 5 | ####################################################################### 6 | # This Source Code Form is subject to the terms of the Mozilla Public # 7 | # License, v. 2.0. If a copy of the MPL was not distributed with this # 8 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. # 9 | ####################################################################### 10 | 11 | 12 | # Use odoo-helper --help for a documentation 13 | 14 | 15 | SCRIPT=$0; 16 | SCRIPT_NAME=$(basename "$SCRIPT"); 17 | F=$(readlink -f "$SCRIPT"); # full script path; 18 | WORKDIR=$(pwd); 19 | 20 | 21 | # load basic conf 22 | if [ -f "/etc/odoo-helper.conf" ]; then 23 | source "/etc/odoo-helper.conf"; 24 | fi 25 | if [ -f "$HOME/odoo-helper.conf" ]; then 26 | source "$HOME/odoo-helper.conf"; 27 | fi 28 | # ----------- 29 | 30 | set -e; # Fail on errors 31 | 32 | 33 | if [ -z "$ODOO_HELPER_BIN" ]; then 34 | echo "Odoo-helper-scripts seems not been installed correctly."; 35 | echo "Reinstall it (see Readme on https://gitlab.com/katyukha/odoo-helper-scripts/)"; 36 | exit 1; 37 | fi 38 | 39 | "$ODOO_HELPER_BIN/odoo-helper" addons "$@"; 40 | -------------------------------------------------------------------------------- /bin/odoo-helper-addons-update: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright © 2019 Dmytro Katyukha 4 | 5 | ####################################################################### 6 | # This Source Code Form is subject to the terms of the Mozilla Public # 7 | # License, v. 2.0. If a copy of the MPL was not distributed with this # 8 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. # 9 | ####################################################################### 10 | 11 | 12 | # Use odoo-helper --help for a documentation 13 | 14 | SCRIPT=$0; 15 | SCRIPT_NAME=$(basename "$SCRIPT"); 16 | F=$(readlink -f "$SCRIPT"); # full script path; 17 | WORKDIR=$(pwd); 18 | 19 | 20 | # load basic conf 21 | if [ -f "/etc/odoo-helper.conf" ]; then 22 | source "/etc/odoo-helper.conf"; 23 | fi 24 | if [ -f "$HOME/odoo-helper.conf" ]; then 25 | source "$HOME/odoo-helper.conf"; 26 | fi 27 | # ----------- 28 | 29 | set -e; # Fail on errors 30 | 31 | 32 | if [ -z "$ODOO_HELPER_BIN" ]; then 33 | echo "Odoo-helper-scripts seems not been installed correctly."; 34 | echo "Reinstall it (see Readme on https://gitlab.com/katyukha/odoo-helper-scripts/)"; 35 | exit 1; 36 | fi 37 | 38 | "$ODOO_HELPER_BIN/odoo-helper" addons update "$@"; 39 | -------------------------------------------------------------------------------- /bin/odoo-helper-db: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright © 2016-2018 Dmytro Katyukha 4 | 5 | ####################################################################### 6 | # This Source Code Form is subject to the terms of the Mozilla Public # 7 | # License, v. 2.0. If a copy of the MPL was not distributed with this # 8 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. # 9 | ####################################################################### 10 | 11 | 12 | # Use odoo-helper --help for a documentation 13 | 14 | 15 | SCRIPT=$0; 16 | SCRIPT_NAME=$(basename "$SCRIPT"); 17 | F=$(readlink -f "$SCRIPT"); # full script path; 18 | WORKDIR=$(pwd); 19 | 20 | 21 | # load basic conf 22 | if [ -f "/etc/odoo-helper.conf" ]; then 23 | source "/etc/odoo-helper.conf"; 24 | fi 25 | if [ -f "$HOME/odoo-helper.conf" ]; then 26 | source "$HOME/odoo-helper.conf"; 27 | fi 28 | # ----------- 29 | 30 | set -e; # Fail on errors 31 | 32 | 33 | if [ -z "$ODOO_HELPER_BIN" ]; then 34 | echo "Odoo-helper-scripts seems not been installed correctly."; 35 | echo "Reinstall it (see Readme on https://gitlab.com/katyukha/odoo-helper-scripts/)"; 36 | exit 1; 37 | fi 38 | 39 | "$ODOO_HELPER_BIN/odoo-helper" db "$@"; 40 | -------------------------------------------------------------------------------- /bin/odoo-helper-fetch: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright © 2016-2018 Dmytro Katyukha 4 | 5 | ####################################################################### 6 | # This Source Code Form is subject to the terms of the Mozilla Public # 7 | # License, v. 2.0. If a copy of the MPL was not distributed with this # 8 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. # 9 | ####################################################################### 10 | 11 | 12 | # Use odoo-helper --help for a documentation 13 | 14 | SCRIPT=$0; 15 | SCRIPT_NAME=$(basename "$SCRIPT"); 16 | F=$(readlink -f "$SCRIPT"); # full script path; 17 | WORKDIR=$(pwd); 18 | 19 | 20 | # load basic conf 21 | if [ -f "/etc/odoo-helper.conf" ]; then 22 | source "/etc/odoo-helper.conf"; 23 | fi 24 | if [ -f "$HOME/odoo-helper.conf" ]; then 25 | source "$HOME/odoo-helper.conf"; 26 | fi 27 | # ----------- 28 | 29 | set -e; # Fail on errors 30 | 31 | 32 | if [ -z "$ODOO_HELPER_BIN" ]; then 33 | echo "Odoo-helper-scripts seems not been installed correctly."; 34 | echo "Reinstall it (see Readme on https://gitlab.com/katyukha/odoo-helper-scripts/)"; 35 | exit 1; 36 | fi 37 | 38 | "$ODOO_HELPER_BIN/odoo-helper" fetch "$@"; 39 | -------------------------------------------------------------------------------- /bin/odoo-helper-link: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright © 2019 Dmytro Katyukha 4 | 5 | ####################################################################### 6 | # This Source Code Form is subject to the terms of the Mozilla Public # 7 | # License, v. 2.0. If a copy of the MPL was not distributed with this # 8 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. # 9 | ####################################################################### 10 | 11 | 12 | # Use odoo-helper --help for a documentation 13 | 14 | SCRIPT=$0; 15 | SCRIPT_NAME=$(basename "$SCRIPT"); 16 | F=$(readlink -f "$SCRIPT"); # full script path; 17 | WORKDIR=$(pwd); 18 | 19 | 20 | # load basic conf 21 | if [ -f "/etc/odoo-helper.conf" ]; then 22 | source "/etc/odoo-helper.conf"; 23 | fi 24 | if [ -f "$HOME/odoo-helper.conf" ]; then 25 | source "$HOME/odoo-helper.conf"; 26 | fi 27 | # ----------- 28 | 29 | set -e; # Fail on errors 30 | 31 | 32 | if [ -z "$ODOO_HELPER_BIN" ]; then 33 | echo "Odoo-helper-scripts seems not been installed correctly."; 34 | echo "Reinstall it (see Readme on https://gitlab.com/katyukha/odoo-helper-scripts/)"; 35 | exit 1; 36 | fi 37 | 38 | "$ODOO_HELPER_BIN/odoo-helper" link "$@"; 39 | -------------------------------------------------------------------------------- /bin/odoo-helper-log: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright © 2017-2018 Dmytro Katyukha 4 | 5 | ####################################################################### 6 | # This Source Code Form is subject to the terms of the Mozilla Public # 7 | # License, v. 2.0. If a copy of the MPL was not distributed with this # 8 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. # 9 | ####################################################################### 10 | 11 | 12 | # Use odoo-helper --help for a documentation 13 | 14 | SCRIPT=$0; 15 | SCRIPT_NAME=$(basename "$SCRIPT"); 16 | F=$(readlink -f "$SCRIPT"); # full script path; 17 | WORKDIR=$(pwd); 18 | 19 | 20 | # load basic conf 21 | if [ -f "/etc/odoo-helper.conf" ]; then 22 | source "/etc/odoo-helper.conf"; 23 | fi 24 | if [ -f "$HOME/odoo-helper.conf" ]; then 25 | source "$HOME/odoo-helper.conf"; 26 | fi 27 | # ----------- 28 | 29 | set -e; # Fail on errors 30 | 31 | 32 | if [ -z "$ODOO_HELPER_BIN" ]; then 33 | echo "Odoo-helper-scripts seems not been installed correctly."; 34 | echo "Reinstall it (see Readme on https://gitlab.com/katyukha/odoo-helper-scripts/)"; 35 | exit 1; 36 | fi 37 | 38 | "$ODOO_HELPER_BIN/odoo-helper" log "$@"; 39 | -------------------------------------------------------------------------------- /bin/odoo-helper-restart: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright © 2017-2018 Dmytro Katyukha 4 | 5 | ####################################################################### 6 | # This Source Code Form is subject to the terms of the Mozilla Public # 7 | # License, v. 2.0. If a copy of the MPL was not distributed with this # 8 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. # 9 | ####################################################################### 10 | 11 | 12 | # Use odoo-helper --help for a documentation 13 | 14 | SCRIPT=$0; 15 | SCRIPT_NAME=$(basename "$SCRIPT"); 16 | F=$(readlink -f "$SCRIPT"); # full script path; 17 | WORKDIR=$(pwd); 18 | 19 | 20 | # load basic conf 21 | if [ -f "/etc/odoo-helper.conf" ]; then 22 | source "/etc/odoo-helper.conf"; 23 | fi 24 | if [ -f "$HOME/odoo-helper.conf" ]; then 25 | source "$HOME/odoo-helper.conf"; 26 | fi 27 | # ----------- 28 | 29 | set -e; # Fail on errors 30 | 31 | 32 | if [ -z "$ODOO_HELPER_BIN" ]; then 33 | echo "Odoo-helper-scripts seems not been installed correctly."; 34 | echo "Reinstall it (see Readme on https://gitlab.com/katyukha/odoo-helper-scripts/)"; 35 | exit 1; 36 | fi 37 | 38 | "$ODOO_HELPER_BIN/odoo-helper" server restart "$@"; 39 | -------------------------------------------------------------------------------- /bin/odoo-helper-server: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright © 2016-2018 Dmytro Katyukha 4 | 5 | ####################################################################### 6 | # This Source Code Form is subject to the terms of the Mozilla Public # 7 | # License, v. 2.0. If a copy of the MPL was not distributed with this # 8 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. # 9 | ####################################################################### 10 | 11 | 12 | # Use odoo-helper --help for a documentation 13 | 14 | SCRIPT=$0; 15 | SCRIPT_NAME=$(basename "$SCRIPT"); 16 | F=$(readlink -f "$SCRIPT"); # full script path; 17 | WORKDIR=$(pwd); 18 | 19 | 20 | # load basic conf 21 | if [ -f "/etc/odoo-helper.conf" ]; then 22 | source "/etc/odoo-helper.conf"; 23 | fi 24 | if [ -f "$HOME/odoo-helper.conf" ]; then 25 | source "$HOME/odoo-helper.conf"; 26 | fi 27 | # ----------- 28 | 29 | set -e; # Fail on errors 30 | 31 | 32 | if [ -z "$ODOO_HELPER_BIN" ]; then 33 | echo "Odoo-helper-scripts seems not been installed correctly."; 34 | echo "Reinstall it (see Readme on https://gitlab.com/katyukha/odoo-helper-scripts/)"; 35 | exit 1; 36 | fi 37 | 38 | "$ODOO_HELPER_BIN/odoo-helper" server "$@"; 39 | -------------------------------------------------------------------------------- /bin/odoo-helper-test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright © 2016-2018 Dmytro Katyukha 4 | 5 | ####################################################################### 6 | # This Source Code Form is subject to the terms of the Mozilla Public # 7 | # License, v. 2.0. If a copy of the MPL was not distributed with this # 8 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. # 9 | ####################################################################### 10 | 11 | 12 | # Use odoo-helper --help for a documentation 13 | 14 | SCRIPT=$0; 15 | SCRIPT_NAME=$(basename "$SCRIPT"); 16 | F=$(readlink -f "$SCRIPT"); # full script path; 17 | WORKDIR=$(pwd); 18 | 19 | 20 | # load basic conf 21 | if [ -f "/etc/odoo-helper.conf" ]; then 22 | source "/etc/odoo-helper.conf"; 23 | fi 24 | if [ -f "$HOME/odoo-helper.conf" ]; then 25 | source "$HOME/odoo-helper.conf"; 26 | fi 27 | # ----------- 28 | 29 | set -e; # Fail on errors 30 | 31 | 32 | if [ -z "$ODOO_HELPER_BIN" ]; then 33 | echo "Odoo-helper-scripts seems not been installed correctly."; 34 | echo "Reinstall it (see Readme on https://gitlab.com/katyukha/odoo-helper-scripts/)"; 35 | exit 1; 36 | fi 37 | 38 | "$ODOO_HELPER_BIN/odoo-helper" test "$@"; 39 | -------------------------------------------------------------------------------- /defaults/odoo-helper.conf: -------------------------------------------------------------------------------- 1 | ODOO_HELPER_ROOT=/opt/odoo-helper-scripts; 2 | ODOO_HELPER_BIN=/opt/odoo-helper-scripts/bin; 3 | ODOO_HELPER_LIB=/opt/odoo-helper-scripts/lib; 4 | 5 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # Documentation 2 | 3 | Look for documentation [here](https://katyukha.gitlab.io/odoo-helper-scripts/) 4 | -------------------------------------------------------------------------------- /docs/frequently-used-commands.md: -------------------------------------------------------------------------------- 1 | ## Frequently used command 2 | 3 | Brief list of frequently used odoo-helper commands 4 | 5 | ### Odoo server management 6 | - `odoo-helper start` - start odoo server 7 | - `odoo-helper restart` - restart odoo server 8 | - `odoo-helper stop` - stop odoo-helper server 9 | - `odoo-helper log` - see odoo server logs 10 | - `odoo-helper ps` - display odoo server processes for current project 11 | - `odoo-helper browse` - open running odoo installation in browser 12 | 13 | ### Odoo addons management 14 | - `odoo-helper addons list ` - list odoo addons in specified directory 15 | - `odoo-helper addons update-list` - update list of available addons in all databases available for this server 16 | - `odoo-helper addons install [addonn]` - install specified odoo addons for all databases available for this server 17 | - `odoo-helper addons update [addonn]` - update specified odoo addons for all databases available for this server 18 | - `odoo-helper addons uninstall [addonn]` - uninstall specified odoo addons for all databases available for this server 19 | - `odoo-helper addons update --dir ` - find all installable addons in specified directory and update them 20 | - `odoo-helper addons install --dir ` - find all installable addons in specified directory and install them 21 | 22 | ### Postgres related 23 | - `odoo-helper postgres psql [-d database]` - connect to db via psql (same credentials as used by odoo server) 24 | - `odoo-helper psql [-d database]` - shortcut for `odoo-helper postgres psql` command 25 | - `sudo odoo-helper postgres user-create ` - create postgres user for odoo 26 | - `odoo-helper postgres stat-activity` - list running postgres queries 27 | - `odoo-helper postgres stat-connections` - show postgres connections statistics 28 | 29 | ### Tests 30 | - `odoo-helper test -m ` - test single module 31 | - `odoo-helper test --dir .` - test all installable addons in current directory 32 | - `odoo-helper test --coverage-html -m ` - test single module and create html coverage report in current dir 33 | - `odoo-helper test --coverage-html --dir .` - test all installable addons in current directory and create html coverage report in current dir 34 | - `odoo-helper test -m --recreate-db` - test single module, but recreate test database first 35 | - `odoo-helper test -m --create-test-db` - test single module on just created clean database. database dropt after tests 36 | 37 | ### Linters 38 | - `odoo-helper lint pylint .` - run [pylint](https://www.pylint.org/) with [pylint\_odoo](https://pypi.org/project/pylint-odoo/) for all addons in current directory 39 | - `odoo-helper lint flake8 .` - run [flake8](http://flake8.pycqa.org/en/latest/) for all addons in current directory 40 | - `odoo-helper lint style .` - run [stylelint](https://stylelint.io/) for all addons in current directories 41 | - `odoo-helper pylint` - alias for `odoo-helper lint pylint` 42 | - `odoo-helper flake8` - alias for `odoo-helper lint flake8` 43 | - `odoo-helper style` - alias for odoo-helper lint style` 44 | 45 | ### Fetch addons 46 | - `odoo-helper link .` - create symlinks for all addons in current directory in `custom_addons` folder to make them visible for odoo 47 | - `odoo-helper fetch --oca web` - fetch all addons from [OCA](https://odoo-community.org/) repository [web](https://github.com/OCA/web) 48 | - `odoo-helper fetch --github ` - fetch all addons from spcified [github](https://github.com) repository 49 | - `odoo-helper fetch --repo --branch 11.0` - fetch all addons from specified *git* repository 50 | 51 | ### Database management 52 | - `odoo-helper db list` - list all databases available for current odoo instance 53 | - `odoo-helper db create my_db` - create database 54 | - `odoo-helper db backup my_db zip` - backup *my\_db* as ZIP archive (with filestore) 55 | - `odoo-helper db backup my_db sql` - backup *my\_db* as SQL dump only (without filestore) 56 | - `odoo-helper db drop my_db` - drop database 57 | 58 | ### Translation management 59 | - `odoo-helper tr regenerate --lang uk_UA --file uk [addon2]...` - regenerate translations for specified language for specified addons 60 | - `odoo-helper tr regenerate --lang uk_UA --file uk --dir ` - regenerate translations for specified language for all installable addon in specified path 61 | - `odoo-helper tr rate --lang uk_UA [addon2]...` - print translation rate for specified addons 62 | - `odoo-helper tr rate --lang uk_UA --dir ` - print translation rate for all installable addons in specified directory 63 | 64 | ### Other 65 | - `odoo-helper pip` - run [pip](https://pypi.org/project/pip/) inside current project's virtual environment [virtualenv](https://virtualenv.pypa.io/en/stable/). 66 | - `odoo-helper npm` - run [npm](https://www.npmjs.com/) inside current project's virtual environment [nodeenv](https://pypi.python.org/pypi/nodeenv) 67 | - `odoo-helper exec my-command` - run command inside project's virtual env 68 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | # odoo-helper-scripts documentation 2 | 3 | *Documentation is work-in-progress, so here is only basic documentation* 4 | 5 | Quick links: 6 | 7 | - [Quick Start Guide](./quick-start-guide.md) 8 | - [Installation](.installation.md) 9 | - [Frequently used commands](./frequently-used-commands.md) 10 | - [Command reference](./command-reference.md) 11 | 12 | ## The War in Ukraine 13 | 14 | 2022-02-24 Russia invaded Ukraine... 15 | 16 | If you want to help or support Ukraine to stand against russian inavasion, 17 | please, visit [the official site of Ukraine](https://war.ukraine.ua/) 18 | and find the best way to do it. 19 | 20 | Thanks. 21 | 22 | 23 | ## Overview 24 | 25 | This project aims to simplify development process of Odoo addons as much as possible. 26 | 27 | odoo-helper-scripts will do all routine operations for you: 28 | - install odoo with ALL dependencies (even those not mentioned in odoo's requirements.txt like [python-slugify](https://pypi.org/project/python-slugify/)) 29 | - manage local development databases 30 | - install custom addons 31 | - check if versions of modules are updated before pushing changes. 32 | - generate / regenerate translations 33 | - run tests 34 | - and a lot more 35 | 36 | If you have any routine operation that you would like to automate with odoo-helper-scripts, 37 | just fill an issue or do pull request, and may be that feature will be available in one of next releases. 38 | 39 | ***WARNING***: If you want to deploy production-ready odoo server, 40 | please, read carefully [Usage notes](#usage-note) section. 41 | 42 | ## Features 43 | 44 | - Easily manage multiple instances of Odoo that ran on same machine 45 | - Wide usage of [virtualenv](https://virtualenv.pypa.io/en/stable/) for isolation purpose 46 | - Use [nodeenv](https://pypi.python.org/pypi/nodeenv) to install [node.js](https://nodejs.org/en/), [phantom.js](http://phantomjs.org/), etc in isolated [virtualenv](https://virtualenv.pypa.io/en/stable/) 47 | - The easiest way to install Odoo for development purposes (but not limited to development) 48 | - single command to install odoo 49 | - ability to build custom python for odoo 50 | - Powerful testing capabilities, including support for: 51 | - *python* and *js* code check via [pylint\_odoo](https://pypi.python.org/pypi/pylint-odoo) (which uses [ESLint](https://eslint.org/) to check JS files) 52 | - *python* code check via [flake8](https://pypi.python.org/pypi/flake8) 53 | - styles (*.css*, *.scss*, *.less* files) check via [stylelint](https://stylelint.io/) 54 | - compute test code coverage via [coverage.py](https://coverage.readthedocs.io) 55 | - Test web tours via [phantom.js](http://phantomjs.org/) or *chromium browser* (Odoo 12.0+) 56 | - Easy addons installation 57 | - Automatiacly resolve and fetch dependencies 58 | - oca\_dependencies.txt ([sample](https://github.com/OCA/maintainer-quality-tools/blob/master/sample_files/oca_dependencies.txt), [mqt tool code](https://github.com/OCA/maintainer-quality-tools/blob/master/sample_files/oca_dependencies.txt)) 59 | - [requirements.txt](https://pip.readthedocs.io/en/stable/user_guide/#requirements-files) 60 | - Own file format to track addon dependencies: [odoo\_requirements.txt](https://katyukha.gitlab.io/odoo-helper-scripts/odoo-requirements-txt/) 61 | - installation directly from [Odoo Market](https://apps.odoo.com/apps) (**experimental**) 62 | - Only free addons 63 | - Including dependencies 64 | - Semi-automatic upgrade when new version released 65 | - installation from *git* repositories 66 | - installation of python dependencies from [PyPI](pypi.python.org/pypi) or any [vcs supported by setuptools](https://setuptools.readthedocs.io/en/latest/setuptools.html?highlight=develop%20mode#dependencies-that-aren-t-in-pypi) 67 | - automatically processing of [requirements.txt](https://pip.pypa.io/en/stable/user_guide/#requirements-files) files located inside repository root and addon directories. 68 | - shortcuts that simplifies fetching addons from [OCA](https://github.com/OCA) or [github](https://github.com) 69 | - works good with long recursive dependencies. 70 | One of the reasons for this script collection development was, 71 | ability to automaticaly install more that 50 addons, 72 | that depend on each other, and where each addon have it's own git repo. 73 | - Easy database management 74 | - easily create / drop / backup / rename / copy databases 75 | - Continious Integration related features 76 | - ensure addon version changed 77 | - ensure repository version changed 78 | - ensure each addon have icon 79 | - ensure all changed addon has correct versions 80 | - simplify forward-port process (move changes from older serie to newer (for example from 11.0 to 12.0)) 81 | - Translation management from command line 82 | - import / export translations by command from shell 83 | - test translation rate for specified language 84 | - regenerate translations for specified language 85 | - generate *.pot* files for modules 86 | - load language (for one db or for old databases) 87 | - Supported odoo versions: 88 | - *8.0* 89 | - *9.0* 90 | - *10.0* 91 | - *11.0* 92 | - *12.0* 93 | - *13.0* 94 | - *14.0* 95 | - *15.0* 96 | - *16.0* 97 | - *17.0* 98 | - *18.0* (**Experimental**) 99 | - OS support: 100 | - On *Ubuntu* should work nice 101 | - Also should work on *Debian* based systems, but some troubles may happen with installation of system dependencies. 102 | - Other linux systems - in most cases should work, but system dependecies must be installed manualy. 103 | - Missed feature? [Fill an issue](https://gitlab.com/katyukha/odoo-helper-scripts/issues/new) 104 | 105 | 106 | ## Usage note 107 | 108 | This script collection is designed to simplify life of addons developer. 109 | This project ***is not designed, to install and configure production ready Odoo instances***, unless you know what you do! 110 | 111 | For ***production-ready*** installations take a look at [crnd-deploy](http://github.com/crnd-inc/crnd-deploy) project - just a single command allows you to get production-ready odoo instance with configured [PostgreSQL](https://www.postgresql.org/) and [Nginx](https://nginx.org/). 112 | 113 | Also take a look at [Yodoo Cockpit](https://crnd.pro/yodoo-cockpit) project, and discover the easiest way to manage your production Odoo installations. 114 | 115 | [![Yodoo Cockpit](https://crnd.pro/web/image/18846/banner_2_4_gif_animation_cut.gif)](https://crnd.pro/yodoo-cockpit) 116 | 117 | Just short notes about [Yodoo Cockpit](https://crnd.pro/yodoo-cockpit): 118 | - start new production-ready odoo instance in 1-2 minutes. 119 | - add custom addons to your odoo instances in 5-10 minutes. 120 | - out-of-the-box email configuration: just press button and add some records to your DNS, and get a working email 121 | - make your odoo instance available to external world (internet) in 30 seconds (just add single record in your DNS) 122 | 123 | 124 | ## Level up your service quality 125 | 126 | Level up your service with [Helpdesk](https://crnd.pro/solutions/helpdesk) / [Service Desk](https://crnd.pro/solutions/service-desk) / [ITSM](https://crnd.pro/itsm) solution by [CR&D](https://crnd.pro/). 127 | 128 | Just test it at [yodoo.systems](https://yodoo.systems/saas/templates): choose template you like, and start working. 129 | 130 | Test all available features of [Bureaucrat ITSM](https://crnd.pro/itsm) with [this template](https://yodoo.systems/saas/template/bureaucrat-itsm-demo-data-95). 131 | 132 | 133 | ## Installation 134 | 135 | For full list of installation options look at [installation documentation](./installation.md) 136 | or [Quick Start Guide](./quick-start-guide.md) 137 | 138 | odoo-helper-scripts could be installed as* [.deb packages](https://katyukha.gitlab.io/odoo-helper-scripts/installation#install-as-deb-package)*, 139 | but this feature is still in alpha. See* [releases](https://gitlab.com/katyukha/odoo-helper-scripts/releases) *page.* 140 | 141 | To install *odoo-helper-scripts* system-wide do folowing: 142 | 143 | ```bash 144 | # Install odoo-helper-scripts 145 | wget -O - https://gitlab.com/katyukha/odoo-helper-scripts/raw/master/install-system.bash | sudo bash -s 146 | 147 | # Install system dependencies required for odoo-helper-scripts 148 | # NOTE: Works only on debian-based systems 149 | odoo-helper install pre-requirements 150 | ``` 151 | 152 | or more explicit way: 153 | 154 | ```bash 155 | # Download installation script 156 | wget -O /tmp/odoo-helper-install.bash https://gitlab.com/katyukha/odoo-helper-scripts/raw/master/install-system.bash; 157 | 158 | # Install odoo-helper-scripts 159 | sudo bash /tmp/odoo-helper-install.bash; 160 | 161 | # Intall system pre-requirements for odoo-helper-scripts 162 | # NOTE: Works only on debian-based systems 163 | odoo-helper install pre-requirements 164 | ``` 165 | 166 | Do not forget to install and configure postgres: 167 | 168 | ```bash 169 | # install postgres and create db user with name 'odoo' and password 'odoo' 170 | odoo-helper install postgres odoo odoo 171 | ``` 172 | 173 | 174 | ## Basic usage 175 | 176 | ### odoo-install 177 | 178 | Install Odoo in specified directory (using virtualenv) 179 | 180 | ```bash 181 | odoo-helper install sys-deps 11.0 # install global system dependencies for specified version of Odoo 182 | odoo-install --odoo-version 11.0 # no sudo required 183 | ``` 184 | 185 | After this you will have odoo and it's dependencies installed into *odoo-11.0* directory. 186 | 187 | This installation also creates *odoo-helper.conf* file inside project, which allows to use 188 | *odoo-helper* script to simplify interaction with this odoo installation. 189 | 190 | Description of *odoo-helper* project's directory structure is [here](./project-directory-structure.md) 191 | 192 | 193 | ### odoo-helper 194 | 195 | This is the main script to manage Odoo instances installed by *odoo-install* 196 | 197 | Most of *odoo-helper-scripts* functionality is implemented as *subcommands* of `odoo-helper`. 198 | For example `odoo-helper server` contains server management commands like: 199 | 200 | - `odoo-helper server start` 201 | - `odoo-helper server stop` 202 | - `odoo-helper server restart` 203 | - etc 204 | 205 | All *odoo-helper commands* may be splited in two groups: 206 | 207 | - Odoo instance management commands 208 | - Other 209 | 210 | *Odoo instance management commands* are commands that manage Odoo instances installed using `odoo-install` script. 211 | Example of such commands may be: `odoo-helper server` or `odoo-helper db` commands. 212 | These commands are required to be ran inside Odoo instance directory (directory with Odoo installed using `odoo-install`) 213 | or its subdirectories. Thus*odoo-helper* could find project/instance [config file](./odoo-helper-configuration.md). 214 | 215 | See [Frequently used commands](./frequently-used-commands.md) and [Command reference](./command-reference.md) for more info about available commands 216 | or just run `odoo-helper --help` 217 | 218 | ## Support 219 | 220 | Have you any quetions? Just [fill an issue](https://gitlab.com/katyukha/odoo-helper-scripts/issues/new) or [send email](mailto:incoming+katyukha/odoo-helper-scripts@incoming.gitlab.com) 221 | -------------------------------------------------------------------------------- /docs/installation.md: -------------------------------------------------------------------------------- 1 | # Installation of odoo-helper-scripts 2 | 3 | Installation of *odoo-helper-scripts* consists of three steps: 4 | 5 | 1. Install *odoo-helper-scripts* 6 | 2. Install system dependencies for *odoo-helper-scripts* 7 | 3. Install dependencies for specific *Odoo* version 8 | 9 | Second step is separated, because installing system dependencies on different 10 | different platforms may differ and automatic installation of system dependencies 11 | only supported on debian-like systems (using apt) 12 | 13 | 14 | ## Installing odoo-helper-scripts itself 15 | There are three options to install *odoo-helper-scripts*: 16 | 17 | - [*user-space* installation](#user-space-installation) 18 | - [*system-wide* installation](#system-wide-installation) 19 | - [*as .deb package* (**experimental**)](#install-as-deb-package) 20 | 21 | ### User-space installation 22 | 23 | ```bash 24 | wget -O - https://gitlab.com/katyukha/odoo-helper-scripts/raw/master/install-user.bash | bash -s 25 | ``` 26 | 27 | or in more explicit way: 28 | 29 | ```bash 30 | wget -O odoo-helper-install-user.bash https://gitlab.com/katyukha/odoo-helper-scripts/raw/master/install-user.bash 31 | bash odoo-helper-install-user.bash 32 | ``` 33 | 34 | After instalation you will have ``odoo-helper-scripts`` directory inside your home directory 35 | And ``$HOME/odoo-helper.conf`` file will be generated with path to odoo-helper-scripts install dir. 36 | *odoo-helper-scripts* executables will be placed in ``$HOME/bin/`` directory. 37 | If this directory does not exists at installation time, then it will be created. 38 | 39 | #### Known bugs and workarounds for user-space installation 40 | 41 | 1. *command not found `odoo-helper`* after installation. Ususaly this happens, because there is 42 | no `$HOME/bin` directory or it is not in `$PATH` before installation. 43 | After installation this directory will be created, but additional steps may be required to add it to `$PATH` 44 | - restart shell session (for example open new terminal window or tab). 45 | This may help if shell is configured to use `$HOME/bin` directory if it is exists. 46 | - if *bash* is used as shell, then it may be enough to source `.profile` file (`$ source $HOME/.profile`) 47 | - add `$HOME/bin` directory to `$PATH` in your shell start-up configration ([Stack Exchange Question](https://unix.stackexchange.com/questions/381228/home-bin-dir-is-not-on-the-path)) 48 | 49 | ### System-wide installation 50 | 51 | To install (system-wide) just do folowing: 52 | 53 | ```bash 54 | # Install odoo-helper-scripts 55 | wget -O - https://gitlab.com/katyukha/odoo-helper-scripts/raw/master/install-system.bash | sudo bash -s 56 | ``` 57 | 58 | or more explicit way: 59 | 60 | ```bash 61 | # Download installation script 62 | wget -O /tmp/odoo-helper-install.bash https://gitlab.com/katyukha/odoo-helper-scripts/raw/master/install-system.bash; 63 | 64 | # Install odoo-helper-scripts 65 | sudo bash /tmp/odoo-helper-install.bash; 66 | ``` 67 | 68 | After instalation *odoo-helper-scripts* code will be placed in ``/opt/odoo-helper-scripts`` directory. 69 | ``odoo-helper.conf`` file that containse global odoo-helper configuration will be placed inside ``/etc/`` directory 70 | *odoo-helper-scripts* executables will be placed in ``/usr/local/bin`` directory. 71 | 72 | ### Install as .deb package 73 | 74 | ***Note***: this feature is experimental! 75 | 76 | It is possible to install *odoo-helper-scripts* as *.deb* package. 77 | Find all generated *.deb* packages in [releases](https://gitlab.com/katyukha/odoo-helper-scripts/-/releases) page. 78 | To install the latest **stable** version just download and install following deb package: [odoo-helper-scripts_master.deb](https://gitlab.com/api/v4/projects/6823247/packages/generic/odoo-helper-scripts/master/odoo-helper-scripts_master.deb) 79 | 80 | ## Install system dependencies for odoo-helper-scripts 81 | 82 | On this step system dependencies have to be installed. 83 | This could be done automaticaly for *debian-based* systems: 84 | 85 | ```bash 86 | odoo-helper install pre-requirements 87 | ``` 88 | 89 | On other operation systems it may require to install system dependencies manualy 90 | For example following command will isntall system dependencies for [OpenSUSE](https://www.opensuse.org/) linux (this command could be outdated) 91 | 92 | ```bash 93 | zypper install git wget python-setuptools gcc postgresql-devel python-devel expect-devel libevent-devel libjpeg-devel libfreetype6-devel zlib-devel libxml2-devel libxslt-devel cyrus-sasl-devel openldap2-devel libssl43 libffi-devel 94 | ``` 95 | 96 | Also, *PostgreSQL* is usualy required for local development. 97 | For *debian-based* systems odoo-helper could be used: 98 | 99 | ```bash 100 | odoo-helper install postgres 101 | ``` 102 | 103 | Postgres user for odoo may be created at same time 104 | 105 | ```bash 106 | odoo-helper install postgres odoo_user odoo_password 107 | ``` 108 | 109 | *Note: it is recommended to create new postgres user for each Odoo instance* 110 | 111 | For other systems it have to be installed manualy 112 | 113 | 114 | ## Install Odoo system dependencies 115 | 116 | To make Odoo work, some system dependencies fpecific for version may be required. 117 | Most of python dependencies are installed in virtualenv, thus no need for sudo access. 118 | But some non-python system libraries may be required. 119 | 120 | For this reason for *debian-based* systems exists one more odoo-helper command 121 | 122 | ```bash 123 | #odoo-helper install sys-deps 124 | odoo-helper install sys-deps 11.0 125 | ``` 126 | 127 | For other systems such depencies have to be installed manualy 128 | 129 | 130 | ## Installation of development version 131 | 132 | Installation scripts could reciev *reference* argument. This could be branch name, tag name or commit hash. 133 | So to install *development* version system-wide run following command: 134 | 135 | ```bash 136 | # Install odoo-helper-scripts (note '- dev' in the end of command) 137 | wget -O - https://gitlab.com/katyukha/odoo-helper-scripts/raw/master/install-system.bash | sudo bash -s - dev 138 | 139 | # Intall system pre-requirements for odoo-helper-scripts 140 | odoo-helper install pre-requirements 141 | ``` 142 | 143 | For user-space install: 144 | 145 | ```bash 146 | wget -O - https://gitlab.com/katyukha/odoo-helper-scripts/raw/master/install-user.bash | bash -s - dev 147 | 148 | # Intall system pre-requirements for odoo-helper-scripts 149 | # NOTE: works only on debian-based systems 150 | odoo-helper install pre-requirements 151 | ``` 152 | 153 | ## Update odoo-helper-scripts 154 | 155 | If you installed old version of odoo-helper scripts and want to update them to new version, 156 | then following command will help you: 157 | 158 | ```bash 159 | odoo-helper system update 160 | ``` 161 | 162 | For example to update to last *dev* commit following command could be used: 163 | 164 | ``` 165 | odoo-helper system update dev 166 | ``` 167 | -------------------------------------------------------------------------------- /docs/odoo-helper-configuration.md: -------------------------------------------------------------------------------- 1 | # odoo-helper-scripts configuration 2 | 3 | 4 | There are two types of config files used by odoo-helper: 5 | - global config 6 | - per project/instance config 7 | 8 | ## Global config 9 | 10 | Glocbal configuration file could be placed in two specific directories: 11 | - `/etc/odoo-helper.conf` - for *system-wide* installations 12 | - `$HOME/odoo-helper.conf` - for *user-space* installations 13 | 14 | Both of them may be present at same time. 15 | In this case *system-wide* config will be loaded first and *user-space* config second. 16 | Thus *user-space* config may override variables defined in *system-wide* config. 17 | 18 | Ususaly these files generated on *odoo-helper-scripts* installation. 19 | 20 | ## Project/Instance Configuration files. 21 | 22 | odoo-helper searches for *project/instance config file* (`odoo-helper.conf`) 23 | starting from current working directory and going up to root directory. 24 | First config found is used. 25 | -------------------------------------------------------------------------------- /docs/odoo-requirements-txt.md: -------------------------------------------------------------------------------- 1 | # odoo\_requirements.txt 2 | 3 | *odoo_requirements.txt* parsed line by line, and each line 4 | must be set of options for [odoo-helper fetch](./command-reference.md#odoo-helper-fetch) command. 5 | 6 | ## Format 7 | 8 | ### Fetch addons form any git repository 9 | 10 | ``` 11 | -r|--repo [-b|--branch ] [-m|--module ] [-n|--name ] 12 | ``` 13 | 14 | ### Fetch addons from github repository 15 | 16 | ``` 17 | --github [-b|--branch ] [-m|--module ] [-n|--name ] 18 | ``` 19 | 20 | ### Fetch [OCA](https://odoo-community.org/) addons from any [OCA github repository](https://github.com/OCA) 21 | 22 | ``` 23 | --oca [-b|--branch ] [-m|--module ] [-n|--name ] 24 | ``` 25 | 26 | ### Fetch addons direcly from [Odoo Apps](https://apps.odoo.com/apps) 27 | 28 | ``` 29 | --odoo-app 30 | ``` 31 | 32 | ### Parse another *odoo_requirments.txt* file 33 | 34 | ``` 35 | --requirements 36 | ``` 37 | 38 | ## Notes 39 | 40 | ***Note*** *odoo_requirements.txt* must end with newline symbol. 41 | 42 | ## Examples 43 | 44 | ``` 45 | --github crnd-inc/generic-addon --module generic_tags -b 12.0 46 | --oca project -m project_description 47 | --odoo-app bureaucrat_helpdesk_lite 48 | ``` 49 | 50 | For details run ```odoo-helper fetch --help``` 51 | -------------------------------------------------------------------------------- /docs/project-directory-structure.md: -------------------------------------------------------------------------------- 1 | # Directory structure for odoo-helper projects 2 | 3 | Directory structure generated by `odoo-install` looks like: 4 | 5 | - `odoo-11.0` - project root (installation directory) 6 | - `backups` - directory for backups generated by `odoo-helper db backup` and `odoo-helper db backup-all` commands 7 | - `bin` - not used now, reserver for future. 8 | - `conf` - directory for configurations used by this odoo project. Usualy contains two files: one for normal local config and one used to run tests 9 | - `odoo.conf` - configuration used by most odoo-helper commands (`odoo-helper server start`, etc) 10 | - `odoo.test.conf` - configuration used to run tests, usualy have different port then `odoo.conf` 11 | - `custom_addons` - directory for all addons that are not part of Odoo. Usualy contains only *symlinks* to addons. 12 | - `data` - Odoo data directory. Here Odoo filestore placed. 13 | - `downloads` - Directory contains addons downloaded directly from [Odoo Market](https://apps.odoo.com/apps). 14 | - `libs` - Not used yet 15 | - `odoo` - Odoo itself. Here may be just unpacked odoo archive, or odoo git repository, dependent of `odoo-install` options. 16 | - `repositories` - Place to store custom addon repositories. 17 | `odoo-helper fetch` command place here source code of fetched repositories and creates symlinks for addons in clonned repo to `custom_addons` directory. 18 | - `venv` - [virtualenv](https://virtualenv.pypa.io/en/stable/) directory 19 | - `odoo-helper.conf` - config for *odoo-helper* projects. 20 | 21 | -------------------------------------------------------------------------------- /docs/quick-start-guide.md: -------------------------------------------------------------------------------- 1 | # Quick Start Guide 2 | 3 | This is quick start guide for *odoo-helper-scripts* for development odoo installations. 4 | 5 | If you want to install Odoo on ***production*** server, then take a look at [crnd-deploy](http://github.com/crnd-inc/crnd-deploy) project - just a single command allows you to get production-ready odoo instance with configured [PostgreSQL](https://www.postgresql.org/) and [Nginx](https://nginx.org/). 6 | 7 | 8 | ## Install odoo-helper scripts 9 | 10 | For full list of installation options look at [installation documentation](./installation.md) 11 | 12 | To install *odoo-helper-scripts* system-wide do folowing: 13 | 14 | ```bash 15 | wget -O - https://gitlab.com/katyukha/odoo-helper-scripts/raw/master/install-system.bash | sudo bash -s 16 | ``` 17 | 18 | or more explicit way: 19 | 20 | ```bash 21 | # Download installation script 22 | wget -O /tmp/odoo-helper-install.bash https://gitlab.com/katyukha/odoo-helper-scripts/raw/master/install-system.bash; 23 | 24 | # Install odoo-helper-scripts 25 | sudo bash /tmp/odoo-helper-install.bash; 26 | ``` 27 | 28 | ## Install dependencies 29 | 30 | Ensure *odoo-helper-scripts* pre-requirements are installed 31 | This step should be usualy ran one time. 32 | It installs dependencies of *odoo-helper-scripts* itself and common odoo dependencies. 33 | 34 | ```bash 35 | odoo-helper install pre-requirements 36 | ``` 37 | 38 | Install system dependencies for specific Odoo version (in this example *11.0*) 39 | Note, that this option requires *sudo*. 40 | 41 | ```bash 42 | odoo-helper install sys-deps 11.0; 43 | ``` 44 | 45 | Install [PostgreSQL Server](https://www.postgresql.org/) and create 46 | postgres user for Odoo with `name='odoo'` and `password='odoo'`. 47 | First argument is postgres user name and second is password. 48 | 49 | ```bash 50 | odoo-helper install postgres odoo odoo 51 | ``` 52 | 53 | ## Install Odoo 54 | 55 | Install *Odoo* 11.0 into *odoo-11.0* directory 56 | 57 | ```bash 58 | odoo-install -i odoo-11.0 --odoo-version 11.0 59 | ``` 60 | 61 | ## Manage installed Odoo 62 | 63 | Change directory to that one contains just installed Odoo instance. 64 | This is required to make instance-management commands work. 65 | 66 | ```bash 67 | cd odoo-11.0 68 | ``` 69 | 70 | Now You have *Odoo 11.0* installed in this directory. 71 | Note, that this odoo installation uses [virtualenv](https://virtualenv.pypa.io/en/stable/) 72 | (`venv` directory) 73 | Also you will find there `odoo-helper.conf` config file 74 | 75 | So now You can run local odoo server (i.e `openerp-server` or `odoo.py` or `odoo-bin` script). 76 | Note that this command run's server in foreground. 77 | Configuration file `conf/odoo.conf` will be automatically used 78 | 79 | ```bash 80 | odoo-helper server run 81 | ``` 82 | 83 | Press `Ctrl+C` to stop the server 84 | 85 | To run server in backgroud use following command: 86 | 87 | ```bash 88 | odoo-helper server start 89 | ``` 90 | 91 | Run command below to open current odoo isntance in browser: 92 | 93 | ```bash 94 | odoo-helper browse 95 | ``` 96 | 97 | By default Odoo service will be accessible on [localhost:8069](http://localhost:8069/) 98 | 99 | There are also additional server related commands (see [Frequently Used Commands](./frequently-used-commands.md)): 100 | 101 | ```bash 102 | odoo-helper server status 103 | odoo-helper server log 104 | odoo-helper server ps 105 | odoo-helper server restart 106 | odoo-helper server stop 107 | ``` 108 | 109 | Also there are shourtcuts for these commands 110 | 111 | ```bash 112 | odoo-helper status 113 | odoo-helper log 114 | odoo-helper restart 115 | odoo-helper stop 116 | ``` 117 | 118 | 119 | ## Create database with demo-data 120 | 121 | To create Odoo database with demo data run following command 122 | 123 | ```bash 124 | odoo-helper db create --demo my-database 125 | ``` 126 | 127 | Then start Odoo server (if it wasn't started yet) 128 | 129 | ```bash 130 | odoo-helper start 131 | ``` 132 | 133 | And login to just created database with following default credentials: 134 | 135 | - login: admin 136 | - password: admin 137 | 138 | 139 | ## Fetch and install Odoo addons 140 | 141 | Let's fetch modules from [OCA repository contract](https://github.com/OCA/contract) 142 | Branch will be detected automatically by *odoo-helper-scripts* 143 | 144 | ```bash 145 | odoo-helper fetch --oca contract 146 | ``` 147 | 148 | Or alternatively 149 | 150 | ```bash 151 | odoo-helper fetch --github OCA/contract --branch 11.0 152 | ``` 153 | 154 | Or alternatively 155 | 156 | ```bash 157 | odoo-helper fetch --repo https://github.com/OCA/contract --branch 11.0 158 | ``` 159 | 160 | If repository have standard branch structure branches have same names as Odoo versions (series) 161 | then odoo-helper will automatically try to switch to right branch, 162 | thus it is not required to specify branch name in this case. 163 | So command above may look like: 164 | 165 | ```bash 166 | odoo-helper fetch --github OCA/contract 167 | ``` 168 | 169 | Now look at `custom_addons/` directory, there will be placed links to addons 170 | from [OCA repository 'contract'](https://github.com/OCA/contract) 171 | But repository itself is placed in `repositories/` directory 172 | 173 | At this point fetched addons are not shown in *Apps* Odoo menu. 174 | That's why we have to update addons list in database. 175 | This can be done by Odoo UI in developer mode (*Apps / Update Applications List*) 176 | or th a simple shell command: 177 | 178 | ```bash 179 | odoo-helper addons update-list 180 | ``` 181 | 182 | Now addons are present in Odoo's database, so they could be installed via UI (*Apps* menu) 183 | Also it is possible to do this via command line with following command: 184 | 185 | ```bash 186 | odoo-helper addons install [-d database] 187 | ``` 188 | 189 | For example following command will install [contract](https://github.com/OCA/contract/tree/11.0/contract) addon 190 | 191 | ```bash 192 | odoo-helper addons install -d my-database contract 193 | ``` 194 | 195 | Also if database is not specified addon will be installed to all vaiablable databases 196 | 197 | 198 | ## Run tests 199 | 200 | Now let's run tests for these just installed modules 201 | 202 | ```bash 203 | odoo-helper test --create-test-db -m contract 204 | ``` 205 | 206 | This will create *test database* (it will be dropt after tests finished) and 207 | run tests for `contract` module 208 | 209 | Or we can run tests for all addons in specified directory, *odoo-helper-scripts* 210 | will automaticaly detect installable addons and run test for them 211 | 212 | ```bash 213 | odoo-helper test --dir ./repositories/contract 214 | ``` 215 | 216 | This will use standard test database, that will not be dropt after tests, 217 | so we do not need to recreate database on each test run, which saves time. 218 | 219 | If you need color output from Odoo, you may use `--use-unbuffer` option, 220 | but it depends on `unbuffer` program that could be found in `expect-dev` package. 221 | 222 | ```bash 223 | odoo-helper --use-unbuffer test -m contract 224 | ``` 225 | 226 | The one cool thing of *odoo-helper-scripts*, you may not remeber paths to odoo instalation directory, 227 | and if you change directory to another inside your *Odoo* project, everything will continue to work. 228 | 229 | ```bash 230 | cd custom_addons 231 | odoo-helper server status 232 | dooo-helper server restart 233 | ``` 234 | 235 | ## One more Odoo install 236 | 237 | So... let's install one more Odoo version 238 | go back to directory containing your projects (that one, where `odoo-11.0` project is placed in) 239 | 240 | ```bash 241 | cd ../../ 242 | ``` 243 | 244 | Let's install *Odoo* of version 12.0 here too. 245 | First, install *system dependencies* for *Odoo* version 12.0 246 | 247 | ```bash 248 | odoo-helper install sys-deps 12.0; 249 | ``` 250 | 251 | And when system dependencies installed, install *Odoo* itself 252 | 253 | ```bash 254 | odoo-install --install-dir odoo-12.0 --odoo-version 12.0 255 | cd odoo-12.0 256 | ``` 257 | 258 | and, for example, install there [partner-contact/base_location](https://github.com/OCA/partner-contact/tree/12.0/base_location) addon 259 | from [partner-contact](https://github.com/OCA/partner-contact) [Odoo Community Association](https://odoo-community.org/) repository 260 | Note that *odoo-helper* script will automaticaly fetch branch named as server version in current install (in this case *12.0*), 261 | if another branch was not specified 262 | 263 | ```bash 264 | odoo-helper fetch --oca partner-contact -m base_location 265 | ``` 266 | 267 | and run tests for it 268 | 269 | ```bash 270 | odoo-helper test --create-test-db -m base_location 271 | ``` 272 | 273 | Also if you want to install python packages in current installation environment, 274 | *odoo-helper* provides *pip alias* to *pip* installed in virtualenv of Odoo instance 275 | 276 | ```bash 277 | odoo-helper pip install phonenumbers 278 | ``` 279 | 280 | ## More 281 | 282 | *odoo-helper-scripts* has much more features. 283 | 284 | Look at [Frequently Used Commands](./frequently-used-commands.md) to gen more info. 285 | -------------------------------------------------------------------------------- /install-system.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright © 2015-2018 Dmytro Katyukha 4 | 5 | ####################################################################### 6 | # This Source Code Form is subject to the terms of the Mozilla Public # 7 | # License, v. 2.0. If a copy of the MPL was not distributed with this # 8 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. # 9 | ####################################################################### 10 | 11 | # Define colors 12 | NC='\e[0m'; 13 | REDC='\e[31m'; 14 | GREENC='\e[32m'; 15 | YELLOWC='\e[33m'; 16 | BLUEC='\e[34m'; 17 | LBLUEC='\e[94m'; 18 | 19 | # Simple script to install odoo-helper-script system-wide 20 | if [[ $UID != 0 ]]; then 21 | echo -e "${REDC}ERROR${NC}: Please run this script with ${YELLOWC}sudo${NC}:" 22 | echo -e "$ ${BLUEC}sudo $0 $* ${NC}" 23 | exit 1 24 | fi 25 | 26 | # Get odoo-helper branch. Default is master 27 | ODOO_HELPER_BRANCH=${1:-master} 28 | 29 | set -e; # Fail on each error 30 | 31 | # Install git if not installed yet 32 | if ! command -v git >/dev/null 2>&1 || ! command -v wget >/dev/null 2>&1; then 33 | if [ -e "/etc/debian_version" ]; then 34 | echo -e "${BLUEC}INFO${NC}: Installing minimal system dependencies...${NC}"; 35 | apt-get install -yqq --no-install-recommends git wget; 36 | else 37 | echo -e "${REDC}ERROR${NC}: Please, install wget and git to be able to install odoo-helper-scripts!" 38 | exit 2; 39 | fi 40 | fi 41 | 42 | # define vars 43 | ODOO_HELPER_SYS_CONF="/etc/odoo-helper.conf"; 44 | 45 | # Test if there is odoo-helper conf in home dir, which means 46 | # that odoo-helper-scripts may be already installed 47 | if [ -f "$ODOO_HELPER_SYS_CONF" ]; then 48 | source $ODOO_HELPER_SYS_CONF; 49 | fi 50 | 51 | # Configure paths 52 | INSTALL_PATH=${ODOO_HELPER_INSTALL_PATH:-/opt/odoo-helper-scripts}; 53 | ODOO_HELPER_LIB=${ODOO_HELPER_LIB:-$INSTALL_PATH/lib}; 54 | ODOO_HELPER_BIN=${ODOO_HELPER_BIN:-$INSTALL_PATH/bin}; 55 | 56 | # clone repo 57 | if [ ! -d $INSTALL_PATH ]; then 58 | echo -e "${BLUEC}INFO${NC}: clonning odoo-helper-scripts...${NC}"; 59 | git clone --recurse-submodules -q https://gitlab.com/katyukha/odoo-helper-scripts $INSTALL_PATH; 60 | echo -e "${BLUEC}INFO${NC}: fetching submodules...${NC}"; 61 | (cd $INSTALL_PATH && git checkout -q $ODOO_HELPER_BRANCH && git submodule init && git submodule update); 62 | # TODO: may be it is good idea to pull changes from repository if it is already exists? 63 | # TODO: implement here some sort of upgrade mechanism? 64 | echo -e "${GREENC}OK${NC}: odoo-helper-scripts successfully clonned${NC}"; 65 | fi 66 | 67 | # install odoo-helper user config 68 | if [ ! -f "$ODOO_HELPER_SYS_CONF" ]; then 69 | echo "ODOO_HELPER_ROOT=$INSTALL_PATH;" >> $ODOO_HELPER_SYS_CONF; 70 | echo "ODOO_HELPER_BIN=$ODOO_HELPER_BIN;" >> $ODOO_HELPER_SYS_CONF; 71 | echo "ODOO_HELPER_LIB=$ODOO_HELPER_LIB;" >> $ODOO_HELPER_SYS_CONF; 72 | fi 73 | 74 | # add odoo-helper-bin to path 75 | for oh_cmd in $ODOO_HELPER_BIN/*; do 76 | if ! command -v $(basename $oh_cmd) >/dev/null 2>&1; then 77 | ln -s $oh_cmd /usr/local/bin/; 78 | fi 79 | done 80 | 81 | 82 | if [ -e "/etc/debian_version" ]; then 83 | odoo-helper install pre-requirements; 84 | ODOO_HELPER_PRE_REQUIREMENTS_INSTALLED=1; 85 | fi 86 | 87 | echo -e "${YELLOWC}odoo-helper-scripts${GREENC} seems to be successfully installed system-wide!${NC}"; 88 | echo -e "Install path is ${YELLOWC}${INSTALL_PATH}${NC}"; 89 | echo; 90 | if [ -z "$ODOO_HELPER_PRE_REQUIREMENTS_INSTALLED" ]; then 91 | echo -e "${YELLOWC}NOTE${NC}: Do not forget to install odoo-helper system dependencies."; 92 | echo -e "To do this for debian-like systems run following command (${YELLOWC}sudo access required${NC}):"; 93 | echo -e " $ ${BLUEC}odoo-helper install pre-requirements${NC}"; 94 | echo; 95 | fi 96 | echo -e "${YELLOWC}NOTE2${NC}: Do not forget to install and configure postgresql."; 97 | echo -e "To do this for debian-like systems run following command (${YELLOWC}sudo access required${NC}):"; 98 | echo -e " $ ${BLUEC}odoo-helper install postgres${NC}"; 99 | echo -e "Or use command below to create postgres user for Odoo too:"; 100 | echo -e " $ ${BLUEC}odoo-helper install postgres odoo odoo${NC}"; 101 | echo; 102 | echo -e "To update odoo-helper-scripts, just run following command:"; 103 | echo -e " $ ${BLUEC}odoo-helper system update${NC}"; 104 | 105 | -------------------------------------------------------------------------------- /install-user.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright © 2015-2018 Dmytro Katyukha 4 | 5 | ####################################################################### 6 | # This Source Code Form is subject to the terms of the Mozilla Public # 7 | # License, v. 2.0. If a copy of the MPL was not distributed with this # 8 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. # 9 | ####################################################################### 10 | 11 | 12 | # Simple script to install odoo-helper-script userspace of current user 13 | # This script does not require sudo, but some features of installed 14 | # odoo-helper-scripts may require sudo. 15 | 16 | set -e; # Fail on each error 17 | 18 | # Define colors 19 | NC='\e[0m'; 20 | REDC='\e[31m'; 21 | GREENC='\e[32m'; 22 | YELLOWC='\e[33m'; 23 | BLUEC='\e[34m'; 24 | LBLUEC='\e[94m'; 25 | 26 | if ! command -v git >/dev/null 2>&1; then 27 | echo -e "${REDC}ERROR${NC}: To use this script collection you must install ${YELLOWC}git${NC}!" 28 | exit 1; 29 | fi 30 | 31 | if ! command -v wget >/dev/null 2>&1; then 32 | echo -e "${REDC}ERROR${NC}: To use this script collection you must install ${YELLOC}wget${NC}!" 33 | exit 1; 34 | fi 35 | 36 | # Get odoo-helper branch. Default is master 37 | ODOO_HELPER_BRANCH=${1:-master} 38 | 39 | # define vars 40 | ODOO_HELPER_USER_CONF="$HOME/odoo-helper.conf"; 41 | 42 | # Test if there is odoo-helper conf in home dir, which means 43 | # that odoo-helper-scripts may be already installed 44 | if [ -f "$ODOO_HELPER_USER_CONF" ]; then 45 | source $ODOO_HELPER_USER_CONF; 46 | fi 47 | 48 | # Configure paths 49 | INSTALL_PATH=${ODOO_HELPER_INSTALL_PATH:-$HOME/odoo-helper-scripts}; 50 | ODOO_HELPER_LIB=${ODOO_HELPER_LIB:-$INSTALL_PATH/lib}; 51 | ODOO_HELPER_BIN=${ODOO_HELPER_BIN:-$INSTALL_PATH/bin}; 52 | 53 | # clone repo 54 | if [ ! -d $INSTALL_PATH ]; then 55 | echo -e "${BLUEC}INFO${NC}: clonning odoo-helper-scripts...${NC}"; 56 | git clone --recurse-submodules -q https://gitlab.com/katyukha/odoo-helper-scripts $INSTALL_PATH; 57 | echo -e "${BLUEC}INFO${NC}: fetching submodules...${NC}"; 58 | (cd $INSTALL_PATH && git checkout -q $ODOO_HELPER_BRANCH && git submodule init && git submodule update); 59 | # TODO: may be it is good idea to pull changes from repository if it is already exists? 60 | # TODO: implement here some sort of upgrade mechanism? 61 | echo -e "${GREENC}OK${NC}: odoo-helper-scripts successfully clonned${NC}"; 62 | fi 63 | 64 | # install odoo-helper user config 65 | if [ ! -f "$ODOO_HELPER_USER_CONF" ]; then 66 | echo "ODOO_HELPER_ROOT=$INSTALL_PATH;" >> $ODOO_HELPER_USER_CONF; 67 | echo "ODOO_HELPER_BIN=$ODOO_HELPER_BIN;" >> $ODOO_HELPER_USER_CONF; 68 | echo "ODOO_HELPER_LIB=$ODOO_HELPER_LIB;" >> $ODOO_HELPER_USER_CONF; 69 | fi 70 | 71 | # add odoo-helper-bin to path 72 | echo -e "${BLUEC}Adding links to ${YELLOWC}$HOME/bin${NC}" 73 | if [ ! -d $HOME/bin ]; then 74 | mkdir -p $HOME/bin; 75 | fi 76 | for oh_cmd in $ODOO_HELPER_BIN/*; do 77 | if ! command -v $(basename $oh_cmd) >/dev/null 2>&1; then 78 | ln -s $oh_cmd $HOME/bin; 79 | fi 80 | done 81 | 82 | 83 | echo -e "${YELLOWC}odoo-helper-scripts${GREENC} seems to be successfully installed for current user!${NC}"; 84 | echo -e "Install path is ${YELLOWC}${INSTALL_PATH}${NC}"; 85 | echo; 86 | echo -e "${YELLOWC}NOTE${NC}: Do not forget to install odoo-helper system dependencies."; 87 | echo -e "To do this for debian-like systems run following command (${YELLOWC}sudo access required${NC}):"; 88 | echo -e " $ ${BLUEC}odoo-helper install pre-requirements${NC}"; 89 | echo; 90 | echo -e "${YELLOWC}NOTE2${NC}: Do not forget to install and configure postgresql."; 91 | echo -e "To do this for debian-like systems run following command (${YELLOWC}sudo access required${NC}):"; 92 | echo -e " $ ${BLUEC}odoo-helper install postgres${NC}"; 93 | echo -e "Or use command below to create postgres user for Odoo too:"; 94 | echo -e " $ ${BLUEC}odoo-helper install postgres odoo odoo${NC}"; 95 | echo; 96 | echo -e "To update odoo-helper-scripts, just run following command:"; 97 | echo -e " $ ${BLUEC}odoo-helper system update${NC}"; 98 | echo; 99 | 100 | if ! command -v odoo-helper >/dev/null 2>&1; then 101 | echo -e "${YELLOWC}WARNING${NC}: ${BLUEC}$HOME/bin${NC} is not on ${BLUEC}\$PATH${NC}. One of following actions may be required:"; 102 | echo -e " - shell reload/restart (for example open new termial window)" 103 | echo -e " - manualy add ${BLUEC}$HOME/bin${NC} directory to ${BLUEC}\$PATH${NC} (Stack Exchange question: https://unix.stackexchange.com/questions/381228/home-bin-dir-is-not-on-the-path)" 104 | fi 105 | -------------------------------------------------------------------------------- /lib/common.bash: -------------------------------------------------------------------------------- 1 | # Copyright © 2015-2018 Dmytro Katyukha 2 | 3 | ####################################################################### 4 | # This Source Code Form is subject to the terms of the Mozilla Public # 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this # 6 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. # 7 | ####################################################################### 8 | 9 | # predefined filenames 10 | CONF_FILE_NAME="odoo-helper.conf"; 11 | 12 | 13 | set -e; # fail on errors 14 | 15 | # Odoo-helper mark that common module is imported 16 | ODOO_HELPER_COMMON_IMPORTED=1; 17 | 18 | declare -A ODOO_HELPER_IMPORTED_MODULES; 19 | ODOO_HELPER_IMPORTED_MODULES[common]=1 20 | 21 | # if odoo-helper root conf is not loaded yet, try to load it 22 | # This is useful when this lib is used by external utils, 23 | # making possible to write things like: 24 | # source $(odoo-helper system lib-path common); 25 | # oh_require 'server' 26 | # ... 27 | 28 | if [ -z "$ODOO_HELPER_ROOT" ]; then 29 | if [ -f "/etc/$CONF_FILE_NAME" ]; then 30 | source "/etc/$CONF_FILE_NAME"; 31 | fi 32 | if [ -f "$HOME/$CONF_FILE_NAME" ]; then 33 | source "$HOME/$CONF_FILE_NAME"; 34 | fi 35 | 36 | if [ -z "$ODOO_HELPER_ROOT" ]; then 37 | echo "Odoo-helper-scripts seems not been installed correctly."; 38 | echo "Reinstall it (see Readme on https://gitlab.com/katyukha/odoo-helper-scripts/)"; 39 | exit 1; 40 | fi 41 | fi 42 | 43 | # Color related definitions 44 | function allow_colors { 45 | NC='\e[0m'; 46 | REDC='\e[31m'; 47 | GREENC='\e[32m'; 48 | YELLOWC='\e[33m'; 49 | BLUEC='\e[34m'; 50 | LBLUEC='\e[94m'; 51 | OH_COLORS_ENABLED=1; 52 | } 53 | 54 | # could be used to hide colors in output 55 | function deny_colors { 56 | NC=''; 57 | REDC=''; 58 | GREENC=''; 59 | YELLOWC=''; 60 | BLUEC=''; 61 | LBLUEC=''; 62 | OH_COLORS_ENABLED=; 63 | } 64 | 65 | # Allow colors by default 66 | allow_colors; 67 | # ------------------------- 68 | 69 | # Get path to specified bash lib 70 | # oh_get_lib_path 71 | function oh_get_lib_path { 72 | local mod_name=$1; 73 | local mod_path="$ODOO_HELPER_LIB/$mod_name.bash"; 74 | if [ -f "$mod_path" ]; then 75 | echo "$mod_path"; 76 | else 77 | >&2 echo -e "${REDC}ERROR${NC}: module ${YELLOWC}${mod_name}${NC} could not been loaded." \ 78 | "Looking for module in '${BLUEC}${ODOO_HELPER_LIB}${NC}'"; 79 | return 1; 80 | fi 81 | } 82 | 83 | # Simplify import controll 84 | # oh_require 85 | function ohelper_require { 86 | local mod_name=$1; 87 | local mod_path; 88 | if [ -z "${ODOO_HELPER_IMPORTED_MODULES[$mod_name]}" ]; then 89 | ODOO_HELPER_IMPORTED_MODULES[$mod_name]=1; 90 | mod_path=$(oh_get_lib_path "$mod_name"); 91 | source "$mod_path"; 92 | fi 93 | } 94 | 95 | # Import version info and utils 96 | ohelper_require "version"; 97 | ohelper_require "utils"; 98 | -------------------------------------------------------------------------------- /lib/config.bash: -------------------------------------------------------------------------------- 1 | # Copyright © 2017-2018 Dmytro Katyukha 2 | 3 | ####################################################################### 4 | # This Source Code Form is subject to the terms of the Mozilla Public # 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this # 6 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. # 7 | ####################################################################### 8 | 9 | if [ -z "$ODOO_HELPER_LIB" ]; then 10 | echo "Odoo-helper-scripts seems not been installed correctly."; 11 | echo "Reinstall it (see Readme on https://gitlab.com/katyukha/odoo-helper-scripts/)"; 12 | exit 1; 13 | fi 14 | 15 | if [ -z "$ODOO_HELPER_COMMON_IMPORTED" ]; then 16 | source "$ODOO_HELPER_LIB/common.bash"; 17 | fi 18 | 19 | ohelper_require 'git'; 20 | # ----------------------------------------------------------------------------- 21 | 22 | # function to print odoo-helper config 23 | function config_print { 24 | echo "PROJECT_ROOT_DIR=$PROJECT_ROOT_DIR;"; 25 | echo "PROJECT_CONFIG_VERSION=$PROJECT_CONFIG_VERSION;"; 26 | echo "ODOO_VERSION=$ODOO_VERSION;"; 27 | echo "ODOO_BRANCH=$ODOO_BRANCH;"; 28 | echo "CONF_DIR=$CONF_DIR;"; 29 | echo "LOG_DIR=$LOG_DIR;"; 30 | echo "LOG_FILE=$LOG_FILE;"; 31 | echo "LIBS_DIR=$LIBS_DIR;"; 32 | echo "DOWNLOADS_DIR=$DOWNLOADS_DIR;"; 33 | echo "ADDONS_DIR=$ADDONS_DIR;"; 34 | echo "DATA_DIR=$DATA_DIR;"; 35 | echo "BIN_DIR=$BIN_DIR;"; 36 | echo "VENV_DIR=$VENV_DIR;"; 37 | echo "ODOO_PATH=$ODOO_PATH;"; 38 | echo "ODOO_CONF_FILE=$ODOO_CONF_FILE;"; 39 | echo "ODOO_TEST_CONF_FILE=$ODOO_TEST_CONF_FILE;"; 40 | echo "ODOO_PID_FILE=$ODOO_PID_FILE;"; 41 | echo "BACKUP_DIR=$BACKUP_DIR;"; 42 | echo "REPOSITORIES_DIR=$REPOSITORIES_DIR;"; 43 | 44 | if [ -n "$INIT_SCRIPT" ]; then 45 | echo "INIT_SCRIPT=$INIT_SCRIPT;"; 46 | fi 47 | if [ -n "$ODOO_REPO" ]; then 48 | echo "ODOO_REPO=$ODOO_REPO;"; 49 | fi 50 | if [ -n "$USE_UNBUFFER" ]; then 51 | echo "USE_UNBUFFER=$USE_UNBUFFER"; 52 | fi 53 | } 54 | 55 | 56 | # Function to configure default variables 57 | function config_set_defaults { 58 | if [ -z "$PROJECT_ROOT_DIR" ]; then 59 | echo -e "${REDC}There is no PROJECT_ROOT_DIR set!${NC}"; 60 | return 1; 61 | fi 62 | PROJECT_CONFIG_VERSION="${PROJECT_CONFIG_VERSION:-$ODOO_HELPER_CONFIG_VERSION}"; 63 | CONF_DIR="${CONF_DIR:-$PROJECT_ROOT_DIR/conf}"; 64 | ODOO_CONF_FILE="${ODOO_CONF_FILE:-$CONF_DIR/odoo.conf}"; 65 | ODOO_TEST_CONF_FILE="${ODOO_TEST_CONF_FILE:-$CONF_DIR/odoo.test.conf}"; 66 | LOG_DIR="${LOG_DIR:-$PROJECT_ROOT_DIR/logs}"; 67 | LOG_FILE="${LOG_FILE:-$LOG_DIR/odoo.log}"; 68 | LIBS_DIR="${LIBS_DIR:-$PROJECT_ROOT_DIR/libs}"; 69 | DOWNLOADS_DIR="${DOWNLOADS_DIR:-$PROJECT_ROOT_DIR/downloads}"; 70 | ADDONS_DIR="${ADDONS_DIR:-$PROJECT_ROOT_DIR/custom_addons}"; 71 | DATA_DIR="${DATA_DIR:-$PROJECT_ROOT_DIR/data}"; 72 | BIN_DIR="${BIN_DIR:-$PROJECT_ROOT_DIR/bin}"; 73 | VENV_DIR="${VENV_DIR:-$PROJECT_ROOT_DIR/venv}"; 74 | ODOO_PID_FILE="${ODOO_PID_FILE:-$PROJECT_ROOT_DIR/odoo.pid}"; 75 | ODOO_PATH="${ODOO_PATH:-$PROJECT_ROOT_DIR/odoo}"; 76 | BACKUP_DIR="${BACKUP_DIR:-$PROJECT_ROOT_DIR/backups}"; 77 | REPOSITORIES_DIR="${REPOSITORIES_DIR:-$PROJECT_ROOT_DIR/repositories}"; 78 | 79 | # No default value for init script 80 | # INIT_SCRIPT="${INIT_SCRIPT}"; 81 | } 82 | 83 | # Return default config for specified tool 84 | # TODO: look at project level for configuration files 85 | # config_get_default_tool_conf 86 | function config_get_default_tool_conf { 87 | local default_conf_dir="${ODOO_HELPER_LIB}/default_config"; 88 | local tool_name="$1"; 89 | local git_repo_root_dir; 90 | if git_is_git_repo "$(pwd)"; then 91 | git_repo_root_dir=$(git_get_abs_repo_path "$(pwd)"); 92 | fi 93 | if [ -n "$git_repo_root_dir" ] && [ -f "$git_repo_root_dir/$tool_name" ]; then 94 | echo "$git_repo_root_dir/$tool_name"; 95 | elif [ -f "$CONF_DIR/$tool_name" ]; then 96 | echo "$CONF_DIR/$tool_name"; 97 | elif [ -f "$default_conf_dir/$tool_name" ]; then 98 | echo "$default_conf_dir/$tool_name"; 99 | else 100 | return 1; 101 | fi 102 | } 103 | 104 | # Check current project configuration 105 | function config_check_project_config { 106 | local proj_conf_version=${PROJECT_CONFIG_VERSION:-0}; 107 | local expected_conf_version=${ODOO_HELPER_CONFIG_VERSION}; 108 | if [[ $proj_conf_version -ge $expected_conf_version ]]; then 109 | return 0; 110 | fi 111 | 112 | echoe -e "${YELLOWC}WARNING${NC}: Current project config version" \ 113 | "${YELLOWC}${proj_conf_version}${NC} is less than" \ 114 | "odoo-helper expected config version ${YELLOWC}${expected_conf_version}${NC}.\n" \ 115 | "Please, upgrade config file for this project (${YELLOWC}$ODOO_HELPER_PROJECT_CONF${NC})!"; 116 | if [ -z "$PROJECT_CONFIG_VERSION" ]; then 117 | echoe -e "${YELLOWC}WARNING${NC}: config variable ${YELLOWC}PROJECT_CONFIG_VERSION${NC} is not specified."; 118 | fi 119 | if [ -z "$PROJECT_ROOT_DIR" ]; then 120 | echoe -e "${YELLOWC}WARNING${NC}: config variable ${YELLOWC}PROJECT_ROOT_DIR${NC} is not specified."; 121 | fi 122 | if [ -z "$CONF_DIR" ]; then 123 | echoe -e "${YELLOWC}WARNING${NC}: config variable ${YELLOWC}CONF_DIR${NC} is not specified."; 124 | fi 125 | if [ -z "$ODOO_CONF_FILE" ]; then 126 | echoe -e "${YELLOWC}WARNING${NC}: config variable ${YELLOWC}ODOO_CONF_FILE${NC} is not specified."; 127 | fi 128 | if [ -z "$ODOO_TEST_CONF_FILE" ]; then 129 | echoe -e "${YELLOWC}WARNING${NC}: config variable ${YELLOWC}ODOO_TEST_CONF_FILE${NC} is not specified."; 130 | fi 131 | if [ -z "$LOG_DIR" ]; then 132 | echoe -e "${YELLOWC}WARNING${NC}: config variable ${YELLOWC}LOG_DIR${NC} is not specified."; 133 | fi 134 | if [ -z "$LOG_FILE" ]; then 135 | echoe -e "${YELLOWC}WARNING${NC}: config variable ${YELLOWC}LOG_FILE${NC} is not specified."; 136 | fi 137 | if [ -z "$LIBS_DIR" ]; then 138 | echoe -e "${YELLOWC}WARNING${NC}: config variable ${YELLOWC}LIBS_DIR${NC} is not specified."; 139 | fi 140 | if [ -z "$DOWNLOADS_DIR" ]; then 141 | echoe -e "${YELLOWC}WARNING${NC}: config variable ${YELLOWC}DOWNLOADS_DIR${NC} is not specified."; 142 | fi 143 | if [ -z "$ADDONS_DIR" ]; then 144 | echoe -e "${YELLOWC}WARNING${NC}: config variable ${YELLOWC}ADDONS_DIR${NC} is not specified."; 145 | fi 146 | if [ -z "$DATA_DIR" ]; then 147 | echoe -e "${YELLOWC}WARNING${NC}: config variable ${YELLOWC}DATA_DIR${NC} is not specified."; 148 | fi 149 | if [ -z "$BIN_DIR" ]; then 150 | echoe -e "${YELLOWC}WARNING${NC}: config variable ${YELLOWC}BIN_DIR${NC} is not specified."; 151 | fi 152 | if [ -z "$ODOO_PID_FILE" ]; then 153 | echoe -e "${YELLOWC}WARNING${NC}: config variable ${YELLOWC}ODOO_PID_FILE${NC} is not specified."; 154 | fi 155 | if [ -z "$ODOO_PATH" ]; then 156 | echoe -e "${YELLOWC}WARNING${NC}: config variable ${YELLOWC}ODOO_PATH${NC} is not specified."; 157 | fi 158 | if [ -z "$BACKUP_DIR" ]; then 159 | echoe -e "${YELLOWC}WARNING${NC}: config variable ${YELLOWC}BACKUP_DIR${NC} is not specified."; 160 | fi 161 | if [ -z "$REPOSITORIES_DIR" ]; then 162 | echoe -e "${YELLOWC}WARNING${NC}: config variable ${YELLOWC}REPOSITORIES_DIR${NC} is not specified."; 163 | fi 164 | if [ -z "$ODOO_VERSION" ]; then 165 | echoe -e "${YELLOWC}WARNING${NC}: config variable ${YELLOWC}ODOO_VERSION${NC} is not specified."; 166 | fi 167 | if [ -z "$ODOO_BRANCH" ]; then 168 | echoe -e "${YELLOWC}WARNING${NC}: config variable ${YELLOWC}ODOO_BRANCH${NC} is not specified."; 169 | fi 170 | } 171 | 172 | 173 | # Load project configuration. No args provided 174 | function config_load_project { 175 | local project_conf; 176 | local work_dir="${1:-$(pwd)}"; 177 | if [ -z "$PROJECT_ROOT_DIR" ]; then 178 | # Load project conf, only if it is not loaded yet. 179 | project_conf=$(search_file_up "$work_dir" "$CONF_FILE_NAME"); 180 | if [ -f "$project_conf" ] && [ ! "$project_conf" == "$HOME/odoo-helper.conf" ]; then 181 | echov -e "${LBLUEC}Loading conf${NC}: $project_conf"; 182 | ODOO_HELPER_PROJECT_CONF=$project_conf; 183 | source "$project_conf"; 184 | 185 | # Set configuration defaults 186 | config_set_defaults; 187 | fi 188 | 189 | if [ -z "$PROJECT_ROOT_DIR" ]; then 190 | echoe -e "${YELLOWC}WARNING${NC}: no project config file found!"; 191 | else 192 | config_check_project_config; 193 | fi 194 | 195 | fi 196 | } 197 | 198 | -------------------------------------------------------------------------------- /lib/default_config/coverage.cfg: -------------------------------------------------------------------------------- 1 | [run] 2 | omit = 3 | */__openerp__.py 4 | */__manifest__.py 5 | .ropeproject/* 6 | parallel = on 7 | 8 | -------------------------------------------------------------------------------- /lib/default_config/flake8.cfg: -------------------------------------------------------------------------------- 1 | [flake8] 2 | # Based on: https://github.com/OCA/maintainer-quality-tools/tree/master/travis/cfg 3 | # E123,E133,E226,E241,E242 are ignored by default by pep8 and flake8 4 | # F811 is legal in odoo 8 when we implement 2 interfaces for a method 5 | ignore = E123,E133,E226,E241,E242,F811,W503,W504 6 | max-line-length = 79 7 | exclude = 8 | .git, 9 | __unported__, 10 | __init__.py, 11 | .ropeproject, 12 | .idea 13 | statistics = True 14 | show_source = True 15 | count = True 16 | -------------------------------------------------------------------------------- /lib/default_config/pylint_odoo.cfg: -------------------------------------------------------------------------------- 1 | # Based on: https://github.com/OCA/maintainer-quality-tools/tree/master/travis/cfg 2 | [MASTER] 3 | profile=no 4 | ignore=CVS,.git,scenarios,.bzr,.idea 5 | persistent=yes 6 | cache-size=500 7 | load-plugins=pylint_odoo 8 | 9 | [MESSAGES CONTROL] 10 | disable=all 11 | 12 | # Enable message and code: 13 | # anomalous-backslash-in-string - W1401 14 | # assignment-from-none - W1111 15 | # dangerous-default-value - W0102 16 | # duplicate-key - W0109 17 | # pointless-statement - W0104 18 | # pointless-string-statement - W0105 19 | # print-statement - E1601 20 | # redundant-keyword-arg - E1124 21 | # reimported - W0404 22 | # relative-import - W0403 23 | # return-in-init - E0101 24 | # too-few-format-args - E1306 25 | # unreachable - W0101 26 | # --- 27 | # bad-whitespace - C0326 28 | # redefined-builtin - W0622 29 | # notimplemented-raised - E0711 30 | # not-callable - E1102 31 | # unnecessary-lambda - W0108 32 | # bad-continuation - C0330 33 | # useless-super-delegation - W0235 34 | # bad-super-call - E1003 35 | # super-init-not-called - W0231 36 | # unused-variable - W0612 37 | # missing-final-newline - C0304 38 | # literal-comparison - R0123 39 | # blacklisted-name - C0102 40 | # len-as-condition - C1801 41 | # too-many-locals - R0914 42 | # too-many-statements - R0915 43 | # too-many-branches - R0912 44 | # too-many-return-statements - R0911 45 | # too-many-nested-blocks - R1702 46 | # too-many-boolean-expressions - R0916 47 | # wildcard-import - W0401 48 | # no-else-return - R1705 49 | # unnecessary-pass - W0107 50 | # function-redefined - E0102 51 | # logging-not-lazy - W1201 52 | # logging-format-interpolation - W1202 53 | # bare-except - W0702 54 | # incoherent-interpreter-exec-perm - W8201 55 | # multiple-statements - C0321 56 | # ungrouped-imports - C0412 57 | # simplifiable-if-statement - R1703 58 | # deprecated-lambda - W0110 59 | # except-pass - W7938 60 | # no-init - W0232 61 | # anomalous-unicode-escape-in-string - W1402 62 | # unidiomatic-typecheck - C0123 63 | # using-constant-test - W0125 64 | # undefined-loop-variable - W0631 65 | # too-many-lines - C0302 66 | # redefined-argument-from-local - R1704 67 | # superfluous-parens - C0325 68 | # bad-indentation - W0311 69 | # no-self-argument - E0213 70 | # bad-classmethod-argument - C0202 71 | # redefined-outer-name - W0621 72 | # consider-using-ternary- R1706 73 | # unused-import - W0611 74 | # trailing-comma-tuple - R1707 75 | # deprecated-method - W1505 76 | # trailing-newlines - C0305 77 | # wrong-import-order - C0411 78 | # no-else-raise - R1720 79 | # consider-using-in - R1714 80 | # relative-beyond-top-level - E0402 81 | # useless-object-inheritance - R0205 82 | # duplicate-except - W0705 83 | # trailing-whitespace - C0303 84 | # self-cls-assignment - W0642 85 | # consider-using-get - R1715 86 | # consider-using-set-comprehension - R1718 87 | # consider-using-dict-comprehension - R1717 88 | # unnecessary-semicolon - W0301 89 | # singleton-comparison - C0121 90 | # unneeded-not - C0113 91 | # too-many-nested-blocks - R1702 92 | # logging-too-many-args - E1205 93 | # redundant-unittest-assert - W1503 94 | # implicit-str-concat-in-sequence - W1403 95 | # simplifiable-if-expression - R1719 96 | # lost-exception - W0150 97 | # useless-return - R1711 98 | # global-statement - W0603 99 | # too-many-boolean-expressions - R0916 100 | # empty-docstring - C0112 101 | # try-except-raise - W0706 102 | # undefined-variable - E0602 103 | # signature-differs - W0222 104 | # inconsistent-return-statements - R1710 105 | # no-else-continue - R1724 106 | # --- 107 | # TODO 108 | # --- 109 | # wrong-import-position - C0413 110 | # misplaced-comparison-constant - C0122 111 | # deprecated-module - W0402 112 | # keyword-arg-before-vararg - W1113 113 | # method-hidden - E0202 114 | # attribute-defined-outside-init - W0201 115 | # broad-except - W0703 116 | # cell-var-from-loop - W0640 117 | # arguments-differ - W0221 118 | # fixme - W0511 119 | # unused-argument - W0613 120 | # no-value-for-parameter - E1120 121 | # assignment-from-no-return - E1111 122 | # chained-comparison - R1716 123 | # abstract-method - W0223 124 | # comparison-with-callable - W0143 125 | # expression-not-assigned - W0106 126 | # too-many-arguments - R0913 127 | 128 | enable=anomalous-backslash-in-string, 129 | assignment-from-none, 130 | dangerous-default-value, 131 | duplicate-key, 132 | missing-import-error, 133 | missing-manifest-dependency, 134 | pointless-statement, 135 | pointless-string-statement, 136 | print-statement, 137 | redundant-keyword-arg, 138 | reimported, 139 | relative-import, 140 | return-in-init, 141 | too-few-format-args, 142 | unreachable, 143 | bad-whitespace, 144 | redefined-builtin, 145 | notimplemented-raised, 146 | not-callable, 147 | unnecessary-lambda, 148 | bad-continuation, 149 | bad-super-call, 150 | useless-super-delegation, 151 | super-init-not-called, 152 | unused-variable, 153 | missing-final-newline, 154 | literal-comparison, 155 | blacklisted-name, 156 | len-as-condition, 157 | too-many-locals, 158 | too-many-statements, 159 | too-many-branches, 160 | too-many-return-statements, 161 | too-many-nested-blocks 162 | wildcard-import, 163 | no-else-return, 164 | unnecessary-pass, 165 | function-redefined, 166 | logging-not-lazy, 167 | logging-format-interpolation, 168 | bare-except, 169 | incoherent-interpreter-exec-perm, 170 | multiple-statements, 171 | redefined-builtin, 172 | ungrouped-imports, 173 | simplifiable-if-statement, 174 | deprecated-lambda, 175 | except-pass, 176 | no-init, 177 | anomalous-unicode-escape-in-string, 178 | unidiomatic-typecheck, 179 | using-constant-test, 180 | undefined-loop-variable, 181 | too-many-lines, 182 | redefined-argument-from-local, 183 | superfluous-parens, 184 | bad-indentation, 185 | no-self-argument, 186 | bad-classmethod-argument, 187 | redefined-outer-name, 188 | consider-using-ternary, 189 | unused-import, 190 | trailing-comma-tuple, 191 | deprecated-method, 192 | trailing-newlines, 193 | wrong-import-order, 194 | no-else-raise, 195 | consider-using-in, 196 | relative-beyond-top-level, 197 | useless-object-inheritance, 198 | duplicate-except, 199 | singleton-comparison, 200 | trailing-whitespace, 201 | unneeded-not, 202 | too-many-nested-blocks, 203 | global-statement, 204 | try-except-raise, 205 | self-cls-assignment, 206 | consider-using-get, 207 | redundant-unittest-assert, 208 | simplifiable-if-expression, 209 | logging-too-many-args, 210 | useless-return, 211 | implicit-str-concat-in-sequence, 212 | consider-using-set-comprehension, 213 | consider-using-dict-comprehension, 214 | lost-exception, 215 | too-many-boolean-expressions, 216 | empty-docstring, 217 | unnecessary-semicolon, 218 | undefined-variable, 219 | signature-differs, 220 | inconsistent-return-statements, 221 | no-else-continue, 222 | odoolint 223 | 224 | 225 | [REPORTS] 226 | msg-template={path}:{line}: [{msg_id}({symbol}), {obj}] {msg} 227 | output-format=colorized 228 | files-output=no 229 | reports=no 230 | evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) 231 | comment=no 232 | 233 | [FORMAT] 234 | indent-string=' ' 235 | 236 | [SIMILARITIES] 237 | ignore-comments=yes 238 | ignore-docstrings=yes 239 | min-similarity-lines=8 240 | 241 | [MISCELLANEOUS] 242 | notes=TODO 243 | 244 | [IMPORTS] 245 | deprecated-modules=pdb,pudb,ipdb,openerp.osv 246 | 247 | [ODOOLINT] 248 | license_allowed=AGPL-3,GPL-2,GPL-2 or any later version,GPL-3,GPL-3 or any later version,LGPL-3,OPL-1,OEEL-1,Other proprietary,Other OSI approved licence 249 | -------------------------------------------------------------------------------- /lib/default_config/pylint_odoo_strict.cfg: -------------------------------------------------------------------------------- 1 | [MASTER] 2 | profile=no 3 | ignore=CVS,.git,scenarios,.bzr,.idea 4 | persistent=yes 5 | cache-size=500 6 | load-plugins=pylint_odoo 7 | 8 | [MESSAGES CONTROL] 9 | #disable=all 10 | disable=missing-docstring,invalid-name,import-error,no-member,too-many-instance-attributes,attribute-defined-outside-init,too-few-public-methods,no-self-use,protected-access,unused-argument,too-many-public-methods,cell-var-from-loop,access-member-before-definition,c-extension-no-member,fixme,broad-except,arguments-differ,duplicate-code,too-many-ancestors,too-many-arguments 11 | 12 | 13 | [REPORTS] 14 | msg-template={path}:{line}: [{msg_id}({symbol}), {obj}] {msg} 15 | output-format=colorized 16 | files-output=no 17 | reports=no 18 | evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) 19 | comment=no 20 | 21 | [FORMAT] 22 | indent-string=' ' 23 | 24 | [SIMILARITIES] 25 | ignore-comments=yes 26 | ignore-docstrings=yes 27 | min-similarity-lines=8 28 | 29 | [MISCELLANEOUS] 30 | notes=TODO 31 | 32 | [IMPORTS] 33 | deprecated-modules=pdb,pudb,ipdb,openerp.osv 34 | 35 | [ODOOLINT] 36 | license_allowed=AGPL-3,GPL-2,GPL-2 or any later version,GPL-3,GPL-3 or any later version,LGPL-3,OPL-1,OEEL-1,Other proprietary,Other OSI approved licence 37 | 38 | -------------------------------------------------------------------------------- /lib/default_config/stylelint-default-less.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "stylelint-config-standard", 3 | "rules": { 4 | "indentation": 4 5 | } 6 | } 7 | 8 | -------------------------------------------------------------------------------- /lib/default_config/stylelint-default-scss.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "stylelint-config-standard-scss", 3 | "rules": { 4 | "indentation": 4 5 | } 6 | } 7 | 8 | -------------------------------------------------------------------------------- /lib/default_config/stylelint-default.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "stylelint-config-standard" 3 | } 4 | -------------------------------------------------------------------------------- /lib/doc-utils.bash: -------------------------------------------------------------------------------- 1 | # Copyright © 2018 Dmytro Katyukha 2 | 3 | ####################################################################### 4 | # This Source Code Form is subject to the terms of the Mozilla Public # 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this # 6 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. # 7 | ####################################################################### 8 | 9 | if [ -z "$ODOO_HELPER_LIB" ]; then 10 | echo "Odoo-helper-scripts seems not been installed correctly."; 11 | echo "Reinstall it (see Readme on https://gitlab.com/katyukha/odoo-helper-scripts/)"; 12 | exit 1; 13 | fi 14 | 15 | if [ -z "$ODOO_HELPER_COMMON_IMPORTED" ]; then 16 | source "$ODOO_HELPER_LIB/common.bash"; 17 | fi 18 | 19 | ohelper_require 'addons'; 20 | ohelper_require 'utils'; 21 | # ---------------------------------------------------------------------------------------- 22 | 23 | set -e; # fail on errors 24 | 25 | 26 | # Internal function to print info about single addon 27 | # doc_utils_addons_list_addon_info_header [field 2] ... [field n] 28 | function doc_utils_addons_list_addon_info_header { 29 | local format=$1; shift; 30 | local field_regex="([^-]+)-(.+)" 31 | 32 | if [ "$format" == "md" ]; then 33 | local result="|" 34 | elif [ "$format" == "csv" ]; then 35 | local result=""; 36 | fi 37 | 38 | for field in "$@"; do 39 | if ! [[ $field =~ $field_regex ]]; then 40 | echoe -e "${REDC}ERROR${NC}: cannot parse field '${YELLOWC}${field}${NC}'! Skipping..."; 41 | else 42 | local t_name; 43 | local field_type=${BASH_REMATCH[1]}; 44 | local field_name=${BASH_REMATCH[2]}; 45 | 46 | if [ "$field_type" == "manifest" ]; then 47 | t_name="${field_name^}"; 48 | elif [ "$field_type" == "system" ] && [ "$field_name" == "name" ]; then 49 | t_name="System Name"; 50 | elif [ "$field_type" == "system" ] && [ "$field_name" == "git_repo" ]; then 51 | t_name="Git URL"; 52 | elif [ "$field_type" == "system" ] && [ "$field_name" == "dependencies" ]; then 53 | t_name="Dependencies"; 54 | elif [ "$field_type" == "custom" ]; then 55 | t_name=""; 56 | else 57 | echoe -e "${REDC}ERROR${NC}: cannot parse field '${YELLOWC}${field}${NC}'! Skipping..."; 58 | continue 59 | fi 60 | 61 | if [ "$format" == "md" ]; then 62 | result="${result} ${t_name} |"; 63 | elif [ "$format" == "csv" ]; then 64 | result="${result}\"${t_name}\","; 65 | fi 66 | 67 | fi 68 | done 69 | 70 | if [ "$format" == "md" ]; then 71 | result="$result\n|"; 72 | for field in "$@"; do 73 | if ! [[ $field =~ $field_regex ]]; then 74 | echoe -e "${REDC}ERROR${NC}: cannot parse field '${YELLOWC}${field}${NC}'! Skipping..."; 75 | else 76 | result="${result}---|"; 77 | fi 78 | done 79 | fi 80 | echo "$result"; 81 | 82 | } 83 | 84 | 85 | # Internal function to print info about single addon 86 | # doc_utils_addons_list_addon_info [field 2] ... [field n] 87 | function doc_utils_addons_list_addon_info { 88 | # Field names is space separated list of names of fields to display. 89 | # field name consist of two parts: - 90 | # field type could be: 91 | # - manifest 92 | # - system 93 | # system fields could be following 94 | # - name 95 | # - git_repo 96 | local field_regex="([^-]+)-(.+)" 97 | 98 | local format=$1; shift; 99 | local addon=$1; shift; 100 | 101 | if [ "$format" == "md" ]; then 102 | local result="|" 103 | elif [ "$format" == "csv" ]; then 104 | local result=""; 105 | fi 106 | for field in "$@"; do 107 | if ! [[ $field =~ $field_regex ]]; then 108 | echoe -e "${REDC}ERROR${NC}: cannot parse field '${YELLOWC}${field}${NC}'! Skipping..."; 109 | else 110 | local t_res=""; 111 | local field_type=${BASH_REMATCH[1]}; 112 | local field_name=${BASH_REMATCH[2]}; 113 | 114 | if [ "$field_type" == "manifest" ]; then 115 | t_res=$(addons_get_manifest_key "$addon" "$field_name" "''" | tr '\n' ' '); 116 | t_res=$(trim "$t_res"); 117 | elif [ "$field_type" == "system" ] && [ "$field_name" == "name" ]; then 118 | t_res=$(basename "$addon"); 119 | elif [ "$field_type" == "system" ] && [ "$field_name" == "git_repo" ]; then 120 | if git_is_git_repo "$addon"; then 121 | t_res=$(git_get_remote_url "$addon"); 122 | else 123 | t_res="Not in git repository"; 124 | fi 125 | elif [ "$field_type" == "system" ] && [ "$field_name" == "dependencies" ]; then 126 | t_res=$(addons_get_addon_dependencies "$addon"); 127 | elif [ "$field_type" == "custom" ]; then 128 | t_res="$field_name"; 129 | else 130 | echoe -e "${REDC}ERROR${NC}: cannot parse field '${YELLOWC}${field}${NC}'! Skipping..."; 131 | fi 132 | if [ "$format" == "md" ]; then 133 | result="${result} ${t_res} |"; 134 | elif [ "$format" == "csv" ]; then 135 | result="${result}\"${t_res}\","; 136 | fi 137 | fi 138 | done 139 | 140 | echo "$result"; 141 | 142 | } 143 | # Print addons table in markdown table 144 | function doc_utils_addons_list { 145 | local usage=" 146 | Usage: 147 | 148 | $SCRIPT_NAME doc-utils addons-list [options] [addons path] - list addons in specified directory 149 | $SCRIPT_NAME doc-utils addons-list --help - show this help message 150 | 151 | Options 152 | -f|--field - display name of field in manifest 153 | --git-repo - display git repository 154 | --sys-name - display system name 155 | --no-header - do not display header 156 | --dependencies - display dependencies list separated by coma 157 | --format - output format. default: md 158 | --custom-val - custom value 159 | --recursive - search for addons recusively 160 | --installable - installable only 161 | 162 | Description 163 | Prints list of addons in specified dierectory in markdown format. 164 | 165 | Could be used like: 166 | $ odoo-helper doc-utils addons-list ./my_addon_repo/ > addons.md 167 | 168 | Or 169 | $ odoo-helper doc-utils addons-list ./my-repo-1 && odoo-helper doc-utils addons-list ./my-repo-2 > addons.md 170 | 171 | Default options is following: 172 | --sys-name -f name -f version -f summary 173 | 174 | Result looks like 175 | 176 | | System Name | Name | Version | Summary | 177 | |---|---|---|---| 178 | | my_addon | My Addon | 11.0.0.1.0 | My Cool Addon | 179 | | my_addon_2 | My Addon 2 | 11.0.0.2.0 | My Cool Addon 2 | 180 | "; 181 | 182 | # look at doc_utils_addons_list_addon_info for info 183 | local field_names=( ); 184 | 185 | local addons_path=; 186 | local format="md"; 187 | 188 | local addons_list_opts=( ); 189 | 190 | while [[ $# -gt 0 ]] 191 | do 192 | local key="$1"; 193 | case $key in 194 | -f|--field) 195 | field_names+=( "manifest-$2" ); 196 | shift; 197 | ;; 198 | --sys-name) 199 | field_names+=( system-name ); 200 | ;; 201 | --git-repo) 202 | field_names+=( system-git_repo ); 203 | ;; 204 | --dependencies) 205 | field_names+=( system-dependencies ); 206 | ;; 207 | --custom-val) 208 | field_names+=( "custom-$2" ); 209 | shift; 210 | ;; 211 | --no-header) 212 | local no_header=1; 213 | ;; 214 | --format) 215 | local format=$2; 216 | shift; 217 | ;; 218 | --recursive) 219 | addons_list_opts+=( --recursive ); 220 | ;; 221 | --installable) 222 | addons_list_opts+=( --installable ); 223 | ;; 224 | -h|--help|help) 225 | echo "$usage"; 226 | return 0; 227 | ;; 228 | *) 229 | addons_path=$key; 230 | shift; 231 | break; 232 | ;; 233 | esac 234 | shift; 235 | done 236 | 237 | addons_path=${addons_path:-$ADDONS_DIR}; 238 | if [ ${#field_names[@]} -eq 0 ]; then 239 | field_names=( system-name manifest-name manifest-version manifest-summary ); 240 | fi 241 | 242 | if [ -z "$no_header" ]; then 243 | result=$(doc_utils_addons_list_addon_info_header "$format" "${field_names[@]}"); 244 | else 245 | result=; 246 | fi 247 | 248 | local addons_list; 249 | mapfile -t addons_list < <(addons_list_in_directory "${addons_list_opts[@]}" "$addons_path"); 250 | for addon in "${addons_list[@]}"; do 251 | local addon_info; 252 | addon_info=$(doc_utils_addons_list_addon_info "$format" "$addon" "${field_names[@]}"); 253 | if [ -z "$result" ]; then 254 | result=$addon_info; 255 | else 256 | result="${result}\n$addon_info"; 257 | fi 258 | done 259 | 260 | echo -e "$result"; 261 | } 262 | 263 | # shellcheck disable=SC2129 264 | function doc_utils_module_graph { 265 | local usage=" 266 | ${YELLOWC}Warning${NC}: 267 | This command is experimental and may be changed in future 268 | 269 | Usage: 270 | 271 | $SCRIPT_NAME doc-utils addons-graph [options] - build depedency graph for addons in directory 272 | $SCRIPT_NAME doc-utils addons-graph --help - show this help message 273 | 274 | Options 275 | --out - output path (default ./graph.svg) 276 | -f|--format - output format (default: svg) 277 | - supported formats: https://graphviz.org/doc/info/output.html 278 | 279 | "; 280 | 281 | 282 | local out_path; 283 | local out_format="svg"; 284 | out_path="$(pwd)/graph.svg"; 285 | while [[ $# -gt 0 ]] 286 | do 287 | local key="$1"; 288 | case $key in 289 | --out) 290 | out_path="$2"; 291 | shift; 292 | ;; 293 | -f|--format) 294 | out_format="$2"; 295 | shift; 296 | ;; 297 | -h|--help|help) 298 | echo -e "$usage"; 299 | return 0; 300 | ;; 301 | *) 302 | break; 303 | ;; 304 | esac 305 | shift; 306 | done 307 | local addons_path="$1"; 308 | 309 | local tmp_graph_file; 310 | tmp_graph_file="/tmp/oh-module-graph-$(date -I)-$(random_string 4).gv"; 311 | echo "digraph G {" > "$tmp_graph_file"; 312 | echo " graph [concentrate=true];" >> "$tmp_graph_file"; 313 | echo " graph [K=1.0];" >> "$tmp_graph_file"; 314 | echo " graph [minlen=3];" >> "$tmp_graph_file"; 315 | echo " graph [nodesep=1.0];" >> "$tmp_graph_file"; 316 | echo " graph [ranksep=2.0];" >> "$tmp_graph_file"; 317 | 318 | addons_path=${addons_path:-$ADDONS_DIR}; 319 | local addons_list; 320 | mapfile -t addons_list < <(addons_list_in_directory "$addons_path"); 321 | for addon_path in "${addons_list[@]}"; do 322 | local addon_name; 323 | addon_name=$(addons_get_addon_name "$addon_path"); 324 | local deps_str; 325 | deps_str=$(addons_get_addon_dependencies "$addon_path"); 326 | local deps; 327 | IFS=" " read -ra deps <<< "$deps_str"; 328 | for dep in "${deps[@]}"; do 329 | echo " $addon_name -> $dep;" >> "$tmp_graph_file"; 330 | done 331 | done; 332 | echo "}" >> "$tmp_graph_file"; 333 | dot "-T${out_format}" -o "$out_path" "$tmp_graph_file"; 334 | rm "$tmp_graph_file"; 335 | } 336 | 337 | 338 | function doc_utils_command { 339 | local usage=" 340 | Usage: 341 | 342 | $SCRIPT_NAME doc-utils addons-list --help - list addons in specified directory 343 | $SCRIPT_NAME doc-utils addons-graph --help - generate graph with addons dependencies 344 | $SCRIPT_NAME doc-utils --help - show this help message 345 | 346 | "; 347 | 348 | if [[ $# -lt 1 ]]; then 349 | echo "$usage"; 350 | return 0; 351 | fi 352 | 353 | while [[ $# -gt 0 ]] 354 | do 355 | local key="$1"; 356 | case $key in 357 | addons-list) 358 | shift; 359 | doc_utils_addons_list "$@"; 360 | return; 361 | ;; 362 | addons-graph) 363 | shift; 364 | doc_utils_module_graph "$@"; 365 | return; 366 | ;; 367 | -h|--help|help) 368 | echo "$usage"; 369 | return 0; 370 | ;; 371 | *) 372 | echo "Unknown option / command $key"; 373 | return 1; 374 | ;; 375 | esac 376 | done 377 | } 378 | -------------------------------------------------------------------------------- /lib/git.bash: -------------------------------------------------------------------------------- 1 | # Copyright © 2015-2018 Dmytro Katyukha 2 | 3 | ####################################################################### 4 | # This Source Code Form is subject to the terms of the Mozilla Public # 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this # 6 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. # 7 | ####################################################################### 8 | 9 | if [ -z "$ODOO_HELPER_LIB" ]; then 10 | echo "Odoo-helper-scripts seems not been installed correctly."; 11 | echo "Reinstall it (see Readme on https://gitlab.com/katyukha/odoo-helper-scripts/)"; 12 | exit 1; 13 | fi 14 | 15 | if [ -z "$ODOO_HELPER_COMMON_IMPORTED" ]; then 16 | source "$ODOO_HELPER_LIB/common.bash"; 17 | fi 18 | 19 | # ---------------------------------------------------------------------------------------- 20 | 21 | set -e; # fail on errors 22 | 23 | 24 | # git_is_git_repo 25 | function git_is_git_repo { 26 | if [ -d "${1}/.git" ] || (cd "${1}" && git rev-parse --git-dir > /dev/null 2>&1); then 27 | return 0; # it is git repository 28 | else 29 | return 1; # It is not git repository 30 | fi 31 | } 32 | 33 | # git_get_abs_repo_path 34 | function git_get_abs_repo_path { 35 | (cd "$1" && git rev-parse --show-toplevel); 36 | } 37 | 38 | # git_get_current_commit 39 | function git_get_current_commit { 40 | (cd "$1" && git rev-parse --verify --short HEAD); 41 | } 42 | 43 | # git_is_merging 44 | function git_is_merging { 45 | (cd "$1" && git rev-parse -q --verify MERGE_HEAD > /dev/null 2>&1); 46 | } 47 | 48 | # git_file_has_conflicts 49 | # return 0 if specified path has conflicts 50 | function git_file_has_conflicts { 51 | ! (cd "$1" && git diff -q --check -- "$2" > /dev/null 2>&1); 52 | } 53 | 54 | # git_get_branch_name [repo_path] 55 | function git_get_branch_name { 56 | local cdir; 57 | cdir=$(pwd); 58 | if [ -n "$1" ]; then 59 | cd "$1"; 60 | fi 61 | 62 | local branch_name; 63 | branch_name=$(git symbolic-ref -q HEAD); 64 | branch_name=${branch_name##refs/heads/}; 65 | branch_name=${branch_name:-HEAD}; 66 | 67 | echo "$branch_name" 68 | 69 | if [ -n "$1" ]; then 70 | cd "$cdir"; 71 | fi 72 | } 73 | 74 | # git_get_remote_url [repo_path] 75 | function git_get_remote_url { 76 | local cdir; 77 | cdir=$(pwd); 78 | if [ -n "$1" ]; then 79 | cd "$1"; 80 | fi 81 | 82 | local git_remote; 83 | local current_branch; 84 | current_branch=$(git_get_branch_name "$1"); 85 | git_remote=$(git config --local --get "branch.$current_branch.remote"); 86 | git config --local --get "remote.$git_remote.url"; 87 | 88 | if [ -n "$1" ]; then 89 | cd "$cdir"; 90 | fi 91 | } 92 | 93 | # Code is based on https://github.com/magicmonty/bash-git-prompt/blob/master/gitstatus.sh 94 | # Parses git status output, and print parsed values line by line, making it availble 95 | # to be used in way like: 96 | # git_status = $(git_parse_status) 97 | # echo "Repo branch ${git_status[0]} 98 | # echo "Repo clean status ${git_status[3]} 99 | # result contains folowing values: 100 | # 0 - branch name 101 | # 1 - remote status 102 | # 2 - upstream info 103 | # 3 - clean status (0 - not clena, 1 - clean) 104 | # 4 - number of staged files 105 | # 5 - number of changed files 106 | # 6 - number of conflicts 107 | # 7 - number of untracked files 108 | # 8 - number of stashes 109 | # git_parse_status 110 | function git_parse_status { 111 | local path_to_repo=$1; 112 | local cdir; 113 | 114 | if ! git_is_git_repo "$path_to_repo"; then 115 | echoe -e "${REDC}ERROR${NC}: Cannot get git status for ${YELLOWC}${path_to_repo}${NC} - it is not git repository"; 116 | return 1; 117 | fi 118 | cdir=$(pwd); 119 | 120 | # Go to repository directory 121 | cd "$path_to_repo"; 122 | 123 | local gitstatus; 124 | gitstatus=$( LC_ALL=C git status --untracked-files=all --porcelain --branch ) 125 | 126 | local num_staged=0 127 | local num_changed=0 128 | local num_conflicts=0 129 | local num_untracked=0 130 | while IFS='' read -r line || [[ -n "$line" ]]; do 131 | if [ -z "$line" ]; then 132 | continue; 133 | fi 134 | 135 | local status=${line:0:2} 136 | case "$status" in 137 | \#\#) 138 | local branch_line="${line/\.\.\./^}"; 139 | ;; 140 | ?M) 141 | ((num_changed++)) 142 | ;; 143 | U?) 144 | ((num_conflicts++)) 145 | ;; 146 | \?\?) 147 | ((num_untracked++)) 148 | ;; 149 | *) 150 | ((num_staged++)) 151 | ;; 152 | esac 153 | done <<< "$gitstatus" 154 | 155 | local num_stashed=0 156 | local stash_file; 157 | stash_file="$(git rev-parse --git-dir)/logs/refs/stash" 158 | if [[ -e "${stash_file}" ]]; then 159 | while IFS='' read -r wcline || [[ -n "$wcline" ]]; do 160 | ((num_stashed++)); 161 | done < "${stash_file}" 162 | fi 163 | 164 | local clean=0 165 | if (( num_changed == 0 && num_staged == 0 && num_untracked == 0 && num_stashed == 0 )) ; then 166 | clean=1 167 | fi 168 | 169 | # --- 170 | local branch_fields; 171 | IFS="^" read -ra branch_fields <<< "${branch_line/\#\# }" 172 | local branch="${branch_fields[0]}"; 173 | local remote; 174 | local upstream; 175 | 176 | if [[ "$branch" == *"Initial commit on"* ]]; then 177 | local fields; 178 | IFS=" " read -ra fields <<< "$branch" 179 | branch="${fields[3]}" 180 | remote="_NO_REMOTE_TRACKING_" 181 | elif [[ "$branch" == *"no branch"* ]]; then 182 | local tag; 183 | tag=$(git describe --exact-match) 184 | if [[ -n "$tag" ]]; then 185 | branch="$tag" 186 | else 187 | branch="_PREHASH_$(git rev-parse --short HEAD)" 188 | fi 189 | else 190 | if [[ "${#branch_fields[@]}" -eq 1 ]]; then 191 | remote="_NO_REMOTE_TRACKING_" 192 | else 193 | local remote_fields; 194 | IFS="[,]" read -ra remote_fields <<< "${branch_fields[1]}" 195 | upstream="${remote_fields[0]}" 196 | for remote_field in "${remote_fields[@]}"; do 197 | if [[ "$remote_field" == *ahead* ]]; then 198 | num_ahead=${remote_field:6} 199 | ahead="_AHEAD_${num_ahead}" 200 | fi 201 | if [[ "$remote_field" == *behind* ]]; then 202 | num_behind=${remote_field:7} 203 | behind="_BEHIND_${num_behind# }" 204 | fi 205 | done 206 | remote="${behind}${ahead}" 207 | fi 208 | fi 209 | 210 | if [[ -z "$branch" ]]; then 211 | branch=$(git_get_branch_name) 212 | fi 213 | 214 | if [[ -z "$remote" ]] ; then 215 | remote='.' 216 | fi 217 | 218 | if [[ -z "$upstream" ]] ; then 219 | upstream='^' 220 | fi 221 | 222 | # --- 223 | 224 | # Print parse result 225 | echo -e "$branch\n$remote\n$upstream\n$clean\n$num_staged\n$num_changed\n$num_conflicts\n$num_untracked\n$num_stashed\n" 226 | 227 | # Go back to working dir 228 | cd "$cdir"; 229 | } 230 | 231 | 232 | # git_is_clean 233 | # Check if repository is clean (no uncommited changes) 234 | function git_is_clean { 235 | local git_status=; 236 | mapfile -t git_status < <({ git_parse_status "$1" || echo ''; } | sed '/^$/d'); 237 | if (( git_status[4] == 0 && git_status[5] == 0 && git_status[6]== 0 && git_status[7] == 0 )) ; then 238 | return 0; # repo is clean 239 | else 240 | return 1; # repo is dirty 241 | fi 242 | } 243 | 244 | 245 | # git_get_commit_date 246 | # Show date of specified commit 247 | function git_get_commit_date { 248 | local repo_path="$1"; 249 | local commit_ref="$2"; 250 | (cd "$repo_path" && git show -s --date=short --format=%cd "$commit_ref"); 251 | } 252 | 253 | # git_get_current_commit_date 254 | # Show date of current commit in repo 255 | function git_get_current_commit_date { 256 | local repo_path="$1"; 257 | local commit_ref; 258 | commit_ref=$(git_get_current_commit "$repo_path"); 259 | git_get_commit_date "$repo_path" "$commit_ref"; 260 | } 261 | 262 | # git_get_addons_changed 263 | # Get list of addons that have changes betwen specified revisions 264 | # Prints paths to addons 265 | function git_get_addons_changed { 266 | local usage=" 267 | Print list of paths of addons changed between specified git revisions 268 | 269 | Usage: 270 | $SCRIPT_NAME git changed-addons [options] 271 | 272 | Options: 273 | --ignore-trans - ignore changed translations 274 | Note: this option may not work on old git versions 275 | -h|--help|help - print this help message end exit 276 | 277 | Parametrs: 278 | - path to git repository to search for changed addons in 279 | - git start revision 280 | - git end revision 281 | "; 282 | if [[ $# -lt 1 ]]; then 283 | echo "$usage"; 284 | return 0; 285 | fi 286 | 287 | while [[ $# -gt 0 ]] 288 | do 289 | local key="$1"; 290 | case $key in 291 | -h|--help|help) 292 | echo "$usage"; 293 | shift; 294 | return 0; 295 | ;; 296 | --ignore-trans) 297 | local exclude_translations=1; 298 | shift; 299 | ;; 300 | *) 301 | break; 302 | ;; 303 | esac 304 | done 305 | 306 | local repo_path; 307 | repo_path=$(git_get_abs_repo_path "$1"); shift; 308 | local ref_start="$1"; shift; 309 | local ref_end="$1"; shift; 310 | local cdir; 311 | cdir=$(pwd); 312 | 313 | local ref_revision; 314 | if [ "$ref_end" == "-working-tree-" ]; then 315 | ref_revision="$ref_start"; 316 | else 317 | ref_revision="$ref_start..$ref_end"; 318 | fi 319 | 320 | cd "$repo_path"; 321 | 322 | local changed_files; 323 | if [ -n "$exclude_translations" ]; then 324 | mapfile -t changed_files < <(git diff --name-only "${ref_revision}" -- ':(exclude)*.po' ':(exclude)*.pot' | sed '/^$/d'); 325 | else 326 | mapfile -t changed_files < <(git diff --name-only "${ref_revision}" | sed '/^$/d'); 327 | fi 328 | for file_path in "${changed_files[@]}"; do 329 | local manifest_path; 330 | manifest_path=$(search_file_up "$file_path" __manifest__.py); 331 | if [ -z "$manifest_path" ]; then 332 | manifest_path=$(search_file_up "$file_path" __openerp__.py); 333 | fi 334 | if [ -n "$manifest_path" ]; then 335 | local addon_path; 336 | manifest_path=$(readlink -f "$manifest_path"); 337 | addon_path=$(dirname "$manifest_path"); 338 | echo "$addon_path"; 339 | fi 340 | done | sort -u; 341 | } 342 | 343 | 344 | function git_command { 345 | local usage=" 346 | Git-related commands 347 | 348 | NOTE: This command is experimental and everything may be changed. 349 | 350 | Usage: 351 | $SCRIPT_NAME git changed-addons [--help] - show list of addons changed 352 | $SCRIPT_NAME git -h|--help|help - show this help message 353 | "; 354 | 355 | if [[ $# -lt 1 ]]; then 356 | echo "$usage"; 357 | return 0; 358 | fi 359 | 360 | while [[ $# -gt 0 ]] 361 | do 362 | local key="$1"; 363 | case $key in 364 | changed-addons) 365 | shift; 366 | git_get_addons_changed "$@"; 367 | return; 368 | ;; 369 | -h|--help|help) 370 | echo "$usage"; 371 | return 0; 372 | ;; 373 | *) 374 | echo "Unknown option / command $key"; 375 | return 1; 376 | ;; 377 | esac 378 | done 379 | } 380 | -------------------------------------------------------------------------------- /lib/link.bash: -------------------------------------------------------------------------------- 1 | # Copyright © 2017-2018 Dmytro Katyukha 2 | 3 | ####################################################################### 4 | # This Source Code Form is subject to the terms of the Mozilla Public # 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this # 6 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. # 7 | ####################################################################### 8 | 9 | if [ -z "$ODOO_HELPER_LIB" ]; then 10 | echo "Odoo-helper-scripts seems not been installed correctly."; 11 | echo "Reinstall it (see Readme on https://gitlab.com/katyukha/odoo-helper-scripts/)"; 12 | exit 1; 13 | fi 14 | 15 | if [ -z "$ODOO_HELPER_COMMON_IMPORTED" ]; then 16 | source "$ODOO_HELPER_LIB/common.bash"; 17 | fi 18 | 19 | # Require libs 20 | ohelper_require 'git'; 21 | ohelper_require 'recursion'; 22 | ohelper_require 'addons'; 23 | ohelper_require 'fetch'; 24 | # ---------------------------------------------------------------------------------------- 25 | 26 | set -e; # fail on errors 27 | 28 | 29 | # link_is_addon_linked 30 | # Return statuses 31 | # * 0 - addon is linked 32 | # * 1 - addon is not present in addons dir 33 | # * 2 - addon is present in addons dir, but link points to another path 34 | function link_is_addon_linked { 35 | local addon_path; 36 | local addon_name; 37 | addon_path=$(readlink -f "$1"); 38 | addon_name=$(basename "$addon_path"); 39 | 40 | if [ ! -e "$ADDONS_DIR/$addon_name" ]; then 41 | # Addon is not present in custom addons 42 | return 1; 43 | fi 44 | local linked_path; 45 | linked_path=$(readlink -f "$ADDONS_DIR/$addon_name") 46 | 47 | if [ "$addon_path" == "$linked_path" ]; then 48 | # Addon is present in custom addons and link points to addon been checked 49 | return 0; 50 | else 51 | return 2; 52 | fi 53 | 54 | } 55 | 56 | 57 | # link_module_impl 58 | function link_module_impl { 59 | local src; src=$(readlink -f "$1"); 60 | local dest=$2; 61 | local force=$3; 62 | local py_deps_manifest="$4"; 63 | local fetch_recursive="$5"; 64 | 65 | if [ "$force" == "on" ] && { [ -e "$dest" ] || [ -L "$dest" ]; }; then 66 | echov "Rewriting module $dest..."; 67 | rm -rf "$dest"; 68 | fi 69 | 70 | if [ ! -d "$dest" ]; then 71 | if [ -z "$USE_COPY" ]; then 72 | if [ -h "$dest" ] && [ ! -e "$dest" ]; then 73 | # If it is broken link, remove it 74 | rm "$dest"; 75 | fi 76 | ln -s "$src" "$dest" ; 77 | else 78 | cp -r "$src" "$dest"; 79 | fi 80 | else 81 | echov "Module $src already linked to $dest"; 82 | fi 83 | fetch_pip_requirements "$dest"; 84 | 85 | if [ "$fetch_recursive" == "on" ]; then 86 | fetch_requirements "$dest"; 87 | fetch_oca_requirements "$dest"; 88 | fi 89 | 90 | if [ "$py_deps_manifest" == "on" ] && [ -f "$dest/__manifest__.py" ]; then 91 | local py_deps; 92 | py_deps=$(exec_py_utils addon-py-deps --addon-path "$dest"); 93 | if [ -n "$py_deps" ]; then 94 | odoo-helper pip install "$py_deps"; 95 | fi 96 | fi 97 | } 98 | 99 | # signature: 100 | # link_module [options] [] 101 | # options: 102 | # --force 103 | # --module-name 104 | # --fetch-manifest-py-deps 105 | # --fetch-recursive 106 | function link_module { 107 | local force=off; 108 | local fetch_manifest_py_deps=off; 109 | local module_name; 110 | local fetch_recursive=on; 111 | 112 | # Parse command line options and run commands 113 | if [[ $# -lt 1 ]]; then 114 | echo "No options supplied $#: $*"; 115 | return 1; 116 | fi 117 | 118 | # Process all args that starts with '-' (ie. options) 119 | while [[ $1 == -* ]] 120 | do 121 | local key="$1"; 122 | case $key in 123 | -f|--force) 124 | force=on; 125 | ;; 126 | --fetch-manifest-py-deps) 127 | fetch_manifest_py_deps=on; 128 | ;; 129 | --module-name) 130 | module_name="$2"; 131 | shift; 132 | ;; 133 | --fetch-recursive) 134 | fetch_recursive="$2"; 135 | shift; 136 | ;; 137 | *) 138 | echo "Unknown option $key"; 139 | return 1; 140 | ;; 141 | esac 142 | shift 143 | done 144 | local repo_path="$1" 145 | 146 | if [ -z "$repo_path" ]; then 147 | echo -e "${REDC}Bad repo path for link: ${YELLOWC}${repo_path}${NC}"; 148 | return 2; 149 | fi 150 | 151 | repo_path=$(readlink -f "$repo_path"); 152 | 153 | local recursion_key="link_module"; 154 | if ! recursion_protection_easy_check "$recursion_key" "${repo_path}__${module_name:-all}"; then 155 | echo -e "${YELLOWC}WARN${NC}: REPO__MODULE ${repo_path}__${module_name:-all} already had been processed. skipping..."; 156 | return 0 157 | fi 158 | 159 | echov "Linking module $repo_path [$module_name] ..."; 160 | 161 | # Guess repository type 162 | if is_odoo_module "$repo_path"; then 163 | # single module repo 164 | local basename_repo; 165 | basename_repo=$(basename "$repo_path"); 166 | link_module_impl "$repo_path" "$ADDONS_DIR/${module_name:-$basename_repo}" "$force" "$fetch_manifest_py_deps" "$fetch_recursive"; 167 | else 168 | # multi module repo 169 | if [ -z "$module_name" ]; then 170 | # Check for requirements files in repository root dir 171 | fetch_pip_requirements "$repo_path"; 172 | if [ "$fetch_recursive" == "on" ]; then 173 | fetch_requirements "$repo_path"; 174 | fetch_oca_requirements "$repo_path"; 175 | fi 176 | 177 | # No module name specified, then all modules in repository should be linked 178 | for file in "$repo_path"/*; do 179 | local base_filename; 180 | base_filename=$(basename "$file"); 181 | if is_odoo_module "$file" && addons_is_installable "$file"; then 182 | # link module 183 | link_module_impl "$file" "$ADDONS_DIR/$base_filename" "$force" "$fetch_manifest_py_deps" "$fetch_recursive"; 184 | elif [ -d "$file" ] && ! is_odoo_module "$file" && [ "$base_filename" != 'setup' ]; then 185 | # if it is directory but not odoo module, 186 | # and not 'setup' dir, then recursively look for addons there 187 | local link_module_opts=( --fetch-recursive "$fetch_recursive" ); 188 | if [ "$force" == on ]; then 189 | link_module_opts+=( --force ) 190 | fi 191 | if [ "$fetch_manifest_py_deps" == on ]; then 192 | link_module_opts+=( --fetch-manifest-py-deps ); 193 | fi 194 | link_module "${link_module_opts[@]}" "$file"; 195 | fi 196 | done 197 | else 198 | # Module name specified, then only single module should be linked 199 | link_module_impl "$repo_path/$module_name" "$ADDONS_DIR/$module_name" "$force" "$fetch_manifest_py_deps" "$fetch_recursive"; 200 | fi 201 | fi 202 | } 203 | 204 | 205 | function link_command { 206 | local usage=" 207 | Usage: 208 | 209 | $SCRIPT_NAME link [options] 210 | 211 | Options: 212 | -f|--force - rewrite links if already exists 213 | --fetch-manifest-py-deps - fetch python dependencies from addon's manifest 214 | --module-name - name of module to link from repo 215 | --no-fetch - Do not fetch repositories recursively 216 | --ual - update addons list after link 217 | "; 218 | 219 | # Parse command line options and run commands 220 | if [[ $# -lt 1 ]]; then 221 | echo "No options supplied $#: $*"; 222 | echo ""; 223 | echo "$usage"; 224 | return 0; 225 | fi 226 | 227 | local link_module_opts=( ) 228 | # Process all args that starts with '-' (ie. options) 229 | while [[ $1 == -* ]] 230 | do 231 | local key="$1"; 232 | case $key in 233 | -h|--help|help) 234 | echo "$usage"; 235 | return 0; 236 | ;; 237 | -f|--force) 238 | link_module_opts+=( --force ); 239 | ;; 240 | --fetch-manifest-py-deps) 241 | link_module_opts+=( --fetch-manifest-py-deps ); 242 | ;; 243 | --module-name) 244 | link_module_opts+=( --module-name "$2" ); 245 | shift; 246 | ;; 247 | --no-fetch) 248 | link_module_opts+=( --fetch-recursive off ); 249 | ;; 250 | --ual) 251 | ual=1; 252 | ;; 253 | *) 254 | echo "Unknown option $key"; 255 | return 1; 256 | ;; 257 | esac 258 | shift 259 | done 260 | 261 | link_module "${link_module_opts[@]}" "$@"; 262 | 263 | if [ -n "$ual" ]; then 264 | addons_update_module_list; 265 | fi 266 | } 267 | -------------------------------------------------------------------------------- /lib/lint.bash: -------------------------------------------------------------------------------- 1 | # Copyright © 2018 Dmytro Katyukha 2 | 3 | ####################################################################### 4 | # This Source Code Form is subject to the terms of the Mozilla Public # 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this # 6 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. # 7 | ####################################################################### 8 | 9 | if [ -z "$ODOO_HELPER_LIB" ]; then 10 | echo "Odoo-helper-scripts seems not been installed correctly."; 11 | echo "Reinstall it (see Readme on https://gitlab.com/katyukha/odoo-helper-scripts/)"; 12 | exit 1; 13 | fi 14 | 15 | if [ -z "$ODOO_HELPER_COMMON_IMPORTED" ]; then 16 | source "$ODOO_HELPER_LIB/common.bash"; 17 | fi 18 | 19 | 20 | ohelper_require "utils"; 21 | ohelper_require "addons"; 22 | ohelper_require "odoo"; 23 | ohelper_require "config"; 24 | # ---------------------------------------------------------------------------------------- 25 | 26 | set -e; # fail on errors 27 | 28 | # lint_run_flake8 [flake8 options] [module2 path] .. [module n path] 29 | function lint_run_flake8 { 30 | local usage=" 31 | Usage: 32 | 33 | $SCRIPT_NAME lint flake8 [addon path] 34 | $SCRIPT_NAME lint flake8 --help 35 | 36 | Description: 37 | Lint addons with [Flake8](http://flake8.pycqa.org) 38 | By default lints only installable addons ('installable' is True) on 39 | specified *addon paths* 40 | 41 | To run unwrapped flake8 use following command: 42 | 43 | $ odoo-helper exec flake8 44 | 45 | "; 46 | # Parse command line options 47 | if [[ $# -lt 1 ]]; then 48 | echo "No options supplied $#: $*"; 49 | echo ""; 50 | echo "$usage"; 51 | exit 0; 52 | fi 53 | 54 | while [[ $1 == -* ]] 55 | do 56 | key="$1"; 57 | case $key in 58 | -h|--help|help) 59 | echo "$usage"; 60 | return 0; 61 | ;; 62 | *) 63 | echo "Unknown option $key"; 64 | return 1; 65 | ;; 66 | esac 67 | done 68 | 69 | local res=0; 70 | local addons_list; 71 | local flake8_config; 72 | flake8_config=$(config_get_default_tool_conf "flake8.cfg"); 73 | mapfile -t addons_list < <(addons_list_in_directory --installable "$@"); 74 | if ! execu flake8 --config="$flake8_config" "${addons_list[@]}"; then 75 | return 1; 76 | fi 77 | } 78 | 79 | 80 | # Run pylint tests for modules 81 | # lint_run_pylint [module2 path] .. [module n path] 82 | # lint_run_pylint [--disable=E111,E222,...] [module2 path] .. [module n path] 83 | function lint_run_pylint { 84 | local pylint_rc 85 | local pylint_opts; 86 | local pylint_disable="manifest-required-author"; 87 | local guess_jslintrc=1; 88 | 89 | pylint_rc=$(config_get_default_tool_conf "pylint_odoo.cfg"); 90 | 91 | # Pre-process commandline arguments to be forwarded to pylint 92 | while [[ "$1" =~ ^--[a-zA-Z0-9\-]+(=[a-zA-Z0-9,-.]+)? ]]; do 93 | if [[ "$1" =~ ^--disable=([a-zA-Z0-9,-]*) ]]; then 94 | local pylint_disable_opt=$1; 95 | local pylint_disable_arg="${BASH_REMATCH[1]}"; 96 | pylint_disable=$(join_by , "$pylint_disable_arg" "manifest-required-author"); 97 | elif [[ "$1" =~ --help|--long-help|--version ]]; then 98 | local show_help=1; 99 | pylint_opts+=( "$1" ); 100 | elif [[ "$1" =~ --pylint-conf=(.+) ]]; then 101 | pylint_rc=$(config_get_default_tool_conf "${BASH_REMATCH[1]}") 102 | elif [[ "$1" =~ --jslintrc.* ]]; then 103 | guess_jslintrc=0; 104 | pylint_opts+=( "$1" ); 105 | else 106 | pylint_opts+=( "$1" ); 107 | fi 108 | shift; 109 | done 110 | 111 | if ! git_is_git_repo "$1"; then 112 | guess_jslintrc=0; 113 | else 114 | local repo_path; 115 | repo_path=$(git_get_abs_repo_path "$1"); 116 | if [ -e "${repo_path}/.jslintrc" ]; then 117 | echoe -e "${BLUEC}INFO${NC}: Applying auto-detected repo-wide jslintrc ${BLUEC}${repo_path}/.jslintrc${NC}."; 118 | pylint_opts+=( "--jslintrc" "${repo_path}/.jslintrc" ); 119 | fi 120 | fi 121 | 122 | # specify valid odoo version for pylint manifest version check 123 | pylint_opts+=( "--rcfile=$pylint_rc" "--valid_odoo_versions=$ODOO_VERSION" ); 124 | 125 | pylint_opts+=( "-d" "$pylint_disable" ); 126 | 127 | # Show help if requested 128 | if [ -n "$show_help" ]; then 129 | execu pylint "${pylint_opts[@]}"; 130 | return; 131 | fi 132 | 133 | local addons; 134 | mapfile -t addons < <(addons_list_in_directory --installable "$@"); 135 | execu pylint "${pylint_opts[@]}" "${addons[@]}"; 136 | return "$?"; 137 | } 138 | 139 | 140 | # lint_run_stylelint_internal 141 | function lint_run_stylelint_internal { 142 | local addon_path="$1"; 143 | local save_dir; 144 | local stylelint_default_conf; 145 | local stylelint_less_conf; 146 | local stylelint_scss_conf; 147 | local res=0; 148 | 149 | if [ -z "$addon_path" ]; then 150 | echoe -e "${REDC}ERROR${NC}: stylelint - no Odoo addon path specified"; 151 | return 1; 152 | fi 153 | 154 | local addon_name; 155 | addon_name=$(basename "$addon_path"); 156 | 157 | save_dir=$(pwd); 158 | cd "$addon_path"; 159 | 160 | stylelint_default_conf=$(config_get_default_tool_conf "stylelint-default.json"); 161 | stylelint_less_conf=$(config_get_default_tool_conf "stylelint-default-less.json"); 162 | stylelint_scss_conf=$(config_get_default_tool_conf "stylelint-default-scss.json"); 163 | 164 | echoe -e "${BLUEC}Processing addon ${YELLOWC}${addon_name}${BLUEC} ...${NC}"; 165 | 166 | if ! execu stylelint --allow-empty-input --config "$stylelint_default_conf" "$addon_path/**/*.css" "!$addon_path/static/lib/**"; then 167 | res=1; 168 | fi 169 | if ! execu stylelint --allow-empty-input --custom-syntax=postcss-less --config "$stylelint_less_conf" "$addon_path/**/*.less" "!$addon_path/static/lib/**"; then 170 | res=1; 171 | fi 172 | if ! execu stylelint --allow-empty-input --custom-syntax=postcss-scss --config "$stylelint_scss_conf" "$addon_path/**/*.scss" "!$addon_path/static/lib/**"; then 173 | res=1; 174 | fi 175 | 176 | if [ ! "$res" -eq "0" ]; then 177 | echoe -e "${BLUEC}Addon ${YELLOWC}${addon_name}${BLUEC}:${REDC}FAIL${NC}"; 178 | else 179 | echoe -e "${BLUEC}Addon ${YELLOWC}${addon_name}${BLUEC}:${GREENC}OK${NC}"; 180 | fi 181 | 182 | cd "$save_dir"; 183 | 184 | return $res; 185 | } 186 | 187 | 188 | # Run stylelint for each addon in specified path 189 | # lint_run_stylelint [path] [path] 190 | function lint_run_stylelint { 191 | local usage=" 192 | Usage: 193 | 194 | $SCRIPT_NAME lint style [addon path] 195 | $SCRIPT_NAME lint style --help 196 | 197 | Description: 198 | Lint styles (*.css, *.less, *.scss). 199 | This command uses [stylelint](https://stylelint.io/) with 200 | standard config (stylelint-config-standard) 201 | 202 | "; 203 | 204 | # Parse command line options 205 | if [[ $# -lt 1 ]]; then 206 | echo "No options supplied $#: $*"; 207 | echo ""; 208 | echo "$usage"; 209 | return 0; 210 | fi 211 | 212 | while [[ $1 == -* ]] 213 | do 214 | key="$1"; 215 | case $key in 216 | -h|--help|help) 217 | echo "$usage"; 218 | return 0; 219 | ;; 220 | *) 221 | echo "Unknown option $key"; 222 | return 1; 223 | ;; 224 | esac 225 | done 226 | 227 | #----- 228 | local res=0; 229 | for addon_path in $(addons_list_in_directory --installable "$@"); do 230 | if ! lint_run_stylelint_internal "$addon_path"; then 231 | res=1; 232 | fi 233 | done 234 | 235 | return $res 236 | } 237 | 238 | 239 | function lint_command { 240 | local usage=" 241 | Check addons with linters 242 | 243 | Usage: 244 | 245 | $SCRIPT_NAME lint flake8 [addon path] 246 | $SCRIPT_NAME lint pylint [addon path] 247 | $SCRIPT_NAME lint pylint [--disable=E111,E222,...] [addon path] 248 | $SCRIPT_NAME lint style [addon path] 249 | 250 | $SCRIPT_NAME lint -h|--help|help - show this help 251 | "; 252 | 253 | # Parse command line options and run commands 254 | if [[ $# -lt 1 ]]; then 255 | echo "No options supplied $#: $*"; 256 | echo ""; 257 | echo "$usage"; 258 | return 0; 259 | fi 260 | 261 | while [[ $# -gt 0 ]] 262 | do 263 | key="$1"; 264 | case $key in 265 | -h|--help|help) 266 | echo "$usage"; 267 | return; 268 | ;; 269 | flake8) 270 | shift; 271 | lint_run_flake8 "$@"; 272 | return; 273 | ;; 274 | pylint) 275 | shift; 276 | lint_run_pylint "$@"; 277 | return; 278 | ;; 279 | style) 280 | shift; 281 | lint_run_stylelint "$@"; 282 | return; 283 | ;; 284 | *) 285 | echo "Unknown option $key"; 286 | return 1; 287 | ;; 288 | esac 289 | done 290 | } 291 | -------------------------------------------------------------------------------- /lib/postgres.bash: -------------------------------------------------------------------------------- 1 | # Copyright © 2016-2018 Dmytro Katyukha 2 | 3 | ####################################################################### 4 | # This Source Code Form is subject to the terms of the Mozilla Public # 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this # 6 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. # 7 | ####################################################################### 8 | 9 | if [ -z "$ODOO_HELPER_LIB" ]; then 10 | echo "Odoo-helper-scripts seems not been installed correctly."; 11 | echo "Reinstall it (see Readme on https://gitlab.com/katyukha/odoo-helper-scripts/)"; 12 | exit 1; 13 | fi 14 | 15 | if [ -z "$ODOO_HELPER_COMMON_IMPORTED" ]; then 16 | source "$ODOO_HELPER_LIB/common.bash"; 17 | fi 18 | 19 | # ---------------------------------------------------------------------------------------- 20 | 21 | set -e; # fail on errors 22 | 23 | 24 | # Check if postgres is installed 25 | # 26 | # postgres_is_installed 27 | function postgres_is_installed { 28 | # TODO: think about better way to check postgres presence 29 | if [ ! -f /etc/init.d/postgresql ]; then 30 | return 1; # not installed 31 | else 32 | return 0; # installed 33 | fi 34 | } 35 | 36 | # Install postgresql 37 | # NOTE: Requires SUDO 38 | # 39 | # postgres_install_postgresql 40 | function postgres_install_postgresql { 41 | with_sudo apt-get install -y postgresql; 42 | } 43 | 44 | 45 | # Test connection to local postgres instance 46 | function postgres_test_connection { 47 | if ! sudo -u postgres -H psql -tA -c "SELECT 1;" >/dev/null 2>&1; then 48 | echoe -e "${REDC}ERROR:${NC} Cannot connect to local postgres DB!"; 49 | return 1; 50 | fi 51 | return 0; 52 | } 53 | 54 | # Check if postgresql user exists 55 | # NOTE: Requires SUDO 56 | # 57 | # postgres_user_exists 58 | function postgres_user_exists { 59 | local user_count; 60 | local user_name="$1"; 61 | 62 | user_count=$(sudo -u postgres -H psql -tA -c "SELECT count(*) FROM pg_user WHERE usename = '$user_name';"); 63 | if [ "$user_count" -eq 0 ]; then 64 | return 1; 65 | else 66 | return 0 67 | fi 68 | } 69 | 70 | # Create new postgresql user 71 | # NOTE: Requires SUDO 72 | # 73 | # postgres_user_create 74 | function postgres_user_create { 75 | local usage=" 76 | Create postgres user for Odoo with specified usernama and password 77 | 78 | Usage: 79 | 80 | $SCRIPT_NAME postgres user-create 81 | $SCRIPT_NAME postgres user-create --help 82 | "; 83 | if [[ $# -lt 1 ]]; then 84 | echo "No options supplied $#: $*"; 85 | echo ""; 86 | echo "$usage"; 87 | return 0; 88 | fi 89 | 90 | # Process all args that starts with '-' (ie. options) 91 | while [[ $1 == -* ]] 92 | do 93 | local key="$1"; 94 | case $key in 95 | -h|--help|help) 96 | echo "$usage"; 97 | return 0; 98 | ;; 99 | *) 100 | break; 101 | ;; 102 | esac 103 | shift 104 | done 105 | 106 | local user_name="$1"; 107 | local user_password="${2:-odoo}"; 108 | 109 | if ! postgres_test_connection; then 110 | return 1; 111 | fi 112 | 113 | if ! postgres_user_exists "$user_name"; then 114 | sudo -u postgres -H psql -c "CREATE USER \"$user_name\" WITH CREATEDB PASSWORD '$user_password';" 115 | echoe -e "${GREENC}OK${NC}: Postgresql user ${BLUEC}$user_name${NC} was created for this Odoo instance"; 116 | else 117 | echoe -e "${YELLOWC}There are $user_name already exists in postgres server${NC}"; 118 | fi 119 | } 120 | 121 | # Connect to database via psql 122 | # Automaticaly pass connection parametrs 123 | # 124 | # postgres_psql .... 125 | function postgres_psql { 126 | local pghost; 127 | local pgport; 128 | local pguser; 129 | local pgpass; 130 | local default_db; 131 | 132 | pghost=$(odoo_get_conf_val db_host); 133 | pgport=$(odoo_get_conf_val db_port); 134 | pguser=$(odoo_get_conf_val db_user); 135 | pgpass=$(odoo_get_conf_val db_password); 136 | default_db=$(odoo_get_conf_val_default db_name postgres); 137 | 138 | if [ -z "$pgport" ] || [ "$pgport" == 'False' ]; then 139 | pgport=; 140 | fi 141 | 142 | PGPASSWORD=$pgpass PGDATABASE=$default_db PGHOST=$pghost \ 143 | PGPORT=$pgport PGUSER=$pguser psql "$@"; 144 | } 145 | 146 | # Run pg_dump 147 | # Automaticaly pass connection parametrs 148 | # 149 | # postgres_pg_dump .... 150 | function postgres_pg_dump { 151 | local pghost; 152 | local pgport; 153 | local pguser; 154 | local pgpass; 155 | local default_db; 156 | 157 | pghost=$(odoo_get_conf_val db_host); 158 | pgport=$(odoo_get_conf_val db_port); 159 | pguser=$(odoo_get_conf_val db_user); 160 | pgpass=$(odoo_get_conf_val db_password); 161 | default_db=$(odoo_get_conf_val_default db_name postgres); 162 | 163 | if [ -z "$pgport" ] || [ "$pgport" == 'False' ]; then 164 | pgport=; 165 | fi 166 | 167 | PGPASSWORD=$pgpass PGDATABASE=$default_db PGHOST=$pghost \ 168 | PGPORT=$pgport PGUSER=$pguser pg_dump --no-owner --no-privileges "$@"; 169 | } 170 | # Show active postgres transactions 171 | # 172 | function postgres_psql_stat_activity { 173 | PGAPPNAME="odoo-helper-pgstat" postgres_psql << EOF 174 | SELECT 175 | datname, 176 | pid, 177 | usename, 178 | application_name, 179 | client_addr, 180 | to_char(query_start, 181 | 'YYYY-MM-DD HH:MM'), 182 | state, 183 | query 184 | FROM pg_stat_activity 185 | WHERE application_name != 'odoo-helper-pgstat'; 186 | EOF 187 | } 188 | 189 | # Show information about connections used by postgresql server 190 | # 191 | function postgres_psql_connection_info { 192 | PGAPPNAME="odoo-helper-pgstat" postgres_psql << EOF 193 | WITH t_used_conn AS ( 194 | SELECT count(*) AS used_connections 195 | FROM pg_stat_activity 196 | WHERE application_name != 'odoo-helper-pgstat' 197 | ), 198 | t_reserved_conn AS ( 199 | SELECT setting::int AS reserved_connections 200 | FROM pg_settings 201 | WHERE name='superuser_reserved_connections' 202 | ), 203 | t_max_conn AS ( 204 | SELECT setting::int AS max_connections 205 | FROM pg_settings 206 | WHERE name='max_connections' 207 | ) 208 | SELECT max_connections, 209 | used_connections, 210 | reserved_connections, 211 | max_connections - used_connections - reserved_connections AS free_connections 212 | FROM t_used_conn, t_reserved_conn, t_max_conn 213 | EOF 214 | } 215 | 216 | function postgres_psql_locks_info { 217 | local usage=" 218 | Fetch info about postgres locks on database 219 | 220 | Usage: 221 | 222 | $SCRIPT_NAME postgres locks-info 223 | $SCRIPT_NAME postgres locks-info --help 224 | "; 225 | local extra_opts=( ); 226 | case $1 in 227 | -h|--help|help) 228 | echo "$usage"; 229 | return 0; 230 | ;; 231 | *) 232 | extra_opts+=( "-d" "$1" ); 233 | ;; 234 | esac 235 | 236 | PGNAME="odoo-helper-pgstat" postgres_psql "${extra_opts[@]}" << EOF 237 | SELECT 238 | pg_stat_activity.datname, 239 | pg_locks.relation::regclass, 240 | pg_locks.transactionid, 241 | pg_locks.mode, 242 | pg_locks.GRANTED, 243 | pg_stat_activity.usename, 244 | pg_stat_activity.query, 245 | pg_stat_activity.query_start, 246 | age(now(), pg_stat_activity.query_start) AS "age", 247 | pg_stat_activity.pid 248 | FROM pg_stat_activity 249 | JOIN pg_locks ON pg_locks.pid = pg_stat_activity.pid 250 | WHERE pg_locks.mode = 'ExclusiveLock' 251 | ORDER BY pg_stat_activity.query_start; 252 | EOF 253 | } 254 | 255 | # Configure local postgresql instance to be faster but less safe 256 | # 257 | # postgres_config_local_speed_unsafe 258 | function postgres_config_speedify_unsafe { 259 | local usage=" 260 | Speedify postgres by disabling fsync, synchronous_commit and full_page_writes 261 | 262 | WARNNING: this make postgres unsafe, and have to be used only for development 263 | 264 | Usage: 265 | 266 | $SCRIPT_NAME postgres speedify 267 | $SCRIPT_NAME postgres speedify --help 268 | "; 269 | case $1 in 270 | -h|--help|help) 271 | echo "$usage"; 272 | return 0; 273 | ;; 274 | esac 275 | 276 | if ! postgres_test_connection; then 277 | return 1; 278 | fi 279 | 280 | sudo -u postgres -H psql -qc "ALTER SYSTEM SET fsync TO off;"; 281 | sudo -u postgres -H psql -qc "ALTER SYSTEM SET synchronous_commit TO off;"; 282 | sudo -u postgres -H psql -qc "ALTER SYSTEM SET full_page_writes TO off;"; 283 | sudo -u postgres -H psql -qc "ALTER SYSTEM SET max_connections TO 1000;"; 284 | sudo service postgresql restart 285 | echoe -e "Postgres speedify: ${GREENC}OK${NC}"; 286 | } 287 | 288 | 289 | # Wait for postgresql availability 290 | function postgres_wait_availability { 291 | while ! postgres_psql -l >/dev/null; do 292 | sleep 2; 293 | done 294 | } 295 | 296 | # Parse command line args 297 | function postgres_command { 298 | local usage=" 299 | PostgreSQL related commands 300 | 301 | Notes: 302 | NOTE: subcommands tagged by [local] applicable only to local postgres instance! 303 | NOTE: subcommands tagged by [sudo] require sudo. (they will use sudo automaticaly) 304 | NOTE: most of commands require sudo 305 | 306 | Usage: 307 | $SCRIPT_NAME postgres psql [psql options] - Run psql with odoo connection params 308 | $SCRIPT_NAME postgres psql -d [psql options] - Run psql connected to specified database 309 | $SCRIPT_NAME postgres pg_dump [pg_dump options] - Run pg_dump with params of this odoo instance 310 | $SCRIPT_NAME postgres pg_dump -d [pg_dump options] - Run pg_dump for specified database 311 | $SCRIPT_NAME postgres user-create - [local][sudo] Create postgres user for odoo 312 | It automaticaly uses credentials used by odoo 313 | $SCRIPT_NAME postgres stat-activity - list running postgres queries in database 314 | print data from pg_stat_activity table. 315 | $SCRIPT_NAME postgres stat-connections - show statistics about postgres connections: 316 | used, reserved, free connections 317 | $SCRIPT_NAME postgres locks-info - Display info about locks 318 | $SCRIPT_NAME postgres speedify - [local][sudo] Modify local postgres config 319 | to make it faster. But also makes postgres unsafe. 320 | Usualy this is normal for dev machines, 321 | but not for production 322 | $SCRIPT_NAME postgres wait-availability - wait for postgresql availability. 323 | This could be usefule inside docker containers. 324 | $SCRIPT_NAME postgres --help - show this help message 325 | 326 | "; 327 | 328 | if [[ $# -lt 1 ]]; then 329 | echo "$usage"; 330 | return 0; 331 | fi 332 | 333 | while [[ $# -gt 0 ]] 334 | do 335 | local key="$1"; 336 | case $key in 337 | user-create) 338 | shift; 339 | postgres_user_create "$@"; 340 | return; 341 | ;; 342 | speedify) 343 | shift; 344 | postgres_config_speedify_unsafe "$@"; 345 | return; 346 | ;; 347 | psql) 348 | shift; 349 | config_load_project; 350 | postgres_psql "$@"; 351 | return; 352 | ;; 353 | pg_dump) 354 | shift; 355 | config_load_project; 356 | postgres_pg_dump "$@"; 357 | return; 358 | ;; 359 | stat-activity) 360 | shift; 361 | config_load_project; 362 | postgres_psql_stat_activity "$@"; 363 | return; 364 | ;; 365 | stat-connections) 366 | shift; 367 | config_load_project; 368 | postgres_psql_connection_info "$@"; 369 | return; 370 | ;; 371 | locks-info) 372 | shift; 373 | config_load_project; 374 | postgres_psql_locks_info "$@"; 375 | return; 376 | ;; 377 | wait-availability) 378 | shift; 379 | config_load_project; 380 | postgres_wait_availability "$@"; 381 | return; 382 | ;; 383 | -h|--help|help) 384 | echo "$usage"; 385 | return 0; 386 | ;; 387 | *) 388 | echo "Unknown option / command $key"; 389 | return 1; 390 | ;; 391 | esac 392 | done 393 | } 394 | -------------------------------------------------------------------------------- /lib/pylib/bash_unwrap.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import os 4 | import sys 5 | import subprocess 6 | 7 | # Unset bash variables 8 | os.unsetenv('PS4') 9 | os.unsetenv('BASH_TRACEFD') 10 | os.unsetenv('SHELLOPTS') 11 | 12 | # Forward arguments to bash 13 | exit( 14 | subprocess.call([ 15 | 'bash', 16 | *sys.argv[1:] 17 | ]) 18 | ) 19 | -------------------------------------------------------------------------------- /lib/pylib/ci_fix_version.py: -------------------------------------------------------------------------------- 1 | import re 2 | import sys 3 | 4 | RE_GIT_VERSION_CONFLICT = re.compile( 5 | r"^<<<<<<< HEAD\n" 6 | r"(\s+[\"']version[\"']:\s[\"'][\d\.]+[\"'],\n)" 7 | r"=======\n" 8 | r"(\s+[\"']version[\"']:\s[\"'][\d\.]+[\"'],\n)" 9 | r">>>>>>> .*\n", flags=re.MULTILINE) 10 | 11 | if __name__ == "__main__": 12 | file_path = sys.argv[1] 13 | with open(file_path, "rt") as f: 14 | file_content = f.read() 15 | 16 | file_content = RE_GIT_VERSION_CONFLICT.sub(r"\2", file_content) 17 | 18 | with open(file_path, "wt") as f: 19 | f.write(file_content) 20 | -------------------------------------------------------------------------------- /lib/pylib/ci_fw_postfixes.py: -------------------------------------------------------------------------------- 1 | """ Fix code after forwardport 2 | 3 | This module, contains tools to automatically fix code to be compatible with 4 | specific odoo versions. 5 | """ 6 | import os 7 | import re 8 | from glob import iglob 9 | 10 | import click 11 | 12 | CHECKS = {} 13 | 14 | CHECKS['12.0'] = { 15 | '.py': [ 16 | ("replace", 17 | r"\.phantom_js\(", 18 | ".browser_js(", 19 | "Replace calls to 'phantom_js' with 'browser_js'."), 20 | ], 21 | } 22 | 23 | # Auto checks for 13.0 24 | CHECKS['13.0'] = { 25 | '.py': [ 26 | ("replace", 27 | r"\.sudo\((?P[^/)]+?)\)", 28 | r".with_user(\g)", 29 | "Replaced sudo(user) -> with_user(user)"), 30 | ("replace", 31 | r".*@api.one.*\n", 32 | "", 33 | "Remove @api.one"), 34 | ("replace", 35 | r".*@api.multi.*\n", 36 | "", 37 | "Remove @api.multi"), 38 | ("replace", 39 | r"\._find_partner_from_emails\(", 40 | "._mail_find_partner_from_emails(", 41 | ("Rename _find_partner_from_emails -> " 42 | "_mail_find_partner_from_emails")), 43 | ("replace", 44 | r"\.phantom_js\(", 45 | ".browser_js(", 46 | "Replace calls to 'phantom_js' with 'browser_js'."), 47 | ("replace", 48 | r"related_sudo=(?P(True|False))", 49 | "compute_sudo=\g", # noqa 50 | "Replace related_sudo to compute_sudo"), 51 | ], 52 | '.xml': [ 53 | ("replace", 54 | r"[\s\t]*.*\n", 55 | "", 56 | "Remove ..."), 57 | ], 58 | } 59 | 60 | # Auto checks for 14.0 61 | CHECKS['14.0'] = { 62 | '.py': [ 63 | ("replace", 64 | r"track_visibility\s*=\s*['\"]\w+['\"]", 65 | "tracking=True", 66 | "Replace track_visibility='...' with tracking=True"), 67 | ("replace", 68 | r"\.phantom_js\(", 69 | ".browser_js(", 70 | "Replace calls to 'phantom_js' with 'browser_js'."), 71 | ("replace", 72 | r"related_sudo=(?P(True|False))", 73 | "compute_sudo=\g", # noqa 74 | "Replace related_sudo to compute_sudo"), 75 | ], 76 | } 77 | 78 | # Auto checks for 15.0 79 | CHECKS['15.0'] = { 80 | '.xml': [ 81 | ("replace", 82 | r"t-raw=(?P['\"])", 83 | "t-out=\g", # noqa 84 | "Replace '@t-raw=...' with '@t-out=...' attribute in xml."), 85 | ], 86 | } 87 | 88 | # Auto checks for 16.0 89 | CHECKS['16.0'] = { 90 | '.xml': [ 91 | ("replace", 92 | r"t-raw=(?P['\"])", 93 | "t-out=\g", # noqa 94 | "Replace '@t-raw=...' with '@t-out=...' attribute in xml."), 95 | ], 96 | } 97 | 98 | 99 | def run_command_replace(fpath, fcontent, expr, subst, msg): 100 | """ Replace all occurences of in by 101 | 102 | :return str: modified file content 103 | """ 104 | if not subst: 105 | subst = "" 106 | fcontent, changes = re.subn(expr, subst, fcontent) 107 | 108 | if changes: 109 | print("File %s updated: %s" % (fpath, msg)) 110 | return fcontent 111 | 112 | 113 | def run_command(fpath, fcontent, command, args): 114 | if command == 'replace': 115 | fcontent = run_command_replace(fpath, fcontent, *args) 116 | 117 | return fcontent 118 | 119 | 120 | @click.command() 121 | @click.option( 122 | '--version', help='Odoo version to apply checks for.') 123 | @click.option( 124 | '--path', type=click.Path(exists=True, 125 | dir_okay=True, 126 | file_okay=False, 127 | resolve_path=True), 128 | help='Path to directory to check code in.') 129 | @click.pass_context 130 | def main(ctx, version, path): 131 | checks = CHECKS.get(version) 132 | if not checks: 133 | click.echo("There are no checks for version %s" % version) 134 | ctx.exit(1) 135 | 136 | for fpath in iglob("%s/**" % path, recursive=True): 137 | if not os.path.isfile(fpath): 138 | continue 139 | 140 | __, fext = os.path.splitext(fpath) 141 | 142 | fchecks = checks.get(fext) 143 | if not fchecks: 144 | continue 145 | 146 | with open(fpath, 'r+') as f: 147 | fcontent = f.read() 148 | for command in fchecks: 149 | fcontent = run_command( 150 | fpath, fcontent, command[0], command[1:]) 151 | f.seek(0) 152 | f.write(fcontent) 153 | f.truncate(f.tell()) 154 | f.flush() 155 | 156 | 157 | if __name__ == '__main__': 158 | main() 159 | -------------------------------------------------------------------------------- /lib/pylib/jinja-cli.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | # Based on: 5 | # https://github.com/mattrobenolt/jinja2-cli/blob/master/jinja2cli/cli.py 6 | 7 | import os 8 | import os.path 9 | import sys 10 | from optparse import OptionParser 11 | 12 | import six 13 | 14 | import jinja2 15 | from jinja2 import Environment, FileSystemLoader 16 | 17 | 18 | class UConverter(object): 19 | """ Simple converter to unicode 20 | 21 | Create instance with specified list of encodings to be used to 22 | try to convert value to unicode 23 | 24 | Example:: 25 | 26 | ustr = UConverter(['utf-8', 'cp-1251']) 27 | my_unicode_str = ustr(b'hello - привет') 28 | """ 29 | default_encodings = ['utf-8', 'ascii', 'utf-16'] 30 | 31 | def __init__(self, hint_encodings=None): 32 | if hint_encodings: 33 | self.encodings = hint_encodings 34 | else: 35 | self.encodings = self.default_encodings[:] 36 | 37 | def __call__(self, value): 38 | """ Convert value to unicode 39 | 40 | :param value: the value to convert 41 | :raise: UnicodeError if value cannot be coerced to unicode 42 | :return: unicode string representing the given value 43 | """ 44 | # it is unicode 45 | if isinstance(value, six.text_type): 46 | return value 47 | 48 | # it is not binary type (str for python2 and bytes for python3) 49 | if not isinstance(value, six.binary_type): 50 | try: 51 | value = six.text_type(value) 52 | except Exception: 53 | # Cannot directly convert to unicode. So let's try to convert 54 | # to binary, and that try diferent encoding to it 55 | try: 56 | value = six.binary_type(value) 57 | except: # noqa 58 | raise UnicodeError('unable to convert to unicode %r' 59 | '' % (value,)) 60 | else: 61 | return value 62 | 63 | # value is binary type (str for python2 and bytes for python3) 64 | for ln in self.encodings: 65 | try: 66 | res = six.text_type(value, ln) 67 | except Exception: 68 | pass 69 | else: 70 | return res 71 | 72 | raise UnicodeError('unable to convert to unicode %r' % (value,)) 73 | 74 | 75 | # default converter instance 76 | ustr = UConverter() 77 | 78 | 79 | def render(template_path, data, extensions, strict=False): 80 | """ Render jinja2 template 81 | """ 82 | env = Environment( 83 | loader=FileSystemLoader(os.path.dirname(template_path)), 84 | extensions=extensions, 85 | keep_trailing_newline=True, 86 | ) 87 | if strict: 88 | from jinja2 import StrictUndefined 89 | env.undefined = StrictUndefined 90 | 91 | # Add environ global 92 | env.globals['environ'] = os.environ.get 93 | 94 | output = env.get_template(os.path.basename(template_path)).render(data) 95 | return output 96 | 97 | 98 | def parse_kv_string(pairs): 99 | """ Parse options (-D) 100 | """ 101 | res = {} 102 | for pair in pairs: 103 | var, value = pair.split('=', 1) 104 | res[var] = ustr(value) 105 | return res 106 | 107 | 108 | def cli(opts, args): 109 | # TODO: make template path configurable via CLI option 110 | template_path = os.path.abspath(args[0]) 111 | 112 | data = {} 113 | 114 | extensions = [] 115 | for ext in opts.extensions: 116 | # Allow shorthand and assume if it's not a module 117 | # path, it's probably trying to use builtin from jinja2 118 | if '.' not in ext: 119 | ext = 'jinja2.ext.' + ext 120 | extensions.append(ext) 121 | 122 | data.update(parse_kv_string(opts.D or [])) 123 | 124 | output = render(template_path, data, extensions, opts.strict) 125 | 126 | output = ustr(output) 127 | 128 | sys.stdout.write(output) 129 | return 0 130 | 131 | # ------------ 132 | 133 | 134 | def main(): 135 | parser = OptionParser( 136 | usage="usage: %prog [options] ", 137 | version="Jinja2 v%s" % jinja2.__version__, 138 | ) 139 | parser.add_option( 140 | '-e', '--extension', 141 | help='extra jinja2 extensions to load', 142 | dest='extensions', action='append', 143 | default=['do', 'with_', 'autoescape', 'loopcontrols']) 144 | parser.add_option( 145 | '-D', 146 | help='Define template variable in the form of key=value', 147 | action='append', metavar='key=value') 148 | parser.add_option( 149 | '--strict', 150 | help='Disallow undefined variables to be used within the template', 151 | dest='strict', action='store_true') 152 | opts, args = parser.parse_args() 153 | 154 | # Dedupe list 155 | opts.extensions = set(opts.extensions) 156 | 157 | if not args: 158 | parser.print_help() 159 | sys.exit(1) 160 | 161 | if args[0] == 'help': 162 | parser.print_help() 163 | sys.exit(1) 164 | 165 | sys.exit(cli(opts, args)) 166 | 167 | 168 | if __name__ == '__main__': 169 | main() 170 | -------------------------------------------------------------------------------- /lib/pylib/parse_deb_deps.py: -------------------------------------------------------------------------------- 1 | import re 2 | import argparse 3 | 4 | 5 | def parse_deb_dependencies(path): 6 | RE_DEPS = re.compile( 7 | r'.*Depends:(?P(\n [^,]+,)+).*', 8 | re.MULTILINE | re.DOTALL) 9 | m = RE_DEPS.match(open(path).read()) 10 | deps = m and m.groupdict().get('deps', '') 11 | deps = deps.replace(',', '').replace(' ', '').split('\n') 12 | return filter(lambda line: line and not line.startswith('${'), deps) 13 | 14 | 15 | if __name__ == '__main__': 16 | parser = argparse.ArgumentParser( 17 | description='Parse dependencies of deb file') 18 | parser.add_argument( 19 | 'path', 20 | help='Path to debian control file.') 21 | args = parser.parse_args() 22 | print("\n".join(parse_deb_dependencies(args.path))) 23 | -------------------------------------------------------------------------------- /lib/pylib/py_utils.py: -------------------------------------------------------------------------------- 1 | """ Various utility functions implemented in python to simplify code 2 | """ 3 | import os 4 | import click 5 | 6 | 7 | def read_addon_manifest(addon_path): 8 | if os.path.exists(os.path.join(addon_path, '__manifest__.py')): 9 | return eval(open('%s/__manifest__.py' % addon_path, 'rt').read()) 10 | if os.path.exists(os.path.join(addon_path, '__openerp__.py')): 11 | return eval(open('%s/__openerp__.py' % addon_path, 'rt').read()) 12 | return False 13 | 14 | 15 | @click.group() 16 | @click.pass_context 17 | def cli(ctx): 18 | pass 19 | 20 | 21 | @cli.command( 22 | 'addon-py-deps', 23 | help="Print space-separated list of python dependencies from addon's " 24 | "manifest file.") 25 | @click.option( 26 | '--addon-path', 27 | type=click.Path( 28 | exists=True, dir_okay=True, file_okay=False, resolve_path=True), 29 | help='Path to addon folder.') 30 | @click.pass_context 31 | def addon_py_deps(ctx, addon_path): 32 | manifest = read_addon_manifest(addon_path) 33 | python_deps = manifest.get( 34 | 'external_dependencies', {} 35 | ).get('python', []) 36 | click.echo(' '.join(python_deps), nl=False) 37 | 38 | 39 | @cli.command( 40 | 'addon-is-installable', 41 | help="Check if addon is installable") 42 | @click.option( 43 | '--addon-path', 44 | type=click.Path( 45 | exists=True, dir_okay=True, file_okay=False, resolve_path=True), 46 | help='Path to addon folder.') 47 | @click.pass_context 48 | def addon_is_installable(ctx, addon_path): 49 | manifest = read_addon_manifest(addon_path) 50 | if not manifest.get('installable', True): 51 | return ctx.exit(1) 52 | 53 | 54 | if __name__ == '__main__': 55 | cli() 56 | -------------------------------------------------------------------------------- /lib/recursion.bash: -------------------------------------------------------------------------------- 1 | # Copyright © 2016-2018 Dmytro Katyukha 2 | 3 | ####################################################################### 4 | # This Source Code Form is subject to the terms of the Mozilla Public # 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this # 6 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. # 7 | ####################################################################### 8 | 9 | # Recursion protection utils 10 | 11 | if [ -z "$ODOO_HELPER_LIB" ]; then 12 | echo "Odoo-helper-scripts seems not been installed correctly."; 13 | echo "Reinstall it (see Readme on https://gitlab.com/katyukha/odoo-helper-scripts/)"; 14 | exit 1; 15 | fi 16 | 17 | if [ -z "$ODOO_HELPER_COMMON_IMPORTED" ]; then 18 | source "$ODOO_HELPER_LIB/common.bash"; 19 | fi 20 | 21 | # ----------------------------------------------------------------------------- 22 | 23 | set -e; # fail on errors 24 | 25 | 26 | # get obj_name for key 27 | function __recursion_get_obj_name { 28 | echo "__RECURSION_PROTECTION__OBJ_${1}__" 29 | } 30 | 31 | 32 | # Initialize recursion protection for key 33 | # recursion_protection_init 34 | function recursion_protection_init { 35 | local obj_name; 36 | obj_name=$(__recursion_get_obj_name "$1"); 37 | if [ -z "${!obj_name:-''}" ]; then 38 | return 1; 39 | fi 40 | 41 | declare -gA "$obj_name"; 42 | return 0; 43 | } 44 | 45 | # Check recursion protection for key,value 46 | # This function check if value for key already checked. 47 | # If not them mark it as checked. 48 | # If passed value already was checked by this function, 49 | # then return non-zero exit code. If passed value was not checked before, 50 | # then return zero exit code. 51 | # 52 | # recursion_protection_check 53 | function recursion_protection_check { 54 | # Exit with 2 code if no key and value specified 55 | if [ -z "$1" ] || [ -z "$2" ]; then 56 | return 2; 57 | fi 58 | 59 | local res; 60 | local value; 61 | local obj_name; 62 | local key=$1; 63 | 64 | value=$(echo "$2" | sed -r "s/[^A-Za-z0-9]/_/g"); 65 | obj_name=$(__recursion_get_obj_name "$key"); 66 | 67 | # shellcheck disable=SC1083,SC2086 68 | res=$(eval echo \"\${${obj_name}[$value]}\"); 69 | 70 | if [ -z "${res:-}" ]; then 71 | eval "${obj_name}['$value']=1"; 72 | return 0; 73 | else 74 | return 1; 75 | fi 76 | } 77 | 78 | 79 | # Close recursion protection for a key. 80 | # Clear recursion cache for specified key 81 | # 82 | # recursion_protection_close 83 | function recursion_protection_close { 84 | unset "$(__recursion_get_obj_name "$1")"; 85 | } 86 | 87 | 88 | # Simplified call to recursion protection 89 | # 90 | # recursion_protection_easy_check 91 | function recursion_protection_easy_check { 92 | recursion_protection_init "$1" || true; 93 | 94 | if recursion_protection_check "$1" "$2"; then 95 | return 0; 96 | else 97 | return 1; 98 | fi 99 | } 100 | -------------------------------------------------------------------------------- /lib/scaffold.bash: -------------------------------------------------------------------------------- 1 | # Copyright © 2016-2018 Dmytro Katyukha 2 | 3 | ####################################################################### 4 | # This Source Code Form is subject to the terms of the Mozilla Public # 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this # 6 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. # 7 | ####################################################################### 8 | 9 | if [ -z "$ODOO_HELPER_LIB" ]; then 10 | echo "Odoo-helper-scripts seems not been installed correctly."; 11 | echo "Reinstall it (see Readme on https://gitlab.com/katyukha/odoo-helper-scripts/)"; 12 | exit 1; 13 | fi 14 | 15 | if [ -z "$ODOO_HELPER_COMMON_IMPORTED" ]; then 16 | source "$ODOO_HELPER_LIB/common.bash"; 17 | fi 18 | 19 | #ohelper_require 'install'; 20 | ohelper_require 'server'; 21 | #ohelper_require 'fetch'; 22 | ohelper_require 'git'; 23 | # ---------------------------------------------------------------------------------------- 24 | 25 | 26 | #----------------------------------------------------------------------------------------- 27 | # functions prefix: scaffold_* 28 | #----------------------------------------------------------------------------------------- 29 | 30 | set -e; # fail on errors 31 | 32 | 33 | # Define tempalte paths 34 | TMPL_GITIGNORE=$ODOO_HELPER_LIB/templates/scaffold/gitignore.tmpl; 35 | TMPL_ADDON=$ODOO_HELPER_LIB/templates/scaffold/addon; 36 | TMPL_ADDON_MANIFEST=$ODOO_HELPER_LIB/templates/scaffold/addon__manifest__.py.tmpl; 37 | TMPL_ADDON_README=$ODOO_HELPER_LIB/templates/scaffold/addon__README.rst.tmpl; 38 | 39 | # Templater 40 | TEMPLATER=$ODOO_HELPER_LIB/pylib/jinja-cli.py 41 | 42 | 43 | # odoo_scaffold [addon_path] 44 | function scaffold_default { 45 | local addon_name=$1; 46 | local addon_dir=${2:-$REPOSITORIES_DIR}; 47 | local addon_path=$addon_dir/$addon_name; 48 | 49 | odoo_py scaffold "$addon_name" "$addon_dir"; 50 | link_module "$addon_path"; 51 | 52 | # if addon is not part of some repo, create repo for it 53 | if ! git_is_git_repo "$addon_path"; then 54 | local cdir; 55 | cdir=$(pwd); 56 | cd "$addon_path"; 57 | git init; 58 | 59 | cp "$TMPL_GITIGNORE" ./.gitignore; 60 | cd "$cdir"; 61 | fi 62 | } 63 | 64 | function scaffold_repo { 65 | local usage=" 66 | Usage 67 | 68 | $SCRIPT_NAME scaffold repo 69 | $SCRIPT_NAME scaffold repo --help 70 | 71 | This command will automatically create git repository with specified 72 | name inside $REPOSITORIES_DIR 73 | "; 74 | 75 | if [[ "$1" =~ help|--help|-h ]]; then 76 | echo "$usage"; 77 | return 0; 78 | fi 79 | 80 | local repo_name=$1; 81 | local repo_path=$REPOSITORIES_DIR/$repo_name; 82 | 83 | if [ -z "$repo_name" ]; then 84 | echo -e "${REDC}ERROR:${NC} No repository name supplied!"; 85 | return 1; 86 | fi 87 | 88 | if [ -d "$repo_path" ]; then 89 | echo -e "${REDC}ERROR:${NC} Such repository already exists!"; 90 | return 2; 91 | fi 92 | 93 | # Create repo dir 94 | mkdir -p "$repo_path"; 95 | 96 | # Init git repository 97 | (cd "$repo_path" && git init); 98 | 99 | # Copy .gitignore to new repo; 100 | cp "$TMPL_GITIGNORE" "$repo_path/.gitignore"; 101 | 102 | echo -e "${GREENC}Repository $repo_name created:${NC} $repo_path$"; 103 | } 104 | 105 | function scaffold_addon { 106 | local usage=" 107 | Usage 108 | 109 | $SCRIPT_NAME scaffold addon [options] 110 | $SCRIPT_NAME scaffold addon --help 111 | 112 | This command will automatically create new addons with specified name 113 | in current working directory. 114 | 115 | Options 116 | 117 | --repo|-r - name or path to repository to create addon iside 118 | --depends|-d - name of addon to be added to depends section of manifest. 119 | Could be specified multiple times 120 | "; 121 | 122 | if [[ $# -lt 1 ]]; then 123 | echo "$usage"; 124 | return 0; 125 | fi 126 | 127 | local depends; 128 | local depends_cs; 129 | local repo_path; 130 | local default_addon_author; 131 | while [[ $# -gt 0 ]] 132 | do 133 | case $1 in 134 | --repo|-r) 135 | local repo=$2; 136 | shift; shift; 137 | ;; 138 | --depends|-d) 139 | depends+=( "'$2'" ); 140 | shift; shift; 141 | ;; 142 | --help|-h|help) 143 | echo "$usage"; 144 | return 0; 145 | ;; 146 | *) 147 | # Options finished 148 | break 149 | ;; 150 | esac 151 | done 152 | 153 | local addon_name=$1; 154 | local addon_dest; 155 | addon_dest=$(pwd); 156 | 157 | if [ -z "$addon_name" ]; then 158 | echoe -e "${REDC}ERROR:${NC} addon_name not specified!" 159 | return 2; 160 | elif ! [[ "$addon_name" =~ ^[a-z0-9_]+$ ]]; then 161 | echoe -e "${REDC}ERROR:${NC} Wrong addon name specified ('$addon_name'). addon name should contain only 'a-z0-9_' sympbols!" 162 | return 1; 163 | fi 164 | 165 | if [ -z "${depends[*]}" ]; then 166 | depends=( "'base'" ) 167 | fi 168 | 169 | depends_cs=$(join_by "," "${depends[@]}"); 170 | 171 | # If repo specified, take it into account 172 | repo_path=$(readlink -f "$repo") 173 | if [ -n "$repo" ] && git_is_git_repo "$REPOSITORIES_DIR/$repo"; then 174 | addon_dest=$REPOSITORIES_DIR/$repo; 175 | elif [ -n "$repo" ] && git_is_git_repo "$repo_path"; then 176 | addon_dest=$(readlink -f "$repo"); 177 | fi 178 | 179 | local addon_path=$addon_dest/$addon_name; 180 | 181 | # Choose correct manifest filename for Odoo version 182 | if [[ "$(odoo_get_major_version)" -lt 10 ]]; then 183 | local manifest_name="__openerp__.py"; 184 | else 185 | local manifest_name="__manifest__.py"; 186 | fi 187 | 188 | # Copy odoo addon skeleton 189 | cp -r "$TMPL_ADDON" "$addon_path"; 190 | 191 | # Generate manifest file for addon 192 | default_addon_author=$(git config user.name) 193 | execv "$TEMPLATER" \ 194 | -D ODOO_VERSION="\"$ODOO_VERSION\"" \ 195 | -D ADDON_NAME="\"$addon_name\"" \ 196 | -D ADDON_AUTHOR="\"${SCAFFOLD_ADDON_AUTHOR:-$default_addon_author}\"" \ 197 | -D ADDON_LICENCE="\"${SCAFFOLD_ADDON_LICENCE}\"" \ 198 | -D ADDON_WEBSITE="\"${SCAFFOLD_ADDON_WEBSITE}\"" \ 199 | -D ADDON_DEPENDS="\"'$depends_cs'\"" \ 200 | "$TMPL_ADDON_MANIFEST" > "$addon_path/$manifest_name"; 201 | 202 | execv "$TEMPLATER" \ 203 | -D ODOO_VERSION="\"$ODOO_VERSION\"" \ 204 | -D ADDON_NAME="\"$addon_name\"" \ 205 | -D ADDON_AUTHOR="\"${SCAFFOLD_ADDON_AUTHOR:-$default_addon_author}\"" \ 206 | -D ADDON_LICENCE="\"${SCAFFOLD_ADDON_LICENCE}\"" \ 207 | -D ADDON_WEBSITE="\"${SCAFFOLD_ADDON_WEBSITE}\"" \ 208 | -D ADDON_DEPENDS="\"'$depends_cs'\"" \ 209 | "$TMPL_ADDON_README" > "$addon_path/README.rst"; 210 | 211 | link_module "$addon_path"; 212 | } 213 | 214 | function scaffold_model { 215 | echo -e "${REDC}Not implemented yet${YELLOWC}:(${NC}"; 216 | } 217 | 218 | function scaffold_parse_cmd { 219 | local usage=" 220 | ${YELLOWC}WARNING${NC}: this command is experimental and not maintained. 221 | 222 | Usage: 223 | 224 | $SCRIPT_NAME scaffold repo [--help] - create new repository 225 | $SCRIPT_NAME scaffold addon [--help] - create new addon. 226 | $SCRIPT_NAME scaffold model [--help] - create new model. 227 | $SCRIPT_NAME scaffold --help - show this help message 228 | 229 | $SCRIPT_NAME scaffold [addon path] - defaut scaffold 230 | (Odoo builtin) 231 | "; 232 | 233 | if [ -z "$1" ]; then 234 | echo "$usage"; 235 | return 0; 236 | fi 237 | 238 | local key="$1"; 239 | case $key in 240 | repo) 241 | shift; 242 | scaffold_repo "$@"; 243 | return 0; 244 | ;; 245 | addon) 246 | shift; 247 | scaffold_addon "$@"; 248 | return 0; 249 | ;; 250 | model) 251 | shift; 252 | scaffold_model "$@"; 253 | return 0; 254 | ;; 255 | -h|--help|help) 256 | echo "$usage"; 257 | return 0; 258 | ;; 259 | *) 260 | scaffold_default "$@"; 261 | return 0; 262 | ;; 263 | esac 264 | } 265 | -------------------------------------------------------------------------------- /lib/system.bash: -------------------------------------------------------------------------------- 1 | # Copyright © 2017-2018 Dmytro Katyukha 2 | 3 | ####################################################################### 4 | # This Source Code Form is subject to the terms of the Mozilla Public # 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this # 6 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. # 7 | ####################################################################### 8 | 9 | if [ -z "$ODOO_HELPER_BIN" ] || [ -z "$ODOO_HELPER_LIB" ]; then 10 | echo "Odoo-helper-scripts seems not been installed correctly."; 11 | echo "Reinstall it (see Readme on https://gitlab.com/katyukha/odoo-helper-scripts/)"; 12 | exit 1; 13 | fi 14 | 15 | if [ -z "$ODOO_HELPER_COMMON_IMPORTED" ]; then 16 | source "$ODOO_HELPER_LIB/common.bash"; 17 | fi 18 | 19 | # ---------------------------------------------------------------------------------------- 20 | 21 | 22 | set -e; # fail on errors 23 | 24 | 25 | function system_update__run_post_update_hooks { 26 | echoe -e "${BLUEC}INFO${NC}: Running post-update hooks..."; 27 | if [ -e "$ODOO_HELPER_ROOT/tools/virtualenv" ]; then 28 | echoe -e "${BLUEC}INFO${NC}: Cleaning up old integrated virtualenv... (Now odoo-helper-scripts will use system virtual env)"; 29 | rm -rf "$ODOO_HELPER_ROOT/tools/virtualenv"; 30 | fi 31 | 32 | # update odoo-helper bin links 33 | base_path=$(dirname "$ODOO_HELPER_ROOT"); 34 | for oh_cmd in "$ODOO_HELPER_BIN"/*; do 35 | local cmd_name; 36 | cmd_name=$(basename "$oh_cmd"); 37 | if ! command -v "$cmd_name" >/dev/null 2>&1; then 38 | if [[ "$base_path" == /opt/* ]]; then 39 | with_sudo ln -s "$oh_cmd" /usr/local/bin/; 40 | elif [[ "$base_path" == "$HOME"/* ]]; then 41 | ln -s "$oh_cmd" "$HOME/bin"; 42 | fi 43 | fi 44 | done 45 | echoe -e "${BLUEC}INFO${NC}: Post-update hooks completed..."; 46 | } 47 | 48 | # update odoo-helper-scripts 49 | function system_update_odoo_helper_scripts { 50 | local cdir; 51 | local base_path; 52 | local scripts_branch=$1; 53 | 54 | # TODO: Add optional ability to get latest release (including RC) 55 | local oh_release_url="https://gitlab.com/api/v4/projects/6823247/packages/generic/odoo-helper-scripts/master/odoo-helper-scripts_master.deb"; 56 | 57 | if ! git_is_git_repo "$ODOO_HELPER_ROOT"; then 58 | if [ "$(dpkg-query -W -f='${Status}' odoo-helper-scripts 2>/dev/null | grep -c 'ok installed')" -eq 0 ]; then 59 | # In this case odoo-helper-scripts installed as debian package. 60 | # So, to run update, we have to download latest stable build 61 | # and install it. 62 | if wget -T 15 -q -O /tmp/odoo-helper-scripts.deb "$oh_release_url"; then 63 | with_sudo dpkg -i "/tmp/odoo-helper-scripts.deb"; 64 | with_sudo apt-get install -f; # Fix missing dependencies 65 | echoe -e "${BLUEC}odoo-helper-scripts updated successfully.${NC}"; 66 | return 0; 67 | fi 68 | else 69 | echoe -e "${REDC}ERROR${NC}: Cannot update non-standard installation of odoo-helper-scripts!"; 70 | return 1 71 | fi 72 | fi 73 | 74 | # update 75 | cdir=$(pwd); 76 | cd "$ODOO_HELPER_ROOT"; 77 | if [ -z "$scripts_branch" ]; then 78 | # TODO: if there is no configured branch to pull from, git shows 79 | # message, that it does not know from where to pull 80 | git pull; 81 | else 82 | git fetch -q origin; 83 | if ! git checkout -q "origin/$scripts_branch"; then 84 | git checkout -q "$scripts_branch"; 85 | fi 86 | fi 87 | cd "$cdir"; 88 | 89 | # Run post-update hooks. 90 | # Running in this way because we want to run new version of code here. 91 | odoo-helper exec system_update__run_post_update_hooks; 92 | 93 | echoe -e "${LBLUEC}HINT${NC}: Update pre-requirements to ensure all system dependencies are installed. To do this, you can run command ${YELLOWC}odoo-helper install pre-requirements${NC}."; 94 | } 95 | 96 | # Check if specified directory or current directory is odoo-hleper project 97 | function system_is_odoo_helper_project { 98 | local dir_name; 99 | local save_dir; 100 | save_dir=$(pwd); 101 | dir_name=$(readlink -f "${1:-$(pwd)}"); 102 | 103 | if [ ! -d "$dir_name" ]; then 104 | echoe -e "${REDC}ERROR${NC}: ${YELLOWC}${dir_name}${NC} does not exists or is not a directory!"; 105 | return 2; 106 | fi 107 | 108 | cd "$dir_name"; 109 | config_load_project 2>/dev/null; 110 | cd "$save_dir"; 111 | if [ -z "$PROJECT_ROOT_DIR" ]; then 112 | return 1; 113 | else 114 | return 0; 115 | fi 116 | } 117 | 118 | # Return odoo-helper path to virtualenv directory 119 | function system_get_venv_dir { 120 | local dir_name; 121 | local save_dir; 122 | save_dir=$(pwd); 123 | dir_name=$(readlink -f "${1:-$(pwd)}"); 124 | 125 | if [ ! -d "$dir_name" ]; then 126 | echoe -e "${REDC}ERROR${NC}: ${YELLOWC}${dir_name}${NC} does not exists or is not a directory!"; 127 | return 2; 128 | fi 129 | 130 | cd "$dir_name"; 131 | config_load_project 2>/dev/null; 132 | cd "$save_dir"; 133 | if [ -n "$PROJECT_ROOT_DIR" ]; then 134 | echo "${VENV_DIR}"; 135 | else 136 | echoe -e "${REDC}ERROR${NC}: directory ${YELLOWC}${dir_name}${NC} is not under odoo-helper project"; 137 | return 1; 138 | fi 139 | } 140 | 141 | 142 | # system entry point 143 | function system_entry_point { 144 | local usage=" 145 | System utils for odoo-helper-scripts 146 | 147 | Usage: 148 | 149 | $SCRIPT_NAME system update [branch] - update odoo-helper-scripts (to specified branch / commit) 150 | $SCRIPT_NAME system lib-path - print path to lib with specified name 151 | $SCRIPT_NAME system is-project [path] - check if specified dir is odoo-helper project 152 | if dirname is not specified then current dir checked 153 | $SCRIPT_NAME system get-venv-dir [path] - if path is part of odoo-helper project than print path 154 | to virtualenv directory for this project. 155 | if path is not specified, then current working directory 156 | is used instead 157 | $SCRIPT_NAME system --help - show this help message 158 | 159 | "; 160 | 161 | if [[ $# -lt 1 ]]; then 162 | echo "$usage"; 163 | return 0; 164 | fi 165 | 166 | while [[ $# -gt 0 ]] 167 | do 168 | local key="$1"; 169 | case $key in 170 | update) 171 | shift; 172 | system_update_odoo_helper_scripts "$@"; 173 | return; 174 | ;; 175 | lib-path) 176 | shift; 177 | oh_get_lib_path "$@" 178 | return; 179 | ;; 180 | is-project) 181 | shift; 182 | system_is_odoo_helper_project "$@"; 183 | return 184 | ;; 185 | get-venv-dir) 186 | shift; 187 | system_get_venv_dir "$@"; 188 | return; 189 | ;; 190 | -h|--help|help) 191 | echo "$usage"; 192 | return; 193 | ;; 194 | *) 195 | echo "Unknown option / command $key"; 196 | return 1; 197 | ;; 198 | esac 199 | done 200 | } 201 | -------------------------------------------------------------------------------- /lib/templates/scaffold/addon/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from . import models 3 | -------------------------------------------------------------------------------- /lib/templates/scaffold/addon/models/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | -------------------------------------------------------------------------------- /lib/templates/scaffold/addon__README.rst.tmpl: -------------------------------------------------------------------------------- 1 | {{ ADDON_NAME }} 2 | {{ '=' * ADDON_NAME | length }} 3 | -------------------------------------------------------------------------------- /lib/templates/scaffold/addon__manifest__.py.tmpl: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | { 3 | 'name': "{{ ADDON_NAME }}", 4 | 5 | 'summary': """ 6 | Short (1 phrase/line) summary of the module's purpose, used as 7 | subtitle on modules listing or apps.openerp.com""", 8 | 9 | 'author': "{{ ADDON_AUTHOR }}", 10 | 'website': "{{ ADDON_WEBSITE | default('http://www.yourcompany.com', true) }}", 11 | 'license': "{{ ADDON_LICENCE | default('LGPL-3', true) }}", 12 | 13 | # Categories can be used to filter modules in modules listing 14 | # Check https://github.com/odoo/odoo/blob/{{ ODOO_VERSION }}/odoo/addons/base/module/module_data.xml 15 | # for the full list 16 | 'category': 'Uncategorized', 17 | 'version': '{{ ODOO_VERSION }}.0.0.1', 18 | 19 | # any module necessary for this one to work correctly 20 | 'depends': [ 21 | {{ ADDON_DEPENDS }} 22 | ], 23 | 24 | # always loaded 25 | 'data': [ 26 | # 'security/ir.model.access.csv', 27 | # 'views/views.xml', 28 | # 'views/templates.xml', 29 | ], 30 | # only loaded in demonstration mode 31 | 'demo': [ 32 | # 'demo/demo.xml', 33 | ], 34 | } 35 | 36 | -------------------------------------------------------------------------------- /lib/templates/scaffold/gitignore.tmpl: -------------------------------------------------------------------------------- 1 | *.py[cow] 2 | *.sw[pno] 3 | *.idea/ 4 | *~ 5 | .ropeproject/ 6 | .coverage 7 | htmlcov 8 | 9 | -------------------------------------------------------------------------------- /lib/utils.bash: -------------------------------------------------------------------------------- 1 | # Copyright © 2017-2018 Dmytro Katyukha 2 | 3 | ####################################################################### 4 | # This Source Code Form is subject to the terms of the Mozilla Public # 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this # 6 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. # 7 | ####################################################################### 8 | 9 | # Odoo Helper Scripts: Utility functions 10 | 11 | if [ -z "$ODOO_HELPER_LIB" ]; then 12 | echo "Odoo-helper-scripts seems not been installed correctly."; 13 | echo "Reinstall it (see Readme on https://gitlab.com/katyukha/odoo-helper-scripts/)"; 14 | exit 1; 15 | fi 16 | 17 | if [ -z "$ODOO_HELPER_COMMON_IMPORTED" ]; then 18 | source "$ODOO_HELPER_LIB/common.bash"; 19 | fi 20 | 21 | 22 | set -e; # fail on errors 23 | 24 | ohelper_require "odoo"; 25 | 26 | # Simple function to exec command in virtual environment if required 27 | function execv { 28 | if [ -n "$VENV_DIR" ] && [ -f "$VENV_DIR/bin/activate" ]; then 29 | source "$VENV_DIR/bin/activate"; 30 | fi 31 | 32 | # Eval command and save result 33 | if "$@"; then 34 | local res=$?; 35 | else 36 | local res=$?; 37 | fi 38 | 39 | # deactivate virtual environment 40 | if [ -n "$VENV_DIR" ] && [ -n "$VIRTUAL_ENV" ]; then 41 | deactivate; 42 | fi 43 | 44 | return $res 45 | 46 | } 47 | 48 | # simply pass all args to exec or unbuffer 49 | # depending on 'USE_UNBUFFER variable 50 | # Also take in account virtualenv 51 | function execu { 52 | # Check unbuffer option 53 | if [ -n "$USE_UNBUFFER" ] && ! command -v unbuffer >/dev/null 2>&1; then 54 | echoe -e "${REDC}Command 'unbuffer' not found. Install it to use --use-unbuffer option"; 55 | echoe -e "It could be installed via package *expect-dev*"; 56 | echoe -e "Or by command *odoo-helper install bin-tools*"; 57 | echoe -e "Using standard behavior${NC}"; 58 | USE_UNBUFFER=; 59 | fi 60 | 61 | # Decide wether to use unbuffer or not 62 | if [ -n "$USE_UNBUFFER" ]; then 63 | execv unbuffer "$@"; 64 | else 65 | local unbuffer_opt=""; 66 | execv "$@"; 67 | fi 68 | } 69 | 70 | # Exec command with specified odoo config 71 | # This function automaticaly set's and unsets Odoo configuration variables 72 | # 73 | # exec_conf 74 | function exec_conf { 75 | local conf=$1; shift; 76 | OPENERP_SERVER="$conf" ODOO_RC="$conf" "$@"; 77 | } 78 | 79 | # Exec pip for this project. Also adds OCA wheelhouse to pip FINDLINKS list 80 | function exec_pip { 81 | exec_py -m pip "$@"; 82 | } 83 | 84 | # Exec npm for this project 85 | function exec_npm { 86 | execu npm "$@"; 87 | } 88 | 89 | 90 | # Simple function to create directories passed as arguments 91 | # create_dirs [dir1] [dir2] ... [dir_n] 92 | function create_dirs { 93 | for dir in "$@"; do 94 | if [ ! -d "$dir" ]; then 95 | mkdir -p "$dir"; 96 | fi 97 | done; 98 | } 99 | 100 | 101 | # Simple function to check if at least one command exists. 102 | # Returns first existing command 103 | function check_command { 104 | for test_cmd in "$@"; do 105 | if execv command -v "$test_cmd" >/dev/null 2>&1; then 106 | execv command -v "$test_cmd"; 107 | return 0; 108 | fi; 109 | done 110 | return 1; 111 | } 112 | 113 | 114 | # echov $@ 115 | # echo if verbose is on 116 | function echov { 117 | if [ -n "$VERBOSE" ]; then 118 | echoe "$@"; 119 | fi 120 | } 121 | 122 | # echoe $@ 123 | # echo to STDERR 124 | function echoe { 125 | >&2 echo "$@"; 126 | } 127 | 128 | # check if process is running 129 | # is_process_running 130 | function is_process_running { 131 | kill -0 "$1" >/dev/null 2>&1; 132 | return "$?"; 133 | } 134 | 135 | # random_string [length] 136 | # default length = 8 137 | function random_string { 138 | < /dev/urandom tr -dc A-Za-z0-9 | head -c"${1:-8}"; 139 | } 140 | 141 | # search_file_up 142 | # Try to find file in start_path, if found, print path, if not found, 143 | # then try to find it in parent directory recursively 144 | function search_file_up { 145 | local search_path; 146 | search_path=$(readlink -f "$1"); 147 | while [[ "$search_path" != "/" ]]; 148 | do 149 | if [ -e "$search_path/$2" ]; then 150 | echo "$search_path/$2"; 151 | return 0; 152 | elif [ -n "$search_path" ] && [ "$search_path" != "/" ]; then 153 | search_path=$(dirname "$search_path"); 154 | else 155 | break; 156 | fi 157 | done 158 | } 159 | 160 | # Try to find file in one of directories specified 161 | # search_file_in [dir2] [dir3] ... 162 | function search_file_in { 163 | local search_path; 164 | local file_name=$1; 165 | shift; # skip first argument 166 | while [[ $# -gt 0 ]] # while there at least one argumet left 167 | do 168 | search_path=$(readlink -f "$1"); 169 | if [ -e "$search_path/$file_name" ]; then 170 | echo "$search_path/$file_name"; 171 | return 0; 172 | fi 173 | shift 174 | done 175 | } 176 | 177 | # is_odoo_module 178 | function is_odoo_module { 179 | if [ ! -d "$1" ]; then 180 | return 1; 181 | elif [ -f "$1/__manifest__.py" ]; then 182 | # Odoo 10.0+ 183 | return 0; 184 | elif [ -f "$1/__openerp__.py" ]; then 185 | # Odoo 6.0 - 9.0 186 | return 0; 187 | else 188 | return 1; 189 | fi 190 | } 191 | 192 | 193 | # with_sudo 194 | # Run command with sudo if required 195 | function with_sudo { 196 | if [[ "$UID" != 0 ]]; then 197 | sudo -E "$@"; 198 | else 199 | "$@"; 200 | fi 201 | } 202 | 203 | # Join arguments useing arg $1 as separator 204 | # join_by , a "b c" d -> a,b c,d 205 | # origin: http://stackoverflow.com/questions/1527049/bash-join-elements-of-an-array#answer-17841619 206 | function join_by { 207 | local IFS="$1"; 208 | shift; 209 | echo "$*"; 210 | } 211 | 212 | # Trim leading and trailing whitespaces 213 | # https://stackoverflow.com/questions/369758/how-to-trim-whitespace-from-a-bash-variable#answer-3352015 214 | function trim { 215 | local var="$*" 216 | # remove leading whitespace characters 217 | var="${var#"${var%%[![:space:]]*}"}" 218 | # remove trailing whitespace characters 219 | var="${var%"${var##*[![:space:]]}"}" 220 | echo -n "$var" 221 | } 222 | 223 | # Exec python 224 | # 225 | function exec_py { 226 | local python_exec; 227 | python_exec=$(odoo_get_python_interpreter); 228 | execv "$python_exec" "$@"; 229 | } 230 | 231 | # Exec python with server user (if provided) 232 | function exec_py_u { 233 | local python_exec; 234 | local current_user; 235 | python_exec=$(odoo_get_python_interpreter); 236 | current_user=$(whoami); 237 | if [ -n "$SERVER_RUN_USER" ] && [ "$SERVER_RUN_USER" != "$current_user" ]; then 238 | execv sudo -u "$SERVER_RUN_USER" -H -E "$python_exec" "$@"; 239 | else 240 | execv "$python_exec" "$@"; 241 | fi 242 | 243 | } 244 | 245 | # Shortcut to exec lodoo command 246 | function exec_lodoo { 247 | execv lodoo "$@"; 248 | } 249 | 250 | function exec_lodoo_u { 251 | local current_user; 252 | current_user=$(whoami); 253 | if [ -n "$SERVER_RUN_USER" ] && [ "$SERVER_RUN_USER" != "$current_user" ]; then 254 | sudo -u "$SERVER_RUN_USER" -H -E odoo-helper exec lodoo "$@"; 255 | else 256 | execv lodoo "$@"; 257 | fi 258 | } 259 | 260 | # Shortcut for exec py_utils 261 | function exec_py_utils { 262 | exec_py "$ODOO_HELPER_LIB/pylib/py_utils.py" "$@"; 263 | } 264 | 265 | 266 | # Check that version1 is greater or equal than version2 267 | # 268 | # version_cmp_gte 269 | function version_cmp_gte { 270 | exec_py -c "from pkg_resources import parse_version as V; exit(not bool(V('$1') >= V('$2')));"; 271 | } 272 | -------------------------------------------------------------------------------- /lib/version.bash: -------------------------------------------------------------------------------- 1 | # Copyright © 2017-2019 Dmytro Katyukha 2 | 3 | ####################################################################### 4 | # This Source Code Form is subject to the terms of the Mozilla Public # 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this # 6 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. # 7 | ####################################################################### 8 | 9 | # Odoo Helper Scripts: Version 10 | 11 | # Define version number 12 | ODOO_HELPER_VERSION="1.6.1"; 13 | ODOO_HELPER_CONFIG_VERSION="1"; 14 | -------------------------------------------------------------------------------- /mkdocs.yml: -------------------------------------------------------------------------------- 1 | site_name: odoo-helper-scripts 2 | site_author: Dmytro Katyukha 3 | site_description: 'Just a simple collection of odoo scripts. mostly to ease addons development process (allows to install and manage odoo instances in virtualenv)' 4 | site_url: https://odoo-helper-scripts.gitlab.io 5 | copyright: "odoo-helper-scripts project is licensed under the Mozilla Public License 2.0" 6 | 7 | repo_url: https://gitlab.com/katyukha/odoo-helper-scripts 8 | repo_name: GitLab 9 | 10 | theme: cinder 11 | 12 | google_analytics: ['UA-122240221-1', 'auto'] 13 | 14 | nav: 15 | - Home: index.md 16 | - User Guide: 17 | - Quick Start: quick-start-guide.md 18 | - Installation: installation.md 19 | - Frequently Used Commands: frequently-used-commands.md 20 | - Reference: 21 | - Configuration: odoo-helper-configuration.md 22 | - Project Directory Structure: project-directory-structure.md 23 | - odoo-requirements.txt format: odoo-requirements-txt.md 24 | - Command Reference: command-reference.md 25 | - About: 26 | - Release Notes: release-notes.md 27 | - Contributing: contributing.md 28 | -------------------------------------------------------------------------------- /scripts/README.md: -------------------------------------------------------------------------------- 1 | # Utility Scripts 2 | 3 | Place for various utility or build scripts 4 | -------------------------------------------------------------------------------- /scripts/build_docs.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | SCRIPT=$0; 4 | SCRIPT_NAME=$(basename "$SCRIPT"); 5 | SCRIPT_DIR=$(readlink -f "$(dirname $SCRIPT)"); 6 | WORK_DIR=$(pwd); 7 | PROJECT_DIR="$(readlink -f $SCRIPT_DIR/..)"; 8 | 9 | set -e; 10 | 11 | echo "Preparing docs..." 12 | bash "$SCRIPT_DIR"/prepare_docs.bash 13 | echo "Docs ready!" 14 | 15 | echo "Building docs..." 16 | mkdocs build -d $PROJECT_DIR/public 17 | echo "Docs built!" 18 | -------------------------------------------------------------------------------- /scripts/build_packages.bash: -------------------------------------------------------------------------------- 1 | #!/bin/env bash 2 | 3 | SCRIPT=$0; 4 | SCRIPT_NAME=`basename $SCRIPT`; 5 | SCRIPT_DIR=$(readlink -f "$(dirname $SCRIPT)"); 6 | WORK_DIR=$(pwd); 7 | PROJECT_DIR="$(readlink -f $SCRIPT_DIR/..)"; 8 | 9 | BUILD_DIR="$PROJECT_DIR/build"; 10 | 11 | source "$PROJECT_DIR/lib/version.bash"; 12 | 13 | 14 | mkdir -p $BUILD_DIR; 15 | rm -f $BUILD_DIR/*; 16 | 17 | deb_version="$ODOO_HELPER_VERSION"; 18 | 19 | if [ -z "$deb_version" ]; then 20 | echo "Version is not specified"; 21 | exit 1; 22 | fi 23 | 24 | echo "Building package for version '$deb_version'..."; 25 | 26 | deb_depends="git wget lsb-release 27 | procps libevent-dev g++ libpq-dev libsass-dev 28 | python3-dev python3-virtualenv libjpeg-dev libyaml-dev 29 | libfreetype6-dev zlib1g-dev libxml2-dev libxslt-dev bzip2 30 | libsasl2-dev libldap2-dev libssl-dev libffi-dev fontconfig 31 | libmagic1"; 32 | deb_depends_opt=$(for dep in $deb_depends; do echo "--depends $dep"; done); 33 | 34 | fpm -s dir -t deb \ 35 | --package "$BUILD_DIR/odoo-helper-scripts.deb" \ 36 | --name odoo-helper-scripts \ 37 | --description "Just a simple collection of odoo scripts. mostly to ease addons development process (allows to install and manage odoo instances in virtualenv)" \ 38 | --config-files /etc/odoo-helper.conf \ 39 | --vendor "Dmytro Katyukha" \ 40 | --maintainer "Dmytro Katyukha" \ 41 | --url "https://katyukha.gitlab.io/odoo-helper-scripts/" \ 42 | --category "utils" \ 43 | --iteration ubuntu\ 44 | --architecture all \ 45 | --version $deb_version \ 46 | $deb_depends_opt \ 47 | --license "Mozilla Public License, v. 2.0" \ 48 | --deb-recommends expect-dev \ 49 | --deb-recommends tcl8.6 \ 50 | $PROJECT_DIR/bin/=/usr/local/bin/ \ 51 | $PROJECT_DIR/lib/=/opt/odoo-helper-scripts/lib/ \ 52 | $PROJECT_DIR/CHANGELOG.md=/opt/odoo-helper-scripts/ \ 53 | $PROJECT_DIR/LICENSE=/opt/odoo-helper-scripts/ \ 54 | $PROJECT_DIR/defaults/odoo-helper.conf=/etc/ 55 | -------------------------------------------------------------------------------- /scripts/run_docker_test.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright © 2017-2018 Dmytro Katyukha 4 | 5 | ####################################################################### 6 | # This Source Code Form is subject to the terms of the Mozilla Public # 7 | # License, v. 2.0. If a copy of the MPL was not distributed with this # 8 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. # 9 | ####################################################################### 10 | 11 | SCRIPT=$0; 12 | SCRIPT_NAME=$(basename $SCRIPT); 13 | SCRIPT_DIR=$(dirname $SCRIPT); 14 | PROJECT_DIR=$(readlink -f "$SCRIPT_DIR/.."); 15 | WORK_DIR=`pwd`; 16 | 17 | 18 | #------------------------------------------------------ 19 | # Environment 20 | #------------------------------------------------------ 21 | E_TEST_TMP_DIR=/opt/odoo-helper-scripts/test-temp; 22 | 23 | #------------------------------------------------------ 24 | # Prepare install 25 | #------------------------------------------------------ 26 | L_LANG='en_US.UTF-8' 27 | L_LANGUAGE="en_US:en" 28 | CMD_INSTALL="apt-get update && apt-get install -y adduser sudo locales && \ 29 | sed -i 's/^# *\($L_LANG\)/\1/' /etc/locale.gen && locale-gen $L_LANG && \ 30 | export LANG=$L_LANG && export LANGUAGE=$L_LANGUAGE && export LC_ALL=$L_LANG && \ 31 | update-locale LANG=$L_LANG && update-locale LANGUAGE=$L_LANGUAGE && \ 32 | adduser --disabled-password --gecos '' --shell '/bin/bash' --home=/home/odoo odoo && \ 33 | echo 'odoo ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers.d/odoo && \ 34 | bash /opt/odoo-helper-scripts/install-system.bash \ 35 | rm -rf $E_TEST_TMP_DIR && \ 36 | sudo mkdir -p $E_TEST_TMP_DIR && \ 37 | sudo chown odoo:odoo -R $E_TEST_TMP_DIR"; 38 | 39 | 40 | #------------------------------------------------------ 41 | # Prepare cleanup cmd 42 | #------------------------------------------------------ 43 | CMD_CLEANUP="sudo rm -rf rm -rf $E_TEST_TMP_DIR"; 44 | 45 | #------------------------------------------------------ 46 | # Set up default values 47 | #------------------------------------------------------ 48 | TEST_FILE=/opt/odoo-helper-scripts/tests/test.bash; 49 | DOCKER_FILE=$PROJECT_DIR/tests/docker/; 50 | DOCKER_TEST_IMAGE=odoo-helper-test 51 | DOCKER_IMAGE="ubuntu:18.04" 52 | 53 | #------------------------------------------------------ 54 | # Parse commandline arguments 55 | #------------------------------------------------------ 56 | usage="Usage: 57 | 58 | $SCRIPT_NAME --docker-build - path to dockerfile to build docker image for. 59 | Default: $DOCKER_FILE 60 | $SCRIPT_NAME --docker-image - name of docker image to test on 61 | Default: $DOCKER_IMAGE 62 | $SCRIPT_NAME --docker-ti - add '-ti' options to 'docker run' cmd 63 | $SCRIPT_NAME --with-coverage - run with code coverage 64 | $SCRIPT_NAME --test-file - run test file. default: $TEST_FILE 65 | $SCRIPT_NAME --help - show this help message 66 | 67 | "; 68 | 69 | if [[ $# -lt 1 ]]; then 70 | echo "$usage"; 71 | exit 0; 72 | fi 73 | 74 | while [[ $# -gt 0 ]] 75 | do 76 | key="$1"; 77 | case $key in 78 | --docker-file) 79 | DOCKER_FILE=$2; 80 | DOCKER_IMAGE=$DOCKER_TEST_IMAGE; 81 | shift; 82 | ;; 83 | --docker-image) 84 | DOCKER_FILE=; 85 | DOCKER_IMAGE=$2; 86 | shift; 87 | ;; 88 | --docker-ti) 89 | EXTRA_DOCKER_RUN_OPT="-ti"; 90 | ;; 91 | --with-coverage) 92 | WITH_COVERAGE=bashcov; 93 | ;; 94 | --test-file) 95 | TEST_FILE=$2; 96 | shift; 97 | ;; 98 | -h|--help|help) 99 | echo "$usage"; 100 | exit 0; 101 | ;; 102 | *) 103 | echo "Unknown option / command $key"; 104 | exit 1; 105 | ;; 106 | esac 107 | shift 108 | done 109 | #------------------------------------------------------ 110 | 111 | D_CMD_TEST="cd /home/odoo && sudo -E -u odoo -H bash $TEST_FILE"; 112 | 113 | set -e; # fail on errors 114 | 115 | if [ ! -z $DOCKER_FILE ]; then 116 | echo "Building image for $DOCKER_FILE" 117 | IMAGE=$(docker build -q -t $DOCKER_TEST_IMAGE $DOCKER_FILE); 118 | else 119 | IMAGE=$DOCKER_IMAGE; 120 | fi 121 | 122 | exec docker run --rm $EXTRA_DOCKER_RUN_OPT \ 123 | -v $PROJECT_DIR:/opt/odoo-helper-scripts:rw \ 124 | -e "DEBIAN_FRONTEND='noninteractive'" \ 125 | -e "CI_RUN=1" -e "TEST_TMP_DIR=$E_TEST_TMP_DIR" \ 126 | "$IMAGE" \ 127 | bash -c "$CMD_INSTALL && $D_CMD_TEST && $CMD_CLEANUP"; 128 | -------------------------------------------------------------------------------- /scripts/serve_docs.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | SCRIPT=$0; 4 | SCRIPT_NAME=$(basename "$SCRIPT"); 5 | SCRIPT_DIR=$(readlink -f "$(dirname $SCRIPT)"); 6 | WORK_DIR=$(pwd); 7 | PROJECT_DIR="$(readlink -f $SCRIPT_DIR/..)"; 8 | 9 | set -e; 10 | 11 | echo "Preparing docs..." 12 | bash "$SCRIPT_DIR"/prepare_docs.bash 13 | echo "Docs ready!" 14 | 15 | echo "Serving docs..." 16 | mkdocs serve 17 | -------------------------------------------------------------------------------- /tests/ci.bash: -------------------------------------------------------------------------------- 1 | # Copyright © 2016-2018 Dmytro Katyukha 2 | 3 | ####################################################################### 4 | # This Source Code Form is subject to the terms of the Mozilla Public # 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this # 6 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. # 7 | ####################################################################### 8 | 9 | # Prepare for test (if running on CI) 10 | if [ ! -z $CI_RUN ]; then 11 | echo -e "\e[33m Running as in CI environment \e[0m"; 12 | export ALWAYS_ANSWER_YES=1; 13 | 14 | if ! command -v "odoo-install" >/dev/null 2>&1 || ! command -v "odoo-helper" >/dev/null 2>&1; then 15 | echo "Seems that odoo-helper-scripts were not installed correctly!"; 16 | echo "PATH: $PATH"; 17 | echo "Current path: $(pwd)"; 18 | echo "Home var: $HOME"; 19 | echo ""; 20 | if [ -f $HOME/odoo-helper.conf ]; then 21 | echo "User conf: "; 22 | echo "$(cat $HOME/odoo-helper.conf)"; 23 | else 24 | echo "User conf not found!"; 25 | fi 26 | echo ""; 27 | echo "Content of ~/.profile file:"; 28 | echo "$(cat $HOME/.profile)"; 29 | echo ""; 30 | echo "Content of ~/.bashrc file:"; 31 | echo "$(cat $HOME/.bashrc)"; 32 | echo ""; 33 | echo "Content of ~/.bash_profile file:"; 34 | echo "$(cat $HOME/.bash_profile)"; 35 | echo ""; 36 | 37 | fi 38 | if [ -f /etc/odoo-helper.conf ]; then 39 | echo "Content of odoo-helper global config"; 40 | echo $(cat /etc/odoo-helper.conf); 41 | fi 42 | if [ -f $HOME/odoo-helper.conf ]; then 43 | echo "Content of odoo-helper home config"; 44 | echo $(cat $HOME/odoo-helper.conf); 45 | fi 46 | else 47 | echo -e "\e[33m CI Environment not enabled \e[0m"; 48 | 49 | fi 50 | -------------------------------------------------------------------------------- /tests/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:14.04 2 | 3 | # Set corect locale-related environment variables 4 | ENV LANG="en_US.UTF-8" LANGUAGE="en_US:en" LC_ALL="en_US.UTF-8" 5 | RUN locale-gen $LANG && \ 6 | update-locale LANG=$LANG && \ 7 | update-locale LANGUAGE=$LANGUAGE 8 | 9 | # Install system deps (used to speed-up tests 10 | # avoiding install of some system packages) 11 | RUN apt-get update -qq && apt-get upgrade -qq -y && \ 12 | apt-get install -y -qq gnupg2 curl wget git && \ 13 | rm -rf /var/lib/apt/lists/* 14 | 15 | # Add user odoo 16 | RUN adduser --home=/home/odoo odoo && \ 17 | echo "odoo ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/odoo 18 | 19 | USER odoo 20 | WORKDIR /home/odoo 21 | 22 | # Configure git for 23 | RUN git config --global user.email "odoo-helper@test.test" \ 24 | git config --global user.name "Odoo Helper Tester" 25 | 26 | # Install RVM 27 | RUN gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 && \ 28 | curl -sSL https://get.rvm.io | bash -s stable --ruby 29 | 30 | # Install ruby 31 | RUN bash -c 'source /home/odoo/.rvm/scripts/rvm; rvm install ruby-2.3; rvm use 2.3' 32 | 33 | # Install test coverage deps 34 | RUN bash -c 'source /home/odoo/.rvm/scripts/rvm; gem install bashcov coveralls' 35 | 36 | # Create empty /home/odoo/bin dir, to make odoo-helper user-install work 37 | RUN mkdir /home/odoo/bin 38 | --------------------------------------------------------------------------------