!C99Shell v. 2.0 [PHP 7 Update] [25.02.2019]!

Software: Apache/2.2.16 (Debian). PHP/5.3.3-7+squeeze19 

uname -a: Linux mail.tri-specialutilitydistrict.com 2.6.32-5-amd64 #1 SMP Tue May 13 16:34:35 UTC
2014 x86_64
 

uid=33(www-data) gid=33(www-data) groups=33(www-data) 

Safe-mode: OFF (not secure)

/usr/share/pyshared/glchess/   drwxr-xr-x
Free 130.05 GB of 142.11 GB (91.51%)
Home    Back    Forward    UPDIR    Refresh    Search    Buffer    Encoder    Tools    Proc.    FTP brute    Sec.    SQL    PHP-code    Update    Feedback    Self remove    Logout    


Viewing file:     history.py (4.76 KB)      -rw-r--r--
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
# -*- coding: utf-8 -*-
__author__ = 'Robert Ancell <bob27@users.sourceforge.net>'
__license__ = 'GNU General Public License Version 2'
__copyright__ = 'Copyright 2005-2006  Robert Ancell'

import os
import errno

import chess.pgn
from defaults import *

class GameHistory:
    
    def __init__(self):
        try:
            os.makedirs(HISTORY_DIR)
        except OSError, e:
            if e.errno != errno.EEXIST:
                print 'Failed to make history directory: %s' % e.strerror
    
    def getUnfinishedGame(self):
        """Get the last game that is unfinished.
        
        Returns the (PGN game, fileName, inHistory) or (None, None, False) if no unfinished games.
        """
        g = None
        fileName = None
        inHistory = False
        try:
            f = file(UNFINISHED_FILE, 'r')
            lines = f.readlines()
            f.close()

            index = 0
            while len(lines) > 0:
                fileName = lines[0].strip()

                try:
                    p = chess.pgn.PGN(fileName, 1)
                except chess.pgn.Error, e:
                    print str(e)
                except IOError, e:
                    print e.strerror
                else:
                    result = p[0].getTag(chess.pgn.TAG_RESULT)
                    if result == chess.pgn.RESULT_INCOMPLETE:
                        g = p[0]
                        inHistory = fileName.startswith(HISTORY_DIR)
                        break
                lines = lines[1:]

        except IOError, e:
            if e.errno != errno.ENOENT:
                print e.errno
                print 'Failed to read unfinished list'
                return (None, None, False)
            lines = []

        # Write the list back
        try:
            f = file(UNFINISHED_FILE, 'w')
            f.writelines(lines)
            f.close()
        except IOError:
            print 'Failed to write unfinished list'

        return (g, fileName, inHistory)

    def load(self, date):
        return
    
    def _getFilename(self, game):
        date = game.getTag(chess.pgn.TAG_DATE)
        try:
            (year, month, day) = date.split('.')
        except ValueError:
            directory = HISTORY_DIR
        else:
            directory = os.path.join(HISTORY_DIR, year, month, day)

        # Create the directory
        try:
            os.makedirs(directory)
        except OSError, e:
            if e.errno != errno.EEXIST:
                return None # FIXME

        # Get a unique name for the file
        count = 0
        fileName = os.path.join(directory, date)
        while os.path.exists(fileName):
            count += 1
            fileName = os.path.join(directory, '%s-%d' % (date, count))
        
        return fileName
    
    def rename(self, oldName, newName):
        try:
            os.unlink(oldName)
        except OSError:
            print 'Failed to remove game from history'

        try:
            f = file(UNFINISHED_FILE, 'r')
            lines = f.readlines()
            f.close()
            
            f = file(UNFINISHED_FILE, 'w')
            for line in lines:
                l = line.strip()
                if l == oldName:
                    f.write(newName + '\n')
                else:
                    f.write(l + '\n')
            f.close()
        except IOError:
            print 'Failed to update unfinished list'
    
    def save(self, g, fileName):
        """Save a game in the history.
        
        'g' is the game to save
        'fileName' is the history file to write to or None to create a new one
        """
        if fileName is None:
            fileName = self._getFilename(g)
            if fileName is None:
                # FIXME: This should be in a dialog
                print 'Unable to find location to save to'
                return

        lines = g.getLines()
        try:
            f = file(fileName, 'w')
            for line in lines:
                f.write(line + '\n')
            f.write('\n')
            f.close()
        except IOError, e:
            # FIXME: This should be in a dialog
            print 'Unable to autosave to %s: %s' % (fileName, str(e))
            
        # Update unfinished list
        result = g.getTag(chess.pgn.TAG_RESULT)
        try:
            f = file(UNFINISHED_FILE, 'r')
            lines = f.readlines()
            f.close()
            
            f = file(UNFINISHED_FILE, 'w')
            if result == chess.pgn.RESULT_INCOMPLETE:
                f.write(fileName + '\n')
            for line in lines:
                l = line.strip()
                if l == fileName and result == chess.pgn.RESULT_INCOMPLETE:
                    continue
                f.write(l + '\n')
            f.close()
        except IOError:
            print 'Failed to update unfinished list'

:: Command execute ::

Enter:
 
Select:
 

:: Search ::
  - regexp 

:: Upload ::
 
[ Read-Only ]

:: Make Dir ::
 
[ Read-Only ]
:: Make File ::
 
[ Read-Only ]

:: Go Dir ::
 
:: Go File ::
 

--[ c99shell v. 2.0 [PHP 7 Update] [25.02.2019] maintained by KaizenLouie | C99Shell Github | Generation time: 0.0072 ]--