Skip to content

Commit

Permalink
Metadata and filename path checks are now in LayerSource
Browse files Browse the repository at this point in the history
  • Loading branch information
suricactus committed Sep 1, 2021
1 parent 12c0dc9 commit 638c936
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 63 deletions.
4 changes: 2 additions & 2 deletions qfieldsync/core/cloud_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@

from qfieldsync.libqfieldsync.layer import LayerSource
from qfieldsync.libqfieldsync.utils.file_utils import copy_images
from qfieldsync.utils.qgis_utils import (
from qfieldsync.libqfieldsync.utils.qgis import (
get_qgis_files_within_dir,
make_temp_qgis_file,
open_project,
)
from qfieldsync.utils.qgis_utils import open_project


class CloudConverter(QObject):
Expand Down
2 changes: 1 addition & 1 deletion qfieldsync/core/cloud_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from qgis.core import QgsProject

from qfieldsync.core.preferences import Preferences
from qfieldsync.utils.qgis_utils import get_qgis_files_within_dir
from qfieldsync.libqfieldsync.utils.qgis import get_qgis_files_within_dir


class ProjectFileCheckout(IntFlag):
Expand Down
2 changes: 1 addition & 1 deletion qfieldsync/gui/cloud_browser_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
from qfieldsync.gui.cloud_login_dialog import CloudLoginDialog
from qfieldsync.gui.cloud_projects_dialog import CloudProjectsDialog
from qfieldsync.gui.cloud_transfer_dialog import CloudTransferDialog
from qfieldsync.utils.qgis_utils import get_qgis_files_within_dir
from qfieldsync.libqfieldsync.utils.qgis import get_qgis_files_within_dir


class QFieldCloudItemProvider(QgsDataItemProvider):
Expand Down
2 changes: 1 addition & 1 deletion qfieldsync/gui/cloud_projects_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@
from qfieldsync.gui.cloud_converter_dialog import CloudConverterDialog
from qfieldsync.gui.cloud_login_dialog import CloudLoginDialog
from qfieldsync.gui.cloud_transfer_dialog import CloudTransferDialog
from qfieldsync.libqfieldsync.utils.qgis import get_qgis_files_within_dir
from qfieldsync.utils.cloud_utils import closure, to_cloud_title
from qfieldsync.utils.permissions import can_change_project_owner, can_delete_project
from qfieldsync.utils.qgis_utils import get_qgis_files_within_dir
from qfieldsync.utils.qt_utils import rounded_pixmap

CloudProjectsDialogUi, _ = loadUiType(
Expand Down
6 changes: 4 additions & 2 deletions qfieldsync/gui/cloud_transfer_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@
from qfieldsync.core.cloud_transferrer import CloudTransferrer, TransferFileLogsModel
from qfieldsync.core.preferences import Preferences
from qfieldsync.libqfieldsync.utils.file_utils import get_unique_empty_dirname
from qfieldsync.utils.qgis_utils import get_qgis_files_within_dir
from qfieldsync.libqfieldsync.utils.qgis import (
get_memory_layers,
get_qgis_files_within_dir,
)

from ..utils.qgis_utils import get_memory_layers
from ..utils.qt_utils import make_folder_selector, make_icon, make_pixmap

CloudTransferDialogUi, _ = loadUiType(
Expand Down
2 changes: 1 addition & 1 deletion qfieldsync/gui/package_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
from qfieldsync.gui.project_configuration_dialog import ProjectConfigurationDialog
from qfieldsync.libqfieldsync import LayerSource, OfflineConverter, ProjectConfiguration
from qfieldsync.libqfieldsync.utils.file_utils import fileparts
from qfieldsync.libqfieldsync.utils.qgis import get_project_title

from ..utils.qgis_utils import get_project_title
from ..utils.qt_utils import make_folder_selector

DialogUi, _ = loadUiType(
Expand Down
7 changes: 2 additions & 5 deletions qfieldsync/gui/synchronize_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,8 @@
get_project_in_folder,
import_file_checksum,
)
from qfieldsync.utils.qgis_utils import (
import_checksums_of_project,
make_temp_qgis_file,
open_project,
)
from qfieldsync.libqfieldsync.utils.qgis import make_temp_qgis_file, open_project
from qfieldsync.utils.qgis_utils import import_checksums_of_project
from qfieldsync.utils.qt_utils import make_folder_selector

DialogUi, _ = loadUiType(
Expand Down
2 changes: 1 addition & 1 deletion qfieldsync/libqfieldsync
52 changes: 3 additions & 49 deletions qfieldsync/utils/qgis_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,46 +19,13 @@
***************************************************************************/
"""

import os
import tempfile
from pathlib import Path
from typing import List, Union
from typing import List

from qgis.core import QgsMapLayer, QgsProject
from qgis.PyQt.QtCore import QCoreApplication
from qgis.core import QgsProject

from qfieldsync.libqfieldsync import ProjectConfiguration
from qfieldsync.libqfieldsync.utils.file_utils import get_project_in_folder


def get_project_title(project: QgsProject) -> str:
""" Gets project title, or if non available, the basename of the filename"""
if project.title():
return project.title()
else:
return Path(project.fileName()).stem


def open_project(filename: str, filename_to_read: str = None) -> bool:
project = QgsProject.instance()
QCoreApplication.processEvents()
project.clear()
QCoreApplication.processEvents()

is_success = project.read(filename_to_read or filename)
project.setFileName(filename)

return is_success


def make_temp_qgis_file(project: QgsProject) -> str:
project_backup_dir = tempfile.mkdtemp()
original_filename = project.fileName()
backup_filename = os.path.join(project_backup_dir, f"{project.baseName()}.qgs")
project.write(backup_filename)
project.setFileName(original_filename)

return backup_filename
from qfieldsync.libqfieldsync.utils.qgis import open_project


def import_checksums_of_project(dirname: str) -> List[str]:
Expand All @@ -68,16 +35,3 @@ def import_checksums_of_project(dirname: str) -> List[str]:
original_project_path = ProjectConfiguration(project).original_project_path
open_project(original_project_path)
return ProjectConfiguration(project).imported_files_checksums


def get_memory_layers(project: QgsProject) -> List[QgsMapLayer]:
return [
layer
for layer in project.mapLayers().values()
if layer.isValid() and layer.dataProvider().name() == "memory"
]


def get_qgis_files_within_dir(dirname: Union[str, Path]) -> List[Path]:
dirname = Path(dirname)
return list(dirname.glob("*.qgs")) + list(dirname.glob("*.qgz"))

0 comments on commit 638c936

Please sign in to comment.