aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/python/pythonproject.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/python/pythonproject.cpp')
-rw-r--r--src/plugins/python/pythonproject.cpp36
1 files changed, 17 insertions, 19 deletions
diff --git a/src/plugins/python/pythonproject.cpp b/src/plugins/python/pythonproject.cpp
index a29847ac7b..e9d503037d 100644
--- a/src/plugins/python/pythonproject.cpp
+++ b/src/plugins/python/pythonproject.cpp
@@ -52,12 +52,12 @@ public:
QString name() const override { return QLatin1String("python"); }
bool saveRawFileList(const QStringList &rawFileList);
- bool saveRawList(const QStringList &rawList, const QString &fileName);
+ bool saveRawList(const QStringList &rawList, const FilePath &filePath);
void parse();
QStringList processEntries(const QStringList &paths,
QHash<QString, QString> *map = nullptr) const;
- bool writePyProjectFile(const QString &fileName, QString &content,
+ bool writePyProjectFile(const FilePath &filePath, QString &content,
const QStringList &rawList, QString *errorMessage);
void triggerParsing() final;
@@ -90,14 +90,13 @@ private:
static QJsonObject readObjJson(const FilePath &projectFile, QString *errorMessage)
{
- QFile file(projectFile.toString());
- if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
- *errorMessage = Tr::tr("Unable to open \"%1\" for reading: %2")
- .arg(projectFile.toUserOutput(), file.errorString());
- return QJsonObject();
+ const expected_str<QByteArray> fileContentsResult = projectFile.fileContents();
+ if (!fileContentsResult) {
+ *errorMessage = fileContentsResult.error();
+ return {};
}
- const QByteArray content = file.readAll();
+ const QByteArray content = *fileContentsResult;
// This assumes the project file is formed with only one field called
// 'files' that has a list associated of the files to include in the project.
@@ -268,25 +267,24 @@ void PythonBuildSystem::triggerParsing()
bool PythonBuildSystem::saveRawFileList(const QStringList &rawFileList)
{
- const bool result = saveRawList(rawFileList, projectFilePath().toString());
+ const bool result = saveRawList(rawFileList, projectFilePath());
// refresh(PythonProject::Files);
return result;
}
-bool PythonBuildSystem::saveRawList(const QStringList &rawList, const QString &fileName)
+bool PythonBuildSystem::saveRawList(const QStringList &rawList, const FilePath &filePath)
{
- const FilePath filePath = FilePath::fromString(fileName);
- FileChangeBlocker changeGuarg(filePath);
+ const FileChangeBlocker changeGuarg(filePath);
bool result = false;
// New project file
- if (fileName.endsWith(".pyproject")) {
+ if (filePath.endsWith(".pyproject")) {
FileSaver saver(filePath, QIODevice::ReadOnly | QIODevice::Text);
if (!saver.hasError()) {
QString content = QTextStream(saver.file()).readAll();
if (saver.finalize(ICore::dialogParent())) {
QString errorMessage;
- result = writePyProjectFile(fileName, content, rawList, &errorMessage);
+ result = writePyProjectFile(filePath, content, rawList, &errorMessage);
if (!errorMessage.isEmpty())
MessageManager::writeDisrupting(errorMessage);
}
@@ -305,13 +303,13 @@ bool PythonBuildSystem::saveRawList(const QStringList &rawList, const QString &f
return result;
}
-bool PythonBuildSystem::writePyProjectFile(const QString &fileName, QString &content,
- const QStringList &rawList, QString *errorMessage)
+bool PythonBuildSystem::writePyProjectFile(const FilePath &filePath, QString &content,
+ const QStringList &rawList, QString *errorMessage)
{
- QFile file(fileName);
+ QFile file(filePath.toString());
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
- *errorMessage = Tr::tr("Unable to open \"%1\" for reading: %2")
- .arg(fileName, file.errorString());
+ *errorMessage = Tr::tr("Unable to open \"%1\" for writing: %2")
+ .arg(filePath.toUserOutput(), file.errorString());
return false;
}