Skip to content

Commit

Permalink
Add optional logger as an argument
Browse files Browse the repository at this point in the history
Update README.md and release_notes.rst
Bump version
  • Loading branch information
dormant-user committed Nov 22, 2023
1 parent 44bcfbc commit 6b7b794
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 43 deletions.
38 changes: 19 additions & 19 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: pypi-publish

# Controls when the workflow will run
on:
workflow_dispatch: {}
workflow_dispatch: { }
release:
types: [ published ]

Expand All @@ -14,21 +14,21 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Create packages
run: python -m build
- name: Run twine check
run: twine check dist/*
- name: Upload to pypi
env:
TWINE_USERNAME: ${{ secrets.PYPI_USER }}
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: twine upload dist/*.whl
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Create packages
run: python -m build
- name: Run twine check
run: twine check dist/*
- name: Upload to pypi
env:
TWINE_USERNAME: ${{ secrets.PYPI_USER }}
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: twine upload dist/*.whl
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
![Generic badge](https://img.shields.io/badge/Platform-Linux|MacOS|Windows-1f425f.svg)
![Platform](https://img.shields.io/badge/Platform-Linux|MacOS|Windows-1f425f.svg)
[![pypi-publish](https://github.com/thevickypedia/pywslocker/actions/workflows/python-publish.yml/badge.svg)](https://github.com/thevickypedia/pywslocker/actions/workflows/python-publish.yml)

# PyBrightness
# PyWSLocker
Python module to lock workstation on Linux, Windows and macOS

### Installation
Expand All @@ -19,12 +19,12 @@ pywslocker.lock()
## [Release Notes](https://github.com/thevickypedia/pywslocker/blob/main/release_notes.rst)
**Requirement**
```shell
python -m pip install changelog-generator
python -m pip install gitverse
```

**Usage**
```shell
changelog reverse -f release_notes.rst -t 'Release Notes'
gitverse-release reverse -f release_notes.rst -t 'Release Notes'
```

## Pypi Package
Expand Down
2 changes: 1 addition & 1 deletion pywslocker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

from .main import lock

version = "0.0.4"
version = "0.5"
25 changes: 16 additions & 9 deletions pywslocker/main.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
import os
import logging
import subprocess

from .module import settings


def lock():
"""Locks the workstation."""
def lock(logger: logging.Logger = None) -> None:
"""Locks the workstation.
Args:
logger: Bring your own logger.
"""
if settings.os == "Darwin":
os.system(
"""osascript -e 'tell application "System Events" to keystroke "q" using {control down, command down}'"""
)
cmd = """osascript -e 'tell application "System Events" to keystroke "q" using {control down, command down}'"""
elif settings.os == "Windows":
try:
import ctypes
ctypes.windll.user32.LockWorkStation()
except (ImportError, AttributeError):
subprocess.call('rundll32.exe user32.dll, LockWorkStation')
return
except (ImportError, AttributeError) as error:
logger.warning(error) if logger else None
cmd = "rundll32.exe user32.dll, LockWorkStation"
else:
os.system("gnome-screensaver-command --lock")
cmd = "gnome-screensaver-command --lock"
result = subprocess.run(cmd, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
if result.returncode and logger:
logger.error("Command `%s` failed with error code: %d", result.args, result.returncode)
16 changes: 6 additions & 10 deletions release_notes.rst
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
Release Notes
=============

0.5 (11/22/2023)
----------------
- Includes optional logging to trace errors

0.0.4 (02/22/2023)
------------------
- Add an alternate to `ctypes` on `WindowsOS`
- Bump to stable version
- Update README.md

0.0.3 (02/21/2023)
------------------
0.0.0a (02/21/2023)
-------------------
- Add pypi requirements and GitHub actions

0.0.2 (02/21/2023)
------------------
- Onboard locker

0.0.1 (02/21/2023)
------------------
- Initial commit

0 comments on commit 6b7b794

Please sign in to comment.