Skip to content

Commit 7abe45c

Browse files
authored
Merge pull request #13 from afonsoc12/develop
Develop
2 parents 04aaa74 + 31984af commit 7abe45c

22 files changed

+835
-497
lines changed

.dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# Project files and folders
2-
.git
32
.github
43
test
54

.github/workflows/deploy_master.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ jobs:
7070
- name: Login to DockerHub
7171
uses: docker/login-action@v1
7272
with:
73+
registry: docker.io
7374
username: ${{ secrets.DOCKER_USERNAME }}
7475
password: ${{ secrets.DOCKER_TOKEN }}
7576
- name: Login to GitHub Container Registry
@@ -85,10 +86,10 @@ jobs:
8586
file: Dockerfile
8687
build-args: |
8788
VERSION=dev-v${{ env.VERSION }}
88-
platforms: linux/amd64,linux/arm64
89+
platforms: linux/amd64,linux/arm64,linux/arm
8990
push: true
9091
tags: |
9192
afonsoc12/firefly-cli:dev-latest
92-
afonsoc12/firefly-cli:dev-v${{ env.VERSION }}
93+
afonsoc12/firefly-cli:dev-${{ env.VERSION }}
9394
ghcr.io/afonsoc12/firefly-cli:dev-latest
94-
ghcr.io/afonsoc12/firefly-cli:dev-v${{ env.VERSION }}
95+
ghcr.io/afonsoc12/firefly-cli:dev-${{ env.VERSION }}

.github/workflows/deploy_releases.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ jobs:
6262
- name: Login to DockerHub
6363
uses: docker/login-action@v1
6464
with:
65+
registry: docker.io
6566
username: ${{ secrets.DOCKER_USERNAME }}
6667
password: ${{ secrets.DOCKER_TOKEN }}
6768
- name: Login to GitHub Container Registry
@@ -78,10 +79,10 @@ jobs:
7879
build-args: |
7980
VERSION=${{ env.VERSION }}
8081
no-cache: true
81-
platforms: linux/amd64,linux/arm64
82+
platforms: linux/amd64,linux/arm64,linux/arm
8283
push: true
8384
tags: |
8485
afonsoc12/firefly-cli:latest
85-
afonsoc12/firefly-cli:v${{ env.VERSION }}
86+
afonsoc12/firefly-cli:${{ env.VERSION }}
8687
ghcr.io/afonsoc12/firefly-cli:latest
87-
ghcr.io/afonsoc12/firefly-cli:v${{ env.VERSION }}
88+
ghcr.io/afonsoc12/firefly-cli:${{ env.VERSION }}

Dockerfile

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,47 @@
1-
FROM python:3.8-alpine
1+
ARG DOCKER_IMAGE=python:3.9-alpine \
2+
USER=nonroot \
3+
GROUP=nonroot \
4+
UID=1234 \
5+
GID=4321
26

3-
LABEL maintainer="Afonso Costa (@afonsoc12)"
7+
# Install image
8+
FROM $DOCKER_IMAGE AS install-image
49

5-
ARG VERSION="n/a"
6-
ENV XDG_CONFIG_HOME=/config
7-
ENV TZ=Europe/Lisbon
8-
9-
LABEL VERSION=${VERSION}
10-
11-
WORKDIR /src
10+
WORKDIR /app
1211

1312
COPY . .
1413

15-
RUN apk update && \
16-
apk add tzdata && \
17-
echo -e "def get_versions():\n return {'version': '${VERSION}', 'full-revisionid': 'n/a', 'date': 'n/a', 'dirty': 'n/a', 'error': 'n/a'}" \
18-
> firefly_cli/_version.py && \
19-
pip install --upgrade pip && \
20-
pip install .
14+
RUN apk add --no-cache tzdata git \
15+
&& pip install --no-cache-dir --upgrade pip \
16+
&& pip install --user --no-cache-dir .
17+
18+
# Runtime image
19+
FROM $DOCKER_IMAGE AS runtime-image
20+
21+
ARG USER \
22+
GROUP \
23+
UID \
24+
GID
25+
26+
ENV PATH="/home/.local/bin:$PATH" \
27+
XDG_CONFIG_HOME=/config \
28+
PYTHONDONTWRITEBYTECODE=1 \
29+
PYTHONUNBUFFERED=1
30+
31+
RUN mkdir -p /home $XDG_CONFIG_HOME \
32+
&& addgroup --gid $GID $GROUP \
33+
&& adduser -D -H --gecos "" \
34+
--home "/home" \
35+
--ingroup "$GROUP" \
36+
--uid "$UID" \
37+
"$USER" \
38+
&& chown -R $USER:$GROUP /home $XDG_CONFIG_HOME \
39+
&& rm -rf /tmp/* /var/{cache,log}/* /var/lib/apt/lists/*
40+
41+
USER nonroot
42+
WORKDIR /home
43+
44+
COPY --from=install-image --chown=$USER:$GROUP /root/.local /home/.local
2145

2246
VOLUME /config
2347

README.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<img src="https://www.firefly-iii.org/assets/logo/color.png" width="150">
22

33
# Firefly III Command Line Interface
4+
[![Docker Pulls](https://img.shields.io/docker/pulls/afonsoc12/firefly-cli?logo=docker)](https://hub.docker.com/repository/docker/afonsoc12/firefly-cli)
45
[![PyPi Version](https://img.shields.io/pypi/v/firefly-cli.svg)](https://pypi.org/project/firefly-cli/)
5-
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
6-
<!-- [![Docker Pulls](https://img.shields.io/docker/pulls/afonsoc12/firefly-cli?logo=docker)](https://hub.docker.com/repository/docker/afonsoc12/firefly-cli) -->
76

8-
[![Github Starts](https://img.shields.io/github/stars/afonsoc12/firefly-cli?logo=github)](https://github.com/afonsoc12/firefly-cli)
9-
[![Github Fork](https://img.shields.io/github/forks/afonsoc12/firefly-cli?logo=github)](https://github.com/afonsoc12/firefly-cli)
107
[![Github Release](https://img.shields.io/github/v/release/afonsoc12/firefly-cli?logo=github)](https://github.com/afonsoc12/firefly-cli/releases)
8+
[![Github Stars](https://img.shields.io/github/stars/afonsoc12/firefly-cli?logo=github)](https://github.com/afonsoc12/firefly-cli)
9+
[![Github Fork](https://img.shields.io/github/forks/afonsoc12/firefly-cli?logo=github)](https://github.com/afonsoc12/firefly-cli)
1110

11+
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
1212
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
1313

1414
A python-based command line interface for conveniently entering expenses in [Firefly III](https://www.firefly-iii.org).
@@ -27,21 +27,23 @@ firefly-cli
2727
```
2828

2929
## 2. Docker Image
30-
Currently, there are images for both `x86-64` and `arm64` architectures.
30+
Currently, there are images for `x86-64`, `arm64` and `arm/v7` architectures.
3131

32-
They are built from python's Linux Alpine base image (`python:3.7-alpine`) which makes the application very slim (less than 20MB).
32+
They are built from python's Linux Alpine base image (`python:3.9-alpine`) which makes the application very slim (less than 20MB).
3333

3434
| Architecture<br>[![Docker Image Size](https://img.shields.io/docker/image-size/afonsoc12/firefly-cli/latest?logo=docker)](https://hub.docker.com/repository/docker/afonsoc12/firefly-cli/tags?page=1&ordering=last_updated&name=latest) | Tag<br>[![Docker Dev Version](https://img.shields.io/docker/v/afonsoc12/firefly-cli/latest?logo=docker)](https://hub.docker.com/repository/docker/afonsoc12/firefly-cli/tags?page=1&ordering=last_updated&name=latest) |
35-
|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
36-
| x86-64 | latest |
37-
| arm64 | latest |
35+
|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
36+
| x86-64 | latest |
37+
| arm64 | latest |
38+
| arm/v7 | latest |
3839

3940
There are also development images with the latest on master branch:
4041

4142
| Architecture<br>[![Docker Image Size](https://img.shields.io/docker/image-size/afonsoc12/firefly-cli/latest?logo=docker)](https://hub.docker.com/repository/docker/afonsoc12/firefly-cli/tags?page=1&ordering=last_updated&name=dev-latest) | Tag<br>[![Docker Dev Version](https://img.shields.io/docker/v/afonsoc12/firefly-cli/dev-latest?logo=docker)](https://hub.docker.com/repository/docker/afonsoc12/firefly-cli/tags?page=1&ordering=last_updated&name=dev-latest) |
4243
|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
4344
| x86-64 | dev-latest |
4445
| arm64 | dev-latest |
46+
| arm/v7 | dev-latest |
4547

4648
Getting started with firefly-cli Docker:
4749
```shell
@@ -98,13 +100,13 @@ python -m firefly_cli
98100
The CLI has two modes of operation:
99101

100102
1. In one-line command style:
101-
103+
102104
```shell
103105
$ firefly-cli add 5.2, Large Mocha, Cash, Starbucks
104106
```
105-
107+
106108
2. Command Line Interface:
107-
109+
108110
```bash
109111
$ firefly-cli
110112

@@ -162,9 +164,9 @@ api_token = eyXXX
162164
firefly-cli can override this behaviour and read/write from the file specified by the environment variable `FIREFLY_CLI_CONFIG`.
163165

164166
# Commands
165-
The scope of this CLI is to enter expenses in a comma-separated style.
167+
The scope of this CLI is to enter expenses in a comma-separated style.
166168

167-
Starting in **[v0.1.0](https://github.com/afonsoc12/firefly-cli/releases/tag/v0.1.0)**, it now supports adding all possible transaction fields using optional arguments (e.g. `--source-name "Bank HSBC"`).
169+
Starting in **[v0.1.0](https://github.com/afonsoc12/firefly-cli/releases/tag/v0.1.0)**, it now supports adding all possible transaction fields using optional arguments (e.g. `--source-name "Bank HSBC"`).
168170
The comma-separated arguments (aka positional arguments) are maintained for backwards-compatibility, but optional arguments will **always** override the comma-separated ones
169171

170172
Summary of the available commands:
@@ -185,7 +187,7 @@ Summary of the available commands:
185187
## Adding a transaction
186188
The command `add` is responsible for entering a new transaction in your Firefly instance. Further help can be shown by typing `add --help` or `help add`.
187189

188-
By default, every transaction is a **withdrawal** and is placed with the current date and time.
190+
By default, every transaction is a **withdrawal** and is placed with the current date and time.
189191
You may change transaction type by including the optional argument `--type`, change the transaction date with `--date yyyy-mm-dd` or if you would like to be more precise `--datetime yyyy-mm-ddTHH:MM:SS`.
190192

191193
The comma-separated fields available are the following:

docker-compose-dev.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ services:
2828
- MYSQL_USER=firefly
2929
- MYSQL_PASSWORD=firefly
3030
- MYSQL_DATABASE=firefly
31+
- TZ=Europe/London
3132
ports:
3233
- 3306:3306

firefly_cli/__init__.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,23 @@
22

33
from firefly_cli._version import get_versions
44
from firefly_cli.cli import FireflyPrompt
5+
from firefly_cli.parser import Parser
56

67
__version__ = get_versions()["version"]
78

89

910
def _real_main():
1011

1112
if len(sys.argv) > 1:
13+
args, ffargs = Parser.entrypoint().parse_known_args()
14+
1215
try:
13-
FireflyPrompt().onecmd(" ".join(sys.argv[1:]))
16+
if args.version:
17+
FireflyPrompt().onecmd("version")
18+
elif args.help:
19+
FireflyPrompt().onecmd("help")
20+
else:
21+
FireflyPrompt().onecmd(" ".join(ffargs))
1422
except Exception:
1523
raise
1624
else:
@@ -24,5 +32,5 @@ def main():
2432
print("\nInterrupted by user")
2533
except:
2634
# Silence raising exceptions
27-
pass
28-
35+
raise
36+
# pass

firefly_cli/__main__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@
1616

1717
if __name__ == "__main__":
1818
import firefly_cli
19+
1920
firefly_cli.main()

firefly_cli/_version.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
# that just contains the computed version number.
66

77
# This file is released into the public domain. Generated by
8-
# versioneer-0.21 (https://github.com/python-versioneer/python-versioneer)
8+
# versioneer-0.22 (https://github.com/python-versioneer/python-versioneer)
99

1010
"""Git implementation of _version.py."""
1111

1212
import errno
13+
import functools
1314
import os
1415
import re
1516
import subprocess
@@ -73,6 +74,14 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=
7374
"""Call the given command(s)."""
7475
assert isinstance(commands, list)
7576
process = None
77+
78+
popen_kwargs = {}
79+
if sys.platform == "win32":
80+
# This hides the console window if pythonw.exe is used
81+
startupinfo = subprocess.STARTUPINFO()
82+
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
83+
popen_kwargs["startupinfo"] = startupinfo
84+
7685
for command in commands:
7786
try:
7887
dispcmd = str([command] + args)
@@ -83,6 +92,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=
8392
env=env,
8493
stdout=subprocess.PIPE,
8594
stderr=(subprocess.PIPE if hide_stderr else None),
95+
**popen_kwargs
8696
)
8797
break
8898
except OSError:
@@ -244,30 +254,29 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
244254
version string, meaning we're inside a checked out source tree.
245255
"""
246256
GITS = ["git"]
247-
TAG_PREFIX_REGEX = "*"
248257
if sys.platform == "win32":
249258
GITS = ["git.cmd", "git.exe"]
250-
TAG_PREFIX_REGEX = r"\*"
259+
260+
# GIT_DIR can interfere with correct operation of Versioneer.
261+
# It may be intended to be passed to the Versioneer-versioned project,
262+
# but that should not change where we get our version from.
263+
env = os.environ.copy()
264+
env.pop("GIT_DIR", None)
265+
runner = functools.partial(runner, env=env)
251266

252267
_, rc = runner(GITS, ["rev-parse", "--git-dir"], cwd=root, hide_stderr=True)
253268
if rc != 0:
254269
if verbose:
255270
print("Directory %s not under git control" % root)
256271
raise NotThisMethod("'git rev-parse --git-dir' returned error")
257272

273+
MATCH_ARGS = ["--match", "%s*" % tag_prefix] if tag_prefix else []
274+
258275
# if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
259276
# if there isn't one, this yields HEX[-dirty] (no NUM)
260277
describe_out, rc = runner(
261278
GITS,
262-
[
263-
"describe",
264-
"--tags",
265-
"--dirty",
266-
"--always",
267-
"--long",
268-
"--match",
269-
"%s%s" % (tag_prefix, TAG_PREFIX_REGEX),
270-
],
279+
["describe", "--tags", "--dirty", "--always", "--long", *MATCH_ARGS],
271280
cwd=root,
272281
)
273282
# --long was added in git-1.5.5

0 commit comments

Comments
 (0)