m0r13 / mclogalyzer

Minecraft Server Log Analyzer
GNU General Public License v3.0
44 stars 21 forks source link

little problem... #16

Open yoan31 opened 9 years ago

yoan31 commented 9 years ago

Hi

I try this program but i must do something wrong... I have this message:

Traceback (most recent call last): File "/usr/local/bin/mclogalyzer", line 7, in mclogalyzer.main() File "/usr/local/lib/python2.7/dist-packages/mclogalyzer/mclogalyzer.py", line 497, in main last_update=time.strftime("%Y-%m-%d %H:%M:%S"))) File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 969, in render return self.environment.handle_exception(exc_info, True) File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 742, in handle_exception reraise(exc_type, exc_value, tb) File "/usr/local/lib/python2.7/dist-packages/mclogalyzer/template.html", line 301, in top-level template code

  • {{ a }}
  • UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 19: ordinal not in range(128)

    Can you help me ? Thanks

    m0r13 commented 9 years ago

    You are probably not doing anything wrong. :) This seems to be an encoding issue with the template file and the server log file. I'll have a look at this tomorrow.

    yoan31 commented 9 years ago

    Thanks, I wait ;)

    m0r13 commented 9 years ago

    Sorry I'm a bit too lazy today and tired of this encoding stuff. I see that you are using Python 2, is there a way for you to use Python 3? (Because Python 3 makes everything encoding related awesome with unicode! :D )

    yoan31 commented 9 years ago

    Thanks for your reply

    I have instal python3, but I have the same result. I see that's python2 always use by the command.

    my command is :

    mclogalyzer /home/minecraft/servers/FTBInfinityServer/logs/ stats.html

    m0r13 commented 9 years ago

    Oh, mclogalyzer is just a python file that you can directly run with python2 or python3. First of all you have to find it: run whereis mclogalyzer. That should be /usr/bin/mclogalyzer. Then you can run it with Python 3: python3 /usr/bin/mclogalyzer ....

    yoan31 commented 9 years ago

    whereis mclogalyzer ---> /usr/local/bin/mclogalyzer

    My command : python3 /usr/local/bin/mclogalyzer /home/minecraft/servers/FTBInfinityServer/logs/ /var/www/stats.html

    Traceback (most recent call last): File "/usr/local/bin/mclogalyzer", line 3, in import mclogalyzer ImportError: No module named mclogalyzer

    m0r13 commented 9 years ago

    Oh, you also have to install mclogalyzer for python3 (python3 setup.py install).

    I forgot to say that for now you can also just run the mclogalyzer script in the source directory manually with python3 without installing it: python3 mclogaylzer/mclogalyzer.py ....

    yoan31 commented 9 years ago

    Another problem....

    I try your command with python3:

    File "mclogalyzer/mclogalyzer.py", line 257 print "### Warning: Unable to find login username:", line ^ SyntaxError: invalid syntax

    2015-07-10 13:15 GMT+02:00 Moritz Hilscher notifications@github.com:

    Oh, you also have to install mclogalyzer for python3 (python3 setup.py install).

    I forgot to say that for now you can also just run the mclogalyzer script in the source directory manually with python3 without installing it: python3 mclogaylzer/mclogalyzer.py ....

    — Reply to this email directly or view it on GitHub https://github.com/m0r13/mclogalyzer/issues/16#issuecomment-120387248.

    nicolasconnault commented 9 years ago

    Same error here when trying to install with python3:

    byte-compiling /usr/local/lib/python3.4/dist-packages/mclogalyzer/mclogalyzer.py to mclogalyzer.cpython-34.pyc File "/usr/local/lib/python3.4/dist-packages/mclogalyzer/mclogalyzer.py", line 294 print "### Warning: Unable to find login username:", line

    SyntaxError: Missing parentheses in call to 'print'

    So this is a change in syntax between Python 2 and 3: all the print statements (about 8) need to use parentheses around their arguments.

    nicolasconnault commented 9 years ago

    @m0r13 I've successfully upgraded your script to Python 3, there were quite a few bits that needed changing. Let me know if you'd like a patch file.

    nicolasconnault commented 9 years ago
    diff --git a/mclogalyzer/mclogalyzer.py b/mclogalyzer/mclogalyzer.py
    index a43ce1b..923f34f 100755
    --- a/mclogalyzer/mclogalyzer.py
    +++ b/mclogalyzer/mclogalyzer.py
    @@ -279,7 +279,7 @@ def grep_logname_date(line):
    
     def grep_log_datetime(date, line):
         try:
    -        d = time.strptime(line.split(" ")[0], "[%H:%M:%S]")
    +        d = time.strptime(line.decode('utf-8').split(" ")[0], "[%H:%M:%S]")
         except ValueError:
             return None
         return datetime.datetime(
    @@ -289,36 +289,36 @@ def grep_log_datetime(date, line):
    
     def grep_login_username(line):
    -    search = REGEX_LOGIN_USERNAME.search(line)
    +    search = REGEX_LOGIN_USERNAME.search(line.decode('utf-8'))
         if not search:
    -        print "### Warning: Unable to find login username:", line
    +        print("### Warning: Unable to find login username:", line)
             return ""
         username = search.group(1).lstrip().rstrip()
    -    return username.decode("ascii", "ignore").encode("ascii", "ignore")
    +    return username
    
     def grep_logout_username(line):
    -    search = REGEX_LOGOUT_USERNAME.search(line)
    +    search = REGEX_LOGOUT_USERNAME.search(line.decode('utf-8'))
         if not search:
    -        search = REGEX_LOGOUT_USERNAME2.search(line)
    +        search = REGEX_LOGOUT_USERNAME2.search(line.decode('utf-8'))
             if not search:
    -            print "### Warning: Unable to find username:", line
    +            print("### Warning: Unable to find username:", line)
                 return ""
         username = search.group(1).lstrip().rstrip()
    -    return username.decode("ascii", "ignore").encode("ascii", "ignore")
    +    return username
    
     def grep_kick_username(line):
    -    search = REGEX_KICK_USERNAME.search(line)
    +    search = REGEX_KICK_USERNAME.search(line.decode('utf-8'))
         if not search:
    -        print "### Warning: Unable to find kick logout username:", line
    +        print("### Warning: Unable to find kick logout username:", line)
             return ""
         return search.group(1)[:-1].decode("ascii", "ignore").encode("ascii", "ignore")
    
     def grep_death(line):
         for regex in REGEX_DEATH_MESSAGES:
    -        search = regex.search(line)
    +        search = regex.search(line.decode())
             if search:
                 return search.group(1), capitalize_first(search.group(2))
         return None, None
    @@ -327,12 +327,12 @@ def grep_chatlog(line):
         search
    
     def grep_achievement(line):
    -    search = REGEX_ACHIEVEMENT.search(line)
    +    search = REGEX_ACHIEVEMENT.search(line.decode('utf-8'))
         if not search:
    -        print "### Warning: Unable to find achievement username or achievement:", line
    +        print("### Warning: Unable to find achievement username or achievement:", line)
             return None, None
         username = search.group(1)
    -    return username.decode("ascii", "ignore").encode("ascii", "ignore"), search.group(2)
    +    return username, search.group(2)
    
     def format_delta(timedelta, days=True, maybe_years=False):
    @@ -373,14 +373,14 @@ def parse_logs(logdir, since=None, whitelist_users=None):
             thisChatDay = ChatDay(today)
             if first_date is None:
                 first_date = today
    -        print "Parsing log %s (%s) ..." % (logname, today)
    +        print("Parsing log %s (%s) ..." % (logname, today))
    
             logfile = gzip.open(os.path.join(logdir, logname))
    
             for line in logfile:
                 line = line.rstrip()
    
    -            if "logged in with entity id" in line:
    +            if b"logged in with entity id" in line:
                     date = grep_log_datetime(today, line)
                     if date is None or (since is not None and date < since):
                         continue
    @@ -404,13 +404,13 @@ def parse_logs(logdir, since=None, whitelist_users=None):
                             server._max_players = len(online_players)
                             server._max_players_date = date
    
    -            elif "lost connection" in line or "[INFO] CONSOLE: Kicked player" in line:
    +            elif b"lost connection" in line or b"[INFO] CONSOLE: Kicked player" in line:
                     date = grep_log_datetime(today, line)
                     if date is None or (since is not None and date < since):
                         continue
    
                     username = ""
    -                if "lost connection" in line:
    +                if b"lost connection" in line:
                         username = grep_logout_username(line)
                     else:
                         username = grep_kick_username(line)
    @@ -426,7 +426,7 @@ def parse_logs(logdir, since=None, whitelist_users=None):
                     if username in online_players:
                         online_players.remove(username)
    
    -            elif "Stopping server" in line or "forcibly shutdown" in line or "Starting minecraft server" in line:
    +            elif b"Stopping server" in line or b"forcibly shutdown" in line or b"Starting minecraft server" in line:
                     date = grep_log_datetime(today, line)
                     if date is None or (since is not None and date < since):
                         continue
    @@ -435,7 +435,7 @@ def parse_logs(logdir, since=None, whitelist_users=None):
                         user.handle_logout(date)
                     online_players = set()
    
    -            elif "earned the achievement" in line:
    +            elif b"earned the achievement" in line:
                     achievement_username, achievement = grep_achievement(line)
                     if achievement_username is not None:
                         if achievement_username in users:
    @@ -455,7 +455,7 @@ def parse_logs(logdir, since=None, whitelist_users=None):
                             death_user._death_types[death_type] += 1
                     else:
                         date = grep_log_datetime(today, line)
    -                    search = REGEX_CHAT_USERNAME.search(line)
    +                    search = REGEX_CHAT_USERNAME.search(line.decode('utf-8'))
                         if not search:
                             continue
                         username = search.group(2)
    @@ -474,7 +474,7 @@ def parse_logs(logdir, since=None, whitelist_users=None):
                 if username not in users:
                     users[username] = UserStats(username)
    
    -    users = users.values()
    +    users = list(users.values())
         users.sort(key=lambda user: user.time, reverse=True)
    
         server._statistics_since = since if since is not None else first_date
    @@ -527,7 +527,7 @@ def main():
             try:
                 d = time.strptime(args["since"], "%Y-%m-%d %H:%M:%S")
             except ValueError:
    -            print "Invalid datetime format! The format must be year-month-day hour:minute:second ."
    +            print("Invalid datetime format! The format must be year-month-day hour:minute:second .")
                 sys.exit(1)
             since = datetime.datetime(*(d[0:6]))
    
    @@ -544,7 +544,7 @@ def main():
         #print template_path
         #print template_dir, template_name
         if not os.path.exists(template_path):
    -        print "Unable to find template file %s!" % template_path
    +        print("Unable to find template file %s!" % template_path)
             sys.exit(1)
    
         env = jinja2.Environment(loader=jinja2.FileSystemLoader(template_dir))