added project import dialog

This commit is contained in:
Nasrullah Taha
2014-10-22 15:03:13 -06:00
parent c8ef818e1c
commit 9d0bd31eea
6 changed files with 202 additions and 5 deletions

View File

@@ -253,16 +253,16 @@ class BaseCloudCtrl(object):
def list_projects(self):
"""
Lists projects in cloud storage
:return: List of (project name, object name in storage)
:return: Dictionary where project names are keys and values are names of objects in storage
"""
try:
gns3_container = self.storage_driver.get_container(self.GNS3_CONTAINER_NAME)
projects = [
(obj.name.replace('projects/', '').replace('.zip', ''), obj.name)
projects = {
obj.name.replace('projects/', '').replace('.zip', ''): obj.name
for obj in gns3_container.list_objects()
if obj.name.startswith('projects/') and obj.name[-4:] == '.zip'
]
}
return projects
except ContainerDoesNotExistError:
return []

View File

@@ -340,3 +340,8 @@ class DownloadProjectThread(QThread):
def stop(self):
pass # TODO cleanup and delete downloaded files
def get_cloud_projects(cloud_settings):
provider = get_provider(cloud_settings)
return provider.list_projects()

View File

@@ -0,0 +1,46 @@
"""
Dialog for importing cloud projects
"""
from ..ui.import_cloud_project_dialog_ui import Ui_ImportCloudProjectDialog
from ..qt import QtGui
from ..cloud.utils import get_cloud_projects, DownloadProjectThread
from ..utils.progress_dialog import ProgressDialog
class ImportCloudProjectDialog(QtGui.QDialog, Ui_ImportCloudProjectDialog):
"""
Import cloud project dialog implementation.
"""
def __init__(self, parent, project_dest_path, images_dest_path, cloud_settings):
QtGui.QDialog.__init__(self, parent)
self.setupUi(self)
self.project_dest_path = project_dest_path
self.images_dest_path = images_dest_path
self.cloud_settings = cloud_settings
self.uiImportProjectAction.clicked.connect(self._importProject)
self._listCloudProjects()
def _importProject(self):
project_file_name = self.projects[self.listWidget.currentItem().text()]
download_thread = DownloadProjectThread(
project_file_name,
self.project_dest_path,
self.images_dest_path,
self.cloud_settings
)
progress_dialog = ProgressDialog(download_thread, "Importing project", "Downloading project files...", "Cancel",
parent=self.parent())
progress_dialog.show()
progress_dialog.exec_()
self.close()
def _listCloudProjects(self):
self.projects = get_cloud_projects(self.cloud_settings)
self.listWidget.addItems(list(self.projects.keys()))

View File

@@ -41,6 +41,7 @@ from .dialogs.about_dialog import AboutDialog
from .dialogs.new_project_dialog import NewProjectDialog
from .dialogs.preferences_dialog import PreferencesDialog
from .dialogs.snapshots_dialog import SnapshotsDialog
from .dialogs.import_cloud_project_dialog import ImportCloudProjectDialog
from .settings import GENERAL_SETTINGS, GENERAL_SETTING_TYPES, CLOUD_SETTINGS, CLOUD_SETTINGS_TYPES
from .utils.progress_dialog import ProgressDialog
from .utils.process_files_thread import ProcessFilesThread
@@ -1602,4 +1603,12 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
progress_dialog.exec_()
def _importProjectActionSlot(self):
print('import project action')
dialog = ImportCloudProjectDialog(
self,
self._settings['projects_path'],
self._settings['images_path'],
self._cloud_settings
)
dialog.show()
dialog.exec_()

View File

@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ImportCloudProjectDialog</class>
<widget class="QDialog" name="ImportCloudProjectDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>471</width>
<height>402</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QListWidget" name="listWidget">
<property name="geometry">
<rect>
<x>20</x>
<y>30</y>
<width>431</width>
<height>271</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="uiImportProjectAction">
<property name="geometry">
<rect>
<x>110</x>
<y>320</y>
<width>99</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>Import</string>
</property>
</widget>
<widget class="QPushButton" name="uiDeleteProjectAction">
<property name="geometry">
<rect>
<x>260</x>
<y>320</y>
<width>99</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>Delete</string>
</property>
</widget>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>300</x>
<y>360</y>
<width>160</width>
<height>25</height>
</rect>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel</set>
</property>
</widget>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ImportCloudProjectDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>403</x>
<y>366</y>
</hint>
<hint type="destinationlabel">
<x>440</x>
<y>318</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'gns3/ui/import_cloud_project_dialog.ui'
#
# Created: Wed Oct 22 12:45:41 2014
# by: PyQt4 UI code generator 4.10.4
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_ImportCloudProjectDialog(object):
def setupUi(self, ImportCloudProjectDialog):
ImportCloudProjectDialog.setObjectName(_fromUtf8("ImportCloudProjectDialog"))
ImportCloudProjectDialog.resize(471, 402)
self.listWidget = QtGui.QListWidget(ImportCloudProjectDialog)
self.listWidget.setGeometry(QtCore.QRect(20, 30, 431, 271))
self.listWidget.setObjectName(_fromUtf8("listWidget"))
self.uiImportProjectAction = QtGui.QPushButton(ImportCloudProjectDialog)
self.uiImportProjectAction.setGeometry(QtCore.QRect(110, 320, 99, 24))
self.uiImportProjectAction.setObjectName(_fromUtf8("uiImportProjectAction"))
self.uiDeleteProjectAction = QtGui.QPushButton(ImportCloudProjectDialog)
self.uiDeleteProjectAction.setGeometry(QtCore.QRect(260, 320, 99, 24))
self.uiDeleteProjectAction.setObjectName(_fromUtf8("uiDeleteProjectAction"))
self.buttonBox = QtGui.QDialogButtonBox(ImportCloudProjectDialog)
self.buttonBox.setGeometry(QtCore.QRect(300, 360, 160, 25))
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel)
self.buttonBox.setObjectName(_fromUtf8("buttonBox"))
self.retranslateUi(ImportCloudProjectDialog)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), ImportCloudProjectDialog.reject)
QtCore.QMetaObject.connectSlotsByName(ImportCloudProjectDialog)
def retranslateUi(self, ImportCloudProjectDialog):
ImportCloudProjectDialog.setWindowTitle(_translate("ImportCloudProjectDialog", "Dialog", None))
self.uiImportProjectAction.setText(_translate("ImportCloudProjectDialog", "Import", None))
self.uiDeleteProjectAction.setText(_translate("ImportCloudProjectDialog", "Delete", None))