eric6/Project/DebuggerPropertiesFile.py

Sat, 27 Feb 2021 12:08:23 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 27 Feb 2021 12:08:23 +0100
changeset 8138
169e65a6787c
parent 8031
ce5858a237d2
child 8218
7c09585bd960
permissions
-rw-r--r--

Shell: added functionality to show a prompt when the main client process has exited (e.g. a script ended).

8006
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
3 # Copyright (c) 2021 Detlev Offenbach <detlev@die-offenbachs.de>
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a class representing the project debugger properties
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 JSON file.
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9 """
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 import json
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 import time
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 import typing
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 from PyQt5.QtCore import QObject
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 from E5Gui import E5MessageBox
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 from E5Gui.E5OverrideCursor import E5OverridenCursor
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 import Preferences
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21
8015
09b24828d787 Cprrected the use of the typing module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8012
diff changeset
22 Project = typing.TypeVar("Project")
8006
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 class DebuggerPropertiesFile(QObject):
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 """
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 Class representing the project debugger properties JSON file.
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 """
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 def __init__(self, project: Project, parent: QObject = None):
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 """
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 Constructor
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 @param project reference to the project object
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 @type Project
8016
e484fc67677e Corrected some code documentation strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8015
diff changeset
35 @param parent reference to the parent object (defaults to None)
8006
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 @type QObject (optional)
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 """
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 super(DebuggerPropertiesFile, self).__init__(parent)
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 self.__project = project
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 def writeFile(self, filename: str) -> bool:
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 """
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 Public method to write the project debugger properties data to a
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 project debugger properties JSON file.
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 @param filename name of the user project file
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 @type str
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 @return flag indicating a successful write
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 @rtype bool
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 """
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 debuggerPropertiesDict = {}
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 debuggerPropertiesDict["header"] = {
8012
ecf45f723038 Several corrections to the JSON file handlers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8006
diff changeset
53 "comment": "eric debugger properties file for project {0}".format(
ecf45f723038 Several corrections to the JSON file handlers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8006
diff changeset
54 self.__project.getProjectName()),
8006
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 "warning": "This file was generated automatically, do not edit.",
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 }
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57
8031
ce5858a237d2 Changed the Project and MultiProject configuration option "XMLTimestamp" to "TimestampFile". A configuration check is suggested.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8016
diff changeset
58 if Preferences.getProject("TimestampFile"):
8006
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 debuggerPropertiesDict["header"]["saved"] = (
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 time.strftime('%Y-%m-%d, %H:%M:%S')
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 )
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 debuggerPropertiesDict["debug_properties"] = (
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 self.__project.debugProperties
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 )
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 try:
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 jsonString = json.dumps(debuggerPropertiesDict, indent=2)
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 with open(filename, "w") as f:
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 f.write(jsonString)
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 except (TypeError, EnvironmentError) as err:
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 with E5OverridenCursor():
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 E5MessageBox.critical(
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 None,
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 self.tr("Save Debugger Properties"),
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 self.tr(
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 "<p>The project debugger properties file"
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 " <b>{0}</b> could not be written.</p>"
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 "<p>Reason: {1}</p>"
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 ).format(filename, str(err))
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 )
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 return False
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 return True
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 def readFile(self, filename: str) -> bool:
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 """
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 Public method to read the project debugger properties data from a
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 project debugger properties JSON file.
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 @param filename name of the project file
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 @type str
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 @return flag indicating a successful read
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 @rtype bool
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 """
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 try:
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 with open(filename, "r") as f:
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 jsonString = f.read()
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 debuggerPropertiesDict = json.loads(jsonString)
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 except (EnvironmentError, json.JSONDecodeError) as err:
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 E5MessageBox.critical(
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 None,
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 self.tr("Read Debugger Properties"),
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 self.tr(
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 "<p>The project debugger properties file <b>{0}</b>"
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 " could not be read.</p><p>Reason: {1}</p>"
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 ).format(filename, str(err))
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 )
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 return False
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 self.__project.debugProperties = (
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 debuggerPropertiesDict["debug_properties"]
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 )
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114
c4110b8b5931 Started converting the various file generators to JSON format (from XML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 return True

eric ide

mercurial