コード例 #1
0
def push_backup(backup_path):
    if backup_path:
        if not mail and not ftp:
            return
        if mail:
            mail.send(
                EMAIL_SUBSCRIBERS,
                attachments=[backup_path],
                subject="{name} -> AutoBackup Universal".format(
                    name=SETTINGS_NAME),
            )
        if ftp:
            task_guid = host.random_guid()
            WORKING_TASKS[task_guid] = backup_path
            host.stats()["run_count"] += 1
            ftp.send(backup_path, task_guid=task_guid)
        if DELETE_BACKUP and not ftp:
            remove_backup(_win_encode_path(backup_path))
コード例 #2
0
    def send(self, file_path, remote_dir=None, callback=None, task_guid=None):
        """

        Args:
            file_path (str): File path
            remote_dir (str, optional): Remote ftp dir
            callback (callable, optional): Function that calling when sending finished
            task_guid (str, optional): Task guid, default: host.random_guid()

        Raises:
            IOError: if file not found
        """

        if not os.path.isfile(_win_encode_path(file_path)):
            raise IOError("File '%s' not found" % file_path)

        if task_guid is None:
            task_guid = host.random_guid()

        callback = callback or self.callback

        kwargs = {
            "file_path": file_path,
            "remote_dir": remote_dir,
            "callback": callback,
            "task_guid": task_guid,
        }

        self.queue.append(kwargs)

        if not self._work_now:
            logger.debug("Start sender")
            self._work_now = True
            self._sender()
        else:
            callback(task_guid, status.in_queue)
            logger.debug("Sender already working")

        return task_guid
コード例 #3
0
    def save(
        self,
        channel_full_guid,
        dt=None,
        figures=False,
        file_name=None,
        file_path=None,
        callback=None,
        task_guid=None,
        fmt=None,
    ):
        """Saving screenshot

        Args:
            channel_full_guid (str): Screenshot full guid, `channelGuid_serverGuid`
            dt (datetime.datetime, optional): Shot datetime, default current time
            figures (bool, optional): Trying to save shots with figures if True
            file_name (str, optional): Screenshot filename, default None
            file_path (str, optional): Path to save shot, default None
            callback (callable, optional): Callback after shot saved, default None
            task_guid (str, optional): Custom task guid, default None
            fmt (Dict[str: Any]): Used as kwargs for filename/filepath formatting

        Returns:
            Tuple[str, str]: task guid and file path
        """
        task_guid = task_guid or host.random_guid()
        callback = callback or self.callback
        logger.debug(
            "ShotSaver.save(%r, dt=%r, figures=%r, file_name=%r, file_path=%r, callback=%r, task_guid=%r)",
            channel_full_guid,
            dt,
            figures,
            file_name,
            file_path,
            callback,
            task_guid,
        )
        if "_" not in channel_full_guid:
            raise ValueError(
                "Expected full channel guid, got {}".format(channel_full_guid))

        channel_guid, server_guid = channel_full_guid.split("_")

        try:
            server = host.settings(
                "/{server_guid}".format(server_guid=server_guid))
        except KeyError:
            raise EnvironmentError(
                host.tr("Server %s not found") % server_guid)
        try:
            channel = host.settings(
                "/{server_guid}/channels/{channel_guid}".format(
                    server_guid=server_guid, channel_guid=channel_guid))
        except KeyError:
            raise EnvironmentError(
                host.tr("Channel %s not found on server %s") %
                (channel_guid, server.name))

        if dt is None:
            ts = 0
            dt = datetime.datetime.now()
        else:
            if not isinstance(dt, datetime.datetime):
                ts = dt
                try:
                    dt = ts_to_dt(dt)
                except ValueError:
                    raise ValueError(
                        "Can't parse datetime from %s, try to use datetime.datetime instance"
                        % dt)
            else:
                ts = dt_to_ts(dt)

        ts = str(ts)

        if fmt is None:
            fmt = {}

        file_name = (file_name or self.file_name_tmpl).format(channel=channel,
                                                              server=server,
                                                              **fmt)
        file_name = dt.strftime(file_name)

        file_path = (file_path
                     or self.screenshots_folder).format(channel=channel,
                                                        server=server,
                                                        **fmt)
        file_path = dt.strftime(file_path)
        created_ts = time.time() + self.buffer_ts
        self.__check_path(file_path)

        self.__thread_pool.add_task(
            self.__async_shot,
            channel_full_guid,
            file_name,
            file_path,
            ts,
            created_ts,
            figures,
            callback,
            task_guid,
        )
        host.timeout(10, lambda: callback(task_guid, status.in_queue))
        return task_guid, _win_encode_path(os.path.join(file_path, file_name))
コード例 #4
0
ファイル: caption.py プロジェクト: trassir/scripts
 def key(self):
     return host.random_guid()
コード例 #5
0
ファイル: auto_universal.py プロジェクト: trassir/scripts
            ShowMessage(show_message_delay=SHOW_MESSAGE_DELAY))

    # -------------------------------------------------------
    # Show popup window
    # -------------------------------------------------------
    if GLOBALS.get("SHOW_POPUP"):
        from reactions import ShowPopup

        mon_popup = GLOBALS.get("MON_POPUP", 1)
        reactions.add_executor(
            ShowPopup(monitor_to_show_archive_from_popup=mon_popup))

    # -------------------------------------------------------
    # Fire event
    # -------------------------------------------------------
    random_guid = host.random_guid()
    reactions.add_executor(
        FireEvent(name="AutoUniversal-{}".format(random_guid),
                  guid=random_guid))

    # -------------------------------------------------------
    # Al senders
    # -------------------------------------------------------
    ALL_SENDERS = []

    # -------------------------------------------------------
    # Initializing email sender
    # -------------------------------------------------------
    if SEND_SCREEN_EMAIL or SEND_EMAIL:
        from senders import AdoptedEmailSender
        from email_sender import EmailSender
コード例 #6
0
ファイル: video_exporter.py プロジェクト: trassir/scripts
    def export(
        self,
        channel_full_guid,
        dt_start,
        dt_end=None,
        duration=60,
        prefer_substream=False,
        file_name=None,
        file_path=None,
        options=None,
        callback=None,
        task_guid=None,
    ):
        """Exporting file

        Call callback(success: bool, file_path: str, channel_full_guid: str)
        when export finished, and clear tasks in trassir main control panel

        Note:
            Export task adding only when previous task finished
            You can set dt_start, dt_end, or dt_start, duration for export
            if dt_end is None: dt_end = dt_start + timedelta(seconds=duration)

        Args:
            channel_full_guid (str): Full channel guid; example: "CFsuNBzt_pV4ggECb"
            dt_start (datetime.datetime): datetime instance for export start
            dt_end (datetime.datetime, optional): datetime instance for export end; default: None
            duration (int, optional): Export duration (dt_start + duration seconds) if dt_end is None; default: 10
            prefer_substream (bool, optional): If True - export substream; default: False
            file_name (str, optional): File name with extension; default: _EXPORTED_VIDEO_NAME_TEMPLATE
            file_path (str, optional): Path to save shot; default: screenshots_folder
            options (Dict[str: str], optional): Options dict; default: None
            callback (function, optional): Function that calling when export finished
            task_guid (str, optional): Task guid; default: host.random_guid()

        Raises:
            ValueError: if bad channel guid
            EnvironmentError: if channel not found
            TypeError: if got unexpected datetime object
        """

        task_guid = task_guid or host.random_guid()
        callback = callback or self.callback

        try:
            channel_guid, server_guid = channel_full_guid.split("_")
        except ValueError:
            raise ValueError(
                "Expected full channel guid, got {}".format(channel_full_guid)
            )

        try:
            channel_name = host.settings(
                "/{}/channels/{}".format(server_guid, channel_guid)
            ).name
        except KeyError:
            raise EnvironmentError("Channel %s not found" % channel_full_guid)

        if not isinstance(dt_start, datetime.datetime):
            raise TypeError("Expected datetime, got {}".format(type(dt_start).__name__))

        if dt_end:
            if not isinstance(dt_end, datetime.datetime):
                raise TypeError(
                    "Expected datetime, got {}".format(type(dt_end).__name__)
                )
        else:
            dt_end = dt_start + datetime.timedelta(seconds=duration)

        if options is None:
            options = {}

        ts_start = "%.0f" % (time.mktime(dt_start.timetuple()) * 1000000)
        ts_end = "%.0f" % (time.mktime(dt_end.timetuple()) * 1000000)

        if file_name is None:
            file_name = self.file_name_tmpl.format(
                name=channel_name,
                dt_start=dt_start.strftime("%Y.%m.%d %H-%M-%S"),
                dt_end=dt_end.strftime("%Y.%m.%d %H-%M-%S"),
                sub="_sub" if prefer_substream else "",
            )

        if file_path is None:
            file_path = self.export_folder

        exporting_path = os.path.join(file_path, file_name)

        options_ = {
            "prefer_substream": prefer_substream,
            "postponed_until_ts": self._get_prebuffer(server_guid, dt_end),
        }
        options_.update(options)

        kwargs = {
            "server_guid": server_guid,
            "channel_guid": channel_guid,
            "exporting_path": exporting_path,
            "ts_start": ts_start,
            "ts_end": ts_end,
            "options": options_,
            "callback": callback,
            "task_guid": task_guid,
        }

        host.timeout(100, lambda: self._create_task(**kwargs))

        return task_guid, exporting_path
コード例 #7
0
ファイル: shot_saver.py プロジェクト: trassir/scripts
    def save(
        self,
        channel_full_guid,
        dt=None,
        figures=False,
        file_name=None,
        file_path=None,
        callback=None,
        task_guid=None,
    ):
        task_guid = task_guid or host.random_guid()
        callback = callback or self.callback
        logger.debug(
            "ShotSaver.save(%r, dt=%r, figures=%r, file_name=%r, file_path=%r, callback=%r, task_guid=%r)",
            channel_full_guid,
            dt,
            figures,
            file_name,
            file_path,
            callback,
            task_guid,
        )
        if "_" not in channel_full_guid:
            raise ValueError(
                "Expected full channel guid, got {}".format(channel_full_guid))

        channel_guid, server_guid = channel_full_guid.split("_")

        try:
            server = host.settings(
                "/{server_guid}".format(server_guid=server_guid))
        except KeyError:
            raise EnvironmentError(
                host.tr("Server %s not found") % server_guid)
        try:
            channel = host.settings(
                "/{server_guid}/channels/{channel_guid}".format(
                    server_guid=server_guid, channel_guid=channel_guid))
        except KeyError:
            raise EnvironmentError(
                host.tr("Channel %s not found on server %s") %
                (channel_guid, server.name))

        if dt is None:
            ts = 0
            dt = datetime.datetime.now()
        else:
            if not isinstance(dt, datetime.datetime):
                ts = dt
                try:
                    dt = ts_to_dt(dt)
                except ValueError:
                    raise ValueError(
                        "Can't parse datetime from %s, try to use datetime.datetime instance"
                        % dt)
            else:
                ts = dt_to_ts(dt)

        ts = str(ts)
        file_name = (file_name or self.file_name_tmpl).format(channel=channel,
                                                              server=server)
        file_name = dt.strftime(file_name)
        file_path = file_path or self.screenshots_folder
        self.__check_path(file_path)

        self.__thread_pool.add_task(
            self.__async_shot,
            channel_full_guid,
            file_name,
            file_path,
            ts,
            figures,
            callback,
            task_guid,
        )
        host.timeout(10, lambda: callback(task_guid, status.in_queue))
        return task_guid, _win_encode_path(os.path.join(file_path, file_name))