From bc3ca14bb6512ed7511a9170ea98056aed403cbf Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Sun, 29 Jan 2023 20:41:38 +0100 Subject: [PATCH 01/22] [REPO] Add plugin inventree-brother-plugin (#113) * Add cups plugin * REPO] Add plugin inventree-brother-plugin * fix format * update listing * update ref * fix olivers short name * fix reference * clean up description * make website optional * fix tags --- _layouts/plugin.html | 2 ++ _news/2022-11-14-website.md | 2 +- _news/2022-12-12-0.9.0.md | 2 +- _posts/2021-11-22-translation.md | 2 +- _posts/2022-12-12-0.9.0.md | 2 +- _posts/2023-01-02-upcoming.md | 2 +- _publishers/schrodingersgat.md | 2 +- _repo/inventree-brother-plugin.md | 36 +++++++++++++++++++++++++++++++ 8 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 _repo/inventree-brother-plugin.md diff --git a/_layouts/plugin.html b/_layouts/plugin.html index 3edf81f6..322d7290 100644 --- a/_layouts/plugin.html +++ b/_layouts/plugin.html @@ -27,12 +27,14 @@ fullwith: true {% if page.pypi and page.package_name %}Package on PyPI:
{{ page.package_name }}
{% endif %}

+ {% if page.website %}

{{ page.website }}

+ {% endif %} {% if page.issue_tracker %} diff --git a/_news/2022-11-14-website.md b/_news/2022-11-14-website.md index 8086aec2..62b7d069 100644 --- a/_news/2022-11-14-website.md +++ b/_news/2022-11-14-website.md @@ -1,5 +1,5 @@ --- -author: oliver +author: schrodingersgat title: New Website --- diff --git a/_news/2022-12-12-0.9.0.md b/_news/2022-12-12-0.9.0.md index ad80894e..637f8bd7 100644 --- a/_news/2022-12-12-0.9.0.md +++ b/_news/2022-12-12-0.9.0.md @@ -1,5 +1,5 @@ --- -author: oliver +author: schrodingersgat title: 0.9.0 Release --- diff --git a/_posts/2021-11-22-translation.md b/_posts/2021-11-22-translation.md index 6e305bcd..754e7216 100644 --- a/_posts/2021-11-22-translation.md +++ b/_posts/2021-11-22-translation.md @@ -1,5 +1,5 @@ --- -author: oliver +author: schrodingersgat title: Translating InvenTree --- diff --git a/_posts/2022-12-12-0.9.0.md b/_posts/2022-12-12-0.9.0.md index 39b6749f..61f73274 100644 --- a/_posts/2022-12-12-0.9.0.md +++ b/_posts/2022-12-12-0.9.0.md @@ -1,5 +1,5 @@ --- -author: oliver +author: schrodingersgat title: 0.9.0 Stable Release --- diff --git a/_posts/2023-01-02-upcoming.md b/_posts/2023-01-02-upcoming.md index 9b6ca2e2..6b49cf4d 100644 --- a/_posts/2023-01-02-upcoming.md +++ b/_posts/2023-01-02-upcoming.md @@ -1,5 +1,5 @@ --- -author: oliver +author: schrodingersgat title: 2022 in Review --- diff --git a/_publishers/schrodingersgat.md b/_publishers/schrodingersgat.md index 3b503aa7..e2ea2e67 100644 --- a/_publishers/schrodingersgat.md +++ b/_publishers/schrodingersgat.md @@ -1,5 +1,5 @@ --- -short_name: oliver +short_name: schrodingersgat name: Oliver github: SchrodingersGat website: https://inventree.org diff --git a/_repo/inventree-brother-plugin.md b/_repo/inventree-brother-plugin.md new file mode 100644 index 00000000..44b8e3af --- /dev/null +++ b/_repo/inventree-brother-plugin.md @@ -0,0 +1,36 @@ +--- +name: inventree-brother-plugin +author: schrodingersgat +license: MIT +open_source: true +stable: False +maintained: true +pypi: true +package_name: inventree-brother-plugin +github: https://github.com/inventree/inventree-brother-plugin +gitlab: +source: +issue_tracker: +website: +categories: Printer +tags: Label Printer Brother +--- +Brother label printer plugin for InvenTree + +A label printing plugin for [InvenTree](https://inventree.org), which provides support for the [Brother label printers](https://www.brother.com.au/en/products/all-labellers/labellers). + +This plugin supports printing to *some* Brother label printers with network (wired or WiFi) support. Refer to the [brother_ql docs](https://github.com/pklaus/brother_ql/blob/master/brother_ql/models.py) for a list of label printers which are directly supported. + +## Installation + +Install this plugin manually as follows: + +``` +pip install inventree-brother-plugin +``` + +Or, add to your `plugins.txt` file to install automatically using the `invoke install` command: + +``` +inventree-brother-plugin +``` From 007f04f9e9921b71ef230e083d5f0fd587ceba79 Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Sun, 29 Jan 2023 20:44:57 +0100 Subject: [PATCH 02/22] Add plugin workflow (#114) * Add cups plugin * Add workflow to add plugins --- .github/collect_plugin.py | 67 ++++++++++++++++++++++++++++ .github/workflows/collect_plugin.yml | 41 +++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 .github/collect_plugin.py create mode 100644 .github/workflows/collect_plugin.yml diff --git a/.github/collect_plugin.py b/.github/collect_plugin.py new file mode 100644 index 00000000..33103b79 --- /dev/null +++ b/.github/collect_plugin.py @@ -0,0 +1,67 @@ +import json +import os +from pathlib import Path +from urllib.request import urlopen, Request + +inp_project = os.environ.get('PROJECT') +inp_author = os.environ.get('AUTHOR') +file_name = Path(f'_repo/{inp_project}.md') +crowdin_projet_id = 452300 + + +def get_data(url, key=None, default=0, auth=None): + """Fetches data from remote endpoint""" + httprequest = Request(url, headers={"Accept": "application/json"}) + + if auth: + httprequest.add_header("Authorization", f"Bearer {auth}") + + with urlopen(httprequest) as response: + data = response.read().decode() + data = json.loads(data) + + if key: + data = data.get(key, default) + + return data + +pypi_data = get_data(f'https://pypi.org/pypi/{inp_project}/json') + +name = pypi_data['info']['name'] +tagline = pypi_data['info']['summary'] +author = inp_author or pypi_data['info']['author_email'] +license = pypi_data['info']['license'] +try: + version = pypi_data['info']['version'] + stable = int(version.split('.')[0])>1 +except: + stable = False +bugtracker = pypi_data['info']['bugtrack_url'] or pypi_data['info']['project_urls'].get('Bug Tracker') or '' +homepage = pypi_data['info']['home_page'] or pypi_data['info']['project_urls'].get('Homepage') +keywords = pypi_data['info']['keywords'] +readme = pypi_data['info']['description'] + +# Write data +file_name.write_text( +f"""--- +name: {name} +author: {author} +license: {license} +open_source: true +stable: {stable} +maintained: true +pypi: true +package_name: {name} +github: {homepage} +gitlab: +source: +issue_tracker:{bugtracker} +website: +categories: +tags: {keywords} +--- +{tagline} + +{readme} +""" +) diff --git a/.github/workflows/collect_plugin.yml b/.github/workflows/collect_plugin.yml new file mode 100644 index 00000000..4060083f --- /dev/null +++ b/.github/workflows/collect_plugin.yml @@ -0,0 +1,41 @@ +name: Collect plugin by PyPI listing + +on: + workflow_dispatch: + inputs: + project: + description: The name of the project on PyPi + required: true + author: + description: Enter the name of the author if you know it + +jobs: + build: + + runs-on: ubuntu-latest + permissions: {} + steps: + - uses: actions/checkout@v2 + with: + token: ${{ secrets.BOT_PAT }} + - name: Get Plugin file + run: python .github/collect_plugin.py + env: + PROJECT: ${{ github.event.inputs.project }} + AUTHOR: ${{ github.event.inputs.author }} + - name: Create Pull Request + uses: peter-evans/create-pull-request@v4 + with: + commit-message: "[REPO] Add plugin ${{ github.event.inputs.project }}" + branch: "plugin/${{ github.event.inputs.project }}" + title: "[REPO] Add plugin ${{ github.event.inputs.project }}" + body: | + Automated PR to add the plugin ${{ github.event.inputs.project }}. + You need to check this manually! + labels: | + plugin + assignees: | + matmair + ${{ github.event.inputs.author }} + reviewers: | + matmair From 311c0904fafbdb74d0699e926ea2a54b8f717cf6 Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Sun, 29 Jan 2023 21:18:40 +0100 Subject: [PATCH 03/22] Fix action ref (#115) * add debug line * add token * remove old token ref * move permission section * clean inputs --- .github/collect_plugin.py | 5 +++-- .github/workflows/collect_plugin.yml | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/collect_plugin.py b/.github/collect_plugin.py index 33103b79..3e9122a6 100644 --- a/.github/collect_plugin.py +++ b/.github/collect_plugin.py @@ -3,11 +3,12 @@ import os from pathlib import Path from urllib.request import urlopen, Request -inp_project = os.environ.get('PROJECT') -inp_author = os.environ.get('AUTHOR') +inp_project = os.environ.get('PROJECT').strip() +inp_author = os.environ.get('AUTHOR').strip() file_name = Path(f'_repo/{inp_project}.md') crowdin_projet_id = 452300 +print(f'Collecting {inp_project} with {inp_author}...') def get_data(url, key=None, default=0, auth=None): """Fetches data from remote endpoint""" diff --git a/.github/workflows/collect_plugin.yml b/.github/workflows/collect_plugin.yml index 4060083f..5fdc7390 100644 --- a/.github/workflows/collect_plugin.yml +++ b/.github/workflows/collect_plugin.yml @@ -13,11 +13,11 @@ jobs: build: runs-on: ubuntu-latest - permissions: {} + permissions: + contents: write + pull-requests: write steps: - uses: actions/checkout@v2 - with: - token: ${{ secrets.BOT_PAT }} - name: Get Plugin file run: python .github/collect_plugin.py env: @@ -26,6 +26,7 @@ jobs: - name: Create Pull Request uses: peter-evans/create-pull-request@v4 with: + token: ${{ secrets.GITHUB_TOKEN }} commit-message: "[REPO] Add plugin ${{ github.event.inputs.project }}" branch: "plugin/${{ github.event.inputs.project }}" title: "[REPO] Add plugin ${{ github.event.inputs.project }}" From ed744083fe3d83b0a03ea950aa7abbebfa5ff3f6 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 29 Jan 2023 21:28:37 +0100 Subject: [PATCH 04/22] [REPO] Add plugin inventree-zapier (#116) * [REPO] Add plugin inventree-zapier * Update ref --------- Co-authored-by: matmair Co-authored-by: Matthias Mair --- _repo/inventree-zapier.md | 54 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 _repo/inventree-zapier.md diff --git a/_repo/inventree-zapier.md b/_repo/inventree-zapier.md new file mode 100644 index 00000000..ea648ad9 --- /dev/null +++ b/_repo/inventree-zapier.md @@ -0,0 +1,54 @@ +--- +name: inventree-zapier +author: matmair +license: MIT +open_source: true +stable: False +maintained: true +pypi: true +package_name: inventree-zapier +github: https://github.com/matmair/inventree-zapier +gitlab: +source: +issue_tracker: https://github.com/matmair/inventree-zapier/issues +website: https://mjmair.com +categories: Event +tags: Zapier +--- +Integrate Zapier into InvenTree + +## Setup + +1. Install +Install this plugin as follows **in the enviroment of your InvenTree instance**: + +```bash +pip install inventree-zapier +``` + +Or, add to your `plugins.txt` file: + +```txt +inventree-zapier +``` + +2. Enable +Enable the plugin in the plugin settings. You need to be signed in as a superuser for this. +**The server will erstart if you enable the plugin** + +3. Migrate +Access your instances python enviroment and run + +```bash +inv migrate +``` + +4. Configure +Create an API-token in the admin interface and add set up the zapier integration in Zapier.com itself. + +## License +This project is licensed as MIT. Copy and do what you want - maybe tag your new plugin so others can find it. The more the merrier. + +## State of the Code +This is currently a PoC / 'beta' - at least till the Zapier App is published. Please feel free to file FRs, issues or just ideas. + From b8d7f0e258bbb53beac95b03fde97f3923268cbb Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Sun, 29 Jan 2023 22:02:39 +0100 Subject: [PATCH 05/22] add more links (#120) --- _repo/inventree-brother-plugin.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_repo/inventree-brother-plugin.md b/_repo/inventree-brother-plugin.md index 44b8e3af..eb37d72f 100644 --- a/_repo/inventree-brother-plugin.md +++ b/_repo/inventree-brother-plugin.md @@ -10,8 +10,8 @@ package_name: inventree-brother-plugin github: https://github.com/inventree/inventree-brother-plugin gitlab: source: -issue_tracker: -website: +issue_tracker: https://github.com/inventree/inventree-brother-plugin/issues +website: https://inventree.org categories: Printer tags: Label Printer Brother --- From 2b468b0996ea739ed171e7265315a007ee59fb2d Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Sun, 29 Jan 2023 22:04:25 +0100 Subject: [PATCH 06/22] [REPO] Add inventree-zebra-plugin (#117) * [REPO] Add inventree-zebra-plugin * Add SergeoLacruz to publishers * update readme --- _publishers/SergeoLacruz.md | 6 ++ _repo/inventree-zebra-plugin.md | 153 ++++++++++++++++++++++++++++++++ 2 files changed, 159 insertions(+) create mode 100644 _publishers/SergeoLacruz.md create mode 100644 _repo/inventree-zebra-plugin.md diff --git a/_publishers/SergeoLacruz.md b/_publishers/SergeoLacruz.md new file mode 100644 index 00000000..d102fa0c --- /dev/null +++ b/_publishers/SergeoLacruz.md @@ -0,0 +1,6 @@ +--- +short_name: SergeoLacruz +name: Michael +github: SergeoLacruz +website: +--- diff --git a/_repo/inventree-zebra-plugin.md b/_repo/inventree-zebra-plugin.md new file mode 100644 index 00000000..8a15e873 --- /dev/null +++ b/_repo/inventree-zebra-plugin.md @@ -0,0 +1,153 @@ +--- +name: inventree-zebra-plugin +author: SergeoLacruz +license: MIT +open_source: true +stable: true +maintained: true +pypi: false +package_name: +github: https://github.com/SergeoLacruz/inventree-zebra-plugin +gitlab: +source: +issue_tracker: https://github.com/SergeoLacruz/inventree-zebra-plugin/issues +website: +categories: Printer +tags: Label Printer Zebra ZPL +--- +Zebra Label Printer Plugin for Inventree + +This is a label printing plugin for [InvenTree](https://inventree.org), which provides support for Zebra Label printers . +It supports printing to just GK420T with one label size (50x30) so far. So it is very simple. It uses the zpl library to +convert the png data provided by InvenTree to Zebras bitmap format. + +It can output the print data either to a local printer connected to the computer via USB or to a network printer +with an IP address. The output can be configured in the InvenTree plugin user interface. So the source code is +a good example for this. + +Error handling is very basic. + +## Installation + +Install this plugin using pip with the following command:: + +``` +pip install git+https://github.com/SergeoLacruz/inventree-zebra-plugin +``` + +## Configuration Options +### Printer Interface +Here you can chose between Local printer or network printer. Default value is a local printer. + +### IP address +In case you use an IP printer set the IPv4 address here. + +### Port +In case you use an IP printer set the port number here. The default port number is 9100. + +### Local Device +In case of a local printer set the device here. The plugin actually puts the data directly to the +device libe /dev/usb/lp0. No printer spooler is involved so far. + +## How it works +First import all the stuff you need. Here we use the translation mechanism from django for multi language support. +The import the InvenTree libs and everything you need for plugin. Here we have zpl for the Zebra bitmaps and socket +for the IP connection to the printer. + +The next part is this: + +```python +class ZebraLabelPlugin(LabelPrintingMixin, SettingsMixin, IntegrationPluginBase): + + AUTHOR = "Michael Buchmann" + DESCRIPTION = "Label printing plugin for Zebra printers" + VERSION = ZEBRA_PLUGIN_VERSION + NAME = "Zebra" + SLUG = "zebra" + TITLE = "Zebra Label Printer" +``` + +The name of the class can be freely chosen. You reference to it in the entry_points section of the setup.py file. +The parameters need to be like in the example. Then there is the description block. The keywords are fixed and +need to be like that. The values are found in the UI as shown in the pictures below. + +![Admin](https://github.com/SergeoLacruz/inventree-zebra-plugin/blob/master/pictures/plugin_admin.png) +![Config](https://github.com/SergeoLacruz/inventree-zebra-plugin/blob/master/pictures/plugin.png) + + +Then we add the configuration parameters. +```python +SETTINGS = { + 'CONNECTION': { + 'name': _('Printer Interface'), + 'description': _('Select local or network printer'), + 'choices': [('local','Local printer e.g. USB'),('network','Network printer with IP address')], + 'default': 'local', + }, + 'PORT': { + 'name': _('Port'), + 'description': _('Network port in case of network printer'), + 'default': '9100', + }, + } + +``` + +We need to define a dict with the name SETTINGS. Please be aware the keys need to be in all CAPITAL letters like CONNECTION. +Simple parameters are just text strings like the port. We can set a default. The name and description shows up in the UI. +Instead of ta simple test we can also use choices. The first string like "local" it the key you use in the code. The second +one is the description in the UI. +After that we need to define a function: + +```python +def print_label(self, **kwargs){ +``` + +The kwargs is a dict with the following keys: + +- pdf_data +- user +- filename +- label_instance +- width +- height +- png_file + +For the Zebra printer we use the png_file. This is a PIL (python Pillow) object with the graphic of the label in PNG format. +The PIL object is a greyscale image. Because the printer can just print pure BW we convert this to a BW picture. + +```python +fn = lambda x : 255 if x > Threshold else 0 +label_image = label_image.convert('L').point(fn, mode='1') +``` + +The threshold can by modified by a plugin parameter. 200 is a good starting value. This trick gives much better prints. +We can put the result this directly into the zpl library. + +```python +l = zpl.Label(50,30,8) +l.origin(0, 0) +l.write_graphic(label_image, 50) +l.endorigin() +``` + +50,30 is the size of the label in millimeters. The third parameter is the resolution of the printer in +dots per mm. As the Zebra printer has 200dpi we put an eight here. write_graphic converts the pillow data +to zpl. 50 is the with of the image in mm. + +The plugin was tested with a label of 50x30 mm defined using css and html in InvenTree as shown below. The DPI scaling +can be chosen in the InvenTree settings. 400 is a good value because it is just double of the printers +resolution. If you save the pillow data to a png file you get a size of 788x473 which fits well to that data. + +``` +