예제 #1
0
    def on_save(self, *args):

        sharesdir = os.path.join(config.data_dir, "usershares")

        try:
            if not os.path.exists(sharesdir):
                os.makedirs(sharesdir)

        except Exception as msg:
            log.add(
                _("Can't create directory '%(folder)s', reported error: %(error)s"
                  ), {
                      'folder': sharesdir,
                      'error': msg
                  })

        try:
            get_path(sharesdir, self.user, self.dump_shares_to_file)
            log.add(
                _("Saved list of shared files for user '%(user)s' to %(dir)s"),
                {
                    'user': self.user,
                    'dir': sharesdir
                })

        except Exception as msg:
            log.add(
                _("Can't save shares, '%(user)s', reported error: %(error)s"),
                {
                    'user': self.user,
                    'error': msg
                })
예제 #2
0
def _handle_log(folder, filename, callback):

    try:
        if not os.path.isdir(folder):
            os.makedirs(folder)

        filename = filename.replace(os.sep, "-") + ".log"
        get_path(folder, filename, callback)

    except Exception as e:
        log.add("Failed to process log file: %s", e)
예제 #3
0
    def read_private_log(self):

        # Read log file
        filename = self.user.replace(os.sep, "-") + ".log"

        try:
            numlines = int(config.sections["logging"]["readprivatelines"])
        except Exception:
            numlines = 15

        try:
            get_path(config.sections["logging"]["privatelogsdir"], filename,
                     self.append_log_lines, numlines)

        except IOError:
            pass

        GLib.idle_add(scroll_bottom, self.ChatScroll.get_parent())
예제 #4
0
    def read_room_logs(self):

        if not config.sections["logging"]["readroomlogs"]:
            return

        filename = self.room.replace(os.sep, "-") + ".log"

        try:
            numlines = int(config.sections["logging"]["readroomlines"])
        except Exception:
            numlines = 15

        try:
            get_path(config.sections["logging"]["roomlogsdir"], filename,
                     self.append_log_lines, numlines)

        except IOError:
            pass

        GLib.idle_add(scroll_bottom, self.ChatScroll.get_parent())
예제 #5
0
    def write_log(self,
                  logsdir,
                  filename,
                  msg,
                  timestamp_format="%Y-%m-%d %H:%M:%S"):

        try:
            filename = filename.replace(os.sep, "-") + ".log"
            oldumask = os.umask(0o077)

            if not os.path.exists(logsdir):
                os.makedirs(logsdir)

            from pynicotine.utils import get_path
            get_path(logsdir, filename, self.write_log_callback,
                     (oldumask, timestamp_format, msg))

        except Exception as error:
            print(
                _("Couldn't write to log file \"%s\": %s") % (filename, error))