Skip to main content

Windows Service Creator

Project description

winsvc

A Windows Service Creator API.

Install

pip install winsvc

Example

# test_svc.py
import os
import sys
import time
import click
import pathlib
from winsvc.cmd import add_svc_command
from winsvc.svc import Service


class TestService(Service):
    _svc_name_ = 'winsvc'
    _svc_display_name_ = "WIN SVC"
    _svc_description_ = 'A Windows Service Creator'
    _exe_name_ = sys.executable

    def __init__(self, path):
        self.running = True
        self.path = path
        self._exe_args_ = f'{os.path.abspath(__file__)} {path}'

    def start(self):
        while self.running:
            pathlib.Path(self.path).touch()
            time.sleep(5)

    def stop(self):
        self.running = False


@add_svc_command()
@click.group(invoke_without_command=True)
@click.argument("path", type=click.Path())
@click.pass_context
def main(ctx, path):
    s = TestService(path)
    if ctx.invoked_subcommand is None:
        # Run in command line
        s.start()
    else:
        # Run in Windows service
        ctx.obj = s


if __name__ == '__main__':
    main()

Run in command line:

python test_svc.py test.txt

Run in service:

python test_svc.py test.txt svc -d . install
python test_svc.py test.txt svc -d . start

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

winsvc-1.0.0-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file winsvc-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: winsvc-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.6.8

File hashes

Hashes for winsvc-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7f51839358bbf189597c878558d5df33aa4ac81d25a673faff0ec829f1d1b477
MD5 91e1afbd56853f3955ebb754417126b6
BLAKE2b-256 a737d050a2e769c8f1d514ab3879f2e73cd225d5d6fb8af3de678848b0006e4f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page