From 42f20550adfa982847947d432424f3461ddad338 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Wed, 22 Aug 2012 23:16:57 +0200 Subject: [PATCH] first working version of the Shutter Scp plugin --- .gitignore | 1 + README.rst | 45 +++++++++++++++++++++++ Scp.pm | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 149 insertions(+) create mode 100644 .gitignore create mode 100644 README.rst create mode 100755 Scp.pm diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..daa30a3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +README.html diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..fb4b963 --- /dev/null +++ b/README.rst @@ -0,0 +1,45 @@ +************************* +Shutter scp upload plugin +************************* +Copies a file via ``scp`` to a remote server and gives you the HTTP URL. + +This is an upload plugin for Shutter__. + +__ http://shutter-project.org/ + +===== +Setup +===== +0. Copy ``Scp.pm`` to ``/usr/share/shutter/resources/system/upload_plugins/upload/`` +1. In the Shutter preferences, go to the upload tab and configure the username + and password for the Scp plugin: + + Username is the remote path you want to copy it to, + e.g. ``example.org:screenshots/``. + + Password is the HTTP base URL to prepend before the file name, + e.g. ``http://example.org/~user/screenshots/`` + +3. I expect that you have a ssh key setup, so that no password is asked. +4. That's it. + + +===== +Usage +===== +0. Make screenshot +1. Right-click on it, "export" +2. Select "Scp" +3. Click "Upload" + + +======= +License +======= +Licensed under the GPLv3 or later. + + +====== +Author +====== +Christian Weiske, cweiske@cweiske.de diff --git a/Scp.pm b/Scp.pm new file mode 100755 index 0000000..1d5e74d --- /dev/null +++ b/Scp.pm @@ -0,0 +1,103 @@ +#! /usr/bin/env perl +################################################### +# +# Copyright (C) 2012 Christian Weiske +# +# This file is part of Shutter. +# +# Shutter is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Shutter is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Shutter; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +################################################### + +package Scp; + +use lib $ENV{'SHUTTER_ROOT'}.'/share/shutter/resources/modules'; + +use utf8; +use strict; +use POSIX qw/setlocale/; +use Locale::gettext; +use Glib qw/TRUE FALSE/; + +use Shutter::Upload::Shared; +our @ISA = qw(Shutter::Upload::Shared); + +my $d = Locale::gettext->domain("shutter-upload-plugins"); +$d->dir( $ENV{'SHUTTER_INTL'} ); + +my %upload_plugin_info = ( + 'module' => "Scp", + 'url' => "", + 'registration' => "", + 'description' => $d->get( "Copy photos via scp. Use user as remote path, password as URL base" ), + 'supports_anonymous_upload' => FALSE, + 'supports_authorized_upload' => TRUE, +); + +binmode( STDOUT, ":utf8" ); +if ( exists $upload_plugin_info{$ARGV[ 0 ]} ) { + print $upload_plugin_info{$ARGV[ 0 ]}; + exit; +} + +################################################### + +sub new { + my $class = shift; + + #call constructor of super class (host, debug_cparam, shutter_root, gettext_object, main_gtk_window, ua) + my $self = $class->SUPER::new( shift, shift, shift, shift, shift, shift ); + + bless $self, $class; + return $self; +} + +sub init { + my $self = shift; + use URI::Escape; + return TRUE; +} + +sub upload { + my ( $self, $upload_filename, $username, $password ) = @_; + + #store as object vars + $self->{_filename} = $upload_filename; + + utf8::encode $upload_filename; + utf8::encode $password; + utf8::encode $username; + + $upload_filename =~ m/\/([^\/]*$)/; + my $file = $1; + + my $target_filename = $username . "/" . $file; + $target_filename =~ s/ /\\ /g; + + my @args = ("scp", $upload_filename, $target_filename); + system(@args); + if ($? == 0) { + #status: success + $self->{_links}{'status'} = 200; + $self->{_links}{'url'} = $password . uri_escape($file); + } else { + #status: error + $self->{_links}{'status'} = "exec failed: @args / $?"; + } + #and return links + return %{ $self->{_links} }; +} + +1; -- 2.30.2