repomonitor / repomonitor / repomonitor.py

# coding: utf8

"""Watch the root of a repo and run a callback

"""


import os, sys, subprocess
from .inotify import *


REPO_ROOT = os.environ["VL_REPOSITORY_ROOT"]
PACKAGE_EXTENSIONS = (".txz", ".tlz", ".tbz", ".tgz")
META_EXTENSIONS = (".meta", ".info")


class RepositoryINotifyHandler(INotifyEventHandler):
    """Watch a repository root for fs changes

    """
    def on_create(self, filepath, mask):
        if ispackage(filepath):
            log.msg("Package written: %s" % filepath)
        elif ismeta(filepath):
            log.msg("Metadata file created: %s" % filepath)

    def on_modify(self, filepath, mask):
        if ispackagestxt(filepath):
            log.msg("PACKAGES.TXT updated")


def update_repository():
    """Run the repository scripts with subprocess

    """
    script = "/usr/libexec/openssh/sftp-server_repo-wrapper"
    try:
        subprocess.check_call(script)
    except:
        log.err()


def ispackage(filepath):
    """Return True if filepath is a path to a package

    """
    file_extension = os.path.splitext(filepath.path)[1]
    return file_extension in PACKAGE_EXTENSIONS


def ismeta(filepath):
    """Return True if filepath is a .meta

    """
    file_extension = os.path.splitext(filepath.path)[1]
    return file_extension in META_EXTENSIONS


def ispackagestxt(filepath):
    """Return True if filepath is PACKAGES.TXT

    """
    return filepath.path.endswith("PACKAGES.TXT")


def main():
    """Create a handler and register it

    """
    handler = RepositoryINotifyHandler(REPO_ROOT)
    handler.register()
    return handler
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.