diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..8ada0347983d773c254ec5271b12dd9f3155cb9e --- /dev/null +++ b/.gitignore @@ -0,0 +1,22 @@ +dist/* +*.egg-info +*.pyc +.tox + +.coverage +coverage.xml +htmlcov/* +build +dist + +# Documentation +docs/source/source_documentation +!docs/source/source_documentation/index.rst +docs/build + +# Setuptools SCM +lofar_tmss_client/_version.py + +# IDE configuration +.vscode +.idea diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..0f3eb2afe196284f8aa3d636f1bea9504afd47cd --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,142 @@ +default: + image: $CI_REGISTRY_IMAGE/ci-build-runner:$CI_COMMIT_REF_SLUG + cache: + paths: + - .cache/pip + # Do not cache .tox, to recreate virtualenvs for every step + +stages: + - prepare + - lint + - test + - package + - images + - integration + - publish # publish instead of deploy + +# Caching of dependencies to speed up builds +variables: + PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip" + PIP_EXTRA_INDEX_URL: https://git.astron.nl/api/v4/projects/744/packages/pypi/simple https://git.astron.nl/api/v4/projects/745/packages/pypi/simple + SECURE_LOG_LEVEL: debug + +include: + - template: Security/SAST.gitlab-ci.yml + - template: Security/Dependency-Scanning.gitlab-ci.yml + - template: Security/Secret-Detection.gitlab-ci.yml + +# Prepare image to run ci on +trigger_prepare: + stage: prepare + trigger: + strategy: depend + include: .prepare.gitlab-ci.yml + +run_black: + stage: lint + script: + - tox -e black + allow_failure: true + +run_flake8: + stage: lint + script: + - tox -e pep8 + allow_failure: true + +run_pylint: + stage: lint + script: + - tox -e pylint + allow_failure: true + +sast: + variables: + SAST_EXCLUDED_ANALYZERS: brakeman, flawfinder, kubesec, nodejs-scan, phpcs-security-audit, + pmd-apex, security-code-scan, sobelow, spotbugs + stage: test + +gemnasium-python-dependency_scanning: + before_script: + - apt-get -qqy update && apt-get install -qqy libpq-dev + +# Basic setup for all Python versions for which we don't have a base image +.run_unit_test_version_base: + before_script: + - python --version # For debugging + - python -m pip install --upgrade pip + - python -m pip install --upgrade tox twine + +# Run all unit tests for Python versions except the base image +run_unit_tests: + extends: .run_unit_test_version_base + stage: test + image: python:3.${PY_VERSION} + allow_failure: true + script: + - tox -e py3${PY_VERSION} + parallel: + matrix: # use the matrix for testing + - PY_VERSION: [10, 11, 12] + +# Run code coverage on the base image thus also performing unit tests +run_unit_tests_coverage: + stage: test + allow_failure: true + script: + - tox -e coverage + coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/' + artifacts: + reports: + coverage_report: + coverage_format: cobertura + path: coverage.xml + paths: + - htmlcov/* + +package_files: + stage: package + artifacts: + expire_in: 1w + paths: + - dist/* + script: + - tox -e build + +run_integration_tests: + stage: integration + allow_failure: true + needs: + - package_files + script: + - echo "make sure to move out of source dir" + - echo "install package from filesystem (or use the artefact)" + - echo "run against foreign systems (e.g. databases, cwl etc.)" + - exit 1 + +publish_on_gitlab: + stage: publish + environment: gitlab + needs: + - package_files + when: manual + rules: + - if: $CI_COMMIT_TAG + script: + - echo "run twine for gitlab" + - | + TWINE_PASSWORD=${CI_JOB_TOKEN} \ + TWINE_USERNAME=gitlab-ci-token \ + python -m twine upload \ + --repository-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi dist/* + +release_job: + stage: publish + image: registry.gitlab.com/gitlab-org/release-cli:latest + rules: + - if: '$CI_COMMIT_TAG && $CI_COMMIT_REF_PROTECTED == "true"' + script: + - echo "running release_job" + release: + tag_name: '$CI_COMMIT_TAG' + description: '$CI_COMMIT_TAG - $CI_COMMIT_TAG_MESSAGE' diff --git a/.prepare.gitlab-ci.yml b/.prepare.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..3e48a271564faec892e42aab9f947d946ecc4d7b --- /dev/null +++ b/.prepare.gitlab-ci.yml @@ -0,0 +1,23 @@ +stages: + - build + +build_ci_runner_image: + stage: build + image: docker + tags: + - dind + script: + - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY + - | + if docker pull $CI_REGISTRY_IMAGE/ci-build-runner:$CI_COMMIT_REF_SLUG; then + docker build --cache-from $CI_REGISTRY_IMAGE/ci-build-runner:$CI_COMMIT_REF_SLUG --tag $CI_REGISTRY_IMAGE/ci-build-runner:$CI_COMMIT_REF_SLUG docker/ci-runner + else + docker pull $CI_REGISTRY_IMAGE/ci-build-runner:latest || true + docker build --cache-from $CI_REGISTRY_IMAGE/ci-build-runner:latest --tag $CI_REGISTRY_IMAGE/ci-build-runner:$CI_COMMIT_REF_SLUG docker/ci-runner + fi + - docker push $CI_REGISTRY_IMAGE/ci-build-runner:$CI_COMMIT_REF_SLUG # push the image + - | + if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then + docker image tag $CI_REGISTRY_IMAGE/ci-build-runner:$CI_COMMIT_REF_SLUG $CI_REGISTRY_IMAGE/ci-build-runner:latest + docker push $CI_REGISTRY_IMAGE/ci-build-runner:latest + fi diff --git a/LICENSE b/LICENSE index 261eeb9e9f8b2b4b0d119366dda99c6fd7d35c64..94a9ed024d3859793618152ea559a168bbcbb5e2 100644 --- a/LICENSE +++ b/LICENSE @@ -1,201 +1,674 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + <program> Copyright (C) <year> <name of author> + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +<http://www.gnu.org/licenses/>. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +<http://www.gnu.org/philosophy/why-not-lgpl.html>. diff --git a/README.md b/README.md index 5f76983b984f088ded15f6b81fc0e88d211b52b4..dd4afbbccd3ba3acc217f8e3ba1e9d68ba2eba35 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # LOFAR TMSS Client - - -<!--  --> + + + A package for interacting with TMSS (Telescope Manager Specification System). This contains the module to connect to TMSS and interact programmatically, as well as CLI utilities. @@ -41,4 +41,4 @@ To automatically apply most suggested linting changes execute: ```tox -e format``` ## License -This project is licensed under the Apache License Version 2.0 +This project is licensed under GPLv3 diff --git a/docker/ci-runner/Dockerfile b/docker/ci-runner/Dockerfile index 6268a1aa5f08de11246abd0fabbb456e2862af84..f6155b74b309e8e4cf0f4ca6eb3a4aeb5da5a0e0 100644 --- a/docker/ci-runner/Dockerfile +++ b/docker/ci-runner/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.12 +FROM python:3.13 RUN python -m pip install --upgrade pip RUN pip install --upgrade tox twine diff --git a/docs/cleanup.py b/docs/cleanup.py deleted file mode 100644 index 3a4508d859234544bea35b1008e3c8e4f73d7cc0..0000000000000000000000000000000000000000 --- a/docs/cleanup.py +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env python3 - -# Copyright (C) 2023 ASTRON (Netherlands Institute for Radio Astronomy) -# SPDX-License-Identifier: Apache-2.0 - -import os - -file_dir = os.path.dirname(os.path.realpath(__file__)) - -clean_dir = os.path.join(file_dir, "source", "source_documentation") -print(f"Cleaning.. {clean_dir}/*") - -if not os.path.exists(clean_dir): - exit() - -for file_name in os.listdir(clean_dir): - file = os.path.join(clean_dir, file_name) - - if file_name == "index.rst": - continue - - print(f"Removing.. {file}") - os.remove(file) diff --git a/docs/requirements.txt b/docs/requirements.txt deleted file mode 100644 index 3c6e46c6db7ddaf65e47cfa22c9ec0b914f7fd38..0000000000000000000000000000000000000000 --- a/docs/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -sphinx!=1.6.6,!=1.6.7,>=1.6.5 # BSD -sphinx-rtd-theme>=0.4.3 #MIT -sphinxcontrib-apidoc>=0.3.0 #BSD -myst-parser>=2.0 # MIT -docutils>=0.17 # BSD diff --git a/docs/source/conf.py b/docs/source/conf.py deleted file mode 100644 index b204c60bcd359aa4e711efd8620360d4d3c3c0c0..0000000000000000000000000000000000000000 --- a/docs/source/conf.py +++ /dev/null @@ -1,93 +0,0 @@ -# Copyright (C) 2023 ASTRON (Netherlands Institute for Radio Astronomy) -# SPDX-License-Identifier: Apache-2.0 - -import os - -from lofar_tmss_client import __version__ - -# -- General configuration ---------------------------------------------------- - -# Add any Sphinx extension module names here, as strings. They can be -# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones. -extensions = [ - "sphinx.ext.autodoc", - "sphinx.ext.viewcode", - "sphinxcontrib.apidoc", - "sphinx_rtd_theme", - "myst_parser" -] - -# Assumes tox is used to call sphinx-build -project_root_directory = os.getcwd() - -apidoc_module_dir = "../../lofar_tmss_client" -apidoc_output_dir = "source_documentation" -apidoc_excluded_paths = [] -apidoc_separate_modules = True -apidoc_toc_file = False -# This should include private methods but does not work -# https://github.com/sphinx-contrib/apidoc/issues/14 -apidoc_extra_args = ["--private"] - -# The suffix of source filenames. -source_suffix = [".rst"] - -# The master toctree document. -master_doc = "index" - -# General information about the project. -project = "LOFAR TMSS Client" -copyright = "2023, ASTRON" - -# openstackdocstheme options -repository_name = "git.astron.nl/ro/lofar_tmss_client" -bug_project = "none" -bug_tag = "" -html_last_updated_fmt = "%Y-%m-%d %H:%M" - -# If true, '()' will be appended to :func: etc. cross-reference text. -add_function_parentheses = True - -version = __version__ - -modindex_common_prefix = ["lofar_tmss_client."] - -# If true, the current module name will be prepended to all description -# unit titles (such as .. function::). -add_module_names = True - -# The name of the Pygments (syntax highlighting) style to use. -pygments_style = "sphinx" - -# -- Options for HTML output -------------------------------------------------- - -# The theme to use for HTML and HTML Help pages. Major themes that come with -# Sphinx are currently 'default' and 'sphinxdoc'. -# html_theme_path = ["."] -html_theme = "sphinx_rtd_theme" -html_static_path = ["static"] -html_css_files = [ - "css/custom.css", -] - -# Output file base name for HTML help builder. -htmlhelp_basename = "%sdoc" % project - -# Conf.py variables exported to sphinx rst files access using |NAME| -variables_to_export = [ - "project", - "copyright", - "version", -] - -# Write to rst_epilog to export `variables_to_export` extract using `locals()` -# https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-rst_epilog -frozen_locals = dict(locals()) -rst_epilog = "\n".join( - map( - lambda x: f".. |{x}| replace:: {frozen_locals[x]}", # noqa: F821 - variables_to_export, - ) -) -# Pep is not able to determine that frozen_locals always exists so noqa -del frozen_locals diff --git a/docs/source/index.rst b/docs/source/index.rst deleted file mode 100644 index 3bea4182af30c4fe466e862d0df78d0d818b2ea8..0000000000000000000000000000000000000000 --- a/docs/source/index.rst +++ /dev/null @@ -1,16 +0,0 @@ -==================================================== -Welcome to the documentation of LOFAR TMSS Client -==================================================== - -.. - To define more variables see rst_epilog generation in conf.py - -Documentation for version: |version| - -Contents: - -.. toctree:: - :maxdepth: 2 - - readme - source_documentation/index diff --git a/docs/source/readme.rst b/docs/source/readme.rst deleted file mode 100644 index 87c96deef60fc04b35a8b9b9cca2f72b7e64e70c..0000000000000000000000000000000000000000 --- a/docs/source/readme.rst +++ /dev/null @@ -1,2 +0,0 @@ -.. include:: ../../README.md - :parser: myst_parser.sphinx_ diff --git a/docs/source/source_documentation/index.rst b/docs/source/source_documentation/index.rst deleted file mode 100644 index 1ae9d0d86e4308d49adb8cda6004bd6f93cf42c5..0000000000000000000000000000000000000000 --- a/docs/source/source_documentation/index.rst +++ /dev/null @@ -1,7 +0,0 @@ -Source code documentation -========================= - -.. toctree:: - :maxdepth: 3 - - lofar_tmss_client diff --git a/docs/source/static/css/custom.css b/docs/source/static/css/custom.css deleted file mode 100644 index 3ea8a2fc0c9c1ecb2b318cbc32edf90d2940c38d..0000000000000000000000000000000000000000 --- a/docs/source/static/css/custom.css +++ /dev/null @@ -1,14 +0,0 @@ -.orange { color: #c65d09; } - -.green { color: #5dc609; } - -.yellow { color: #c6c609; } - -.bolditalic { - font-weight: bold; - font-style: italic; -} - -.rst-content code, .rst-content tt, code { - white-space: break-spaces; -} diff --git a/tests/test_tmss_client.py b/integration_tests/test_tmss_client.py similarity index 79% rename from tests/test_tmss_client.py rename to integration_tests/test_tmss_client.py index dd50b3c99254eeaef19a1cf21999a81a23a47a0e..176c4c0b2df2c932efbc0ea882a90affdb3ca176 100644 --- a/tests/test_tmss_client.py +++ b/integration_tests/test_tmss_client.py @@ -1,7 +1,8 @@ # Copyright (C) 2023 ASTRON (Netherlands Institute for Radio Astronomy) -# SPDX-License-Identifier: Apache-2.0 +# SPDX-License-Identifier: GPL-3.0-or-later + +"""Testing connecting with client""" -"""Testing of the Cool Module""" from unittest import TestCase from lofar_tmss_client.tmss_http_rest_client import TMSSsession diff --git a/lofar_tmss_client/__init__.py b/lofar_tmss_client/__init__.py index 227f125329b2595c5971ee4ead8163cc0a4cd006..16b2302ba2422f8970be101e15bd10dcb3736fcb 100644 --- a/lofar_tmss_client/__init__.py +++ b/lofar_tmss_client/__init__.py @@ -1,11 +1,4 @@ -# Copyright (C) 2023 ASTRON (Netherlands Institute for Radio Astronomy) -# SPDX-License-Identifier: Apache-2.0 +# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: GPL-3.0-or-later """ LOFAR TMSS Client """ - -try: - from importlib import metadata -except ImportError: # for Python<3.8 - import importlib_metadata as metadata - -__version__ = metadata.version("lofar_tmss_client") diff --git a/lofar_tmss_client/bin/tmss_adapt_scheduling_unit_blueprint_to_start_and_stop_times b/lofar_tmss_client/bin/tmss_adapt_scheduling_unit_blueprint_to_start_and_stop_times deleted file mode 100755 index 3a7926aadfa62c0f6fba2733a8b1e903367026cf..0000000000000000000000000000000000000000 --- a/lofar_tmss_client/bin/tmss_adapt_scheduling_unit_blueprint_to_start_and_stop_times +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/python3 - -# Copyright (C) 2012-2015 ASTRON (Netherlands Institute for Radio Astronomy) -# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands -# -# This file is part of the LOFAR software suite. -# The LOFAR software suite is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# The LOFAR software suite is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. - - -# Script to set start and stop times of fixed-time-scheduled scheduling units - -from lofar_tmss_client.mains import main_adapt_scheduling_unit_blueprint_to_start_and_stop_times - -if __name__ == "__main__": - main_adapt_scheduling_unit_blueprint_to_start_and_stop_times() diff --git a/lofar_tmss_client/bin/tmss_adapt_scheduling_unit_draft_to_start_and_stop_times b/lofar_tmss_client/bin/tmss_adapt_scheduling_unit_draft_to_start_and_stop_times deleted file mode 100755 index 41ca2b6ccc9e8e06ebf69c60128c5b2b3a440cae..0000000000000000000000000000000000000000 --- a/lofar_tmss_client/bin/tmss_adapt_scheduling_unit_draft_to_start_and_stop_times +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/python3 - -# Copyright (C) 2012-2015 ASTRON (Netherlands Institute for Radio Astronomy) -# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands -# -# This file is part of the LOFAR software suite. -# The LOFAR software suite is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# The LOFAR software suite is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. - - -# Script to set start and stop times of fixed-time-scheduled scheduling units - -from lofar_tmss_client.mains import main_adapt_scheduling_unit_draft_to_start_and_stop_times - -if __name__ == "__main__": - main_adapt_scheduling_unit_draft_to_start_and_stop_times() diff --git a/lofar_tmss_client/bin/tmss_cancel_subtask b/lofar_tmss_client/bin/tmss_cancel_subtask deleted file mode 100755 index 2f5709b1b36473c39b62d5ca25b2b14111dcd620..0000000000000000000000000000000000000000 --- a/lofar_tmss_client/bin/tmss_cancel_subtask +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/python3 - -# Copyright (C) 2012-2015 ASTRON (Netherlands Institute for Radio Astronomy) -# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands -# -# This file is part of the LOFAR software suite. -# The LOFAR software suite is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# The LOFAR software suite is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. - -from lofar_tmss_client.mains import main_cancel_subtask - -if __name__ == "__main__": - main_cancel_subtask() diff --git a/lofar_tmss_client/bin/tmss_create_and_process_feedback_for_subtask_from_specification_and_set_to_finished b/lofar_tmss_client/bin/tmss_create_and_process_feedback_for_subtask_from_specification_and_set_to_finished deleted file mode 100755 index 4fab2ff6c659ead4d4d41ff88416c72e1fc4d7ee..0000000000000000000000000000000000000000 --- a/lofar_tmss_client/bin/tmss_create_and_process_feedback_for_subtask_from_specification_and_set_to_finished +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/python3 - -# Copyright (C) 2012-2015 ASTRON (Netherlands Institute for Radio Astronomy) -# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands -# -# This file is part of the LOFAR software suite. -# The LOFAR software suite is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# The LOFAR software suite is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. - -from lofar_tmss_client.mains import main_create_and_process_feedback_for_subtask_from_specification_and_set_to_finished - -if __name__ == "__main__": - main_create_and_process_feedback_for_subtask_from_specification_and_set_to_finished() diff --git a/lofar_tmss_client/bin/tmss_create_lofar2_sibling b/lofar_tmss_client/bin/tmss_create_lofar2_sibling deleted file mode 100755 index add0c5e08ffec002d8ce60e9b4012adedb5b7f7c..0000000000000000000000000000000000000000 --- a/lofar_tmss_client/bin/tmss_create_lofar2_sibling +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/python3 - -# Copyright (C) 2012-2015 ASTRON (Netherlands Institute for Radio Astronomy) -# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands -# -# This file is part of the LOFAR software suite. -# The LOFAR software suite is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# The LOFAR software suite is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. - -from lofar_tmss_client.mains import main_create_lofar2_sibling_scheduling_unit - -if __name__ == "__main__": - main_create_lofar2_sibling_scheduling_unit() diff --git a/lofar_tmss_client/bin/tmss_get_setting b/lofar_tmss_client/bin/tmss_get_setting deleted file mode 100755 index d8631f6bb12eecedd0e7a8ba048ee72ed675e7eb..0000000000000000000000000000000000000000 --- a/lofar_tmss_client/bin/tmss_get_setting +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/python3 - -# Copyright (C) 2012-2015 ASTRON (Netherlands Institute for Radio Astronomy) -# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands -# -# This file is part of the LOFAR software suite. -# The LOFAR software suite is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# The LOFAR software suite is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. - -from lofar_tmss_client.mains import main_get_setting - -if __name__ == "__main__": - main_get_setting() diff --git a/lofar_tmss_client/bin/tmss_get_subtask b/lofar_tmss_client/bin/tmss_get_subtask deleted file mode 100755 index 85f1cd031dded316cb27721026ce42c873d6a55a..0000000000000000000000000000000000000000 --- a/lofar_tmss_client/bin/tmss_get_subtask +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/python3 - -# Copyright (C) 2012-2015 ASTRON (Netherlands Institute for Radio Astronomy) -# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands -# -# This file is part of the LOFAR software suite. -# The LOFAR software suite is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# The LOFAR software suite is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. - -from lofar_tmss_client.mains import main_get_subtask - -if __name__ == "__main__": - main_get_subtask() diff --git a/lofar_tmss_client/bin/tmss_get_subtask_json b/lofar_tmss_client/bin/tmss_get_subtask_json deleted file mode 100755 index cce6206e82f60c89b77e1f2d3b6231f5c2661c50..0000000000000000000000000000000000000000 --- a/lofar_tmss_client/bin/tmss_get_subtask_json +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/python3 - -# Copyright (C) 2012-2015 ASTRON (Netherlands Institute for Radio Astronomy) -# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands -# -# This file is part of the LOFAR software suite. -# The LOFAR software suite is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# The LOFAR software suite is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. - - -# Script to create, setup, and run a temporary ldap service with fixtures for easy functional testing - -from lofar_tmss_client.mains import main_get_subtask_json - -if __name__ == "__main__": - main_get_subtask_json() diff --git a/lofar_tmss_client/bin/tmss_get_subtask_l2stationspecs b/lofar_tmss_client/bin/tmss_get_subtask_l2stationspecs deleted file mode 100755 index aaea27155c4fbc6021a00ae5dd32e25f192febe9..0000000000000000000000000000000000000000 --- a/lofar_tmss_client/bin/tmss_get_subtask_l2stationspecs +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/python3 - -# Copyright (C) 2012-2015 ASTRON (Netherlands Institute for Radio Astronomy) -# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands -# -# This file is part of the LOFAR software suite. -# The LOFAR software suite is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# The LOFAR software suite is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. - - -# Script to create, setup, and run a temporary ldap service with fixtures for easy functional testing - -from lofar_tmss_client.mains import main_get_subtask_l2stationspecs - -if __name__ == "__main__": - main_get_subtask_l2stationspecs() diff --git a/lofar_tmss_client/bin/tmss_get_subtask_parset b/lofar_tmss_client/bin/tmss_get_subtask_parset deleted file mode 100755 index 7ed5357a9ae7e56159bc36cb988c844fe8e97c9c..0000000000000000000000000000000000000000 --- a/lofar_tmss_client/bin/tmss_get_subtask_parset +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/python3 - -# Copyright (C) 2012-2015 ASTRON (Netherlands Institute for Radio Astronomy) -# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands -# -# This file is part of the LOFAR software suite. -# The LOFAR software suite is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# The LOFAR software suite is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. - - -# Script to create, setup, and run a temporary ldap service with fixtures for easy functional testing - -from lofar_tmss_client.mains import main_get_subtask_parset - -if __name__ == "__main__": - main_get_subtask_parset() diff --git a/lofar_tmss_client/bin/tmss_get_subtask_predecessors b/lofar_tmss_client/bin/tmss_get_subtask_predecessors deleted file mode 100755 index 1857fa662f89902db783fccdcc7bd8f46cc2ae12..0000000000000000000000000000000000000000 --- a/lofar_tmss_client/bin/tmss_get_subtask_predecessors +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/python3 - -# Copyright (C) 2012-2015 ASTRON (Netherlands Institute for Radio Astronomy) -# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands -# -# This file is part of the LOFAR software suite. -# The LOFAR software suite is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# The LOFAR software suite is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. - -from lofar_tmss_client.mains import main_get_subtask_predecessors - -if __name__ == "__main__": - main_get_subtask_predecessors() diff --git a/lofar_tmss_client/bin/tmss_get_subtask_successors b/lofar_tmss_client/bin/tmss_get_subtask_successors deleted file mode 100755 index 79033b75d21c17eaade236ebca6e25f19655c18d..0000000000000000000000000000000000000000 --- a/lofar_tmss_client/bin/tmss_get_subtask_successors +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/python3 - -# Copyright (C) 2012-2015 ASTRON (Netherlands Institute for Radio Astronomy) -# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands -# -# This file is part of the LOFAR software suite. -# The LOFAR software suite is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# The LOFAR software suite is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. - -from lofar_tmss_client.mains import main_get_subtask_successors - -if __name__ == "__main__": - main_get_subtask_successors() diff --git a/lofar_tmss_client/bin/tmss_get_subtasks b/lofar_tmss_client/bin/tmss_get_subtasks deleted file mode 100755 index a644fe9c3f7e2776badfb2cb99731d9b4c768bcc..0000000000000000000000000000000000000000 --- a/lofar_tmss_client/bin/tmss_get_subtasks +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/python3 - -# Copyright (C) 2012-2015 ASTRON (Netherlands Institute for Radio Astronomy) -# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands -# -# This file is part of the LOFAR software suite. -# The LOFAR software suite is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# The LOFAR software suite is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. - -from lofar_tmss_client.mains import main_get_subtasks - -if __name__ == "__main__": - main_get_subtasks() diff --git a/lofar_tmss_client/bin/tmss_mark_scheduling_unit_dynamically_scheduled b/lofar_tmss_client/bin/tmss_mark_scheduling_unit_dynamically_scheduled deleted file mode 100755 index ba5ba1fe70cf1f4fcc96d949ebc6f03ec9402674..0000000000000000000000000000000000000000 --- a/lofar_tmss_client/bin/tmss_mark_scheduling_unit_dynamically_scheduled +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/python3 - -# Copyright (C) 2012-2015 ASTRON (Netherlands Institute for Radio Astronomy) -# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands -# -# This file is part of the LOFAR software suite. -# The LOFAR software suite is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# The LOFAR software suite is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. - -from lofar_tmss_client.mains import main_mark_scheduling_unit_dynamically_scheduled - -if __name__ == "__main__": - main_mark_scheduling_unit_dynamically_scheduled() diff --git a/lofar_tmss_client/bin/tmss_mark_scheduling_unit_fixed_time_scheduled_at_scheduled_starttime b/lofar_tmss_client/bin/tmss_mark_scheduling_unit_fixed_time_scheduled_at_scheduled_starttime deleted file mode 100755 index 655eb289de0ae2827375a9ba8940725265234dd4..0000000000000000000000000000000000000000 --- a/lofar_tmss_client/bin/tmss_mark_scheduling_unit_fixed_time_scheduled_at_scheduled_starttime +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/python3 - -# Copyright (C) 2012-2015 ASTRON (Netherlands Institute for Radio Astronomy) -# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands -# -# This file is part of the LOFAR software suite. -# The LOFAR software suite is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# The LOFAR software suite is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. - -from lofar_tmss_client.mains import main_mark_scheduling_unit_fixed_time_scheduled_at_scheduled_starttime - -if __name__ == "__main__": - main_mark_scheduling_unit_fixed_time_scheduled_at_scheduled_starttime() diff --git a/lofar_tmss_client/bin/tmss_mark_subtask_as_obsolete b/lofar_tmss_client/bin/tmss_mark_subtask_as_obsolete deleted file mode 100755 index 4c9f73b9a5d22470f95e270f99619d0921d3a92f..0000000000000000000000000000000000000000 --- a/lofar_tmss_client/bin/tmss_mark_subtask_as_obsolete +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/python3 - -# Copyright (C) 2012-2015 ASTRON (Netherlands Institute for Radio Astronomy) -# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands -# -# This file is part of the LOFAR software suite. -# The LOFAR software suite is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# The LOFAR software suite is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. - -from lofar_tmss_client.mains import main_mark_subtask_as_obsolete - -if __name__ == "__main__": - main_mark_subtask_as_obsolete() diff --git a/lofar_tmss_client/bin/tmss_remove_stations_from_scheduling_unit_blueprint b/lofar_tmss_client/bin/tmss_remove_stations_from_scheduling_unit_blueprint deleted file mode 100755 index c947c25fba4ebe1d7e1e3799dfd47ba84a89df5c..0000000000000000000000000000000000000000 --- a/lofar_tmss_client/bin/tmss_remove_stations_from_scheduling_unit_blueprint +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/python3 - -# Copyright (C) 2012-2015 ASTRON (Netherlands Institute for Radio Astronomy) -# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands -# -# This file is part of the LOFAR software suite. -# The LOFAR software suite is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# The LOFAR software suite is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. - -from lofar_tmss_client.mains import main_create_scheduling_unit_blueprint_copy_without_given_stations - -if __name__ == "__main__": - main_create_scheduling_unit_blueprint_copy_without_given_stations() diff --git a/lofar_tmss_client/bin/tmss_reset_schedule b/lofar_tmss_client/bin/tmss_reset_schedule deleted file mode 100755 index c02fb0f9bbd37581db65dcc64bcc0172e13da079..0000000000000000000000000000000000000000 --- a/lofar_tmss_client/bin/tmss_reset_schedule +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/python3 - -# Copyright (C) 2012-2015 ASTRON (Netherlands Institute for Radio Astronomy) -# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands -# -# This file is part of the LOFAR software suite. -# The LOFAR software suite is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# The LOFAR software suite is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. - -from lofar_tmss_client.mains import main_reset_schedule - -if __name__ == "__main__": - main_reset_schedule() diff --git a/lofar_tmss_client/bin/tmss_schedule_scheduling_unit_at_given_starttime b/lofar_tmss_client/bin/tmss_schedule_scheduling_unit_at_given_starttime deleted file mode 100755 index e82441d622f41e74828c7d8e9dbc972bf7a97028..0000000000000000000000000000000000000000 --- a/lofar_tmss_client/bin/tmss_schedule_scheduling_unit_at_given_starttime +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/python3 - -# Copyright (C) 2012-2015 ASTRON (Netherlands Institute for Radio Astronomy) -# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands -# -# This file is part of the LOFAR software suite. -# The LOFAR software suite is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# The LOFAR software suite is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. - -from lofar_tmss_client.mains import main_schedule_scheduling_unit_at_given_starttime - -if __name__ == "__main__": - main_schedule_scheduling_unit_at_given_starttime() diff --git a/lofar_tmss_client/bin/tmss_schedule_subtask b/lofar_tmss_client/bin/tmss_schedule_subtask deleted file mode 100755 index 7d1fa48851c9289d345b67d06c37427b514ec850..0000000000000000000000000000000000000000 --- a/lofar_tmss_client/bin/tmss_schedule_subtask +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/python3 - -# Copyright (C) 2012-2015 ASTRON (Netherlands Institute for Radio Astronomy) -# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands -# -# This file is part of the LOFAR software suite. -# The LOFAR software suite is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# The LOFAR software suite is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. - -from lofar_tmss_client.mains import main_schedule_subtask - -if __name__ == "__main__": - main_schedule_subtask() diff --git a/lofar_tmss_client/bin/tmss_set_setting b/lofar_tmss_client/bin/tmss_set_setting deleted file mode 100755 index c39921a2adf7bb355023f966ec27e86991213a66..0000000000000000000000000000000000000000 --- a/lofar_tmss_client/bin/tmss_set_setting +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/python3 - -# Copyright (C) 2012-2015 ASTRON (Netherlands Institute for Radio Astronomy) -# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands -# -# This file is part of the LOFAR software suite. -# The LOFAR software suite is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# The LOFAR software suite is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. - -from lofar_tmss_client.mains import main_set_setting - -if __name__ == "__main__": - main_set_setting() diff --git a/lofar_tmss_client/bin/tmss_set_subtask_state b/lofar_tmss_client/bin/tmss_set_subtask_state deleted file mode 100755 index 4032070cd9a1bd9d5b0245757a0ba5fca3e68865..0000000000000000000000000000000000000000 --- a/lofar_tmss_client/bin/tmss_set_subtask_state +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/python3 - -# Copyright (C) 2012-2015 ASTRON (Netherlands Institute for Radio Astronomy) -# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands -# -# This file is part of the LOFAR software suite. -# The LOFAR software suite is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# The LOFAR software suite is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. - - -# Script to create, setup, and run a temporary ldap service with fixtures for easy functional testing - -from lofar_tmss_client.mains import main_set_subtask_state - -if __name__ == "__main__": - main_set_subtask_state() diff --git a/lofar_tmss_client/bin/tmss_submit_trigger b/lofar_tmss_client/bin/tmss_submit_trigger deleted file mode 100755 index ef38357a2a030a234c4776c3dddd5c546d0d46bd..0000000000000000000000000000000000000000 --- a/lofar_tmss_client/bin/tmss_submit_trigger +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/python3 - -# Copyright (C) 2012-2015 ASTRON (Netherlands Institute for Radio Astronomy) -# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands -# -# This file is part of the LOFAR software suite. -# The LOFAR software suite is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# The LOFAR software suite is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. - -from lofar_tmss_client.mains import main_submit_trigger - -if __name__ == "__main__": - main_submit_trigger() diff --git a/lofar_tmss_client/bin/tmss_unschedule_scheduling_unit b/lofar_tmss_client/bin/tmss_unschedule_scheduling_unit deleted file mode 100755 index 9f2e1c0fb2ae8eb0dbb12d6eb2445d3c2e709fc7..0000000000000000000000000000000000000000 --- a/lofar_tmss_client/bin/tmss_unschedule_scheduling_unit +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/python3 - -# Copyright (C) 2012-2015 ASTRON (Netherlands Institute for Radio Astronomy) -# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands -# -# This file is part of the LOFAR software suite. -# The LOFAR software suite is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# The LOFAR software suite is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. - -from lofar_tmss_client.mains import main_unschedule_scheduling_unit - -if __name__ == "__main__": - main_unschedule_scheduling_unit() diff --git a/lofar_tmss_client/bin/tmss_unschedule_subtask b/lofar_tmss_client/bin/tmss_unschedule_subtask deleted file mode 100755 index 0772d0674460f12368957beea55782a03abd7c8a..0000000000000000000000000000000000000000 --- a/lofar_tmss_client/bin/tmss_unschedule_subtask +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/python3 - -# Copyright (C) 2012-2015 ASTRON (Netherlands Institute for Radio Astronomy) -# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands -# -# This file is part of the LOFAR software suite. -# The LOFAR software suite is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# The LOFAR software suite is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. - -from lofar_tmss_client.mains import main_unschedule_subtask - -if __name__ == "__main__": - main_unschedule_subtask() diff --git a/lofar_tmss_client/bin/tmss_wait_for_subtask_state b/lofar_tmss_client/bin/tmss_wait_for_subtask_state deleted file mode 100755 index 09f44951e86fbfbd54de4fb31feb05689ab3eb32..0000000000000000000000000000000000000000 --- a/lofar_tmss_client/bin/tmss_wait_for_subtask_state +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/python3 - -# Copyright (C) 2012-2015 ASTRON (Netherlands Institute for Radio Astronomy) -# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands -# -# This file is part of the LOFAR software suite. -# The LOFAR software suite is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# The LOFAR software suite is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. - - -# Script to create, setup, and run a temporary ldap service with fixtures for easy functional testing - -from lofar_tmss_client.mains import main_wait_for_subtask_state - -if __name__ == "__main__": - main_wait_for_subtask_state() diff --git a/lofar_tmss_client/dbcredentials.py b/lofar_tmss_client/dbcredentials.py deleted file mode 100644 index 172e578451be8c221b5bc87c4d9ecc53a5d09ed0..0000000000000000000000000000000000000000 --- a/lofar_tmss_client/dbcredentials.py +++ /dev/null @@ -1,373 +0,0 @@ -#!/usr/bin/env python3 - -# Copyright (C) 2012-2015 ASTRON (Netherlands Institute for Radio Astronomy) -# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands -# -# This file is part of the LOFAR software suite. -# The LOFAR software suite is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# The LOFAR software suite is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. - -# $Id$ - -from glob import glob -import os -import pwd -from configparser import ConfigParser, NoSectionError, DuplicateSectionError -from optparse import OptionGroup -from os import stat, path, chmod -import logging - -logger = logging.getLogger(__name__) - -__all__ = ["Credentials", "DBCredentials", "options_group", "parse_options"] - -# obtain the environment, and add USER and HOME if needed (since supervisord does not) -environ = os.environ - -try: - # Throws a KeyError if user info is not found in /etc/passwd (f.e. in Docker environments) - user_info = pwd.getpwuid(os.getuid()) - - environ.setdefault("HOME", user_info.pw_dir) - environ.setdefault("USER", user_info.pw_name) -except KeyError: - pass - - -def findfiles(pattern): - """ Returns a list of files matched by `pattern'. - The pattern can include environment variables using the - {VAR} notation. - """ - try: - return glob(pattern.format(**environ)) - except KeyError: - return [] - - -class Credentials: - def __init__(self): - # Flavour of database (postgres, mysql, oracle, sqlite) - self.type = "postgres" - - # Connection information (port 0 = use default) - self.host = "localhost" - self.port = 0 - - # Authentication - self.user = environ["USER"] - self.password = "" - - # Database selection - self.database = "" - - # All key-value pairs found in the config - self.config = {} - - def __str__(self): - return "db={database} addr={host}:{port} auth={user}:{password} type={type}".format(**self.__dict__) - - def stringWithHiddenPassword(self): - return "db={database} addr={host}:{port} auth={user}:XXXXXX type={type}".format(**self.__dict__) - - def __eq__(self, other): - return (self.host == other.host and - self.port == other.port and - self.user == other.user and - self.password == other.password and - self.database == other.database) - - def __ne__(self, other): - return not self.__eq__(other) - - def pg_connect_options(self): - """ - Returns a dict of options to provide to PyGreSQL's pg.connect function. Use: - - conn = pg.connect(**dbcreds.pg_connect_options()) - """ - return { - "host": self.host, - "port": self.port or -1, - - "user": self.user, - "passwd": self.password, - - "dbname": self.database, - } - - def psycopg2_connect_options(self): - """ - Returns a dict of options to provide to PsycoPG2's psycopg2.connect function. Use: - - conn = psycopg2.connect(**dbcreds.psycopg2_connect_options()) - """ - return { - "host": self.host, - "port": self.port or None, - - "user": self.user, - "password": self.password, - - "database": self.database, - } - - def mysql_connect_options(self): - """ - Returns a dict of options to provide to python's mysql.connector.connect function. Use: - - from mysql import connector - conn = connector.connect(**dbcreds.mysql_connect_options()) - """ - options = {"host": self.host, - "user": self.user, - "passwd": self.password, - "database": self.database} - - if self.port: - options["port"] = self.port - - return options - - -class DBCredentials: - NoSectionError = NoSectionError - - def __init__(self, filepatterns=None): - self.filepatterns = filepatterns if filepatterns is not None else [ - "{LOFARROOT}/etc/dbcredentials/*.ini", - "{HOME}/.lofar/dbcredentials/*.ini", - ] - self.read_config_from_files() - - def read_config_from_files(self, filepatterns=None): - """ - Read database credentials from all configuration files matched by any of the patterns. - - By default, the following files are read: - - $LOFARROOT/etc/dbcredentials/*.ini - ~/.lofar/dbcredentials/*.ini - - The configuration files allow for any number of database sections: - - [database:OTDB] - type = postgres # postgres, mysql, oracle, sqlite - host = localhost - port = 0 # 0 = use default port - user = paulus - password = boskabouter - database = LOFAR_4 - - These database credentials can subsequently be queried under their - symbolic name ("OTDB" in the example). - """ - if filepatterns is not None: - self.filepatterns = filepatterns - - self.files = sum([findfiles(p) for p in self.filepatterns], []) - - # make sure the files are mode 600 to hide passwords - for file in self.files: - if oct(stat(file).st_mode & 0o777) != '0o600': - logger.info('Changing permissions of %s to 600' % file) - try: - chmod(file, 0o600) - except Exception as e: - logger.error('Error: Could not change permissions on %s: %s' % (file, str(e))) - - # read the files into config - self.config = ConfigParser() - self.config.read(self.files) - - def create_default_file(self, database): - """ - creates a dbcredentials file with defaults in ~/.lofar/dbcredentials/<database>.ini - :param database: name of the database/file - """ - extensions = list(set(os.path.splitext(pat)[1] for pat in self.filepatterns)) - if extensions: - # pick first extension - extension = extensions[0] - new_path = os.path.join(user_info.pw_dir, '.lofar', 'dbcredentials', database + extension) - if not os.path.exists(os.path.dirname(new_path)): - os.makedirs(os.path.dirname(new_path)) - with open(new_path, 'w+') as new_file: - new_file.write( - "[database:%s]\nhost=localhost\nuser=%s\npassword=unknown\ntype=unknown\nport=0\ndatabase=%s" - % (database, user_info.pw_name, database)) - logger.info("Created default dbcredentials file for database=%s at %s", database, new_path) - logger.warning( - " *** Please fill in the proper credentials for database=%s in new empty credentials file: '%s' ***", - database, new_path) - - def get(self, database): - """ - Return credentials for a given database. - """ - # create default credentials - creds = Credentials() - - try: - # read configuration (can throw NoSectionError) - d = dict(self.config.items(self._section(database))) - except NoSectionError: - # create defaults file, and reload - self.create_default_file(database) - self.read_config_from_files() - # re-read configuration now that we have created a new file with defaults - d = dict(self.config.items(self._section(database))) - - # save the full config to support custom fields - creds.config = d - - # parse and convert config information - if "host" in d: creds.host = d["host"] - if "port" in d: creds.port = int(d["port"] or 0) - - if "user" in d: creds.user = d["user"] - if "password" in d: creds.password = d["password"] - - if "database" in d: creds.database = d["database"] - - if "type" in d: creds.type = d["type"] - - return creds - - def set(self, database, credentials): - """ - Add or overwrite credentials for a given database. - """ - section = self._section(database) - - # create section if needed - try: - self.config.add_section(section) - except DuplicateSectionError: - pass - - # set or override credentials - self.config.set(section, "type", credentials.type) - self.config.set(section, "host", credentials.host) - self.config.set(section, "port", str(credentials.port)) - self.config.set(section, "user", credentials.user) - self.config.set(section, "password", credentials.password) - self.config.set(section, "database", credentials.database) - - def list(self): - """ - Return a list of databases for which credentials are available. - """ - sections = self.config.sections() - return [s[9:] for s in sections if s.startswith("database:")] - - def _section(self, database): - return "database:%s" % (database,) - - -def options_group(parser, default_credentials=""): - """ - Return an optparse.OptionGroup containing command-line parameters - for database connections and authentication. - """ - group = OptionGroup(parser, "Database Credentials") - group.add_option("-D", "--database", dest="dbName", type="string", default="", - help="Name of the database") - group.add_option("-H", "--host", dest="dbHost", type="string", default="", - help="Hostname of the database server") - group.add_option("-p", "--port", dest="dbPort", type="string", default="", - help="Port number of the database server") - group.add_option("-U", "--user", dest="dbUser", type="string", default="", - help="User of the database server") - group.add_option("-P", "--password", dest="dbPassword", type="string", default="", - help="Password of the database server") - group.add_option("-C", "--dbcredentials", dest="dbcredentials", type="string", default=default_credentials, - help="Name of database credential set to use [default=%default]") - - return group - - -def parse_options(options, filepatterns=None): - """ - Parses command-line parameters provided through options_group() - and returns a credentials dictionary. - - `filepatterns' can be used to override the patterns used to find configuration - files. - """ - - dbc = DBCredentials(filepatterns) - - # get default values - try: - creds = dbc.get(options.dbcredentials) - except NoSectionError: - # credentials will have to be supplied on the command line - creds = Credentials() - - # process supplied overrides - if options.dbHost: creds.host = options.dbHost - if options.dbPort: creds.port = options.dbPort - if options.dbUser: creds.user = options.dbUser - if options.dbPassword: creds.password = options.dbPassword - if options.dbName: creds.database = options.dbName - - return creds - - -if __name__ == "__main__": - import sys - from optparse import OptionParser - - parser = OptionParser("%prog [options]") - parser.add_option("-D", "--database", dest="database", type="string", default="", - help="Print credentials of a specific database") - parser.add_option("-S", "--shell", dest="shell", action="store_true", default=False, - help="Use machine-readable output for use in shell scripts") - parser.add_option("-L", "--list", dest="list", action="store_true", default=False, - help="List known databases") - parser.add_option("-F", "--files", dest="files", action="store_true", default=False, - help="List names of parsed configuration files") - (options, args) = parser.parse_args() - - if not options.database and not options.list and not options.files: - logger.error("Missing database name") - parser.print_help() - sys.exit(1) - - dbc = DBCredentials() - - if options.files: - """ Print list of configuration files that we've read. """ - if dbc.files: - logger.info("\n".join(dbc.files)) - sys.exit(0) - - if options.list: - """ Print list of databases. """ - databases = dbc.list() - if databases: - logger.info("\n".join(databases)) - sys.exit(0) - - """ Print credentials of a specific database. """ - creds = dbc.get(options.database) - - if options.shell: - print("DBUSER=%s" % (creds.user,)) - print("DBPASSWORD=%s" % (creds.password,)) - print("DBDATABASE=%s" % (creds.database,)) - print("DBHOST=%s" % (creds.host,)) - print("DBPORT=%s" % (creds.port,)) - else: - logger.info(str(creds)) diff --git a/tests/.gitkeep b/lofar_tmss_client/entrypoints/__init__.py similarity index 100% rename from tests/.gitkeep rename to lofar_tmss_client/entrypoints/__init__.py diff --git a/lofar_tmss_client/entrypoints/_arguments.py b/lofar_tmss_client/entrypoints/_arguments.py new file mode 100644 index 0000000000000000000000000000000000000000..8b102ea1e5afc46c4fc739af427846f51789ee56 --- /dev/null +++ b/lofar_tmss_client/entrypoints/_arguments.py @@ -0,0 +1,15 @@ +# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: GPL-3.0-or-later + +from argparse import ArgumentParser + +from lofar_tmss_client.entrypoints._defaults import CLIENT_RETRY_COUNT + + +def add_tmss_client_arguments(parser: ArgumentParser, subtask: bool = False): + if subtask: + parser.add_argument("subtask_id", type=int, help="The ID of the TMSS subtask") + parser.add_argument('-R', '--rest_api_credentials', type=str, default='TMSSClient', + help='TMSS django REST API credentials name, default: TMSSClient') + parser.add_argument('-r', '--retry_count', type=int, default=CLIENT_RETRY_COUNT, + help='Retry <retry_count> times upon (recoverable) failure, default: [%default]') \ No newline at end of file diff --git a/lofar_tmss_client/entrypoints/_defaults.py b/lofar_tmss_client/entrypoints/_defaults.py new file mode 100644 index 0000000000000000000000000000000000000000..5df3810b2764bebe2ed8af8347915e4916b88f00 --- /dev/null +++ b/lofar_tmss_client/entrypoints/_defaults.py @@ -0,0 +1,6 @@ +# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: GPL-3.0-or-later + +CLIENT_RETRY_COUNT=5 +CLIENT_POLL_TIMEOUT = 10 +CLIENT_POLL_INTERVAL = 1.0 \ No newline at end of file diff --git a/lofar_tmss_client/entrypoints/adapt_scheduling_unit_blueprint_to_start_and_stop_times.py b/lofar_tmss_client/entrypoints/adapt_scheduling_unit_blueprint_to_start_and_stop_times.py new file mode 100644 index 0000000000000000000000000000000000000000..3d7c82bb43bd8342918f61b8baca7462debac153 --- /dev/null +++ b/lofar_tmss_client/entrypoints/adapt_scheduling_unit_blueprint_to_start_and_stop_times.py @@ -0,0 +1,33 @@ +# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: GPL-3.0-or-later + +import argparse +from pprint import pprint +import urllib3 + +from tmss_pycommon.datetimeutils import parseDatetime + +from lofar_tmss_client.entrypoints._arguments import add_tmss_client_arguments +from lofar_tmss_client.tmss_http_rest_client import TMSSsession + +urllib3.disable_warnings() + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("scheduling_unit_blueprint_id", type=int, help="The ID of the TMSS scheduling_unit_blueprint that should be adapted.") + parser.add_argument('start_time', type=str, help='start_time in ISO format') + parser.add_argument('stop_time', type=str, help='stop_time in ISO format') + parser.add_argument('-f', '--mark_fixed_time', action='store_true', help='optionally switch scheduler for this unit to fixed-time') + add_tmss_client_arguments(parser) + args = parser.parse_args() + + try: + with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: + pprint(session.adapt_scheduling_unit_blueprint_to_start_and_stop_times(scheduling_unit_blueprint_id=args.scheduling_unit_blueprint_id, + start_time=parseDatetime(args.start_time), + stop_time=parseDatetime(args.stop_time), + mark_fixed_time=args.mark_fixed_time, + retry_count=args.retry_count)) + except Exception as e: + print(e) + exit(1) \ No newline at end of file diff --git a/lofar_tmss_client/entrypoints/adapt_scheduling_unit_draft_to_start_and_stop_times.py b/lofar_tmss_client/entrypoints/adapt_scheduling_unit_draft_to_start_and_stop_times.py new file mode 100644 index 0000000000000000000000000000000000000000..a324d42d6743f9962a8e3a15a5870be485c6363d --- /dev/null +++ b/lofar_tmss_client/entrypoints/adapt_scheduling_unit_draft_to_start_and_stop_times.py @@ -0,0 +1,37 @@ +# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: GPL-3.0-or-later + +import argparse +from pprint import pprint +import urllib3 + +from tmss_pycommon.datetimeutils import parseDatetime + +from lofar_tmss_client.entrypoints._arguments import add_tmss_client_arguments +from lofar_tmss_client.tmss_http_rest_client import TMSSsession + +urllib3.disable_warnings() + +DEFAULT_CLIENT_RETRY_COUNT=5 +DEFAULT_CLIENT_POLL_TIMEOUT = 10 +DEFAULT_CLIENT_POLL_INTERVAL = 1.0 + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("scheduling_unit_draft_id", type=int, help="The ID of the TMSS scheduling_unit_draft that should be adapted.") + parser.add_argument('start_time', type=str, help='start_time in ISO format') + parser.add_argument('stop_time', type=str, help='stop_time in ISO format') + parser.add_argument('-f', '--mark_fixed_time', action='store_true', help='optionally switch scheduler for this unit to fixed-time') + add_tmss_client_arguments(parser) + args = parser.parse_args() + + try: + with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: + pprint(session.adapt_scheduling_unit_draft_to_start_and_stop_times(scheduling_unit_draft_id=args.scheduling_unit_draft_id, + start_time=parseDatetime(args.start_time), + stop_time=parseDatetime(args.stop_time), + mark_fixed_time=args.mark_fixed_time, + retry_count=args.retry_count)) + except Exception as e: + print(e) + exit(1) \ No newline at end of file diff --git a/lofar_tmss_client/entrypoints/cancel_subtask.py b/lofar_tmss_client/entrypoints/cancel_subtask.py new file mode 100644 index 0000000000000000000000000000000000000000..bf2978b70a2213669f8703b7805fa6cbbd60b495 --- /dev/null +++ b/lofar_tmss_client/entrypoints/cancel_subtask.py @@ -0,0 +1,26 @@ +# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: GPL-3.0-or-later + +import argparse +from pprint import pprint +import urllib3 + +from lofar_tmss_client.entrypoints._arguments import add_tmss_client_arguments +from lofar_tmss_client.tmss_http_rest_client import TMSSsession + +urllib3.disable_warnings() + +DEFAULT_CLIENT_RETRY_COUNT=5 + + +def main(): + parser = argparse.ArgumentParser() + add_tmss_client_arguments(parser, subtask=True) + args = parser.parse_args() + + try: + with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: + pprint(session.cancel_subtask(args.subtask_id, retry_count=args.retry_count)) + except Exception as e: + print(e) + exit(1) \ No newline at end of file diff --git a/lofar_tmss_client/entrypoints/create_and_process_feedback_for_subtask_from_specification_and_set_to_finished.py b/lofar_tmss_client/entrypoints/create_and_process_feedback_for_subtask_from_specification_and_set_to_finished.py new file mode 100644 index 0000000000000000000000000000000000000000..b2c931509068d83fcdc94389152f868356f433ac --- /dev/null +++ b/lofar_tmss_client/entrypoints/create_and_process_feedback_for_subtask_from_specification_and_set_to_finished.py @@ -0,0 +1,27 @@ +# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: GPL-3.0-or-later + +import argparse +from pprint import pprint +import urllib3 + +from lofar_tmss_client.entrypoints._arguments import add_tmss_client_arguments +from lofar_tmss_client.tmss_http_rest_client import TMSSsession + +urllib3.disable_warnings() + +DEFAULT_CLIENT_RETRY_COUNT=5 + + +def main_create_and_process_feedback_for_subtask_from_specification_and_set_to_finished(): + parser = argparse.ArgumentParser() + add_tmss_client_arguments(parser, subtask=True) + args = parser.parse_args() + + try: + with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: + pprint(session.create_and_process_feedback_for_subtask_from_specification_and_set_to_finished(args.subtask_id, + retry_count=args.retry_count)) + except Exception as e: + print(e) + exit(1) \ No newline at end of file diff --git a/lofar_tmss_client/entrypoints/create_lofar2_sibling_scheduling_unit.py b/lofar_tmss_client/entrypoints/create_lofar2_sibling_scheduling_unit.py new file mode 100644 index 0000000000000000000000000000000000000000..adf4d65edf116af5c1a2e5a4fdb3bb7d71ee52c8 --- /dev/null +++ b/lofar_tmss_client/entrypoints/create_lofar2_sibling_scheduling_unit.py @@ -0,0 +1,25 @@ +# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: GPL-3.0-or-later + +import argparse +from pprint import pprint +import urllib3 + +from lofar_tmss_client.entrypoints._arguments import add_tmss_client_arguments +from lofar_tmss_client.tmss_http_rest_client import TMSSsession + +urllib3.disable_warnings() + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("scheduling_unit_blueprint_id", type=int, help="The ID of the TMSS scheduling_unit_blueprint for which we want to create a Lofar2 sibling.") + add_tmss_client_arguments(parser) + args = parser.parse_args() + + try: + with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: + pprint(session.create_lofar2_sibling_scheduling_unit(args.scheduling_unit_blueprint_id, retry_count=args.retry_count)) + except Exception as e: + print(e) + exit(1) \ No newline at end of file diff --git a/lofar_tmss_client/entrypoints/create_scheduling_unit_blueprint_copy_without_given_stations.py b/lofar_tmss_client/entrypoints/create_scheduling_unit_blueprint_copy_without_given_stations.py new file mode 100644 index 0000000000000000000000000000000000000000..0cb5a64908b3aad5b25eedd634a2114036419c1a --- /dev/null +++ b/lofar_tmss_client/entrypoints/create_scheduling_unit_blueprint_copy_without_given_stations.py @@ -0,0 +1,28 @@ +# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: GPL-3.0-or-later + +import argparse +import urllib3 + +from lofar_tmss_client.entrypoints._arguments import add_tmss_client_arguments +from lofar_tmss_client.tmss_http_rest_client import TMSSsession + +urllib3.disable_warnings() + +def create_scheduling_unit_blueprint_copy_without_given_stations(): + parser = argparse.ArgumentParser() + parser.add_argument("scheduling_unit_blueprint_id", type=int, help="The ID of the TMSS scheduling_unit_blueprint from which the station(s) have to be removed.") + parser.add_argument("stations_to_be_removed", type=str, help="A comma seperated string of stations.") + add_tmss_client_arguments(parser) + args = parser.parse_args() + + try: + with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: + stations_to_be_removed = [s.strip() for s in args.stations_to_be_removed.split(',')] + scheduling_unit_blueprint_copy = session.create_scheduling_unit_blueprint_copy_without_given_stations(args.scheduling_unit_blueprint_id, + stations_to_be_removed, + retry_count=args.retry_count) + print("Here is your new scheduling_unit without station(s)", ','.join(stations_to_be_removed), scheduling_unit_blueprint_copy['url']) + except Exception as e: + print(e) + exit(1) \ No newline at end of file diff --git a/lofar_tmss_client/entrypoints/get_setting.py b/lofar_tmss_client/entrypoints/get_setting.py new file mode 100644 index 0000000000000000000000000000000000000000..4c9a8f83916a2d3147e4431783224c014e84c772 --- /dev/null +++ b/lofar_tmss_client/entrypoints/get_setting.py @@ -0,0 +1,25 @@ +# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: GPL-3.0-or-later + +import argparse +from pprint import pprint +import urllib3 + +from lofar_tmss_client.entrypoints._arguments import add_tmss_client_arguments +from lofar_tmss_client.tmss_http_rest_client import TMSSsession + +urllib3.disable_warnings() + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("setting_name", type=str, help="The name of the TMSS setting to get") + add_tmss_client_arguments(parser) + args = parser.parse_args() + + try: + with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: + pprint(session.get_setting(args.setting_name)) + except Exception as e: + print(e) + exit(1) \ No newline at end of file diff --git a/lofar_tmss_client/entrypoints/get_subtask.py b/lofar_tmss_client/entrypoints/get_subtask.py new file mode 100644 index 0000000000000000000000000000000000000000..c33e528b1326b45798fded6d33986a03ba9479f1 --- /dev/null +++ b/lofar_tmss_client/entrypoints/get_subtask.py @@ -0,0 +1,24 @@ +# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: GPL-3.0-or-later + +import argparse +from pprint import pprint +import urllib3 + +from lofar_tmss_client.entrypoints._arguments import add_tmss_client_arguments +from lofar_tmss_client.tmss_http_rest_client import TMSSsession + +urllib3.disable_warnings() + + +def main(): + parser = argparse.ArgumentParser() + add_tmss_client_arguments(parser, subtask=True) + args = parser.parse_args() + + try: + with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: + pprint(session.get_subtask(args.subtask_id)) + except Exception as e: + print(e) + exit(1) \ No newline at end of file diff --git a/lofar_tmss_client/entrypoints/get_subtask_json.py b/lofar_tmss_client/entrypoints/get_subtask_json.py new file mode 100644 index 0000000000000000000000000000000000000000..34a279a8f2a54bf8d7644ee79549a5092545abc0 --- /dev/null +++ b/lofar_tmss_client/entrypoints/get_subtask_json.py @@ -0,0 +1,23 @@ +# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: GPL-3.0-or-later + +import argparse +import urllib3 + +from lofar_tmss_client.entrypoints._arguments import add_tmss_client_arguments +from lofar_tmss_client.tmss_http_rest_client import TMSSsession + +urllib3.disable_warnings() + + +def main(): + parser = argparse.ArgumentParser() + add_tmss_client_arguments(parser, subtask=True) + args = parser.parse_args() + + try: + with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: + print(session.get_subtask_json(args.subtask_id, retry_count=args.retry_count)) + except Exception as e: + print(e) + exit(1) \ No newline at end of file diff --git a/lofar_tmss_client/entrypoints/get_subtask_l2stationspecs.py b/lofar_tmss_client/entrypoints/get_subtask_l2stationspecs.py new file mode 100644 index 0000000000000000000000000000000000000000..df6f8261e02c9292f947d3c7c692ba3e9c043f57 --- /dev/null +++ b/lofar_tmss_client/entrypoints/get_subtask_l2stationspecs.py @@ -0,0 +1,25 @@ +# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: GPL-3.0-or-later + +import argparse +from pprint import pprint +import urllib3 + +from lofar_tmss_client.entrypoints._arguments import add_tmss_client_arguments +from lofar_tmss_client.tmss_http_rest_client import TMSSsession + +urllib3.disable_warnings() + +DEFAULT_CLIENT_RETRY_COUNT=5 + +def main_get_subtask_l2stationspecs(): + parser = argparse.ArgumentParser() + add_tmss_client_arguments(parser, subtask=True) + args = parser.parse_args() + + try: + with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: + pprint(session.get_subtask_l2stationspecs(args.subtask_id, retry_count=args.retry_count)) + except Exception as e: + print(e) + exit(1) \ No newline at end of file diff --git a/lofar_tmss_client/entrypoints/get_subtask_parset.py b/lofar_tmss_client/entrypoints/get_subtask_parset.py new file mode 100644 index 0000000000000000000000000000000000000000..054a63786ecc323e3668bec56d32606e89d58395 --- /dev/null +++ b/lofar_tmss_client/entrypoints/get_subtask_parset.py @@ -0,0 +1,23 @@ +# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: GPL-3.0-or-later + +import argparse +import urllib3 + +from lofar_tmss_client.entrypoints._arguments import add_tmss_client_arguments +from lofar_tmss_client.tmss_http_rest_client import TMSSsession + +urllib3.disable_warnings() + + +def main(): + parser = argparse.ArgumentParser() + add_tmss_client_arguments(parser, subtask=True) + args = parser.parse_args() + + try: + with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: + print(session.get_subtask_parset(args.subtask_id, retry_count=args.retry_count)) + except Exception as e: + print(e) + exit(1) \ No newline at end of file diff --git a/lofar_tmss_client/entrypoints/get_subtask_predecessors.py b/lofar_tmss_client/entrypoints/get_subtask_predecessors.py new file mode 100644 index 0000000000000000000000000000000000000000..b1f2dd3b1b0c6c8eb50a7f725068d60e6d9669fd --- /dev/null +++ b/lofar_tmss_client/entrypoints/get_subtask_predecessors.py @@ -0,0 +1,25 @@ +# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: GPL-3.0-or-later + +import argparse +from pprint import pprint +import urllib3 + +from lofar_tmss_client.entrypoints._arguments import add_tmss_client_arguments +from lofar_tmss_client.tmss_http_rest_client import TMSSsession + +urllib3.disable_warnings() + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('-s', '--state', help="only get predecessors with this state") + add_tmss_client_arguments(parser, subtask=True) + args = parser.parse_args() + + try: + with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: + pprint(session.get_subtask_predecessors(args.subtask_id, state=args.state)) + except Exception as e: + print(e) + exit(1) \ No newline at end of file diff --git a/lofar_tmss_client/entrypoints/get_subtask_successors.py b/lofar_tmss_client/entrypoints/get_subtask_successors.py new file mode 100644 index 0000000000000000000000000000000000000000..aae69cbad10d44a9b77c3399d295c9b8438814ab --- /dev/null +++ b/lofar_tmss_client/entrypoints/get_subtask_successors.py @@ -0,0 +1,25 @@ +# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: GPL-3.0-or-later + +import argparse +from pprint import pprint +import urllib3 + +from lofar_tmss_client.entrypoints._arguments import add_tmss_client_arguments +from lofar_tmss_client.tmss_http_rest_client import TMSSsession + +urllib3.disable_warnings() + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('-s', '--state', help="only get successors with this state") + add_tmss_client_arguments(parser, subtask=True) + args = parser.parse_args() + + try: + with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: + pprint(session.get_subtask_successors(args.subtask_id, state=args.state)) + except Exception as e: + print(e) + exit(1) \ No newline at end of file diff --git a/lofar_tmss_client/entrypoints/get_subtasks.py b/lofar_tmss_client/entrypoints/get_subtasks.py new file mode 100644 index 0000000000000000000000000000000000000000..0151cd23adc89a0be5c31ff146eb53865ddf5889 --- /dev/null +++ b/lofar_tmss_client/entrypoints/get_subtasks.py @@ -0,0 +1,40 @@ +# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: GPL-3.0-or-later + +import argparse +from pprint import pprint +import urllib3 + +from tmss_pycommon.datetimeutils import parseDatetime + +from lofar_tmss_client.entrypoints._arguments import add_tmss_client_arguments +from lofar_tmss_client.tmss_http_rest_client import TMSSsession + +urllib3.disable_warnings() + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('-s', '--state', help="only get subtasks with this state") + parser.add_argument('-t', '--type', help="only get subtasks with this type") + parser.add_argument('-c', '--cluster', help="only get subtasks for this cluster") + parser.add_argument('--start_time_less_then', help="only get subtasks with a start time less then this timestamp") + parser.add_argument('--start_time_greater_then', help="only get subtasks with a start time greater then this timestamp") + parser.add_argument('--stop_time_less_then', help="only get subtasks with a stop time less then this timestamp") + parser.add_argument('--stop_time_greater_then', help="only get subtasks with a stop time greater then this timestamp") + add_tmss_client_arguments(parser) + args = parser.parse_args() + + try: + with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: + result = session.get_subtasks(state=args.state, + subtask_type=args.type, + cluster=args.cluster, + scheduled_start_time_less_then=parseDatetime(args.start_time_less_then) if args.start_time_less_then else None, + scheduled_start_time_greater_then=parseDatetime(args.start_time_greater_then) if args.start_time_greater_then else None, + scheduled_stop_time_less_then=parseDatetime(args.stop_time_less_then) if args.stop_time_less_then else None, + scheduled_stop_time_greater_then=parseDatetime(args.stop_time_greater_then) if args.stop_time_greater_then else None) + pprint(result) + except Exception as e: + print(e) + exit(1) \ No newline at end of file diff --git a/lofar_tmss_client/entrypoints/mark_scheduling_unit_dynamically_scheduled.py b/lofar_tmss_client/entrypoints/mark_scheduling_unit_dynamically_scheduled.py new file mode 100644 index 0000000000000000000000000000000000000000..0c80bcb231ce77a3357b7c2baa3f27aeb753d750 --- /dev/null +++ b/lofar_tmss_client/entrypoints/mark_scheduling_unit_dynamically_scheduled.py @@ -0,0 +1,22 @@ +# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: GPL-3.0-or-later + +import argparse +from pprint import pprint + +from lofar_tmss_client.entrypoints._arguments import add_tmss_client_arguments +from lofar_tmss_client.tmss_http_rest_client import TMSSsession + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("scheduling_unit_blueprint_id", type=int, help="The ID of the TMSS scheduling_unit_blueprint to be marked as dynamically-scheduled") + add_tmss_client_arguments(parser) + args = parser.parse_args() + + try: + with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: + pprint(session.mark_scheduling_unit_dynamically_scheduled(args.scheduling_unit_blueprint_id, retry_count=args.retry_count)) + except Exception as e: + print(e) + exit(1) \ No newline at end of file diff --git a/lofar_tmss_client/entrypoints/mark_scheduling_unit_fixed_time_scheduled_at_scheduled_starttime.py b/lofar_tmss_client/entrypoints/mark_scheduling_unit_fixed_time_scheduled_at_scheduled_starttime.py new file mode 100644 index 0000000000000000000000000000000000000000..b6e0c6d2924479bfb36366dc6d894484952b32c2 --- /dev/null +++ b/lofar_tmss_client/entrypoints/mark_scheduling_unit_fixed_time_scheduled_at_scheduled_starttime.py @@ -0,0 +1,25 @@ +# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: GPL-3.0-or-later + +import argparse +from pprint import pprint +import urllib3 + +from lofar_tmss_client.entrypoints._arguments import add_tmss_client_arguments +from lofar_tmss_client.tmss_http_rest_client import TMSSsession + +urllib3.disable_warnings() + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("scheduling_unit_blueprint_id", type=int, help="The ID of the TMSS scheduling_unit_blueprint to be marked as fixed_time-scheduled") + add_tmss_client_arguments(parser) + args = parser.parse_args() + + try: + with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: + pprint(session.mark_scheduling_unit_fixed_time_scheduled_at_scheduled_starttime(args.scheduling_unit_blueprint_id, retry_count=args.retry_count)) + except Exception as e: + print(e) + exit(1) \ No newline at end of file diff --git a/lofar_tmss_client/entrypoints/mark_subtask_as_obsolete.py b/lofar_tmss_client/entrypoints/mark_subtask_as_obsolete.py new file mode 100644 index 0000000000000000000000000000000000000000..5501a7ce286ff46113eabfba9ed1cb7690f93011 --- /dev/null +++ b/lofar_tmss_client/entrypoints/mark_subtask_as_obsolete.py @@ -0,0 +1,26 @@ +# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: GPL-3.0-or-later + +import argparse +from pprint import pprint +import urllib3 + +from lofar_tmss_client.entrypoints._arguments import add_tmss_client_arguments +from lofar_tmss_client.tmss_http_rest_client import TMSSsession + +urllib3.disable_warnings() + +DEFAULT_CLIENT_RETRY_COUNT=5 + + +def main(): + parser = argparse.ArgumentParser() + add_tmss_client_arguments(parser, subtask=True) + args = parser.parse_args() + + try: + with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: + pprint(session.mark_subtask_as_obsolete(args.subtask_id, retry_count=args.retry_count)) + except Exception as e: + print(e) + exit(1) \ No newline at end of file diff --git a/lofar_tmss_client/entrypoints/reset_schedule.py b/lofar_tmss_client/entrypoints/reset_schedule.py new file mode 100644 index 0000000000000000000000000000000000000000..9164e377d7854d8fa4d1f4e0b1d50abdbc66e17e --- /dev/null +++ b/lofar_tmss_client/entrypoints/reset_schedule.py @@ -0,0 +1,28 @@ +# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: GPL-3.0-or-later + +import argparse +import datetime + +from lofar_tmss_client.entrypoints._arguments import add_tmss_client_arguments +from lofar_tmss_client.tmss_http_rest_client import TMSSsession + + +def main(): + # default 'parking'-timestamp is at noon seven days from now. + timestamp = (datetime.datetime.utcnow() + datetime.timedelta(days=7)).replace(hour=12, minute=0, second=0, microsecond=0) + + parser = argparse.ArgumentParser(description="Reset the status of all unschedulable units to schedulable, and then position all schedulable units at the given start_time. Typical usage: reset the schedule using this tool and let the scheduler place all units.") + parser.add_argument('-t', '--timestamp', type=str, default=timestamp.strftime("%Y-%m-%d %H:%M"), help="Position/park all schedulable units at this timestamp expressed as \"YYYY-MM-DD HH:MM\"") + parser.add_argument('-s', '--scheduled', action='store_true', help='also unschedule all scheduled units') + add_tmss_client_arguments(parser) + args = parser.parse_args() + + try: + with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as client: + client.post_to_path_and_get_result_as_json_object('scheduling_unit_blueprint/reset_schedule', + params={'scheduled': args.scheduled, + 'timestamp': args.timestamp}) + except Exception as e: + print(e) + exit(1) \ No newline at end of file diff --git a/lofar_tmss_client/entrypoints/schedule_scheduling_unit_at_given_starttime.py b/lofar_tmss_client/entrypoints/schedule_scheduling_unit_at_given_starttime.py new file mode 100644 index 0000000000000000000000000000000000000000..43290b826fef9f0f5a6dcf51d6f9575ae7749ac8 --- /dev/null +++ b/lofar_tmss_client/entrypoints/schedule_scheduling_unit_at_given_starttime.py @@ -0,0 +1,27 @@ +# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: GPL-3.0-or-later + +import argparse +from pprint import pprint + +from tmss_pycommon.datetimeutils import parseDatetime + +from lofar_tmss_client.entrypoints._arguments import add_tmss_client_arguments +from lofar_tmss_client.tmss_http_rest_client import TMSSsession + + +def main(): + parser = argparse.ArgumentParser(description="force the scheduling_unit with the given id to be scheduled at the given starttime, bypassing the scheduler but also marking it as 'fixed_time' at 'at' in the constraints for a next scheduling round.") + parser.add_argument("scheduling_unit_blueprint_id", type=int, help="The ID of the TMSS scheduling_unit_blueprint to be marked as fixed_time-scheduled") + parser.add_argument("start_time", type=str, help="The starttime expressed as \"YYYY-MM-DD HH:MM::SS\"") + add_tmss_client_arguments(parser) + args = parser.parse_args() + + try: + with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: + pprint(session.schedule_scheduling_unit(args.scheduling_unit_blueprint_id, + parseDatetime(args.start_time), + retry_count=args.retry_count)) + except Exception as e: + print(e) + exit(1) \ No newline at end of file diff --git a/lofar_tmss_client/entrypoints/schedule_subtask.py b/lofar_tmss_client/entrypoints/schedule_subtask.py new file mode 100644 index 0000000000000000000000000000000000000000..8c5f4accce7aa393f399c01ce3b112418c6b36ff --- /dev/null +++ b/lofar_tmss_client/entrypoints/schedule_subtask.py @@ -0,0 +1,28 @@ +# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: GPL-3.0-or-later + +import argparse +import datetime +from pprint import pprint +import urllib3 + +from lofar_tmss_client.entrypoints._arguments import add_tmss_client_arguments +from lofar_tmss_client.tmss_http_rest_client import TMSSsession + +urllib3.disable_warnings() + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('-s', '--start_time', type=str, default=None, help='optional start_time in ISO format, default: None, so the start_time of the subtask instance itself is used.') + add_tmss_client_arguments(parser, subtask=True) + args = parser.parse_args() + + try: + with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: + pprint(session.schedule_subtask(args.subtask_id, + scheduled_start_time=datetime.datetime.strptime(args.start_time, "%Y-%m-%d %H:%M:%S") if args.start_time else None, + retry_count=args.retry_count)) + except Exception as e: + print(e) + exit(1) \ No newline at end of file diff --git a/lofar_tmss_client/entrypoints/set_setting.py b/lofar_tmss_client/entrypoints/set_setting.py new file mode 100644 index 0000000000000000000000000000000000000000..9797dd1dca57e01dc42d5516c92a6b17274670c9 --- /dev/null +++ b/lofar_tmss_client/entrypoints/set_setting.py @@ -0,0 +1,27 @@ +# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: GPL-3.0-or-later + +import argparse +from pprint import pprint +import urllib3 + +from lofar_tmss_client.entrypoints._arguments import add_tmss_client_arguments +from lofar_tmss_client.tmss_http_rest_client import TMSSsession + +urllib3.disable_warnings() + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("setting_name", type=str, help="The name of the TMSS setting to set") + parser.add_argument("setting_value", type=lambda s: s.lower() in ['true', 'True', '1'], # argparse is noot very good at speaking bool... + help="The value to set for the TMSS setting") + add_tmss_client_arguments(parser) + args = parser.parse_args() + + try: + with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: + pprint(session.set_setting(args.setting_name, args.setting_value)) + except Exception as e: + print(e) + exit(1) \ No newline at end of file diff --git a/lofar_tmss_client/entrypoints/set_subtask_state.py b/lofar_tmss_client/entrypoints/set_subtask_state.py new file mode 100644 index 0000000000000000000000000000000000000000..7b12aa3215d88f7680bfc29e0c36288b848b00af --- /dev/null +++ b/lofar_tmss_client/entrypoints/set_subtask_state.py @@ -0,0 +1,26 @@ +# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: GPL-3.0-or-later + +import argparse +import urllib3 + +from lofar_tmss_client.entrypoints._arguments import add_tmss_client_arguments +from lofar_tmss_client.tmss_http_rest_client import TMSSsession + +urllib3.disable_warnings() + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("state", help="The state to set") + parser.add_argument('-e', '--error_reason', default=None, help="Optional error message string when setting a subtask to error.") + add_tmss_client_arguments(parser, subtask=True) + args = parser.parse_args() + + try: + with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: + changed_subtask = session.set_subtask_status(args.subtask_id, args.state, args.error_reason, retry_count=args.retry_count) + print("%s now has state %s, see: %s" % (changed_subtask['id'], changed_subtask['state_value'], changed_subtask['url'])) + except Exception as e: + print(e) + exit(1) \ No newline at end of file diff --git a/lofar_tmss_client/entrypoints/submit_trigger.py b/lofar_tmss_client/entrypoints/submit_trigger.py new file mode 100644 index 0000000000000000000000000000000000000000..67ee3ff2e731a25aa2673690fc4ab5e760f36c33 --- /dev/null +++ b/lofar_tmss_client/entrypoints/submit_trigger.py @@ -0,0 +1,72 @@ +# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: GPL-3.0-or-later + +import argparse +import datetime +import urllib3 + +from tmss_pycommon.util import dict_search_and_replace + +from lofar_tmss_client.entrypoints._arguments import add_tmss_client_arguments +from lofar_tmss_client.tmss_http_rest_client import TMSSsession + +urllib3.disable_warnings() + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("observing_strategy_template", type=str, help="Which observing strategy template do you want to use to create the scheduling unit from? This template name should've been provided to you.") + parser.add_argument("pointing_angle1", type=float, help="First angle of the pointing [rad]") + parser.add_argument("pointing_angle2", type=float, help="Second angle of the pointing [rad]") + parser.add_argument("--pointing_direction_type", type=str, default="J2000", help="The direction type of the pointing. Defaults to J2000.") + parser.add_argument("--start_at", type=str, default=None, help="The start time of the observation as ISO string. If specified, a constraint will be added so that the observation must start exactly at this time. Defaults to None.") + parser.add_argument("--end_before", type=str, default=None, help="The latest end time of the observation as ISO string. If specified, a constraint will be added so that the observation will run at any time before this time. Defaults to None.") + parser.add_argument("--target_name", type=str, default=None, help="The name of the observation target. Defaults to None.") + parser.add_argument("duration", type=int, help="The duration of the observation in seconds.") + parser.add_argument("scheduling_set_id", type=int, help="The ID of the scheduling set the trigger should be placed in. This should've been provided to you.") + parser.add_argument("--mode", type=str, required=True, help="Which trigger mode? 'test' or 'run'. Specify Whether this is a test submission or should be actually run.") + add_tmss_client_arguments(parser) + args = parser.parse_args() + + try: + with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: + # get a prepared valid trigger_doc for the requested template + try: + trigger_doc = session.get_trigger_specification_doc_for_scheduling_unit_observing_strategy_template(args.observing_strategy_template) + except ValueError as e: + # no such template available... get a list of all templates and print it, so the user can lookup the one that he wants + print("ERROR:", e) + print() + print("Available templates:") + for template in session.get_scheduling_unit_observing_strategy_templates(): + print("id=%s name='%s' version=%s" % (template['id'], template['name'], template['version'])) + exit(1) + + # alter it with our parameters + trigger_doc["name"] = "Trigger - %s - %s" % (args.observing_strategy_template, datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M")) + trigger_doc["description"] = "Trigger submitted via CLI tools: %s" % args.observing_strategy_template + trigger_doc["mode"] = args.mode + trigger_doc["scheduling_set_id"] = args.scheduling_set_id + overrides = trigger_doc['scheduling_unit_observing_strategy_template']['overrides'] + + # this is a bit flacky, as it assumes that these parameters are available in the overrides dict + dict_search_and_replace(overrides, 'angle1', args.pointing_angle1) + dict_search_and_replace(overrides, 'angle2', args.pointing_angle2) + dict_search_and_replace(overrides, 'duration', args.duration) + + if args.target_name: + dict_search_and_replace(overrides, 'target', args.target_name) + dict_search_and_replace(overrides, 'name', args.target_name) + + if args.end_before: + overrides['scheduling_constraints_doc']['time']['before'] = args.end_before + + if args.start_at: + overrides['scheduling_constraints_doc']['time']['at'] = args.start_at + + print("Submitting trigger...") + scheduling_unit = session.submit_trigger(trigger_doc) + print("Submitted trigger, and created Scheduling Unit:", scheduling_unit['url'].replace('api/scheduling_unit_', 'schedulingunit/view/')) + except Exception as e: + print(e) + exit(1) \ No newline at end of file diff --git a/lofar_tmss_client/entrypoints/unschedule_scheduling_unit.py b/lofar_tmss_client/entrypoints/unschedule_scheduling_unit.py new file mode 100644 index 0000000000000000000000000000000000000000..41fc41b738b46c8d15747d0d61cf6ef36d455398 --- /dev/null +++ b/lofar_tmss_client/entrypoints/unschedule_scheduling_unit.py @@ -0,0 +1,22 @@ +# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: GPL-3.0-or-later + +import argparse +from pprint import pprint + +from lofar_tmss_client.entrypoints._arguments import add_tmss_client_arguments +from lofar_tmss_client.tmss_http_rest_client import TMSSsession + + +def main(): + parser = argparse.ArgumentParser(description="Force the scheduling_unit to be unscheduled. NB: the scheduler mey schedule it again in the background.") + parser.add_argument("scheduling_unit_blueprint_id", type=int, help="The ID of the TMSS scheduling_unit_blueprint to be marked as fixed_time-scheduled") + add_tmss_client_arguments(parser) + args = parser.parse_args() + + try: + with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: + pprint(session.unschedule_scheduling_unit(args.scheduling_unit_blueprint_id, retry_count=args.retry_count)) + except Exception as e: + print(e) + exit(1) \ No newline at end of file diff --git a/lofar_tmss_client/entrypoints/unschedule_subtask.py b/lofar_tmss_client/entrypoints/unschedule_subtask.py new file mode 100644 index 0000000000000000000000000000000000000000..c3dbb79101ceb6d20a9b34f277c49b36ea19ff35 --- /dev/null +++ b/lofar_tmss_client/entrypoints/unschedule_subtask.py @@ -0,0 +1,24 @@ +# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: GPL-3.0-or-later + +import argparse +from pprint import pprint +import urllib3 + +from lofar_tmss_client.entrypoints._arguments import add_tmss_client_arguments +from lofar_tmss_client.tmss_http_rest_client import TMSSsession + +urllib3.disable_warnings() + + +def main(): + parser = argparse.ArgumentParser() + add_tmss_client_arguments(parser, subtask=True) + args = parser.parse_args() + + try: + with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: + pprint(session.unschedule_subtask(args.subtask_id, retry_count=args.retry_count)) + except Exception as e: + print(e) + exit(1) \ No newline at end of file diff --git a/lofar_tmss_client/entrypoints/wait_for_subtask_state.py b/lofar_tmss_client/entrypoints/wait_for_subtask_state.py new file mode 100644 index 0000000000000000000000000000000000000000..c74c76fb9bcdeb28b51673a450d14ec3f97f9735 --- /dev/null +++ b/lofar_tmss_client/entrypoints/wait_for_subtask_state.py @@ -0,0 +1,28 @@ +# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: GPL-3.0-or-later + +import argparse +import urllib3 + +from lofar_tmss_client.entrypoints._arguments import add_tmss_client_arguments +from lofar_tmss_client.entrypoints._defaults import CLIENT_POLL_TIMEOUT, CLIENT_POLL_INTERVAL +from lofar_tmss_client.tmss_http_rest_client import TMSSsession + +urllib3.disable_warnings() + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("state", help="The expected state to wait for") + add_tmss_client_arguments(parser, subtask=True) + parser.add_argument('-t', '--timeout', type=int, default=CLIENT_POLL_TIMEOUT, help='Poll for <timeout> seconds until this times out, default: [%default]') + parser.add_argument('-i', '--interval', type=int, default=CLIENT_POLL_INTERVAL, help='Check every <interval> seconds for current subtask state, default: [%default]') + args = parser.parse_args() + + try: + with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: + subtask = session.wait_for_subtask_status(args.subtask_id, args.state, timeout=args.timeout, poll_interval=args.interval) + print("%s now has state %s, see: %s" % (subtask['id'], subtask['state_value'], subtask['url'])) + except Exception as e: + print(e) + exit(1) \ No newline at end of file diff --git a/lofar_tmss_client/mains.py b/lofar_tmss_client/mains.py deleted file mode 100644 index 0c34fbf4923cd3b6b2d8938a8d8e473bb071d709..0000000000000000000000000000000000000000 --- a/lofar_tmss_client/mains.py +++ /dev/null @@ -1,516 +0,0 @@ -#!/usr/bin/python3 - -# Copyright (C) 2012-2015 ASTRON (Netherlands Institute for Radio Astronomy) -# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands -# -# This file is part of the LOFAR software suite. -# The LOFAR software suite is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# The LOFAR software suite is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. - -import json -import argparse -from pprint import pprint -from lofar_tmss_client.tmss_http_rest_client import TMSSsession -from lofar_tmss_client.util import parseDatetime -from lofar_tmss_client.util import dict_search_and_replace -import dateutil.parser -import datetime - -import urllib3 -urllib3.disable_warnings() - -DEFAULT_CLIENT_RETRY_COUNT=5 -DEFAULT_CLIENT_POLL_TIMEOUT = 10 -DEFAULT_CLIENT_POLL_INTERVAL = 1.0 - -def main_get_subtask_parset(): - parser = argparse.ArgumentParser() - parser.add_argument("subtask_id", help="The ID of the TMSS subtask to get the parset from") - parser.add_argument('-R', '--rest_api_credentials', type=str, default='TMSSClient', help='TMSS django REST API credentials name, default: TMSSClient') - parser.add_argument('-r', '--retry_count', type=int, default=DEFAULT_CLIENT_RETRY_COUNT, help='Retry <retry_count> times upon (recoverable) failure, default: [%default]') - args = parser.parse_args() - - try: - with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: - print(session.get_subtask_parset(args.subtask_id, retry_count=args.retry_count)) - except Exception as e: - print(e) - exit(1) - - -def main_get_subtask_json(): - parser = argparse.ArgumentParser() - parser.add_argument("subtask_id", help="The ID of the TMSS subtask to get the MAC/COBALT json from") - parser.add_argument('-R', '--rest_api_credentials', type=str, default='TMSSClient', help='TMSS django REST API credentials name, default: TMSSClient') - parser.add_argument('-r', '--retry_count', type=int, default=DEFAULT_CLIENT_RETRY_COUNT, help='Retry <retry_count> times upon (recoverable) failure, default: [%default]') - args = parser.parse_args() - - try: - with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: - print(session.get_subtask_json(args.subtask_id, retry_count=args.retry_count)) - except Exception as e: - print(e) - exit(1) - - -def main_get_subtask_predecessors(): - parser = argparse.ArgumentParser() - parser.add_argument("subtask_id", type=int, help="The ID of the TMSS subtask to get the predecessors for") - parser.add_argument('-s', '--state', help="only get predecessors with this state") - parser.add_argument('-R', '--rest_api_credentials', type=str, default='TMSSClient', help='TMSS django REST API credentials name, default: TMSSClient') - args = parser.parse_args() - - try: - with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: - pprint(session.get_subtask_predecessors(args.subtask_id, state=args.state)) - except Exception as e: - print(e) - exit(1) - - -def main_get_subtask_successors(): - parser = argparse.ArgumentParser() - parser.add_argument("subtask_id", type=int, help="The ID of the TMSS subtask to get the successors for") - parser.add_argument('-s', '--state', help="only get successors with this state") - parser.add_argument('-R', '--rest_api_credentials', type=str, default='TMSSClient', help='TMSS django REST API credentials name, default: TMSSClient') - args = parser.parse_args() - - try: - with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: - pprint(session.get_subtask_successors(args.subtask_id, state=args.state)) - except Exception as e: - print(e) - exit(1) - - -def main_get_subtask(): - parser = argparse.ArgumentParser() - parser.add_argument("subtask_id", type=int, help="The ID of the TMSS subtask to get") - parser.add_argument('-R', '--rest_api_credentials', type=str, default='TMSSClient', help='TMSS django REST API credentials name, default: TMSSClient') - args = parser.parse_args() - - try: - with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: - pprint(session.get_subtask(args.subtask_id)) - except Exception as e: - print(e) - exit(1) - - -def main_get_subtasks(): - parser = argparse.ArgumentParser() - parser.add_argument('-s', '--state', help="only get subtasks with this state") - parser.add_argument('-t', '--type', help="only get subtasks with this type") - parser.add_argument('-c', '--cluster', help="only get subtasks for this cluster") - parser.add_argument('--start_time_less_then', help="only get subtasks with a start time less then this timestamp") - parser.add_argument('--start_time_greater_then', help="only get subtasks with a start time greater then this timestamp") - parser.add_argument('--stop_time_less_then', help="only get subtasks with a stop time less then this timestamp") - parser.add_argument('--stop_time_greater_then', help="only get subtasks with a stop time greater then this timestamp") - parser.add_argument('-R', '--rest_api_credentials', type=str, default='TMSSClient', help='TMSS django REST API credentials name, default: TMSSClient') - args = parser.parse_args() - - try: - with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: - result = session.get_subtasks(state=args.state, - subtask_type=args.type, - cluster=args.cluster, - scheduled_start_time_less_then=parseDatetime(args.start_time_less_then) if args.start_time_less_then else None, - scheduled_start_time_greater_then=parseDatetime(args.start_time_greater_then) if args.start_time_greater_then else None, - scheduled_stop_time_less_then=parseDatetime(args.stop_time_less_then) if args.stop_time_less_then else None, - scheduled_stop_time_greater_then=parseDatetime(args.stop_time_greater_then) if args.stop_time_greater_then else None) - pprint(result) - except Exception as e: - print(e) - exit(1) - - -def main_set_subtask_state(): - parser = argparse.ArgumentParser() - parser.add_argument("subtask_id", type=int, help="The ID of the TMSS subtask to set the status on") - parser.add_argument("state", help="The state to set") - parser.add_argument('-e', '--error_reason', default=None, help="Optional error message string when setting a subtask to error.") - parser.add_argument('-R', '--rest_api_credentials', type=str, default='TMSSClient', help='TMSS django REST API credentials name, default: TMSSClient') - parser.add_argument('-r', '--retry_count', type=int, default=DEFAULT_CLIENT_RETRY_COUNT, help='Retry <retry_count> times upon (recoverable) failure, default: [%default]') - args = parser.parse_args() - - try: - with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: - changed_subtask = session.set_subtask_status(args.subtask_id, args.state, args.error_reason, retry_count=args.retry_count) - print("%s now has state %s, see: %s" % (changed_subtask['id'], changed_subtask['state_value'], changed_subtask['url'])) - except Exception as e: - print(e) - exit(1) - - -def main_wait_for_subtask_state(): - parser = argparse.ArgumentParser() - parser.add_argument("subtask_id", type=int, help="The ID of the TMSS subtask to wait for a particular state on") - parser.add_argument("state", help="The expected state to wait for") - parser.add_argument('-R', '--rest_api_credentials', type=str, default='TMSSClient', help='TMSS django REST API credentials name, default: TMSSClient') - parser.add_argument('-t', '--timeout', type=int, default=DEFAULT_CLIENT_POLL_TIMEOUT, help='Poll for <timeout> seconds until this times out, default: [%default]') - parser.add_argument('-i', '--interval', type=int, default=DEFAULT_CLIENT_POLL_INTERVAL, help='Check every <interval> seconds for current subtask state, default: [%default]') - args = parser.parse_args() - - try: - with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: - subtask = session.wait_for_subtask_status(args.subtask_id, args.state, timeout=args.timeout, poll_interval=args.interval) - print("%s now has state %s, see: %s" % (subtask['id'], subtask['state_value'], subtask['url'])) - except Exception as e: - print(e) - exit(1) - - -def main_schedule_subtask(): - parser = argparse.ArgumentParser() - parser.add_argument("subtask_id", type=int, help="The ID of the TMSS subtask to be scheduled") - parser.add_argument('-s', '--start_time', type=str, default=None, help='optional start_time in ISO format, default: None, so the start_time of the subtask instance itself is used.') - parser.add_argument('-R', '--rest_api_credentials', type=str, default='TMSSClient', help='TMSS django REST API credentials name, default: TMSSClient') - parser.add_argument('-r', '--retry_count', type=int, default=DEFAULT_CLIENT_RETRY_COUNT, help='Retry <retry_count> times upon (recoverable) failure, default: [%default]') - args = parser.parse_args() - - try: - with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: - pprint(session.schedule_subtask(args.subtask_id, - scheduled_start_time=datetime.datetime.strptime(args.start_time, "%Y-%m-%d %H:%M:%S") if args.start_time else None, - retry_count=args.retry_count)) - except Exception as e: - print(e) - exit(1) - - -def main_unschedule_subtask(): - parser = argparse.ArgumentParser() - parser.add_argument("subtask_id", type=int, help="The ID of the TMSS subtask to be unscheduled") - parser.add_argument('-R', '--rest_api_credentials', type=str, default='TMSSClient', help='TMSS django REST API credentials name, default: TMSSClient') - parser.add_argument('-r', '--retry_count', type=int, default=DEFAULT_CLIENT_RETRY_COUNT, help='Retry <retry_count> times upon (recoverable) failure, default: [%default]') - args = parser.parse_args() - - try: - with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: - pprint(session.unschedule_subtask(args.subtask_id, retry_count=args.retry_count)) - except Exception as e: - print(e) - exit(1) - - -def main_cancel_subtask(): - parser = argparse.ArgumentParser() - parser.add_argument("subtask_id", type=int, help="The ID of the TMSS subtask to be cancelled") - parser.add_argument('-R', '--rest_api_credentials', type=str, default='TMSSClient', help='TMSS django REST API credentials name, default: TMSSClient') - parser.add_argument('-r', '--retry_count', type=int, default=DEFAULT_CLIENT_RETRY_COUNT, help='Retry <retry_count> times upon (recoverable) failure, default: [%default]') - args = parser.parse_args() - - try: - with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: - pprint(session.cancel_subtask(args.subtask_id, retry_count=args.retry_count)) - except Exception as e: - print(e) - exit(1) - - -def main_mark_subtask_as_obsolete(): - parser = argparse.ArgumentParser() - parser.add_argument("subtask_id", type=int, help="The ID of the TMSS subtask to be marked as obsolete") - parser.add_argument('-R', '--rest_api_credentials', type=str, default='TMSSClient', help='TMSS django REST API credentials name, default: TMSSClient') - parser.add_argument('-r', '--retry_count', type=int, default=DEFAULT_CLIENT_RETRY_COUNT, help='Retry <retry_count> times upon (recoverable) failure, default: [%default]') - args = parser.parse_args() - - try: - with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: - pprint(session.mark_subtask_as_obsolete(args.subtask_id, retry_count=args.retry_count)) - except Exception as e: - print(e) - exit(1) - - -def main_create_and_process_feedback_for_subtask_from_specification_and_set_to_finished(): - parser = argparse.ArgumentParser() - parser.add_argument("subtask_id", type=int, help="The ID of the TMSS subtask to be scheduled") - parser.add_argument('-R', '--rest_api_credentials', type=str, default='TMSSClient', help='TMSS django REST API credentials name, default: TMSSClient') - parser.add_argument('-r', '--retry_count', type=int, default=DEFAULT_CLIENT_RETRY_COUNT, help='Retry <retry_count> times upon (recoverable) failure, default: [%default]') - args = parser.parse_args() - - try: - with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: - pprint(session.create_and_process_feedback_for_subtask_from_specification_and_set_to_finished(args.subtask_id, - retry_count=args.retry_count)) - except Exception as e: - print(e) - exit(1) - - -def main_get_setting(): - parser = argparse.ArgumentParser() - parser.add_argument("setting_name", type=str, help="The name of the TMSS setting to get") - parser.add_argument('-R', '--rest_api_credentials', type=str, default='TMSSClient', help='TMSS django REST API credentials name, default: TMSSClient') - args = parser.parse_args() - - try: - with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: - pprint(session.get_setting(args.setting_name)) - except Exception as e: - print(e) - exit(1) - - -def main_set_setting(): - parser = argparse.ArgumentParser() - parser.add_argument("setting_name", type=str, help="The name of the TMSS setting to set") - parser.add_argument("setting_value", type=lambda s: s.lower() in ['true', 'True', '1'], # argparse is noot very good at speaking bool... - help="The value to set for the TMSS setting") - parser.add_argument('-R', '--rest_api_credentials', type=str, default='TMSSClient', help='TMSS django REST API credentials name, default: TMSSClient') - args = parser.parse_args() - - try: - with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: - pprint(session.set_setting(args.setting_name, args.setting_value)) - except Exception as e: - print(e) - exit(1) - - -def main_submit_trigger(): - ''' - ''' - parser = argparse.ArgumentParser() - parser.add_argument("observing_strategy_template", type=str, help="Which observing strategy template do you want to use to create the scheduling unit from? This template name should've been provided to you.") - parser.add_argument("pointing_angle1", type=float, help="First angle of the pointing [rad]") - parser.add_argument("pointing_angle2", type=float, help="Second angle of the pointing [rad]") - parser.add_argument("--pointing_direction_type", type=str, default="J2000", help="The direction type of the pointing. Defaults to J2000.") - parser.add_argument("--start_at", type=str, default=None, help="The start time of the observation as ISO string. If specified, a constraint will be added so that the observation must start exactly at this time. Defaults to None.") - parser.add_argument("--end_before", type=str, default=None, help="The latest end time of the observation as ISO string. If specified, a constraint will be added so that the observation will run at any time before this time. Defaults to None.") - parser.add_argument("--target_name", type=str, default=None, help="The name of the observation target. Defaults to None.") - parser.add_argument("duration", type=int, help="The duration of the observation in seconds.") - parser.add_argument("scheduling_set_id", type=int, help="The ID of the scheduling set the trigger should be placed in. This should've been provided to you.") - parser.add_argument("--mode", type=str, required=True, help="Which trigger mode? 'test' or 'run'. Specify Whether this is a test submission or should be actually run.") - parser.add_argument('-R', '--rest_api_credentials', type=str, default='TMSSClient', help='TMSS django REST API credentials name, default: TMSSClient') - args = parser.parse_args() - - try: - import uuid - - with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: - # get a prepared valid trigger_doc for the requested template - try: - trigger_doc = session.get_trigger_specification_doc_for_scheduling_unit_observing_strategy_template(args.observing_strategy_template) - except ValueError as e: - # no such template available... get a list of all templates and print it, so the user can lookup the one that he wants - print("ERROR:", e) - print() - print("Available templates:") - for template in session.get_scheduling_unit_observing_strategy_templates(): - print("id=%s name='%s' version=%s" % (template['id'], template['name'], template['version'])) - exit(1) - - # alter it with our parameters - trigger_doc["name"] = "Trigger - %s - %s" % (args.observing_strategy_template, datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M")) - trigger_doc["description"] = "Trigger submitted via CLI tools: %s" % args.observing_strategy_template - trigger_doc["mode"] = args.mode - trigger_doc["scheduling_set_id"] = args.scheduling_set_id - overrides = trigger_doc['scheduling_unit_observing_strategy_template']['overrides'] - - # this is a bit flacky, as it assumes that these parameters are available in the overrides dict - dict_search_and_replace(overrides, 'angle1', args.pointing_angle1) - dict_search_and_replace(overrides, 'angle2', args.pointing_angle2) - dict_search_and_replace(overrides, 'duration', args.duration) - - if args.target_name: - dict_search_and_replace(overrides, 'target', args.target_name) - dict_search_and_replace(overrides, 'name', args.target_name) - - if args.end_before: - overrides['scheduling_constraints_doc']['time']['before'] = args.end_before - - if args.start_at: - overrides['scheduling_constraints_doc']['time']['at'] = args.start_at - - print("Submitting trigger...") - scheduling_unit = session.submit_trigger(trigger_doc) - print("Submitted trigger, and created Scheduling Unit:", scheduling_unit['url'].replace('api/scheduling_unit_', 'schedulingunit/view/')) - except Exception as e: - print(e) - exit(1) - - -def main_get_subtask_l2stationspecs(): - parser = argparse.ArgumentParser() - parser.add_argument("subtask_id", help="The ID of the TMSS subtask to get the Lofar 2.0 station specs for") - parser.add_argument('-R', '--rest_api_credentials', type=str, default='TMSSClient', help='TMSS django REST API credentials name, default: TMSSClient') - parser.add_argument('-r', '--retry_count', type=int, default=DEFAULT_CLIENT_RETRY_COUNT, help='Retry <retry_count> times upon (recoverable) failure, default: [%default]') - args = parser.parse_args() - - try: - with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: - pprint(session.get_subtask_l2stationspecs(args.subtask_id, retry_count=args.retry_count)) - except Exception as e: - print(e) - exit(1) - - -def main_mark_scheduling_unit_fixed_time_scheduled_at_scheduled_starttime(): - parser = argparse.ArgumentParser() - parser.add_argument("scheduling_unit_blueprint_id", type=int, help="The ID of the TMSS scheduling_unit_blueprint to be marked as fixed_time-scheduled") - parser.add_argument('-R', '--rest_api_credentials', type=str, default='TMSSClient', help='TMSS django REST API credentials name, default: TMSSClient') - parser.add_argument('-r', '--retry_count', type=int, default=DEFAULT_CLIENT_RETRY_COUNT, help='Retry <retry_count> times upon (recoverable) failure, default: [%default]') - args = parser.parse_args() - - try: - with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: - pprint(session.mark_scheduling_unit_fixed_time_scheduled_at_scheduled_starttime(args.scheduling_unit_blueprint_id, retry_count=args.retry_count)) - except Exception as e: - print(e) - exit(1) - -def main_schedule_scheduling_unit_at_given_starttime(): - parser = argparse.ArgumentParser(description="force the scheduling_unit with the given id to be scheduled at the given starttime, bypassing the scheduler but also marking it as 'fixed_time' at 'at' in the constraints for a next scheduling round.") - parser.add_argument("scheduling_unit_blueprint_id", type=int, help="The ID of the TMSS scheduling_unit_blueprint to be marked as fixed_time-scheduled") - parser.add_argument("start_time", type=str, help="The starttime expressed as \"YYYY-MM-DD HH:MM::SS\"") - parser.add_argument('-R', '--rest_api_credentials', type=str, default='TMSSClient', help='TMSS django REST API credentials name, default: TMSSClient') - parser.add_argument('-r', '--retry_count', type=int, default=DEFAULT_CLIENT_RETRY_COUNT, help='Retry <retry_count> times upon (recoverable) failure, default: [%default]') - args = parser.parse_args() - - try: - with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: - pprint(session.schedule_scheduling_unit(args.scheduling_unit_blueprint_id, - parseDatetime(args.start_time), - retry_count=args.retry_count)) - except Exception as e: - print(e) - exit(1) - -def main_unschedule_scheduling_unit(): - parser = argparse.ArgumentParser(description="Force the scheduling_unit to be unscheduled. NB: the scheduler mey schedule it again in the background.") - parser.add_argument("scheduling_unit_blueprint_id", type=int, help="The ID of the TMSS scheduling_unit_blueprint to be marked as fixed_time-scheduled") - parser.add_argument('-R', '--rest_api_credentials', type=str, default='TMSSClient', help='TMSS django REST API credentials name, default: TMSSClient') - parser.add_argument('-r', '--retry_count', type=int, default=DEFAULT_CLIENT_RETRY_COUNT, help='Retry <retry_count> times upon (recoverable) failure, default: [%default]') - args = parser.parse_args() - - try: - with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: - pprint(session.unschedule_scheduling_unit(args.scheduling_unit_blueprint_id, retry_count=args.retry_count)) - except Exception as e: - print(e) - exit(1) - -def main_mark_scheduling_unit_dynamically_scheduled(): - parser = argparse.ArgumentParser() - parser.add_argument("scheduling_unit_blueprint_id", type=int, help="The ID of the TMSS scheduling_unit_blueprint to be marked as dynamically-scheduled") - parser.add_argument('-R', '--rest_api_credentials', type=str, default='TMSSClient', help='TMSS django REST API credentials name, default: TMSSClient') - parser.add_argument('-r', '--retry_count', type=int, default=DEFAULT_CLIENT_RETRY_COUNT, help='Retry <retry_count> times upon (recoverable) failure, default: [%default]') - args = parser.parse_args() - - try: - with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: - pprint(session.mark_scheduling_unit_dynamically_scheduled(args.scheduling_unit_blueprint_id, retry_count=args.retry_count)) - except Exception as e: - print(e) - exit(1) - - -def main_reset_schedule(): - # default 'parking'-timestamp is at noon seven days from now. - timestamp = (datetime.datetime.utcnow() + datetime.timedelta(days=7)).replace(hour=12, minute=0, second=0, microsecond=0) - - parser = argparse.ArgumentParser(description="Reset the status of all unschedulable units to schedulable, and then position all schedulable units at the given start_time. Typical usage: reset the schedule using this tool and let the scheduler place all units.") - parser.add_argument('-t', '--timestamp', type=str, default=timestamp.strftime("%Y-%m-%d %H:%M"), help="Position/park all schedulable units at this timestamp expressed as \"YYYY-MM-DD HH:MM\"") - parser.add_argument('-s', '--scheduled', action='store_true', help='also unschedule all scheduled units') - parser.add_argument('-R', '--rest_api_credentials', type=str, default='TMSSClient', help='TMSS django REST API credentials name, default: TMSSClient') - args = parser.parse_args() - - try: - with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as client: - client.post_to_path_and_get_result_as_json_object('scheduling_unit_blueprint/reset_schedule', - params={'scheduled': args.scheduled, - 'timestamp': args.timestamp}) - except Exception as e: - print(e) - exit(1) - - -def main_create_lofar2_sibling_scheduling_unit(): - parser = argparse.ArgumentParser() - parser.add_argument("scheduling_unit_blueprint_id", type=int, help="The ID of the TMSS scheduling_unit_blueprint for which we want to create a Lofar2 sibling.") - parser.add_argument('-R', '--rest_api_credentials', type=str, default='TMSSClient', help='TMSS django REST API credentials name, default: TMSSClient') - parser.add_argument('-r', '--retry_count', type=int, default=DEFAULT_CLIENT_RETRY_COUNT, help='Retry <retry_count> times upon (recoverable) failure, default: [%default]') - args = parser.parse_args() - - try: - with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: - pprint(session.create_lofar2_sibling_scheduling_unit(args.scheduling_unit_blueprint_id, retry_count=args.retry_count)) - except Exception as e: - print(e) - exit(1) - - -def main_create_scheduling_unit_blueprint_copy_without_given_stations(): - parser = argparse.ArgumentParser() - parser.add_argument("scheduling_unit_blueprint_id", type=int, help="The ID of the TMSS scheduling_unit_blueprint from which the station(s) have to be removed.") - parser.add_argument("stations_to_be_removed", type=str, help="A comma seperated string of stations.") - parser.add_argument('-R', '--rest_api_credentials', type=str, default='TMSSClient', help='TMSS django REST API credentials name, default: TMSSClient') - parser.add_argument('-r', '--retry_count', type=int, default=DEFAULT_CLIENT_RETRY_COUNT, help='Retry <retry_count> times upon (recoverable) failure, default: [%default]') - args = parser.parse_args() - - try: - with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: - stations_to_be_removed = [s.strip() for s in args.stations_to_be_removed.split(',')] - scheduling_unit_blueprint_copy = session.create_scheduling_unit_blueprint_copy_without_given_stations(args.scheduling_unit_blueprint_id, - stations_to_be_removed, - retry_count=args.retry_count) - print("Here is your new scheduling_unit without station(s)", ','.join(stations_to_be_removed), scheduling_unit_blueprint_copy['url']) - except Exception as e: - print(e) - exit(1) - - -def main_adapt_scheduling_unit_draft_to_start_and_stop_times(): - parser = argparse.ArgumentParser() - parser.add_argument("scheduling_unit_draft_id", type=int, help="The ID of the TMSS scheduling_unit_draft that should be adapted.") - parser.add_argument('start_time', type=str, help='start_time in ISO format') - parser.add_argument('stop_time', type=str, help='stop_time in ISO format') - parser.add_argument('-f', '--mark_fixed_time', action='store_true', help='optionally switch scheduler for this unit to fixed-time') - parser.add_argument('-R', '--rest_api_credentials', type=str, default='TMSSClient', help='TMSS django REST API credentials name, default: TMSSClient') - parser.add_argument('-r', '--retry_count', type=int, default=DEFAULT_CLIENT_RETRY_COUNT, help='Retry <retry_count> times upon (recoverable) failure, default: [%default]') - args = parser.parse_args() - - try: - with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: - pprint(session.adapt_scheduling_unit_draft_to_start_and_stop_times(scheduling_unit_draft_id=args.scheduling_unit_draft_id, - start_time=parseDatetime(args.start_time), - stop_time=parseDatetime(args.stop_time), - mark_fixed_time=args.mark_fixed_time, - retry_count=args.retry_count)) - except Exception as e: - print(e) - exit(1) - - -def main_adapt_scheduling_unit_blueprint_to_start_and_stop_times(): - parser = argparse.ArgumentParser() - parser.add_argument("scheduling_unit_blueprint_id", type=int, help="The ID of the TMSS scheduling_unit_blueprint that should be adapted.") - parser.add_argument('start_time', type=str, help='start_time in ISO format') - parser.add_argument('stop_time', type=str, help='stop_time in ISO format') - parser.add_argument('-f', '--mark_fixed_time', action='store_true', help='optionally switch scheduler for this unit to fixed-time') - parser.add_argument('-R', '--rest_api_credentials', type=str, default='TMSSClient', help='TMSS django REST API credentials name, default: TMSSClient') - parser.add_argument('-r', '--retry_count', type=int, default=DEFAULT_CLIENT_RETRY_COUNT, help='Retry <retry_count> times upon (recoverable) failure, default: [%default]') - args = parser.parse_args() - - try: - with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=args.rest_api_credentials) as session: - pprint(session.adapt_scheduling_unit_blueprint_to_start_and_stop_times(scheduling_unit_blueprint_id=args.scheduling_unit_blueprint_id, - start_time=parseDatetime(args.start_time), - stop_time=parseDatetime(args.stop_time), - mark_fixed_time=args.mark_fixed_time, - retry_count=args.retry_count)) - except Exception as e: - print(e) - exit(1) diff --git a/lofar_tmss_client/standalone_trigger_client.py b/lofar_tmss_client/standalone_trigger_client.py index 55c0047ebe891ed6894977d5d8dd4445b242d80e..0c0242cf109b50d8abcba1bc84b1b3459c74b15e 100644 --- a/lofar_tmss_client/standalone_trigger_client.py +++ b/lofar_tmss_client/standalone_trigger_client.py @@ -1,26 +1,11 @@ -#!/usr/bin/python3 - -# Copyright (C) 2012-2015 ASTRON (Netherlands Institute for Radio Astronomy) -# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands -# -# This file is part of the LOFAR software suite. -# The LOFAR software suite is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# The LOFAR software suite is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. +# Copyright (C) 2012 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: GPL-3.0-or-later +import urllib3 +import logging import argparse import datetime import time -import requests from http.client import responses import json import html @@ -28,10 +13,9 @@ from urllib.parse import quote from threading import RLock import os -import urllib3 -urllib3.disable_warnings() +import requests -import logging +urllib3.disable_warnings() logger = logging.getLogger(__name__) diff --git a/lofar_tmss_client/tmss_bus_listener.py b/lofar_tmss_client/tmss_bus_listener.py new file mode 100644 index 0000000000000000000000000000000000000000..c7f6ada28cfd38cd2de670849f1462e204c8c226 --- /dev/null +++ b/lofar_tmss_client/tmss_bus_listener.py @@ -0,0 +1,413 @@ +# Copyright (C) 2015 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: GPL-3.0-or-later + +""" +TMSSBusListener listens on the lofar notification message bus and calls (empty) on<SomeMessage> methods when such a message is received. +Typical usage is to derive your own subclass from TMSSBusListener and implement the specific on<SomeMessage> methods that you are interested in. +""" + +from datetime import datetime +from dateutil import parser +import logging + +from tmss_pymessaging.messagebus import BusListener, AbstractMessageHandler +from tmss_pymessaging.config import DEFAULT_BUSNAME, DEFAULT_BROKER +from tmss_pymessaging.messages import EventMessage +from tmss_pymessaging.exceptions import MessageHandlerUnknownSubjectError +from tmss_pycommon.util import single_line_with_single_spaces + +logger = logging.getLogger(__name__) + + +_TMSS_EVENT_PREFIX_TEMPLATE = 'TMSS.Event.%s' +TMSS_SUBTASK_OBJECT_EVENT_PREFIX = _TMSS_EVENT_PREFIX_TEMPLATE % 'SubTask.Object' +TMSS_SUBTASK_STATUS_EVENT_PREFIX = _TMSS_EVENT_PREFIX_TEMPLATE % 'SubTask.Status' +TMSS_TASKBLUEPRINT_OBJECT_EVENT_PREFIX = _TMSS_EVENT_PREFIX_TEMPLATE % 'TaskBlueprint.Object' +TMSS_TASKBLUEPRINT_STATUS_EVENT_PREFIX = _TMSS_EVENT_PREFIX_TEMPLATE % 'TaskBlueprint.Status' +TMSS_TASKDRAFT_OBJECT_EVENT_PREFIX = _TMSS_EVENT_PREFIX_TEMPLATE % 'TaskDraft.Object' +TMSS_SCHEDULINGUNITBLUEPRINT_OBJECT_EVENT_PREFIX = _TMSS_EVENT_PREFIX_TEMPLATE % 'SchedulingUnitBlueprint.Object' +TMSS_SCHEDULINGUNITBLUEPRINT_STATUS_EVENT_PREFIX = _TMSS_EVENT_PREFIX_TEMPLATE % 'SchedulingUnitBlueprint.Status' +TMSS_SCHEDULINGUNITDRAFT_OBJECT_EVENT_PREFIX = _TMSS_EVENT_PREFIX_TEMPLATE % 'SchedulingUnitDraft.Object' +TMSS_SCHEDULINGCONSTRAINTSWEIGHTFACTOR_OBJECT_EVENT_PREFIX = _TMSS_EVENT_PREFIX_TEMPLATE % 'SchedulingConstraintsWeightFactor.Object' +TMSS_PROJECT_OBJECT_EVENT_PREFIX = _TMSS_EVENT_PREFIX_TEMPLATE % 'Project.Object' +TMSS_PROJECT_STATUS_EVENT_PREFIX = _TMSS_EVENT_PREFIX_TEMPLATE % 'Project.Status' +TMSS_PROJECTQUOTAARCHIVELOCATION_OBJECT_EVENT_PREFIX = _TMSS_EVENT_PREFIX_TEMPLATE % 'ProjectQuotaArchiveLocation.Object' +TMSS_PROJECTCYCLES_OBJECT_EVENT_PREFIX = _TMSS_EVENT_PREFIX_TEMPLATE % 'ProjectCycles.Object' +TMSS_SUBSYSTEM_STATUS_EVENT_PREFIX = _TMSS_EVENT_PREFIX_TEMPLATE % 'Subsystem.Status' +TMSS_SETTING_OBJECT_EVENT_PREFIX = _TMSS_EVENT_PREFIX_TEMPLATE % 'Setting.Object' +TMSS_RESERVATION_OBJECT_EVENT_PREFIX = _TMSS_EVENT_PREFIX_TEMPLATE % 'Reservation.Object' +TMSS_ALL_OBJECT_EVENTS_FILTER = _TMSS_EVENT_PREFIX_TEMPLATE % '.*.Object.#' +TMSS_ALL_STATUS_EVENTS_FILTER = _TMSS_EVENT_PREFIX_TEMPLATE % '.*.Status.#' +TMSS_ALL_EVENTS_FILTER = _TMSS_EVENT_PREFIX_TEMPLATE % '#' + + +class TMSSEventMessageHandler(AbstractMessageHandler): + ''' + Base-type messagehandler for handling all TMSS event messages. + Typical usage is to derive your own subclass from TMSSEventMessageHandler and implement the specific on<SomeMessage> methods that you are interested in. + ''' + + def __init__(self, log_event_messages: bool=False) -> None: + self.log_event_messages = log_event_messages + super().__init__() + + + def handle_message(self, msg: EventMessage): + if not isinstance(msg, EventMessage): + raise ValueError("%s: Ignoring non-EventMessage: %s" % (self.__class__.__name__, msg)) + + stripped_subject = msg.subject.replace(_TMSS_EVENT_PREFIX_TEMPLATE%('',), '') + + if self.log_event_messages: + logger.info("%s %s: %s" % (self.__class__.__name__, stripped_subject, single_line_with_single_spaces(msg.content))) + + # sorry, very big if/elif/else tree. + # it just maps all possible event subjects for all possible objects and statuses onto handler methods. + if stripped_subject == 'SubTask.Object.Created': + self.onSubTaskCreated(**msg.content) + elif stripped_subject == 'SubTask.Object.Updated': + self.onSubTaskUpdated(**msg.content) + elif stripped_subject == 'SubTask.Object.Deleted': + self.onSubTaskDeleted(**msg.content) + elif stripped_subject == 'TaskBlueprint.Object.Created': + self.onTaskBlueprintCreated(**msg.content) + elif stripped_subject == 'TaskBlueprint.Object.Updated': + self.onTaskBlueprintUpdated(**msg.content) + elif stripped_subject == 'TaskBlueprint.Object.Deleted': + self.onTaskBlueprintDeleted(**msg.content) + elif stripped_subject == 'TaskDraft.Object.Created': + self.onTaskDraftCreated(**msg.content) + elif stripped_subject == 'TaskDraft.Object.Updated': + self.onTaskDraftUpdated(**msg.content) + elif stripped_subject == 'TaskDraft.Object.Deleted': + self.onTaskDraftDeleted(**msg.content) + elif stripped_subject == 'SchedulingUnitBlueprint.Object.Created': + self.onSchedulingUnitBlueprintCreated(**msg.content) + elif stripped_subject == 'SchedulingUnitBlueprint.Object.Updated': + self.onSchedulingUnitBlueprintUpdated(**msg.content) + elif stripped_subject == 'SchedulingUnitBlueprint.Object.Deleted': + self.onSchedulingUnitBlueprintDeleted(**msg.content) + elif stripped_subject == 'SchedulingUnitDraft.Object.Created': + self.onSchedulingUnitDraftCreated(**msg.content) + elif stripped_subject == 'SchedulingUnitDraft.Object.Updated': + self.onSchedulingUnitDraftUpdated(**msg.content) + elif stripped_subject == 'SchedulingUnitDraft.Object.Deleted': + self.onSchedulingUnitDraftDeleted(**msg.content) + elif stripped_subject.startswith('SubTask.Status.'): + self.onSubTaskStatusChanged(**msg.content) + elif stripped_subject.startswith('TaskBlueprint.Status.'): + self.onTaskBlueprintStatusChanged(**msg.content) + elif stripped_subject.startswith('SchedulingUnitBlueprint.Status.'): + self.onSchedulingUnitBlueprintStatusChanged(**msg.content) + elif stripped_subject == 'SchedulingConstraintsWeightFactor.Object.Updated': + self.onSchedulingConstraintsWeightFactorUpdated(**msg.content) + elif stripped_subject == 'Setting.Object.Updated': + self.onSettingUpdated(**msg.content) + elif stripped_subject == 'Subsystem.Status.Updated': + self.onSubsystemStatusUpdated(**msg.content) + elif stripped_subject == 'Project.Object.Created': + self.onProjectCreated(**msg.content) + elif stripped_subject == 'Project.Object.Updated': + self.onProjectUpdated(**msg.content) + elif stripped_subject.startswith('Project.Status.'): + self.onProjectStatusUpdated(**msg.content) + elif stripped_subject == 'Project.Object.Deleted': + self.onProjectDeleted(**msg.content) + elif stripped_subject == 'Project.Object.Rank.Updated': + self.onProjectRankUpdated(**msg.content) + elif stripped_subject == 'ProjectQuotaArchiveLocation.Object.Created': + self.onProjectQuotaArchiveLocationCreated(**msg.content) + elif stripped_subject == 'ProjectQuotaArchiveLocation.Object.Updated': + self.onProjectQuotaArchiveLocationUpdated(**msg.content) + elif stripped_subject == 'ProjectQuotaArchiveLocation.Object.Deleted': + self.onProjectQuotaArchiveLocationDeleted(**msg.content) + elif stripped_subject == 'ProjectCycles.Object.Created': + self.onProjectCyclesCreated(**msg.content) + elif stripped_subject == 'ProjectCycles.Object.Updated': + self.onProjectCyclesUpdated(**msg.content) + elif stripped_subject == 'ProjectCycles.Object.Deleted': + self.onProjectCyclesDeleted(**msg.content) + elif stripped_subject == 'SchedulingUnitBlueprint.Object.Constraints.Updated': + self.onSchedulingUnitBlueprintConstraintsUpdated(**msg.content) + elif stripped_subject == 'SchedulingUnitBlueprint.Object.OutputPinningUpdated': + self.onSchedulingUnitBlueprintOutputPinningUpdated(**msg.content) + elif stripped_subject == 'SchedulingUnitBlueprint.Object.Rank.Updated': + self.onSchedulingUnitBlueprintRankUpdated(**msg.content) + elif stripped_subject == 'SchedulingUnitBlueprint.Object.PriorityQueue.Updated': + self.onSchedulingUnitBlueprintPriorityQueueUpdated(**msg.content) + elif stripped_subject == 'SchedulingUnitBlueprint.Object.IngestPermissionGranted': + self.onSchedulingUnitBlueprintIngestPermissionGranted(id=msg.content['id'], + ingest_permission_granted_since=parser.parse(msg.content['ingest_permission_granted_since'], ignoretz=True)) + elif stripped_subject == 'TaskBlueprint.Object.OutputPinningUpdated': + self.onTaskBlueprintOutputPinningUpdated(**msg.content) + elif stripped_subject == 'Reservation.Object.Created': + self.onReservationCreated(**msg.content) + elif stripped_subject == 'Reservation.Object.Updated': + self.onReservationUpdated(**msg.content) + elif stripped_subject == 'Reservation.Object.Deleted': + self.onReservationDeleted(**msg.content) + else: + raise MessageHandlerUnknownSubjectError("TMSSBusListener.handleMessage: unknown subject: %s" % msg.subject) + + + def onSubTaskStatusChanged(self, id: int, status:str): + '''onSubTaskStatusChanged is called upon receiving a SubTask.Status.* message, which is sent when a SubTasks changes status. + :param id: the TMSS id of the SubTask + :param status: the new status of the SubTask + ''' + pass + + def onTaskBlueprintStatusChanged(self, id: int, status:str): + '''onTaskBlueprintStatusChanged is called upon receiving a TaskStatus.Choices.* message, which is sent when a TaskBlueprint changes status. + :param id: the TMSS id of the TaskBlueprint + :param status: the new status of the TaskBlueprint + ''' + pass + + def onSchedulingUnitBlueprintStatusChanged(self, id: int, status:str): + '''onSchedulingUnitBlueprintStatusChanged is called upon receiving a SchedulingUnitStatus.Choices.* message, which is sent when a SchedulingUnitBlueprints changes status. + :param id: the TMSS id of the SchedulingUnitBlueprint + :param status: the new status of the SchedulingUnitBlueprint + ''' + pass + + def onSchedulingConstraintsWeightFactorUpdated(self, id: int): + '''onSchedulingConstraintsWeightFactorUpdated is called upon receiving a SchedulingConstraintsWeightFactor.Object.Updated message, which is sent when a SchedulingConstraintsWeightFactor object updates. + :param id: the TMSS id of the SchedulingConstraintsWeightFactor + ''' + pass + + def onSubTaskCreated(self, id: int): + '''onSubTaskCreated is called upon receiving a SubTask.Object.Created message, which is sent when a SubTasks was created. + :param id: the TMSS id of the SubTask + ''' + pass + + def onSubTaskUpdated(self, id: int): + '''onSubTaskUpdated is called upon receiving a SubTask.Object.Updated message, which is sent when a SubTasks was created. + :param id: the TMSS id of the SubTask + ''' + pass + + def onSubTaskDeleted(self, id: int): + '''onSubTaskDeleted is called upon receiving a SubTask.Object.Deleted message, which is sent when a SubTasks was created. + :param id: the TMSS id of the SubTask + ''' + pass + + def onTaskDraftCreated(self, id: int): + '''onTaskDraftCreated is called upon receiving a TaskDraft.Object.Created message, which is sent when a TaskDrafts was created. + :param id: the TMSS id of the TaskDraft + ''' + pass + + def onTaskDraftUpdated(self, id: int): + '''onTaskDraftUpdated is called upon receiving a TaskDraft.Object.Updated message, which is sent when a TaskDrafts was created. + :param id: the TMSS id of the TaskDraft + ''' + pass + + def onTaskDraftDeleted(self, id: int): + '''onTaskDraftDeleted is called upon receiving a TaskDraft.Object.Deleted message, which is sent when a TaskDrafts was created. + :param id: the TMSS id of the TaskDraft + ''' + pass + + def onTaskBlueprintCreated(self, id: int): + '''onTaskBlueprintCreated is called upon receiving a TaskBlueprint.Object.Created message, which is sent when a TaskBlueprints was created. + :param id: the TMSS id of the TaskBlueprint + ''' + pass + + def onTaskBlueprintUpdated(self, id: int): + '''onTaskBlueprintUpdated is called upon receiving a TaskBlueprint.Object.Updated message, which is sent when a TaskBlueprints was created. + :param id: the TMSS id of the TaskBlueprint + ''' + pass + + def onTaskBlueprintDeleted(self, id: int): + '''onTaskBlueprintDeleted is called upon receiving a TaskBlueprint.Object.Deleted message, which is sent when a TaskBlueprints was created. + :param id: the TMSS id of the TaskBlueprint + ''' + pass + + def onSchedulingUnitDraftCreated(self, id: int): + '''onSchedulingUnitDraftCreated is called upon receiving a SchedulingUnitDraft.Object.Created message, which is sent when a SchedulingUnitDrafts was created. + :param id: the TMSS id of the SchedulingUnitDraft + ''' + pass + + def onSchedulingUnitDraftUpdated(self, id: int): + '''onSchedulingUnitDraftUpdated is called upon receiving a SchedulingUnitDraft.Object.Updated message, which is sent when a SchedulingUnitDrafts was created. + :param id: the TMSS id of the SchedulingUnitDraft + ''' + pass + + def onSchedulingUnitBlueprintConstraintsUpdated(self, id: int, scheduling_constraints_doc: dict): + '''onSchedulingUnitBlueprintConstraintsUpdated is called upon receiving a SchedulingUnitDraft.Object.Constraints.Updated message, which is sent when a the constraints on a SchedulingUnitDrafts were updated. + :param id: the TMSS id of the SchedulingUnitDraft + ''' + pass + + def onSchedulingUnitBlueprintRankUpdated(self, id: int, rank: float): + '''onSchedulingUnitBlueprintRankUpdated is called upon receiving a SchedulingUnitBlueprint.Object.Rank.Updated message, which is sent when a the rank on a SchedulingUnitDrafts was updated. + :param id: the TMSS id of the SchedulingUnitBlueprint + ''' + pass + + def onSchedulingUnitBlueprintPriorityQueueUpdated(self, id: int, priority_queue: str): + '''onSchedulingUnitBlueprintPriorityQueueUpdated is called upon receiving a SchedulingUnitBlueprint.Object.PriorityQueue.Updated message, which is sent when a the priority_queue on a SchedulingUnitDrafts was updated. + :param id: the TMSS id of the SchedulingUnitBlueprint + ''' + pass + + def onSchedulingUnitDraftDeleted(self, id: int): + '''onSchedulingUnitDraftDeleted is called upon receiving a SchedulingUnitDraft.Object.Deleted message, which is sent when a SchedulingUnitDrafts was created. + :param id: the TMSS id of the SchedulingUnitDraft + ''' + pass + + def onSchedulingUnitBlueprintCreated(self, id: int): + '''onSchedulingUnitBlueprintCreated is called upon receiving a SchedulingUnitBlueprint.Object.Created message, which is sent when a SchedulingUnitBlueprints was created. + :param id: the TMSS id of the SchedulingUnitBlueprint + ''' + pass + + def onSchedulingUnitBlueprintUpdated(self, id: int, **kwargs): + '''onSchedulingUnitBlueprintUpdated is called upon receiving a SchedulingUnitBlueprint.Object.Updated message, which is sent when a SchedulingUnitBlueprints was created. + :param id: the TMSS id of the SchedulingUnitBlueprint + ''' + pass + + def onSchedulingUnitBlueprintOutputPinningUpdated(self, id: int, output_pinned: bool): + pass + + def onSchedulingUnitBlueprintDeleted(self, id: int): + '''onSchedulingUnitBlueprintDeleted is called upon receiving a SchedulingUnitBlueprint.Object.Deleted message, which is sent when a SchedulingUnitBlueprints was created. + :param id: the TMSS id of the SchedulingUnitBlueprint + ''' + pass + + def onProjectCreated(self, name: str): + '''onProjectCreated is called upon receiving a Project.Object.Created message, which is sent when a Project was created. + ''' + pass + + def onProjectUpdated(self, name: str): + '''onProjectUpdated is called upon receiving a Project.Object.Updated message, which is sent when a Project was created. + ''' + pass + + def onProjectStatusUpdated(self, name: str, status: str): + '''onProjectStatusUpdated is called upon receiving a Project.Status.* message, which is sent when a Project was assigned a new status. + ''' + pass + + def onProjectRankUpdated(self, name: str, rank: float): + '''onProjectRankUpdated is called upon receiving a Project.Rank.Updated message, which is sent when a Project was assigned a new rank. + ''' + pass + + def onProjectDeleted(self, name: str): + '''onProjectDeleted is called upon receiving a Project.Object.Deleted message, which is sent when a Project was created. + ''' + pass + + def onProjectQuotaArchiveLocationCreated(self, id: int): + '''onProjectQuotaArchiveLocationCreated is called upon receiving a ProjectQuotaArchiveLocation.Object.Created message, which is sent when a ProjectQuotaArchiveLocation was created. + :param id: the TMSS id of the ProjectQuotaArchiveLocation + ''' + pass + + def onProjectQuotaArchiveLocationUpdated(self, id: int): + '''onProjectQuotaArchiveLocationUpdated is called upon receiving a ProjectQuotaArchiveLocation.Object.Updated message, which is sent when a ProjectQuotaArchiveLocation was created. + :param id: the TMSS id of the ProjectQuotaArchiveLocation + ''' + pass + + def onProjectQuotaArchiveLocationDeleted(self, id: int): + '''onProjectQuotaArchiveLocationDeleted is called upon receiving a ProjectQuotaArchiveLocation.Object.Deleted message, which is sent when a ProjectQuotaArchiveLocation was created. + :param id: the TMSS id of the ProjectQuotaArchiveLocation + ''' + pass + + def onProjectCyclesCreated(self, id: int): + '''onProjectCyclesCreated is called upon receiving a ProjectCycles.Object.Created message, which is sent when a ProjectCycles was created. + :param id: the TMSS id of the ProjectCycles + ''' + pass + + def onProjectCyclesUpdated(self, id: int): + '''onProjectCyclesUpdated is called upon receiving a ProjectCycles.Object.Updated message, which is sent when a ProjectCycles was created. + :param id: the TMSS id of the ProjectCycles + ''' + pass + + def onProjectCyclesDeleted(self, id: int): + '''onProjectCyclesDeleted is called upon receiving a ProjectCycles.Object.Deleted message, which is sent when a ProjectCycles was created. + :param id: the TMSS id of the ProjectCycles + ''' + pass + + def onSettingUpdated(self, name: str, value): + '''onSettingUpdated is called upon receiving a Setting.Object.Updated message, which is sent when a Setting was updated. + :param name: the name of the Setting + ''' + pass + + + def onSubsystemStatusUpdated(self, name: str, status: str): + '''onSubsystemStatusUpdated is called upon receiving a Subsystem.Status.Updated message, which is sent when a Subsystem's status was updated. + :param name: the name of the subsystem + :param status: the new status of the subsystem + ''' + pass + + + def onSchedulingUnitBlueprintIngestPermissionGranted(self, id: int, ingest_permission_granted_since: datetime): + '''onSchedulingUnitBlueprintIngestPermissionGranted is called upon receiving a SchedulingUnitBlueprint.Object.IngestPermissionGranted message, usually as a result of setting the permissing in the database via the QA Workflow. + :param id: the TMSS id of the SchedulingUnitBlueprint + :param ingest_permission_granted_since: the timestamp when the permission was granted + ''' + pass + + def onTaskBlueprintOutputPinningUpdated(self, id: int, output_pinned: bool): + '''onTaskBlueprintOutputPinningUpdated is called upon receiving a TaskBlueprint.Object.OutputPinningUpdated message, usually as a result of a change on the TaskBlueprint output_pinned field. + :param id: the TMSS id of the TaskBlueprint + :param output_pinned: True if the output of this task is pinned to disk, that is, forbidden to be removed. + ''' + pass + + def onReservationCreated(self, id: int): + '''onReservationCreated is called upon receiving a Reservation.Object.Created message, which is sent when a Reservation was created. + ''' + pass + + def onReservationUpdated(self, id: int): + '''onReservationUpdated is called upon receiving a Reservation.Object.Updated message, which is sent when a Reservation was created. + ''' + pass + + def onReservationDeleted(self, id: int, start_time, stop_time): + '''onReservationDeleted is called upon receiving a Reservation.Object.Deleted message, which is sent when a Reservation was created. + ''' + pass + + +class TMSSBusListener(BusListener): + def __init__(self, + handler_type: TMSSEventMessageHandler.__class__ = TMSSEventMessageHandler, + handler_kwargs: dict = None, + exchange: str = DEFAULT_BUSNAME, + routing_key: str = TMSS_ALL_EVENTS_FILTER, + num_threads: int = 1, + broker: str = DEFAULT_BROKER, + queue_name_postfix: str = None): + """ + TMSSSubTaskBusListener listens on the lofar notification message bus and calls on<SomeMessage> methods in the TMSSEventMessageHandler when such a message is received. + Typical usage is to derive your own subclass from TMSSEventMessageHandler and implement the specific on<SomeMessage> methods that you are interested in. + """ + if not issubclass(handler_type, TMSSEventMessageHandler): + raise TypeError("handler_type should be a TMSSEventMessageHandler subclass") + + super().__init__(handler_type, handler_kwargs, exchange, routing_key, num_threads, broker, queue_name_postfix=queue_name_postfix) diff --git a/lofar_tmss_client/tmss_http_rest_client.py b/lofar_tmss_client/tmss_http_rest_client.py index 45340798754f79cbc3173d8bfd2013c436357674..409f68bf8c1f3422d861566436f28d8a606f8132 100644 --- a/lofar_tmss_client/tmss_http_rest_client.py +++ b/lofar_tmss_client/tmss_http_rest_client.py @@ -1,31 +1,26 @@ -#!/usr/bin/python3 - -# Copyright (C) 2012-2015 ASTRON (Netherlands Institute for Radio Astronomy) -# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands -# -# This file is part of the LOFAR software suite. -# The LOFAR software suite is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# The LOFAR software suite is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. +# Copyright (C) 2012 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: GPL-3.0-or-later import logging import time import typing - -logger = logging.getLogger(__name__) +from http.client import responses +import os +try: + # try to use the fast ujson module, else plain json + import ujson as json +except ImportError: + import json +from datetime import datetime, timedelta +import html +from typing import Union +import socket +from threading import RLock # see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings # and https://stackoverflow.com/questions/27981545/suppress-insecurerequestwarning-unverified-https-request-is-being-made-in-pytho import urllib3 +from urllib.parse import quote import requests if requests.__version__ >= '2.16.0': urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) @@ -36,19 +31,8 @@ else: except ImportError: pass -from http.client import responses -import os -try: - # try to use the fast ujson module, else plain json - import ujson as json -except ImportError: - import json -from datetime import datetime, timedelta -import html -from urllib.parse import quote -from typing import Union -import socket -from threading import RLock +logger = logging.getLogger(__name__) + # usage example: # @@ -89,7 +73,7 @@ class TMSSsession(object): if dbcreds_name is None: dbcreds_name = os.environ.get("TMSS_CLIENT_DBCREDENTIALS", "TMSSClient") - from lofar_tmss_client.dbcredentials import DBCredentials + from tmss_pycommon.dbcredentials import DBCredentials dbcreds = DBCredentials().get(dbcreds_name) return TMSSsession.create_from_dbcreds(dbcreds) diff --git a/lofar_tmss_client/util.py b/lofar_tmss_client/util.py deleted file mode 100644 index 3a8eddbb6d8a997ce23cc4d1ececc103b03fdfa2..0000000000000000000000000000000000000000 --- a/lofar_tmss_client/util.py +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/python3 - -# Copyright (C) 2012-2015 ASTRON (Netherlands Institute for Radio Astronomy) -# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands -# -# This file is part of the LOFAR software suite. -# The LOFAR software suite is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# The LOFAR software suite is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. - -# -# This module contains functions copied from the LOFAR PyCommon package, -# to allow their use without a full-blown LOFAR software stack installation. -# todo: We should probably factor out PyCommon to an independent package -# that we can use here and elsewhere. -# - -from configparser import ConfigParser, NoSectionError, DuplicateSectionError -from datetime import datetime - -from glob import glob -import os -from optparse import OptionGroup -from os import stat, path, chmod -import logging - -logger = logging.getLogger(__name__) - -def parseDatetime(date_time: str) -> datetime: - """ Parse the datetime format used in LOFAR parsets. """ - return datetime.strptime(date_time, ('%Y-%m-%d %H:%M:%S.%f' if '.' in date_time else '%Y-%m-%d %H:%M:%S')) - - -def dict_search_and_replace(d: dict, key, value): - '''perform an in-place search-and-replace to replace all items for the given key by the given value''' - if key in d: - d[key] = value - - # recurse over nested items. - for k in d: - if isinstance(d[k], dict): - dict_search_and_replace(d[k], key, value) - elif isinstance(d[k], list): - for i in d[k]: - if isinstance(i, dict): - dict_search_and_replace(i, key, value) - diff --git a/requirements.txt b/requirements.txt index 1c52df1aedae203251e594ccfcebeb781df303ae..5467d866d98c4dddc7a0f8c3e1bc21cff55cf6e5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,7 @@ -importlib-metadata>=0.12, <5.0;python_version<"3.8" +# ../pycommon # install from relative folder +# tmss-pycommon@git+https://git.astron.nl/tmss/libraries/pycommon@branch/commithash #install branch from url +tmss-pycommon >= 1.0 # GPLv3 pip index: https://git.astron.nl/api/v4/projects/744/packages/pypi/simple +tmss-pymessaging >= 1.0 # GPLv3 pip index: https://git.astron.nl/api/v4/projects/745/packages/pypi/simple urllib3 dateutils requests \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index db44453b8eff194308e10a6134fbde84c12e941a..c10e6410406f11658dd1f4b8807f382c5350523b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,64 +1,60 @@ [metadata] name = lofar_tmss_client -description = An example package for CI/CD working group +description = A package for interacting with TMSS (Telescope Manager Specification System). long_description = file: README.md long_description_content_type = text/markdown -url = https://git.astron.nl/ro/lofar_tmss_client -license = Apache License 2.0 +url = https://git.astron.nl/tmss/lofar_tmss_client +license = GNU General Public License v3.0 classifiers = - Development Status :: 3 - Alpha - Environment :: Web Environment + Development Status :: 5 - Production/Stable Intended Audience :: Developers Intended Audience :: Science/Research - License :: OSI Approved :: Apache Software License + License :: OSI Approved :: GPL-3.0-only Operating System :: OS Independent Programming Language :: Python Programming Language :: Python :: 3 Programming Language :: Python :: 3 :: Only - Programming Language :: Python :: 3.8 - Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 Programming Language :: Python :: 3.11 Programming Language :: Python :: 3.12 - Topic :: Internet :: WWW/HTTP - Topic :: Internet :: WWW/HTTP :: Dynamic Content + Programming Language :: Python :: 3.13 Topic :: Scientific/Engineering Topic :: Scientific/Engineering :: Astronomy [options] include_package_data = true packages = find: -python_requires = >=3.7 +python_requires = >=3.10 install_requires = file: requirements.txt [options.entry_points] console_scripts = - tmss_set_subtask_state = lofar_tmss_client.mains:main_set_subtask_state - tmss_get_subtask_parset = lofar_tmss_client.mains:main_get_subtask_parset - tmss_get_subtask_json = lofar_tmss_client.mains:main_get_subtask_json - tmss_get_subtask = lofar_tmss_client.mains:main_get_subtask - tmss_get_subtasks = lofar_tmss_client.mains:main_get_subtasks - tmss_get_subtask_predecessors = lofar_tmss_client.mains:main_get_subtask_predecessors - tmss_get_subtask_successors = lofar_tmss_client.mains:main_get_subtask_successors - tmss_schedule_subtask = lofar_tmss_client.mains:main_schedule_subtask - tmss_unschedule_subtask = lofar_tmss_client.mains:main_unschedule_subtask - tmss_cancel_subtask = lofar_tmss_client.mains:main_cancel_subtask - tmss_mark_subtask_as_obsolete = lofar_tmss_client.mains:main_mark_subtask_as_obsolete - tmss_get_setting = lofar_tmss_client.mains:main_get_setting - tmss_set_setting = lofar_tmss_client.mains:main_set_setting - tmss_submit_trigger = lofar_tmss_client.mains:main_submit_trigger - tmss_remove_stations_from_scheduling_unit_blueprint = lofar_tmss_client.mains:main_create_scheduling_unit_blueprint_copy_without_given_stations - tmss_wait_for_subtask_state = lofar_tmss_client.mains:main_wait_for_subtask_state - tmss_get_subtask_l2stationspecs = lofar_tmss_client.mains:main_get_subtask_l2stationspecs - tmss_mark_scheduling_unit_dynamically_scheduled = lofar_tmss_client.mains:main_mark_scheduling_unit_dynamically_scheduled - tmss_mark_scheduling_unit_fixed_time_scheduled_at_scheduled_starttime = lofar_tmss_client.mains:main_mark_scheduling_unit_fixed_time_scheduled_at_scheduled_starttime - tmss_schedule_scheduling_unit_at_given_starttime = lofar_tmss_client.mains:main_schedule_scheduling_unit_at_given_starttime - tmss_unschedule_scheduling_unit = lofar_tmss_client.mains:main_unschedule_scheduling_unit - tmss_create_and_process_feedback_for_subtask_from_specification_and_set_to_finished = lofar_tmss_client.mains:main_create_and_process_feedback_for_subtask_from_specification_and_set_to_finished - tmss_reset_schedule = lofar_tmss_client.mains:main_reset_schedule - tmss_create_lofar2_sibling = lofar_tmss_client.mains:main_create_lofar2_sibling - tmss_adapt_scheduling_unit_draft_to_start_and_stop_times = lofar_tmss_client.mains:main_adapt_scheduling_unit_draft_to_start_and_stop_times - tmss_adapt_scheduling_unit_blueprint_to_start_and_stop_times = lofar_tmss_client.mains:main_adapt_scheduling_unit_blueprint_to_start_and_stop_times + tmss_set_subtask_state = lofar_tmss_client.set_subtask_state:main + tmss_get_subtask_parset = lofar_tmss_client.get_subtask_parset:main + tmss_get_subtask_json = lofar_tmss_client.get_subtask_json:main + tmss_get_subtask = lofar_tmss_client.get_subtask:main + tmss_get_subtasks = lofar_tmss_client.get_subtasks:main + tmss_get_subtask_predecessors = lofar_tmss_client.get_subtask_predecessors:main + tmss_get_subtask_successors = lofar_tmss_client.get_subtask_successors:main + tmss_schedule_subtask = lofar_tmss_client.schedule_subtask:main + tmss_unschedule_subtask = lofar_tmss_client.unschedule_subtask:main + tmss_cancel_subtask = lofar_tmss_client.cancel_subtask:main + tmss_mark_subtask_as_obsolete = lofar_tmss_client.mark_subtask_as_obsolete:main + tmss_get_setting = lofar_tmss_client.get_setting:main + tmss_set_setting = lofar_tmss_client.set_setting:main + tmss_submit_trigger = lofar_tmss_client.submit_trigger:main + tmss_remove_stations_from_scheduling_unit_blueprint = lofar_tmss_client.create_scheduling_unit_blueprint_copy_without_given_stations:main + tmss_wait_for_subtask_state = lofar_tmss_client.wait_for_subtask_state:main + tmss_get_subtask_l2stationspecs = lofar_tmss_client.get_subtask_l2stationspecs:main + tmss_mark_scheduling_unit_dynamically_scheduled = lofar_tmss_client.mark_scheduling_unit_dynamically_scheduled:main + tmss_mark_scheduling_unit_fixed_time_scheduled_at_scheduled_starttime = lofar_tmss_client.mark_scheduling_unit_fixed_time_scheduled_at_scheduled_starttime:main + tmss_schedule_scheduling_unit_at_given_starttime = lofar_tmss_client.schedule_scheduling_unit_at_given_starttime:main + tmss_unschedule_scheduling_unit = lofar_tmss_client.unschedule_scheduling_unit:main + tmss_create_and_process_feedback_for_subtask_from_specification_and_set_to_finished = lofar_tmss_client.create_and_process_feedback_for_subtask_from_specification_and_set_to_finished:main + tmss_reset_schedule = lofar_tmss_client.reset_schedule:main + tmss_create_lofar2_sibling = lofar_tmss_client.create_lofar2_sibling:main + tmss_adapt_scheduling_unit_draft_to_start_and_stop_times = lofar_tmss_client.adapt_scheduling_unit_draft_to_start_and_stop_times:main + tmss_adapt_scheduling_unit_blueprint_to_start_and_stop_times = lofar_tmss_client.adapt_scheduling_unit_blueprint_to_start_and_stop_times:main [flake8] max-line-length = 88 diff --git a/tox.ini b/tox.ini index 2879c3009147b0e16c93e0615ad05748886feba5..bb70b8db9ec322fa4a2271000e1673a679cb2e56 100644 --- a/tox.ini +++ b/tox.ini @@ -1,17 +1,17 @@ [tox] # Generative environment list to test all supported Python versions -envlist = py3{8,9,10,11,12},black,pep8,pylint -minversion = 3.18.0 +envlist = py3{10,11,12,13},black,pep8,pylint +min_version = 4.3.3 +requires = + tox-ignore-env-name-mismatch >= 0.2.0 [testenv] usedevelop = True package = wheel wheel_build_env = .pkg - setenv = - LANGUAGE=en_US - LC_ALL=en_US.UTF-8 PYTHONWARNINGS=default::DeprecationWarning + PIP_EXTRA_INDEX_URL=https://git.astron.nl/api/v4/projects/744/packages/pypi/simple https://git.astron.nl/api/v4/projects/745/packages/pypi/simple deps = -r{toxinidir}/requirements.txt -r{toxinidir}/tests/requirements.txt @@ -28,28 +28,19 @@ commands = # for all linting jobs. [testenv:{pep8,black,pylint,format}] usedevelop = False +package = editable envdir = {toxworkdir}/linting commands = pep8: {envpython} -m flake8 --version - pep8: {envpython} -m flake8 lofar_tmss_client tests + pep8: {envpython} -m flake8 lofar_tmss_client tests integration_tests black: {envpython} -m black --version - black: {envpython} -m black --check --diff lofar_tmss_client tests + black: {envpython} -m black --check --diff lofar_tmss_client tests integration_tests pylint: {envpython} -m pylint --version pylint: {envpython} -m pylint lofar_tmss_client tests format: {envpython} -m autopep8 -v -aa --in-place --recursive lofar_tmss_client format: {envpython} -m autopep8 -v -aa --in-place --recursive tests - format: {envpython} -m black -v lofar_tmss_client tests - -[testenv:docs] -; unset LC_ALL / LANGUAGE from testenv, would fail sphinx otherwise -setenv = -deps = - -r{toxinidir}/requirements.txt - -r{toxinidir}/docs/requirements.txt -changedir = {toxinidir} -commands = - {envpython} docs/cleanup.py - sphinx-build -b html docs/source docs/build/html + format: {envpython} -m autopep8 -v -aa --in-place --recursive integration_tests + format: {envpython} -m black -v lofar_tmss_client tests integration_tests [testenv:build] usedevelop = False