Skip to content

Commit

Permalink
Merge pull request #9 from Binaergewitter/feature/add-ci
Browse files Browse the repository at this point in the history
Feature: add ci & python linting
  • Loading branch information
fliiiix authored Nov 20, 2021
2 parents 05d137b + 8ba85fe commit 2fc706e
Show file tree
Hide file tree
Showing 10 changed files with 302 additions and 175 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: ci
on: [push]

jobs:
test:
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: [3.6, 3.7, 3.8, 3.9, "3.10"]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}

- name: install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install poetry==1.1.11
python -m poetry install
- name: run backend linter
run: |
python -m poetry run pflake8 chapter_marker
- name: build and install
run: |
python -m poetry build
python -m poetry install
- name: run chapter-marker
uses: GabrielBB/xvfb-action@v1
with:
run: python -m poetry run chapter-marker --help
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
__pycache__
*.lst
dist
doit.sh
result
UNKNOWN.egg-info
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
lint:
poetry run flake8 --max-line-length 100 chapter_marker
poetry run pflake8 chapter_marker
format:
poetry run isort --apply
poetry run black chapter_marker
9 changes: 6 additions & 3 deletions chapter_marker/bgt_get_titles.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
returns the id of the next bgt show
"""

import requests
import urllib.request
import os
import urllib.request

import requests
from docopt import docopt

url = "https://etherpad.euer.krebsco.de/api/1.2.15/getText?apikey={}&padID={}"
Expand All @@ -38,7 +39,9 @@ def main():
show = current_show()
try:
ret = requests.get(url.format(apikey, show)).json()["data"]["text"]
except:
except: # noqa E722
# way to complicated to do right:
# https://stackoverflow.com/questions/16511337
print("for url:" + url.format(apikey, show))
print(f"response: {requests.get(url.format(apikey,show))}")
header = True
Expand Down
14 changes: 7 additions & 7 deletions chapter_marker/bgt_replace_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
returns the id of the next bgt show
"""

import requests
import urllib.request
import os
import urllib.request

import requests
from docopt import docopt

baseurl = "https://etherpad.euer.krebsco.de/api/1.2.15/{}?apikey={}&padID={}"
Expand Down Expand Up @@ -44,11 +45,10 @@ def main():
print(f"replacing <SENDUNGSNUMMER> with {show.upper()}")
text = text.replace("<SENDUNGSNUMMER>", show.upper())
print("updating shownotes")
ret = requests.post(baseurl.format("setText", apikey, show), data={"text": text})
except:
print("for url:" + url.format(apikey, show))
print(f"response: {requests.get(url.format(apikey,show))}")
header = True
requests.post(baseurl.format("setText", apikey, show), data={"text": text})
except: # noqa E722
print(f"for url: {baseurl.format(apikey, show)}")
print(f"response: {requests.get(baseurl.format(apikey,show))}")


if __name__ == "__main__":
Expand Down
8 changes: 2 additions & 6 deletions chapter_marker/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -1802,15 +1802,11 @@


def qInitResources():
QtCore.qRegisterResourceData(
rcc_version, qt_resource_struct, qt_resource_name, qt_resource_data
)
QtCore.qRegisterResourceData(rcc_version, qt_resource_struct, qt_resource_name, qt_resource_data)


def qCleanupResources():
QtCore.qUnregisterResourceData(
rcc_version, qt_resource_struct, qt_resource_name, qt_resource_data
)
QtCore.qUnregisterResourceData(rcc_version, qt_resource_struct, qt_resource_name, qt_resource_data)


qInitResources()
105 changes: 36 additions & 69 deletions chapter_marker/tray.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env nix-shell
#!nix-shell -p python3Packages.docopt python3Packages.pyqt5 python3Packages.notify2 python3Packages.requests qt5.qtbase -i python3
#!nix-shell -p python3Packages.docopt python3Packages.pyqt5 python3Packages.notify2 python3Packages.requests qt5.qtbase -i python3 # noqa
""" usage: chapter-marker [options] TITLEFILE [SHOW]
options:
Expand All @@ -9,41 +9,30 @@
starts chapter-marker with the given TITLE and starts with the top entry of TITLEFILE
if the chapter marker file for this SHOW already exists it will be backed up.
"""
import sys, re
from docopt import docopt
from datetime import datetime, timedelta
import requests
from os.path import exists, join, expanduser
import logging
import pickle
from PyQt5.Qt import QApplication, QClipboard
from PyQt5.QtGui import QIcon, QKeySequence
from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt5.QtWidgets import (
QMainWindow,
QWidget,
QPlainTextEdit,
QPushButton,
QSystemTrayIcon,
QMenu,
QDialog,
QShortcut,
)
from PyQt5.QtCore import QSize, pyqtSlot, Qt, QObject, pyqtSignal
import sys
from datetime import datetime, timedelta
from os.path import expanduser, join

from docopt import docopt
from pynput import keyboard
from PyQt5 import QtGui, QtWidgets
from PyQt5.QtCore import QObject, pyqtSignal
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QMenu, QSystemTrayIcon

from . import resources # noqa F401

try:
import notify2
except ImportError:
import fakenotify2 as notify2

now = datetime.now

import logging
from . import resources
now = datetime.now

log = logging.getLogger("chapter-tray")

logging.basicConfig(level=logging.INFO)


Expand All @@ -56,13 +45,11 @@ def current_show():


class KeyBoardManager(QObject):
jSignal = pyqtSignal()
uSignal = pyqtSignal()
j_signal = pyqtSignal()
u_signal = pyqtSignal()

def start(self):
self.hotkeys = keyboard.GlobalHotKeys(
{"<ctrl>+j": self.jSignal.emit, "<ctrl>+u": self.uSignal.emit}
)
self.hotkeys = keyboard.GlobalHotKeys({"<ctrl>+j": self.j_signal.emit, "<ctrl>+u": self.u_signal.emit})
self.hotkeys.start()


Expand All @@ -72,13 +59,9 @@ def __init__(self, parent=None):

self.dateAction = QtWidgets.QAction(QIcon(":/icons/start-date.png"), "Start Date", self)
self.addAction(self.dateAction)
self.currentChapterAction = QtWidgets.QAction(
QIcon(":/icons/current-chapter.png"), "Current Chapter", self
)
self.currentChapterAction = QtWidgets.QAction(QIcon(":/icons/current-chapter.png"), "Current Chapter", self)
self.addAction(self.currentChapterAction)
self.nextChapterAction = QtWidgets.QAction(
QIcon(":/icons/next-chapter.png"), "Next Chapter", self
)
self.nextChapterAction = QtWidgets.QAction(QIcon(":/icons/next-chapter.png"), "Next Chapter", self)
self.addAction(self.nextChapterAction)


Expand All @@ -100,8 +83,8 @@ def __str__(self):
millis = round(self.delta.microseconds / 1000)
return f"{h:02}:{m:02}:{s:02}.{millis:03} {self.title}"

def toSimpleElement(self):
raise NotImplemented("sorry")
def to_simple_element(self):
raise NotImplementedError("sorry")


states = ["preshow", "show", "postshow"]
Expand Down Expand Up @@ -153,9 +136,7 @@ def begin(self):
duration = self.timers["show"] - self.timers["preshow"]
m, s = divmod(duration.seconds, 60)
h, m = divmod(m, 60)
self.add_comment(
f"Preshow ende um {self.start_date.replace(microsecond=0) } ({h:02}:{m:02}:{s:02} Vorgeplänkel)"
)
self.add_comment(f"Preshow ende um {self.start_date.replace(microsecond=0) } ({h:02}:{m:02}:{s:02} Vorgeplänkel)")
self.get_current().delta = timedelta(seconds=0)

def end(self):
Expand Down Expand Up @@ -235,40 +216,33 @@ def __init__(self, parent, show, titles, settingsdir):
menu = QMenu(parent=None)
self.setContextMenu(menu)

settingAction = menu.addAction(QIcon(":/icons/save.png"), "save")
settingAction.triggered.connect(self.save)
setting_action = menu.addAction(QIcon(":/icons/save.png"), "save")
setting_action.triggered.connect(self.save)

settingAction = menu.addAction("---")
setting_action = menu.addAction("---")

settingAction = menu.addAction(QIcon(":/icons/main.png"), "Reset and Restart")
settingAction.triggered.connect(self.reset)
setting_action = menu.addAction(QIcon(":/icons/main.png"), "Reset and Restart")
setting_action.triggered.connect(self.reset)

settingAction = menu.addAction(QIcon(":/icons/exit.png"), "exit")
settingAction.triggered.connect(self.exit)
setting_action = menu.addAction(QIcon(":/icons/exit.png"), "exit")
setting_action.triggered.connect(self.exit)

manager = KeyBoardManager(self)
manager.jSignal.connect(self.next_chapter)
manager.j_signal.connect(self.next_chapter)
manager.start()

# clipboard handling
# QApplication.clipboard().dataChanged.connect(self.clipboardChanged)

# shortcuts

def exit(self):
log.info("Persisting Chaptermarks")
self.markers.persist()
sys.exit()

def refresh_menu(self):
self.left_menu.dateAction.setText(
f"{self.markers.state} since {self.markers.timers[self.markers.state].replace(microsecond=0)}"
)
self.left_menu.dateAction.setText(f"{self.markers.state} since {self.markers.timers[self.markers.state].replace(microsecond=0)}")
self.left_menu.currentChapterAction.setText(f"Current: {self.markers.get_current()}")
try:
self.left_menu.nextChapterAction.setText(f"Next: {self.markers.get_next().title}")
except:
self.left_menu.nextChapterAction.setText(f"No next Chapter")
except: # noqa E722
self.left_menu.nextChapterAction.setText("No next Chapter")

def next_chapter(self):
log.info("Markers Status:")
Expand All @@ -282,8 +256,8 @@ def next_chapter(self):
notify2.Notification(f"Next Chapter: {self.markers.get_current().title}").show()
log.info(f"next chapter {self.markers.get_current().title}")
else:
log.info(f"Cannot move to next chapter")
notify2.Notification(f"Cannot move to next Chapter").show()
log.info("Cannot move to next chapter")
notify2.Notification("Cannot move to next Chapter").show()

def left_click(self, value):
self.refresh_menu()
Expand All @@ -298,13 +272,6 @@ def reset(self):
def save(self):
self.markers.persist()

# Get the system clipboard contents
def clipboardChanged(self):
text = QApplication.clipboard().text()
if type(text) != str:
return
# print(text)


def main():
args = docopt(__doc__)
Expand All @@ -315,7 +282,7 @@ def main():
else:

class FakeNotify2:
def Notification(self, text):
def Notification(self, text): # noqa N802
return self

def show(self):
Expand All @@ -327,7 +294,7 @@ def show(self):
if not show:
show = current_show()

titles = [l.strip() for l in open(args["TITLEFILE"]).readlines()]
titles = [line.strip() for line in open(args["TITLEFILE"]).readlines()]

app = QtWidgets.QApplication([]) # can also take sys.argv
tray = SystemTrayIcon(app, show, titles, settingsdir)
Expand Down
Loading

0 comments on commit 2fc706e

Please sign in to comment.