Beispiel #1
0
    def doUpdates(self):
        """ Update menu info, once every 10 calls """
        self.counter += 1
        if self.counter > 10:
            self.sabpaused, bytes_left, bpsnow, time_left = api.fast_queue()
            mb_left = to_units(bytes_left)
            speed = to_units(bpsnow)

            if self.sabpaused:
                if bytes_left > 0:
                    self.hover_text = "%s - %s: %sB" % (
                        self.txt_paused, self.txt_remaining, mb_left)
                else:
                    self.hover_text = self.txt_paused
                self.icon = self.sabicons["pause"]
            elif bytes_left > 0:
                self.hover_text = "%sB/s - %s: %sB (%s)" % (
                    speed, self.txt_remaining, mb_left, time_left)
                self.icon = self.sabicons["green"]
            else:
                self.hover_text = self.txt_idle
                self.icon = self.sabicons["default"]

            self.refresh_icon()
            self.counter = 0
Beispiel #2
0
def endjob(filename, msgid, cat, status, path, bytes, stages, script,
           script_output, script_ret):
    """ Send end-of-job email """

    # Translate the stage names
    tr = sabnzbd.api.Ttemplate
    xstages = {}
    for stage in stages:
        lines = []
        for line in stages[stage]:
            if '\n' in line or '<br/>' in line:
                lines.extend(line.replace('<br/>', '\n').split('\n'))
            else:
                lines.append(line)
        xstages[tr('stage-' + stage.lower())] = lines

    parm = {}
    parm['status'] = status
    parm['name'] = filename
    parm['path'] = path
    parm['msgid'] = str(msgid)
    parm['stages'] = xstages
    parm['script'] = script
    parm['script_output'] = script_output
    parm['script_ret'] = script_ret
    parm['cat'] = cat
    parm['size'] = "%sB" % to_units(bytes)
    parm['end_time'] = time.strftime(time_format('%Y-%m-%d %H:%M:%S'),
                                     time.localtime(time.time()))

    return send_with_template('email', parm)
Beispiel #3
0
def endjob(filename, msgid, cat, status, path, bytes, fail_msg, stages, script, script_output, script_ret, test=None):
    """ Send end-of-job email """

    # Translate the stage names
    tr = sabnzbd.api.Ttemplate
    if not status and fail_msg:
        xstages = {tr('stage-fail'): (fail_msg,)}
    else:
        xstages = {}

    for stage in stages:
        lines = []
        for line in stages[stage]:
            if '\n' in line or '<br/>' in line:
                lines.extend(line.replace('<br/>', '\n').split('\n'))
            else:
                lines.append(line)
        xstages[tr('stage-'+stage.lower())] = lines

    parm = {}
    parm['status'] = status
    parm['name'] = filename
    parm['path'] = path
    parm['msgid'] = str(msgid)
    parm['stages'] = xstages
    parm['script'] = script
    parm['script_output'] = script_output
    parm['script_ret'] = script_ret
    parm['cat'] = cat
    parm['size'] = "%sB" % to_units(bytes)
    parm['end_time'] = time.strftime(time_format('%Y-%m-%d %H:%M:%S'), time.localtime(time.time()))

    return send_with_template('email', parm, test)
Beispiel #4
0
 def test_to_units(self):
     assert "1 K" == misc.to_units(1024)
     assert "1 KBla" == misc.to_units(1024, postfix="Bla")
     assert "1.0 M" == misc.to_units(1024 * 1024)
     assert "1.0 M" == misc.to_units(1024 * 1024 + 10)
     assert "10.0 M" == misc.to_units(1024 * 1024 * 10)
     assert "100.0 M" == misc.to_units(1024 * 1024 * 100)
     assert "9.8 G" == misc.to_units(1024 * 1024 * 10000)
     assert "1024.0 P" == misc.to_units(1024 ** 6)
Beispiel #5
0
    def run(self):
        self.sabpaused, bytes_left, bpsnow, time_left = api.fast_queue()
        mb_left = to_units(bytes_left, dec_limit=1)
        speed = to_units(bpsnow, dec_limit=1)

        if self.sabpaused:
            self.tooltip = T('Paused')
            self.icon = self.sabicons['pause']
        elif bytes_left > 0:
            self.tooltip = "%sB/s %s: %sB (%s)" % (speed, T('Remaining'), mb_left, time_left)
            self.icon = self.sabicons['green']
        else:
            self.tooltip = T('Idle')
            self.icon = self.sabicons['default']

        self.refresh_icon()
        self.refresh_tooltip()
        return 1
Beispiel #6
0
    def run(self):
        self.sabpaused, bytes_left, bpsnow, time_left = api.fast_queue()
        mb_left = to_units(bytes_left)
        speed = to_units(bpsnow)

        if self.sabpaused:
            self.tooltip = T('Paused')
            self.icon = self.sabicons['pause']
        elif bytes_left > 0:
            self.tooltip = "%sB/s %s: %sB (%s)" % (speed, T('Remaining'), mb_left, time_left)
            self.icon = self.sabicons['green']
        else:
            self.tooltip = T('Idle')
            self.icon = self.sabicons['default']

        self.refresh_icon()
        self.refresh_tooltip()
        return 1
Beispiel #7
0
    def run(self):
        self.sabpaused, bytes_left, bpsnow, time_left = api.fast_queue()
        mb_left = to_units(bytes_left)
        speed = to_units(bpsnow)

        if self.sabpaused:
            self.tooltip = T("Paused")
            self.icon = self.sabicons["pause"]
        elif bytes_left > 0:
            self.tooltip = "%sB/s %s: %sB (%s)" % (speed, T("Remaining"), mb_left, time_left)
            self.icon = self.sabicons["green"]
        else:
            self.tooltip = T("Idle")
            self.icon = self.sabicons["default"]

        self.refresh_icon()
        self.tooltip = "SABnzbd %s\n%s" % (sabnzbd.__version__, self.tooltip)
        self.refresh_tooltip()
        return 1
Beispiel #8
0
    def doUpdates(self):
        """ Update menu info, once every 10 calls """
        self.counter += 1
        if self.counter > 10:
            self.sabpaused, bytes_left, bpsnow, time_left = api.fast_queue()
            mb_left = to_units(bytes_left, dec_limit=1)
            speed = to_units(bpsnow, dec_limit=1)

            if self.sabpaused:
                self.hover_text = self.txt_paused
                self.icon = self.sabicons['pause']
            elif bytes_left > 0:
                self.hover_text = "%sB/s %s: %sB (%s)" % (speed, self.txt_remaining, mb_left, time_left)
                self.icon = self.sabicons['green']
            else:
                self.hover_text = self.txt_idle
                self.icon = self.sabicons['default']

            self.refresh_icon()
            self.counter = 0
Beispiel #9
0
    def doUpdates(self):
        """ Update menu info, once every 10 calls """
        self.counter += 1
        if self.counter > 10:
            self.sabpaused, bytes_left, bpsnow, time_left = api.fast_queue()
            mb_left = to_units(bytes_left, dec_limit=1)
            speed = to_units(bpsnow, dec_limit=1)

            if self.sabpaused:
                self.hover_text = T('Paused')
                self.icon = self.sabicons['pause']
            elif bytes_left > 0:
                self.hover_text = "%sB/s %s: %sB (%s)" % (speed, T('Remaining'), mb_left, time_left)
                self.icon = self.sabicons['green']
            else:
                self.hover_text = T('Idle')
                self.icon = self.sabicons['default']

            self.refresh_icon()
            self.counter = 0
        if sabnzbd.SABSTOP:
            self.terminate = True
Beispiel #10
0
    def doUpdates(self):
        """ Update menu info, once every 10 calls """
        self.counter += 1
        if self.counter > 10:
            self.sabpaused, bytes_left, bpsnow, time_left = api.fast_queue()
            mb_left = to_units(bytes_left, dec_limit=1)
            speed = to_units(bpsnow, dec_limit=1)

            if self.sabpaused:
                self.hover_text = T('Paused')
                self.icon = self.sabicons['pause']
            elif bytes_left > 0:
                self.hover_text = "%sB/s %s: %sB (%s)" % (speed, T('Remaining'), mb_left, time_left)
                self.icon = self.sabicons['green']
            else:
                self.hover_text = T('Idle')
                self.icon = self.sabicons['default']

            self.refresh_icon()
            self.counter = 0
        if sabnzbd.SABSTOP:
            self.terminate = True
Beispiel #11
0
def endjob(filename,
           cat,
           status,
           path,
           bytes,
           fail_msg,
           stages,
           script,
           script_output,
           script_ret,
           test=None):
    """ Send end-of-job email """
    # Is it allowed?
    if not check_cat('misc', cat, keyword='email') and not test:
        return None

    # Translate the stage names
    tr = sabnzbd.api.Ttemplate
    if not status and fail_msg:
        xstages = {tr('stage-fail'): (fail_msg, )}
    else:
        xstages = {}

    for stage in stages:
        lines = []
        for line in stages[stage]:
            if '\n' in line or '<br/>' in line:
                lines.extend(line.replace('<br/>', '\n').split('\n'))
            else:
                lines.append(line)
        xstages[tr('stage-' + stage.lower())] = lines

    parm = {}
    parm['status'] = status
    parm['name'] = filename
    parm['path'] = path
    parm['msgid'] = ''
    parm['stages'] = xstages
    parm['script'] = script
    parm['script_output'] = script_output
    parm['script_ret'] = script_ret
    parm['cat'] = cat
    parm['size'] = "%sB" % to_units(bytes)
    parm['end_time'] = time.strftime(time_format('%Y-%m-%d %H:%M:%S'),
                                     time.localtime(
                                         time.time())).decode(codepage)

    return send_with_template('email', parm, test)
Beispiel #12
0
def endjob(filename,
           cat,
           status,
           path,
           bytes_downloaded,
           fail_msg,
           stages,
           script,
           script_output,
           script_ret,
           test=None):
    """ Send end-of-job email """
    # Is it allowed?
    if not check_cat("misc", cat, keyword="email") and not test:
        return None

    # Translate the stage names
    tr = sabnzbd.api.Ttemplate
    if not status and fail_msg:
        xstages = {tr("stage-fail"): (fail_msg, )}
    else:
        xstages = {}

    for stage in stages:
        lines = []
        for line in stages[stage]:
            if "\n" in line or "<br/>" in line:
                lines.extend(line.replace("<br/>", "\n").split("\n"))
            else:
                lines.append(line)
        xstages[tr("stage-" + stage.lower())] = lines

    parm = {}
    parm["status"] = status
    parm["name"] = filename
    parm["path"] = path
    parm["msgid"] = ""
    parm["stages"] = xstages
    parm["script"] = script
    parm["script_output"] = script_output
    parm["script_ret"] = script_ret
    parm["cat"] = cat
    parm["size"] = "%sB" % to_units(bytes_downloaded)
    parm["end_time"] = time.strftime(time_format("%Y-%m-%d %H:%M:%S"),
                                     time.localtime(time.time()))

    return send_with_template("email", parm, test)
Beispiel #13
0
    def stateUpdate(self):
        try:
            paused, bytes_left, bpsnow, time_left = fast_queue()

            if paused:
                self.state = T('Paused')
                if sabnzbd.scheduler.pause_int() != "0":
                    self.setMenuTitle_("\n\n%s\n" %
                                       (sabnzbd.scheduler.pause_int()))
                else:
                    self.setMenuTitle_("")
            elif bytes_left > 0:
                self.state = ""
                speed = to_units(bpsnow)
                # "10.1 MB/s" doesn't fit, remove space char
                if 'M' in speed and len(speed) > 5:
                    speed = speed.replace(' ', '')
                time_left = (bpsnow > 10 and time_left) or "------"

                statusbarText = "\n\n%s\n%sB/s\n" % (time_left, speed)

                if sabnzbd.SABSTOP:
                    statusbarText = "..."

                if not sabnzbd.cfg.osx_speed():
                    statusbarText = ""

                self.setMenuTitle_(statusbarText)
            else:
                self.state = T('Idle')
                self.setMenuTitle_("")

            if self.state != "" and self.info != "":
                self.state_menu_item.setTitle_("%s - %s" %
                                               (self.state, self.info))
            if self.info == "":
                self.state_menu_item.setTitle_("%s" % (self.state))
            else:
                self.state_menu_item.setTitle_("%s" % (self.info))

        except:
            logging.info("[osx] stateUpdate Exception %s" %
                         (sys.exc_info()[0]))
Beispiel #14
0
    def stateUpdate(self):
        try:
            paused, bytes_left, bpsnow, time_left = fast_queue()

            if paused:
                self.state = T("Paused")
                if sabnzbd.Scheduler.pause_int() != "0":
                    self.setMenuTitle_("\n%s\n%s\n" % (T("Paused"), sabnzbd.Scheduler.pause_int()))
                else:
                    self.setMenuTitle_("")
            elif bytes_left > 0:
                self.state = ""
                speed = to_units(bpsnow)
                # "10.1 MB/s" doesn't fit, remove space char
                if "M" in speed and len(speed) > 5:
                    speed = speed.replace(" ", "")
                time_left = (bpsnow > 10 and time_left) or "------"

                statusbarText = "\n\n%s\n%sB/s\n" % (time_left, speed)

                if sabnzbd.SABSTOP:
                    statusbarText = "..."

                if not sabnzbd.cfg.osx_speed():
                    statusbarText = ""

                self.setMenuTitle_(statusbarText)
            else:
                self.state = T("Idle")
                self.setMenuTitle_("")

            if self.state != "" and self.info != "":
                self.state_menu_item.setTitle_("%s - %s" % (self.state, self.info))
            if self.info == "":
                self.state_menu_item.setTitle_("%s" % self.state)
            else:
                self.state_menu_item.setTitle_("%s" % self.info)

            if not config.get_servers():
                self.state_menu_item.setTitle_(T("Go to wizard"))
        except:
            logging.info("[osx] stateUpdate Exception", exc_info=True)
Beispiel #15
0
    def stateUpdate(self):
        try:
            qnfo = NzbQueue.do.queue_info()
            bpsnow = BPSMeter.do.get_bps()
            if sabnzbd.downloader.Downloader.do.paused:
                self.state = T('Paused')
                if sabnzbd.scheduler.pause_int() != "0":
                    self.setMenuTitle("\n\n%s\n" % (sabnzbd.scheduler.pause_int()))
                else:
                    self.setMenuTitle("")
            elif qnfo[QNFO_BYTES_LEFT_FIELD] / MEBI > 0:

                self.state = ""
                speed = to_units(bpsnow, dec_limit=1) + 'B/s'
                # "10.1 MB/s" doesn't fit, remove space char
                if 'M' in speed and len(speed) > 8:
                    speed = speed.replace(' ', '')
                timeleft = (bpsnow>10 and self.calc_timeleft(qnfo[QNFO_BYTES_LEFT_FIELD],bpsnow)) or "--"

                statusbarText = "\n\n%s\n%s\n" % (timeleft, speed)

                if sabnzbd.SABSTOP:
                    statusbarText = "..."

                if not sabnzbd.cfg.osx_speed():
                    statusbarText = ""

                self.setMenuTitle(statusbarText)
            else:
                self.state = T('Idle')
                self.setMenuTitle("")

            if self.state != "" and self.info != "":
                self.state_menu_item.setTitle_("%s - %s" % (self.state,self.info))
            if self.info == "":
                self.state_menu_item.setTitle_("%s" % (self.state))
            else:
                self.state_menu_item.setTitle_("%s" % (self.info))

        except :
            logging.info("[osx] stateUpdate Exception %s" % (sys.exc_info()[0]))
Beispiel #16
0
    def stateUpdate(self):
        try:
            paused, bytes_left, bpsnow, time_left = fast_queue()

            if paused:
                self.state = T('Paused')
                if sabnzbd.scheduler.pause_int() != "0":
                    self.setMenuTitle("\n\n%s\n" % (sabnzbd.scheduler.pause_int()))
                else:
                    self.setMenuTitle("")
            elif bytes_left > 0:
                self.state = ""
                speed = to_units(bpsnow, dec_limit=1)
                # "10.1 MB/s" doesn't fit, remove space char
                if 'M' in speed and len(speed) > 5:
                    speed = speed.replace(' ', '')
                time_left = (bpsnow>10 and time_left) or "------"

                statusbarText = "\n\n%s\n%sB/s\n" % (time_left, speed)

                if sabnzbd.SABSTOP:
                    statusbarText = "..."

                if not sabnzbd.cfg.osx_speed():
                    statusbarText = ""

                self.setMenuTitle(statusbarText)
            else:
                self.state = T('Idle')
                self.setMenuTitle("")

            if self.state != "" and self.info != "":
                self.state_menu_item.setTitle_("%s - %s" % (self.state,self.info))
            if self.info == "":
                self.state_menu_item.setTitle_("%s" % (self.state))
            else:
                self.state_menu_item.setTitle_("%s" % (self.info))

        except :
            logging.info("[osx] stateUpdate Exception %s" % (sys.exc_info()[0]))
Beispiel #17
0
def endjob(filename, msgid, cat, status, path, bytes, stages, script, script_output, script_ret):
    """ Send end-of-job email """

    # Translate the stage names
    xstages = {}
    for stage in stages:
        xstages[Tx('stage-'+stage.lower())] = stages[stage]

    parm = {}
    parm['status'] = status
    parm['name'] = filename
    parm['path'] = path
    parm['msgid'] = str(msgid)
    parm['stages'] = xstages
    parm['script'] = script
    parm['script_output'] = script_output
    parm['script_ret'] = script_ret
    parm['cat'] = cat
    parm['size'] = "%sB" % to_units(bytes)
    parm['end_time'] = time.strftime(time_format('%Y-%m-%d %H:%M:%S'), time.localtime(time.time()))

    return send_with_template('email', parm)
Beispiel #18
0
def endjob(filename, msgid, cat, status, path, bytes, stages, script,
           script_output, script_ret):
    """ Send end-of-job email """

    # Translate the stage names
    xstages = {}
    for stage in stages:
        xstages[Tx('stage-' + stage.lower())] = stages[stage]

    parm = {}
    parm['status'] = status
    parm['name'] = filename
    parm['path'] = path
    parm['msgid'] = str(msgid)
    parm['stages'] = xstages
    parm['script'] = script
    parm['script_output'] = script_output
    parm['script_ret'] = script_ret
    parm['cat'] = cat
    parm['size'] = "%sB" % to_units(bytes)
    parm['end_time'] = time.strftime(time_format('%Y-%m-%d %H:%M:%S'),
                                     time.localtime(time.time()))

    return send_with_template('email', parm)
Beispiel #19
0
 def test_unit_back_and_forth(self):
     assert 100 == misc.from_units(misc.to_units(100))
     assert 1024 == misc.from_units(misc.to_units(1024))
     assert 1024 ** 3 == misc.from_units(misc.to_units(1024 ** 3))