[pitivi/ges] Add basic export functionality
- From: Jean-FranÃois Fortin Tam <jfft src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi/ges] Add basic export functionality
- Date: Mon, 2 Apr 2012 19:46:01 +0000 (UTC)
commit be6cb03958672cf2e4bd742d052ba004b0a99999
Author: Paul Lange <palango gmx de>
Date: Tue Mar 27 12:27:00 2012 -0600
Add basic export functionality
This commit adds a new action to export a project to a tar-file.
This tar-file includes the project file and all source files. So
far no compression is used but could be added easily.
data/ui/mainwindow.xml | 1 +
pitivi/mainwindow.py | 63 ++++++++++++++++++++++++++++++++++++++++++++++++
pitivi/project.py | 54 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 118 insertions(+), 0 deletions(-)
---
diff --git a/data/ui/mainwindow.xml b/data/ui/mainwindow.xml
index 1b1614d..9d05fbb 100644
--- a/data/ui/mainwindow.xml
+++ b/data/ui/mainwindow.xml
@@ -6,6 +6,7 @@
<menuitem action="SaveProject" />
<menuitem action="SaveProjectAs" />
<menuitem action="RevertToSavedProject" />
+ <menuitem action="ExportProject" />
<separator />
<menuitem action="RenderProject" />
<separator />
diff --git a/pitivi/mainwindow.py b/pitivi/mainwindow.py
index 1f49ce6..566313d 100644
--- a/pitivi/mainwindow.py
+++ b/pitivi/mainwindow.py
@@ -259,6 +259,9 @@ class PitiviMainWindow(gtk.Window, Loggable):
("RevertToSavedProject", gtk.STOCK_REVERT_TO_SAVED, None,
None, _("Reload the current project"), self._revertToSavedProjectCb),
+ ("ExportProject", gtk.STOCK_HARDDISK, _("Export as Archive..."),
+ None, _("Export the current project"), self._exportProjectAsTarCb),
+
("ProjectSettings", gtk.STOCK_PROPERTIES, _("Project Settings"),
None, _("Edit the project settings"), self._projectSettingsCb),
@@ -564,6 +567,15 @@ class PitiviMainWindow(gtk.Window, Loggable):
def _revertToSavedProjectCb(self, unused_action):
return self.app.projectManager.revertToSavedProject()
+ def _exportProjectAsTarCb(self, unused_action):
+ uri = self._showExportDialog(self.app.current)
+ if uri:
+ result = self.app.projectManager.exportProject(self.app.current, uri)
+
+ if not result:
+ self.log("Project couldn't be exported")
+ return result
+
def _projectSettingsCb(self, unused_action):
self.showProjectSettingsDialog()
@@ -701,6 +713,9 @@ class PitiviMainWindow(gtk.Window, Loggable):
#FIXME GES we should re-enable this when possible
#self._syncDoUndo(self.app.action_log)
+ # Enable export functionality
+ self.actiongroup.get_action("ExportProject").set_sensitive(True)
+
#FIXME GES reimplement me
if self._missingUriOnLoading:
self.app.current.setModificationState(True)
@@ -1065,6 +1080,54 @@ class PitiviMainWindow(gtk.Window, Loggable):
self.timeline_ui.pipeline_state = new
## other
+ def _showExportDialog(self, project):
+ self.log("Export requested")
+ chooser = gtk.FileChooserDialog(_("Export To..."),
+ self,
+ action=gtk.FILE_CHOOSER_ACTION_SAVE,
+ buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
+ gtk.STOCK_SAVE, gtk.RESPONSE_OK))
+
+ chooser.set_icon_name("pitivi")
+ chooser.set_select_multiple(False)
+
+ if not project.name:
+ chooser.set_current_name(_("Untitled") + ".tar")
+ else:
+ chooser.set_current_name(project.name + ".tar")
+ chooser.set_current_folder(self.settings.lastProjectFolder)
+ chooser.props.do_overwrite_confirmation = True
+
+ filt = gtk.FileFilter()
+ filt.set_name("Tar Archive")
+ filt.add_pattern("*.tar")
+ chooser.add_filter(filt)
+ default = gtk.FileFilter()
+ default.set_name(_("Detect Automatically"))
+ default.add_pattern("*")
+ chooser.add_filter(default)
+
+ response = chooser.run()
+ current_folder = chooser.get_current_folder()
+ if current_folder:
+ self.settings.lastProjectFolder = current_folder
+
+ if response == gtk.RESPONSE_OK:
+ self.log("User chose a URI to export project to")
+ # need to do this to work around bug in gst.uri_construct
+ # which escapes all /'s in path!
+ uri = "file://" + chooser.get_filename()
+ format = chooser.get_filter().get_name()
+ if format == _("Detect Automatically"):
+ format = None
+ self.log("uri:%s , format:%s", uri, format)
+ ret = uri
+ else:
+ self.log("User didn't choose a URI to export project to")
+ ret = None
+
+ chooser.destroy()
+ return ret
def _showSaveAsDialog(self, project):
self.log("Save URI requested")
diff --git a/pitivi/project.py b/pitivi/project.py
index 5b2700b..2101715 100644
--- a/pitivi/project.py
+++ b/pitivi/project.py
@@ -29,6 +29,7 @@ import gst
import gtk
import gio
import gobject
+import tarfile
from time import time
from datetime import datetime
@@ -261,6 +262,59 @@ class ProjectManager(Signallable, Loggable):
self.debug('Saved backup "%s"' % uri)
return saved
+ def exportProject(self, project, uri):
+ """
+ Export a project to a *.tar archive which includes the project file
+ and all sources
+ """
+ # write project file to temporary file
+ project_name = project.name if project.name else "project"
+ tmp_name = "%s.xptv" % project_name
+
+ try:
+ directory = os.path.dirname(uri)
+ tmp_uri = os.path.join(directory, tmp_name)
+ self.saveProject(project, tmp_uri, overwrite=True)
+
+ # create tar file
+ with tarfile.open(path_from_uri(uri), mode="w") as tar:
+ # top directory in tar-file
+ top = "%s-export" % project_name
+ # add temporary project file
+ tar.add(path_from_uri(tmp_uri), os.path.join(top, tmp_name))
+
+ # get common path
+ sources = project.medialibrary.getSources()
+ if self._allSourcesInHomedir(sources):
+ common = os.path.expanduser("~")
+ else:
+ common = "/"
+
+ # add all sources
+ for source in sources:
+ path = path_from_uri(source.get_uri())
+ tar.add(path, os.path.join(top, os.path.relpath(path, common)))
+ tar.close()
+
+ # remove temporary file
+ os.remove(path_from_uri(tmp_uri))
+ except:
+ return False
+
+ return True
+
+ def _allSourcesInHomedir(self, sources):
+ """
+ Checks if all sources are located in the users home directory
+ """
+ homedir = os.path.expanduser("~")
+
+ for source in sources:
+ if not path_from_uri(source.get_uri()).startswith(homedir):
+ return False
+
+ return True
+
def closeRunningProject(self):
""" close the current project """
self.info("closing running project")
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]