Skip to content
This repository has been archived by the owner on Nov 4, 2021. It is now read-only.

Commit

Permalink
Add functionality to delete transmission image data and service unit …
Browse files Browse the repository at this point in the history
…file.
  • Loading branch information
Iolaum committed Mar 14, 2021
1 parent 9534332 commit 1f0cf66
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 28 deletions.
5 changes: 5 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
History
=======

0.1.3 (2021-03-14)
-------------------

- Add functionality to delete transmission image data and service unit file.

0.1.2 (2021-03-14)
-------------------

Expand Down
45 changes: 41 additions & 4 deletions docs/_build/man/podcust.1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.\" Man page generated from reStructuredText.
.
.TH "PODCUST" "1" "Mar 14, 2021" "0.1.2" "Podman Custodian"
.TH "PODCUST" "1" "Mar 14, 2021" "0.1.3" "Podman Custodian"
.SH NAME
podcust \- Podman Custodian Documentation
.
Expand Down Expand Up @@ -124,18 +124,42 @@ $ python setup.py install
.UNINDENT
.UNINDENT
.SH USAGE
.SS Using Transmission container image
.sp
To use Podman Custodian in a project:
To use transmission container image in production:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
import podcust
$ podcust transmission deploy
$ podcust transmission service setup
$ podcust transmission service activate
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
Now the transmission container is up and running. It will automatically be stopped during shutdown
and will be restarted, and updated if possible, after boot.
.sp
To clear the system from a running image and all associated files:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
$ podcust transmission service deactivate
$ podcust transmission service delete
$ podcust transmission stop
$ podcust transmission rm
$ podcust transmission clear
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
Note: Container images stored by podman still need to be manually deleted.
.SH PODCUST
.SS podcust package
.SS Subpackages
Expand Down Expand Up @@ -343,11 +367,19 @@ Check if there is a new version of the transmission docker image from linuxserve
.UNINDENT
.INDENT 7.0
.TP
.B clear_location()
Delete all files within the (hard\-coded) path used by the transmission image under the
podman custodian.
.UNINDENT
.INDENT 7.0
.TP
.B deploy()
Create a pod named transmission to deploy our container.
For a successful deployment the following steps must take place:
The steps taken during deployment are the following:
.INDENT 7.0
.IP \(bu 2
Delete path we ‘ll use to ensure a clean start.
.IP \(bu 2
Create the necessary folders, and give them proper permissions.
.IP \(bu 2
Write the proper kube yaml file that we ‘ll use to deploy the container.
Expand Down Expand Up @@ -677,6 +709,11 @@ Nikolaos Perrakis <\fI\%nikperrakis@gmail.com\fP>
.sp
None yet. Why not be the first?
.SH HISTORY
.SS 0.1.3 (2021\-03\-14)
.INDENT 0.0
.IP \(bu 2
Add functionality to delete transmission image data and service unit file.
.UNINDENT
.SS 0.1.2 (2021\-03\-14)
.INDENT 0.0
.IP \(bu 2
Expand Down
24 changes: 22 additions & 2 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@
Usage
=====

To use Podman Custodian in a project::

import podcust
Using Transmission container image
-----------------------------------


To use transmission container image in production::

$ podcust transmission deploy
$ podcust transmission service setup
$ podcust transmission service activate

Now the transmission container is up and running. It will automatically be stopped during shutdown
and will be restarted, and updated if possible, after boot.

To clear the system from a running image and all associated files::

$ podcust transmission service deactivate
$ podcust transmission service delete
$ podcust transmission stop
$ podcust transmission rm
$ podcust transmission clear

Note: Container images stored by podman still need to be manually deleted.
7 changes: 5 additions & 2 deletions podcust.spec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
%global pypi_name podcust

Name: %{pypi_name}
Version: 0.1.2
Version: 0.1.3
Release: 1%{?dist}
Summary: Python utility to handle podman containers within Fedora

Expand Down Expand Up @@ -62,7 +62,10 @@ rm -rf html/.{doctrees,buildinfo}
%{python3_sitelib}/%{pypi_name}-%{version}-py%{python3_version}.egg-info

%changelog
* Sun Mar 14 2021 Nikolaos Perrakis <nikperrakis@gmail.com> - 0.1.1-1
* Sun Mar 14 2021 Nikolaos Perrakis <nikperrakis@gmail.com> - 0.1.3-1
- Add functionality to delete transmission image data and service unit file.

* Sun Mar 14 2021 Nikolaos Perrakis <nikperrakis@gmail.com> - 0.1.2-1
- Recreate transmission kubernetes template for podman 3.0.

* Sun Mar 07 2021 Nikolaos Perrakis <nikperrakis@gmail.com> - 0.1.1-1
Expand Down
2 changes: 1 addition & 1 deletion podcust/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
# fmt: off
__author__ = """Nikolaos Perrakis"""
__email__ = 'nikperrakis@gmail.com'
__version__ = '0.1.2'
__version__ = '0.1.3'
# fmt: on
18 changes: 18 additions & 0 deletions podcust/commands/transmission.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,20 @@ def update(obj):
click.echo("Transmission pod updated!")


@click.command()
@click.pass_obj
def clear(obj):
"""Clear data of transmission image."""
obj.clear_location()
click.echo("All files used by the transmission image have been deleted.")


transmission.add_command(deploy)
transmission.add_command(stop)
transmission.add_command(start)
transmission.add_command(rm)
transmission.add_command(update)
transmission.add_command(clear)


@click.group()
Expand Down Expand Up @@ -120,8 +129,17 @@ def logs(
)


@click.command()
@click.pass_obj
def delete(obj):
"""Delete transmission service unit file."""
obj.delete_service_unit()
click.echo("Transmission service unit file deleted.")


transmission.add_command(service)
service.add_command(setup)
service.add_command(activate)
service.add_command(deactivate)
service.add_command(logs)
service.add_command(delete)
43 changes: 26 additions & 17 deletions podcust/transmission/custodian.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def __init__(self, name: str = "ghcr.io/linuxserver/transmission"):
self.name = name
self.image_id = ""
self.username = getpass.getuser()
# Main path we 'll use for the container
self.main_path: Path = Path.home().joinpath("transmission")

def pull_latest_transmission_image(self):
"""
Expand Down Expand Up @@ -63,37 +65,45 @@ def pull_latest_transmission_image(self):
except Exception as e:
print(e)

def clear_location(self):
"""
Delete all files within the (hard-coded) path used by the transmission image under the
podman custodian.
"""

try:
if self.main_path.exists():
rmtree(self.main_path)
except PermissionError as err:
print(
f"Please manually delete folder {str(self.main_path)} with required permissions."
)
raise err

def deploy(self):
"""
Create a pod named transmission to deploy our container.
For a successful deployment the following steps must take place:
The steps taken during deployment are the following:
- Delete path we 'll use to ensure a clean start.
- Create the necessary folders, and give them proper permissions.
- Write the proper kube yaml file that we 'll use to deploy the container.
- Open the necessary firewall port.
- Execute the podman play command to start the pod with the transmission container.
"""

# Let's create master path where we 'll put the container
main_path: Path = Path.home().joinpath("transmission")

# Let's delete everything allready present on the space we want to use:
try:
if main_path.exists():
rmtree(main_path)
except PermissionError as err:
print(f"Please manually delete folder {str(main_path)} and re run command.")
raise err
self.clear_location()

# let's recreate the directory now
print("Creating key directories:")
main_path.mkdir()
self.main_path.mkdir()
# let's create additional needed directories
config_dir = main_path.joinpath("config")
config_dir = self.main_path.joinpath("config")
config_dir.mkdir()
watch_dir = main_path.joinpath("watch")
watch_dir = self.main_path.joinpath("watch")
watch_dir.mkdir()
downloads_dir = main_path.joinpath("downloads")
downloads_dir = self.main_path.joinpath("downloads")
downloads_dir.mkdir()

# We also need to change the SELinux security context of the new directories:
Expand Down Expand Up @@ -198,7 +208,7 @@ def deploy(self):
yaml_template = yaml_template.replace("$LOCAL_USER", self.username)

# write kubernetes template
kube_yaml_path = main_path.joinpath("transmission-kube.yml")
kube_yaml_path = self.main_path.joinpath("transmission-kube.yml")
kube_yaml_path.write_text(yaml_template)

subprocess.run(
Expand Down Expand Up @@ -291,8 +301,7 @@ def update_running_image(self):
self.stop()
self.rm()

main_path: Path = Path.home().joinpath("transmission")
kube_yaml_path = main_path.joinpath("transmission-kube.yml")
kube_yaml_path = self.main_path.joinpath("transmission-kube.yml")

subprocess.run(
"podman play kube " + str(kube_yaml_path),
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.1.2
current_version = 0.1.3
commit = False
tag = False
allow_dirty = True
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@
# Adding man pages to python package: https://stackoverflow.com/a/48381612/1904901
data_files = [('/usr/share/man/man1/', ['docs/_build/man/podcust.1'])],
url='https://github.com/Iolaum/podcust',
version='0.1.2',
version='0.1.3',
zip_safe=False,
)

0 comments on commit 1f0cf66

Please sign in to comment.