How to use cysystemd - 10 common examples

To help you get started, we’ve selected a few cysystemd examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Jahia / paas_jelastic_backup / autobackup / import_package_as_user.py View on Github external
package = parser.add_argument_group('package')
    package.add_argument("-u", "--url",
                         help="package url")
    package.add_argument("--settings",
                         help="package settings (dict format)")
    cluster = parser.add_argument_group('Jelastic Cluster')
    cluster.add_argument("-j", "--jelastic",
                         default=JELHOST,
                         help="Jelastic Cluster DNS")
    return parser.parse_args()

args = argparser()

# logging = logging.getLogger(name=re.split('[@.]', args.sudo)[1])
logging = logging.getLogger(name='jahiacloudbackup')
logging.addHandler(journal.JournaldLogHandler(identifier=(args.env)))
logging.info("BACKUP START")

def importPackage(classname):
    try:
        resp = classname.devScriptEval(urlpackage=args.url,
                                       shortdomain=args.env,
                                       settings=json.loads(args.settings))
    except:
        logging.error("BACKUP END: An error was returning during package execution")
        if userSess:
            userSess.signOut()
        if adminSess:
            adminSess.signOut()
        quit(1)
    return resp
github mosquito / cysystemd / cysystemd / async_reader.py View on Github external
log = logging.getLogger("cysystemd.async_reader")


class Base:
    def __init__(self, loop: asyncio.AbstractEventLoop = None, executor=None):
        self._executor = executor
        self._loop = loop or asyncio.get_event_loop()

    async def _exec(self, func, *args, **kwargs):
        # noinspection PyTypeChecker
        return await self._loop.run_in_executor(
            self._executor, partial(func, *args, **kwargs)
        )


class AsyncJournalReader(Base):
    def __init__(self, executor=None, loop: asyncio.AbstractEventLoop = None):
        super().__init__(loop=loop, executor=executor)
        self.__reader = JournalReader()
        self.__flags = None
        self.__wait_lock = asyncio.Lock()

    async def wait(self) -> bool:
        async with self.__wait_lock:
            loop = self._loop
            reader = self.__reader
            event = asyncio.Event()

            loop.add_reader(reader.fd, event.set)

            try:
                await event.wait()
github mosquito / cysystemd / examples / asyncio_reader.py View on Github external
async def main():
    reader = AsyncJournalReader()
    await reader.open(JournalOpenMode.SYSTEM)
    await reader.seek_tail()

    while await reader.wait():
        async for record in reader:
            print(json.dumps(record.data, indent=1, sort_keys=True))
github mosquito / cysystemd / examples / asyncio_reader.py View on Github external
async def main():
    reader = AsyncJournalReader()
    await reader.open(JournalOpenMode.SYSTEM)
    await reader.seek_tail()

    while await reader.wait():
        async for record in reader:
            print(json.dumps(record.data, indent=1, sort_keys=True))
github mosquito / cysystemd / cysystemd / journal.py View on Github external
def write(message, priority=Priority.INFO):
    """ Write message into systemd journal 
    :type priority: Priority
    :type message: str
    """

    priority = int(Priority(int(priority)))

    send(priority=priority, message=message)


class JournaldLogHandler(logging.Handler):
    LEVELS = {
        logging.CRITICAL: Priority.CRITICAL.value,
        logging.FATAL: Priority.PANIC.value,
        logging.ERROR: Priority.ERROR.value,
        logging.WARNING: Priority.WARNING.value,
        logging.WARN: Priority.WARNING.value,
        logging.INFO: Priority.INFO.value,
        logging.DEBUG: Priority.DEBUG.value,
        logging.NOTSET: Priority.NONE.value,
    }

    __slots__ = ("__facility",)

    def __init__(self, identifier=None, facility=Facility.DAEMON):
        """

        :type identifier: Override default journald identifier
        :type facility: Facility
github mosquito / cysystemd / cysystemd / journal.py View on Github external
def write(message, priority=Priority.INFO):
    """ Write message into systemd journal 
    :type priority: Priority
    :type message: str
    """

    priority = int(Priority(int(priority)))

    send(priority=priority, message=message)
github mosquito / cysystemd / cysystemd / journal.py View on Github external
def write(message, priority=Priority.INFO):
    """ Write message into systemd journal 
    :type priority: Priority
    :type message: str
    """

    priority = int(Priority(int(priority)))

    send(priority=priority, message=message)
github mosquito / cysystemd / cysystemd / journal.py View on Github external
def write(message, priority=Priority.INFO):
    """ Write message into systemd journal 
    :type priority: Priority
    :type message: str
    """

    priority = int(Priority(int(priority)))

    send(priority=priority, message=message)


class JournaldLogHandler(logging.Handler):
    LEVELS = {
        logging.CRITICAL: Priority.CRITICAL.value,
        logging.FATAL: Priority.PANIC.value,
        logging.ERROR: Priority.ERROR.value,
        logging.WARNING: Priority.WARNING.value,
        logging.WARN: Priority.WARNING.value,
        logging.INFO: Priority.INFO.value,
        logging.DEBUG: Priority.DEBUG.value,
        logging.NOTSET: Priority.NONE.value,
    }

    __slots__ = ("__facility",)

    def __init__(self, identifier=None, facility=Facility.DAEMON):
        """

        :type identifier: Override default journald identifier
        :type facility: Facility
        """
        logging.Handler.__init__(self)
github mosquito / cysystemd / cysystemd / journal.py View on Github external
""" Write message into systemd journal 
    :type priority: Priority
    :type message: str
    """

    priority = int(Priority(int(priority)))

    send(priority=priority, message=message)


class JournaldLogHandler(logging.Handler):
    LEVELS = {
        logging.CRITICAL: Priority.CRITICAL.value,
        logging.FATAL: Priority.PANIC.value,
        logging.ERROR: Priority.ERROR.value,
        logging.WARNING: Priority.WARNING.value,
        logging.WARN: Priority.WARNING.value,
        logging.INFO: Priority.INFO.value,
        logging.DEBUG: Priority.DEBUG.value,
        logging.NOTSET: Priority.NONE.value,
    }

    __slots__ = ("__facility",)

    def __init__(self, identifier=None, facility=Facility.DAEMON):
        """

        :type identifier: Override default journald identifier
        :type facility: Facility
        """
        logging.Handler.__init__(self)
        self.__identifier = identifier
github mosquito / cysystemd / cysystemd / journal.py View on Github external
priority = int(Priority(int(priority)))

    send(priority=priority, message=message)


class JournaldLogHandler(logging.Handler):
    LEVELS = {
        logging.CRITICAL: Priority.CRITICAL.value,
        logging.FATAL: Priority.PANIC.value,
        logging.ERROR: Priority.ERROR.value,
        logging.WARNING: Priority.WARNING.value,
        logging.WARN: Priority.WARNING.value,
        logging.INFO: Priority.INFO.value,
        logging.DEBUG: Priority.DEBUG.value,
        logging.NOTSET: Priority.NONE.value,
    }

    __slots__ = ("__facility",)

    def __init__(self, identifier=None, facility=Facility.DAEMON):
        """

        :type identifier: Override default journald identifier
        :type facility: Facility
        """
        logging.Handler.__init__(self)
        self.__identifier = identifier
        self.__facility = Facility(int(facility))

    @staticmethod
    def _to_microsecond(ts):