summaryrefslogtreecommitdiff
path: root/games-board/pychess/files/pychess-setup-no-display.patch
blob: 29b06bd93fe84e533e1cb16422a87a3bb58bb77e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
From faf456bf2d081aa3cff52d0f9f714748a04628b1 Mon Sep 17 00:00:00 2001
From: gbtami <gbtami@gmail.com>
Date: Sat, 18 May 2019 18:50:17 +0200
Subject: [PATCH] Fix bdist_rpm. Prevent importing GLib from setup.py

---
 lib/pychess/Savers/pgn.py         |  8 ++++----
 lib/pychess/Utils/__init__.py     | 18 ++++++++++++++++++
 lib/pychess/widgets/ChessClock.py | 20 ++------------------
 3 files changed, 24 insertions(+), 22 deletions(-)

diff --git a/lib/pychess/Savers/pgn.py b/lib/pychess/Savers/pgn.py
index ac4238471..2b089e1d1 100644
--- a/lib/pychess/Savers/pgn.py
+++ b/lib/pychess/Savers/pgn.py
@@ -10,8 +10,6 @@
 import sys
 import textwrap
 
-from gi.repository import GLib
-
 import pexpect
 
 from sqlalchemy import String
@@ -23,7 +21,6 @@
     WON_RESIGN, DRAW, BLACKWON, WHITEWON, NORMALCHESS, DRAW_AGREE, FIRST_PAGE, PREV_PAGE, NEXT_PAGE, \
     ABORTED_REASONS, ADJOURNED_REASONS, WON_CALLFLAG, DRAW_ADJUDICATION, WON_ADJUDICATION, \
     WHITE_ENGINE_DIED, BLACK_ENGINE_DIED, RUNNING, TOOL_NONE, TOOL_CHESSDB, TOOL_SCOUTFISH
-
 from pychess.System import conf
 from pychess.System.Log import log
 from pychess.System.protoopen import PGN_ENCODING
@@ -35,7 +32,7 @@
 from pychess.Utils.elo import get_elo_rating_change_pgn
 from pychess.Utils.logic import getStatus
 from pychess.Variants import name2variant, NormalBoard, variants
-from pychess.widgets.ChessClock import formatTime
+from pychess.Utils import formatTime
 from pychess.Savers.ChessFile import ChessFile, LoadingError
 from pychess.Savers.database import col2label, TagDatabase, parseDateTag
 from pychess.Database import model as dbmodel
@@ -460,6 +457,7 @@ def init_tag_database(self, importer=None):
             if size > 10000000:
                 drop_indexes(self.engine)
             if self.progressbar is not None:
+                from gi.repository import GLib
                 GLib.idle_add(self.progressbar.set_text, _("Importing game headers..."))
             if importer is None:
                 importer = PgnImport(self)
@@ -477,6 +475,7 @@ def init_chess_db(self):
         if chess_db_path is not None and self.path and self.size > 0:
             try:
                 if self.progressbar is not None:
+                    from gi.repository import GLib
                     GLib.idle_add(self.progressbar.set_text, _("Creating .bin index file..."))
                 self.chess_db = Parser(engine=(chess_db_path, ))
                 self.chess_db.open(self.path)
@@ -503,6 +502,7 @@ def init_scoutfish(self):
         if scoutfish_path is not None and self.path and self.size > 0:
             try:
                 if self.progressbar is not None:
+                    from gi.repository import GLib
                     GLib.idle_add(self.progressbar.set_text, _("Creating .scout index file..."))
                 self.scoutfish = Scoutfish(engine=(scoutfish_path, ))
                 self.scoutfish.open(self.path)
diff --git a/lib/pychess/Utils/__init__.py b/lib/pychess/Utils/__init__.py
index 481273854..038c798da 100755
--- a/lib/pychess/Utils/__init__.py
+++ b/lib/pychess/Utils/__init__.py
@@ -1,9 +1,27 @@
 import asyncio
 import weakref
+from math import ceil
 
 from pychess.Utils.lutils.ldata import MATE_VALUE, MATE_DEPTH
 
 
+def formatTime(seconds, clk2pgn=False):
+    minus = ""
+    if seconds <= -10 or seconds >= 10:
+        seconds = ceil(seconds)
+    if seconds < 0:
+        minus = "-"
+        seconds = -seconds
+    hours, remainder = divmod(seconds, 3600)
+    minutes, seconds = divmod(remainder, 60)
+    if hours or clk2pgn:
+        return minus + "%d:%02d:%02d" % (hours, minutes, seconds)
+    elif not minutes and seconds < 10:
+        return minus + "%.1f" % seconds
+    else:
+        return minus + "%d:%02d" % (minutes, seconds)
+
+
 def prettyPrintScore(s, depth, format_mate=False):
     """The score parameter is an eval value from White point of view"""
 
diff --git a/lib/pychess/widgets/ChessClock.py b/lib/pychess/widgets/ChessClock.py
index 8811d13db..740e0828a 100644
--- a/lib/pychess/widgets/ChessClock.py
+++ b/lib/pychess/widgets/ChessClock.py
@@ -1,32 +1,16 @@
 # -*- coding: UTF-8 -*-
 
-from math import ceil, pi, cos, sin
+from math import pi, cos, sin
 
 import cairo
 from gi.repository import GLib, Gtk, Gdk, Pango, PangoCairo, GObject
 
 from pychess.System import conf
+from pychess.Utils import formatTime
 from pychess.Utils.const import BLACK, WHITE, LOCAL, UNFINISHED_STATES, DRAW, WHITEWON, BLACKWON, UNKNOWN_STATE
 from . import preferencesDialog
 
 
-def formatTime(seconds, clk2pgn=False):
-    minus = ""
-    if seconds <= -10 or seconds >= 10:
-        seconds = ceil(seconds)
-    if seconds < 0:
-        minus = "-"
-        seconds = -seconds
-    hours, remainder = divmod(seconds, 3600)
-    minutes, seconds = divmod(remainder, 60)
-    if hours or clk2pgn:
-        return minus + "%d:%02d:%02d" % (hours, minutes, seconds)
-    elif not minutes and seconds < 10:
-        return minus + "%.1f" % seconds
-    else:
-        return minus + "%d:%02d" % (minutes, seconds)
-
-
 class ChessClock(Gtk.DrawingArea):
     def __init__(self):
         GObject.GObject.__init__(self)