Skip to content

Commit

Permalink
Source divided into smaller parts
Browse files Browse the repository at this point in the history
  • Loading branch information
grzegorz-gutowski committed Mar 7, 2024
1 parent 43742ca commit 4ac90f1
Show file tree
Hide file tree
Showing 16 changed files with 921 additions and 433 deletions.
3 changes: 2 additions & 1 deletion .copr/openvpn3-indicator.spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
]))

SOURCES = [
'openvpn3-indicator',
'src',
'scripts'
'Makefile',
'LICENSE',
'README.md',
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
*.bak
*.swp
__pycache__
/.copr/*.spec
/.copr/*.tar.gz
/.copr/*.rpm
/build
/openvpn3-indicator
3 changes: 2 additions & 1 deletion .launchpad/openvpn3-indicator.control.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@
]

SOURCES = [
'openvpn3-indicator',
'src',
'scripts',
'Makefile',
'LICENSE',
'README.md',
Expand Down
36 changes: 32 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
PROGRAM := openvpn3-indicator
DESTDIR ?=
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
DATADIR ?= $(PREFIX)/share
AUTOSTART ?= /etc/xdg/autostart
VERSION ?= $(shell git log -n 1 --format=format:devel-%cd-%h --date=format-local:%Y%m%d%H%M%S)
PREPAREDIR ?= build/prepare

DESTDIR := $(DESTDIR:/=)
PREFIX := $(PREFIX:/=)
BINDIR := $(BINDIR:/=)
DATADIR := $(DATADIR:/=)
AUTOSTART := $(AUTOSTART:/=)
PREPAREDIR := $(PREPAREDIR:/=)

SOURCES := $(shell find src -iname tests -prune -o -iname __pycache__ -prune -o -iname about.py -o -type f -print)
ABOUT := $(shell find src -type f -iname about.py)
SHARES := $(shell find share -type f -not -iname "*.[1-8]" -not -iname "*.desktop" -not -iname "*.bak" -not -iname "*.swp")
SHARES := $(patsubst share/%,%,$(SHARES))
MANS := $(shell find share -type f -iname "*.[1-8]")
MANS := $(patsubst share/%,%,$(MANS))
APPLICATION := $(shell find share -type f -iname "*.desktop")
APPLICATION := $(patsubst share/%,%,$(APPLICATION))

PREPARE_SOURCES := $(patsubst src/%,$(PREPAREDIR)/%,$(SOURCES))
PREPARE_ABOUT := $(patsubst src/%,$(PREPAREDIR)/%,$(ABOUT))

INSTALL_SHARES := $(patsubst %,$(DESTDIR)$(DATADIR)/%,$(SHARES))

INSTALL_SHARES := $(patsubst %,$(DESTDIR)$(DATADIR)/%,$(SHARES))
INSTALL_MANS := $(patsubst %,$(DESTDIR)$(DATADIR)/%.gz,$(MANS))
INSTALL_APPLICATION := $(patsubst %,$(DESTDIR)$(DATADIR)/%,$(APPLICATION))
Expand All @@ -37,7 +53,20 @@ default:
@echo

.PHONY: all
all:
all: $(PROGRAM)


$(PROGRAM): $(PREPARE_SOURCES) $(PREPARE_ABOUT) Makefile scripts/build_executable
scripts/build_executable --directory $(PREPAREDIR) --executable $@

$(PREPARE_SOURCES): $(PREPAREDIR)/% : src/%
@install --directory $(dir $@)
install --mode 0644 $< $@

$(PREPARE_ABOUT): $(PREPAREDIR)/% : src/%
@install --directory $(dir $@)
install --mode 0644 $< $@
sed -E -e "s|^( *APPLICATION_VERSION *= *)'[^']*'$$|\1'$(VERSION)'|" -i $@

.PHONY: package
package: $(DESTDIR)$(BINDIR)/$(PROGRAM) $(INSTALL_SHARES) $(INSTALL_MANS) $(INSTALL_AUTOSTART)
Expand All @@ -52,7 +81,6 @@ install: package
$(DESTDIR)$(BINDIR)/$(PROGRAM) : $(PROGRAM)
@install --directory $(dir $@)
install --mode 0755 $< $@
sed -E -e "s|^APPLICATION_VERSION = '[^']*'$$|APPLICATION_VERSION = '$(VERSION)'|" -i $@

$(INSTALL_SHARES): $(DESTDIR)$(DATADIR)/% : share/%
@install --directory $(dir $@)
Expand All @@ -65,7 +93,7 @@ $(INSTALL_MANS): $(DESTDIR)$(DATADIR)/%.gz : share/%

$(INSTALL_APPLICATION): share/$(APPLICATION)
@install --directory $(dir $@)
sed -E -e "s|/usr/bin|$(BINDIR)/|g" $< > $@
sed -E -e "s|/usr/bin/|$(BINDIR)/|g" $< > $@
@chmod 0644 $@

$(INSTALL_AUTOSTART) : $(INSTALL_APPLICATION)
Expand All @@ -85,7 +113,7 @@ devel: $(HOME)/.local/bin/$(PROGRAM) $(DEVEL_SHARES) $(DEVEL_APPLICATION) $(DEVE
update-mime-database $(HOME)/.local/share/mime
gtk-update-icon-cache -f -t $(HOME)/.local/share/icons/*

$(HOME)/.local/bin/$(PROGRAM) : $(PROGRAM)
$(HOME)/.local/bin/$(PROGRAM) : src/__main__.py
@install --directory $(dir $@)
ln --force --symbolic $(abspath $<) $@

Expand Down
21 changes: 21 additions & 0 deletions scripts/build_executable
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python3

import argparse
import pathlib
import subprocess

parser = argparse.ArgumentParser()
parser.add_argument('--directory', required=True)
parser.add_argument('--executable', required=True)
args = parser.parse_args()
directory = pathlib.Path(args.directory)
executable = pathlib.Path(args.executable)

assert directory.is_dir()

header = b'#!/usr/bin/env python3\n'

binary = subprocess.run(['zip', '-', '--recurse-paths', '-9', '.', ], cwd=directory, stdout=subprocess.PIPE).stdout

executable.write_bytes(header + binary)
executable.chmod(0o755)
25 changes: 25 additions & 0 deletions src/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python3
# vim:ts=4:sts=4:sw=4:expandtab

#
# openvpn3-indicator - Simple GTK indicator GUI for OpenVPN3.
# Copyright (C) 2024 Grzegorz Gutowski <[email protected]>
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License,
# or 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.
# If not, see <https://www.gnu.org/licenses/>.
#

if __name__ == '__main__':
import openvpn3_indicator
openvpn3_indicator.main()
46 changes: 46 additions & 0 deletions src/openvpn3_indicator/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python3
# vim:ts=4:sts=4:sw=4:expandtab

#
# openvpn3-indicator - Simple GTK indicator GUI for OpenVPN3.
# Copyright (C) 2024 Grzegorz Gutowski <[email protected]>
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License,
# or 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.
# If not, see <https://www.gnu.org/licenses/>.
#

import logging
import sys
import traceback

from openvpn3_indicator.about import *
from openvpn3_indicator.application import Application

###
#
# Main
#
###

def main():
try:
import setproctitle
setproctitle.setproctitle(f'{APPLICATION_NAME}')
except ImportError:
pass
application = Application()
application.run(sys.argv)

if __name__ == '__main__':
main()
27 changes: 27 additions & 0 deletions src/openvpn3_indicator/about.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env python3
# vim:ts=4:sts=4:sw=4:expandtab

#
# openvpn3-indicator - Simple GTK indicator GUI for OpenVPN3.
# Copyright (C) 2024 Grzegorz Gutowski <[email protected]>
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License,
# or 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.
# If not, see <https://www.gnu.org/licenses/>.
#

APPLICATION_NAME = 'openvpn3-indicator'
APPLICATION_DESCRIPTION = 'OpenVPN3 Indicator'
APPLICATION_ID = 'net.openvpn.openvpn3_indicator'
APPLICATION_URL = 'https://github.com/OpenVPN/openvpn3-indicator'
APPLICATION_VERSION = '0.1'
Loading

0 comments on commit 4ac90f1

Please sign in to comment.