Exemple #1
0
    def execute(self, script):
        out, err = decode(super(Rhino, self).execute(script))
        try:
            return out.encode("ISO-8859-1"), err

        finally:
            return out, err
Exemple #2
0
def get_download(path):
    path = urllib.unquote(decode(path))
    #@TODO some files can not be downloaded

    root = API.get_config_value("general", "download_folder")

    path = path.replace("..", "")
    return bottle.static_file(fs_encode(path), fs_encode(root))
Exemple #3
0
def from_string(value, typ=None):
    """Cast value to given type, unicode for strings"""

    # value is no string
    if not isinstance(value, basestring):
        return value

    value = decode(value)

    if typ == InputType.Int:
        return int(value)
    elif typ == InputType.Bool:
        return to_bool(value)
    elif typ == InputType.Time:
        if not value: value = "0:00"
        if not ":" in value: value += ":00"
        return value
    else:
        return value
Exemple #4
0
 def get(self, section, option):
     """Get value"""
     value = self.config[section][option]["value"]
     return decode(value)
Exemple #5
0
def logs(item=-1):
    s = bottle.request.environ.get('beaker.session')

    perpage = s.get('perpage', 34)
    reversed = s.get('reversed', False)

    warning = ""
    conf = API.get_config_value("log", "file_log")
    if not conf:
        warning = "Warning: File log is disabled, see settings page."

    perpage_p = ((20, 20), (50, 50), (100, 100), (250, 250), (0, 'all'))
    fro = None

    if bottle.request.environ.get('REQUEST_METHOD', "GET") == "POST":
        try:
            fro = datetime.datetime.strptime(bottle.request.forms['from'], '%d.%m.%Y %H:%M:%S')
        except Exception:
            pass
        try:
            perpage = int(bottle.request.forms['perpage'])
            s['perpage'] = perpage

            reversed = bool(bottle.request.forms.get('reversed', False))
            s['reversed'] = reversed
        except Exception:
            pass

        s.save()

    try:
        item = int(item)
    except Exception:
        pass

    log = API.get_log()
    if not perpage:
        item = 1

    if item < 1 or type(item) is not int:
        item = 1 if len(log) - perpage + 1 < 1 else len(log) - perpage + 1

    if type(fro) is datetime.datetime:  #: we will search for datetime.datetime
        item = -1

    data = []
    counter = 0
    perpagecheck = 0
    for l in log:
        counter += 1

        if counter >= item:
            try:
                date, time, level, message = decode(l).split(" ", 3)
                dtime = datetime.datetime.strptime(date + ' ' + time, '%Y-%m-%d %H:%M:%S')
            except Exception:
                dtime = None
                date = '?'
                time = ' '
                level = '?'
                message = l

            if item == -1 and dtime is not None and fro <= dtime:
                item = counter  #: found our datetime.datetime

            if item >= 0:
                data.append({'line': counter, 'date': date + " " + time, 'level': level, 'message': message})
                perpagecheck += 1
                if fro is None and dtime is not None:  #: if fro not set set it to first showed line
                    fro = dtime

            if perpagecheck >= perpage > 0:
                break

    if fro is None:  #: still not set, empty log?
        fro = datetime.datetime.now()
    if reversed:
        data.reverse()
    return render_to_response('logs.html', {'warning': warning, 'log': data, 'from': fro.strftime('%d.%m.%Y %H:%M:%S'),
                                            'reversed': reversed, 'perpage': perpage, 'perpage_p': sorted(perpage_p),
                                            'iprev': 1 if item - perpage < 1 else item - perpage,
                                            'inext': (item + perpage) if item + perpage < len(log) else item,
                                            'color_console': API.get_config_value("log", "color_console")},
                              [pre_processor])
Exemple #6
0
 def read_string(self):
     len = self.read_i32()
     str = self.trans.read_all(len)
     return decode(str)
Exemple #7
0
    def add_package(self, name, links, dest=Destination.Queue):
        """
        Adds a package, with links to desired destination.

        :param name: name of the new package
        :param links: list of urls
        :param dest: `Destination`
        :return: package id of the new package
        """
        if self.pyload.config.get("general", "folder_per_package"):
            folder = urlparse.urlparse(name).path.split("/")[-1]
        else:
            folder = ""

        folder = safe_filename(folder)

        pid = self.pyload.files.add_package(name, folder, dest)

        self.pyload.files.add_links(links, pid)

        self.pyload.log.info(_("Added package %(name)s containing %(count)d links") % {"name": decode(name), "count": len(links)})

        self.pyload.files.save()

        return pid