kate-get 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENCE +21 -0
- data/README +94 -0
- data/bin/kate-get +13 -0
- data/lib/kate-get.rb +62 -0
- metadata +69 -0
data/LICENCE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2011 Evan Boyd Sosenko
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
= Kate-Get
|
2
|
+
|
3
|
+
Kate-Get takes a space separated list of file paths and checks each one against a list of sources. If a match is found, the file is copied via rsync to a local directory. Options for each source are controlled by a config file. Subdirectories are handled automatically based on how local and remote root paths are set.
|
4
|
+
|
5
|
+
== Making a config file
|
6
|
+
|
7
|
+
By default, Kate-Get looks for the YAML file
|
8
|
+
|
9
|
+
~/.kate-get.yml
|
10
|
+
|
11
|
+
An example of a config file
|
12
|
+
|
13
|
+
:global:
|
14
|
+
:host: "example.com"
|
15
|
+
:port: 22
|
16
|
+
:user: "user-name"
|
17
|
+
|
18
|
+
:sources:
|
19
|
+
"foo.com":
|
20
|
+
:local: "~/Development/foo"
|
21
|
+
:root: "/var/www/vhosts/##source_name##/htdocs"
|
22
|
+
:base: "sftp://user@foo.com:22/var/www/vhosts/##source_name##/htdocs/"
|
23
|
+
"bar.com":
|
24
|
+
:local: "~/Development/bar"
|
25
|
+
:root: "/var/www/vhosts/##source_name##/htdocs"
|
26
|
+
:base: "sftp://user@bar.com:22/var/www/vhosts/##source_name##/htdocs/"
|
27
|
+
:host: "bar.com"
|
28
|
+
:port: 42
|
29
|
+
:user: "bar-user-name"
|
30
|
+
|
31
|
+
There are two sections
|
32
|
+
* *global* - rsync connection information
|
33
|
+
* *host* - hostname or IP
|
34
|
+
* *port* - port to connect on
|
35
|
+
* *user* - username to connect with
|
36
|
+
* These options may be overridden on a per-source basis by specifying them there.
|
37
|
+
|
38
|
+
* *sources* - each entry is a source name (string) with the following options
|
39
|
+
* *local* - path to local folder where files should be copied too (no leading slash)
|
40
|
+
* *root* - path to remote folder (input file must exist in some subdirectory of this to be copied)
|
41
|
+
* *base* - prefix string that will be stripped from the file name
|
42
|
+
|
43
|
+
Note that the string ##source_name## will be automatically replaced by the source name.
|
44
|
+
|
45
|
+
== Limitations
|
46
|
+
|
47
|
+
* Currently, only rsync over ssh is supported.
|
48
|
+
* An input file path matches a source if the input file path contains the source name.
|
49
|
+
* This can cause unexpected behavior if the input file name includes two strings which match two different source names.
|
50
|
+
|
51
|
+
== Setting up Kate to use Kate-Get
|
52
|
+
|
53
|
+
Kate-Get is meant to be used with Kate (http://kate-editor.org/) as an external tool. For information on adding external tools to Kate see http://docs.kde.org/stable/en/kdesdk/kate/config-dialog.html.
|
54
|
+
|
55
|
+
|
56
|
+
If you want a tool that only copies the currently open file use
|
57
|
+
|
58
|
+
kate-get "%URL"
|
59
|
+
|
60
|
+
If you want to loop through all open files use
|
61
|
+
|
62
|
+
kate-get "%URLs"
|
63
|
+
|
64
|
+
Note that you may need to use the full path to the kate-get binary, usually
|
65
|
+
|
66
|
+
/var/lib/gems/1.9.1/bin/kate-get
|
67
|
+
|
68
|
+
== Installation
|
69
|
+
|
70
|
+
=== Gem Installation
|
71
|
+
|
72
|
+
Download and install Kate-Get with
|
73
|
+
|
74
|
+
gem install kate-get
|
75
|
+
|
76
|
+
== Development
|
77
|
+
|
78
|
+
=== Source Repository
|
79
|
+
|
80
|
+
Kate-Get is currently hosted at github. The github web page is
|
81
|
+
https://github.com/razor-x/kate-get. To clone the project run
|
82
|
+
|
83
|
+
git clone git://github.com/razor-x/kate-get.git
|
84
|
+
|
85
|
+
== License
|
86
|
+
|
87
|
+
Kate-Get is licensed under the MIT license.
|
88
|
+
|
89
|
+
== Warranty
|
90
|
+
|
91
|
+
This software is provided "as is" and without any express or
|
92
|
+
implied warranties, including, without limitation, the implied
|
93
|
+
warranties of merchantibility and fitness for a particular
|
94
|
+
purpose.
|
data/bin/kate-get
ADDED
data/lib/kate-get.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Main class for Kate-Get.
|
2
|
+
class KateGet
|
3
|
+
|
4
|
+
# Reads in a YAML config file or hash.
|
5
|
+
# @param [String, Hash] config YAML config file or hash of config options
|
6
|
+
def initialize config
|
7
|
+
@config = \
|
8
|
+
if config.is_a? String
|
9
|
+
require 'yaml'
|
10
|
+
file = File.expand_path config
|
11
|
+
YAML.load File.read file if File.exists? file
|
12
|
+
elsif config.is_a? Hash
|
13
|
+
config
|
14
|
+
end
|
15
|
+
|
16
|
+
fail "Failed to load config." unless @config.is_a? Hash
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
# Files to get
|
21
|
+
# @param [String] files space seperated list of file paths
|
22
|
+
def add_file file
|
23
|
+
@files = [] unless @files
|
24
|
+
@files << file
|
25
|
+
end
|
26
|
+
|
27
|
+
# Uses rsync to download files based on config options.
|
28
|
+
def get
|
29
|
+
|
30
|
+
@files.each do |f|
|
31
|
+
|
32
|
+
# Look for the first source that matches the file.
|
33
|
+
site, name = nil
|
34
|
+
@config[:sources].each do |n, s|
|
35
|
+
name, site = [n, s] if f[n]
|
36
|
+
break if site
|
37
|
+
end
|
38
|
+
|
39
|
+
# Skip the file if there is no matching source.
|
40
|
+
next if site.nil?
|
41
|
+
|
42
|
+
# Load global connection settings and merge with source specific ones.
|
43
|
+
remote = @config[:global]
|
44
|
+
remote.merge! site[:remote] unless site[:remote].nil?
|
45
|
+
|
46
|
+
# Prepare the elements for the rsync command.
|
47
|
+
root_dir = site[:root].sub "##source_name##", name
|
48
|
+
base_url = site[:base].sub "##source_name##", name
|
49
|
+
|
50
|
+
# Skip the file if it is not in the root directory of the source.
|
51
|
+
next unless f[root_dir]
|
52
|
+
|
53
|
+
f.sub! base_url, ""
|
54
|
+
base = File.basename f
|
55
|
+
|
56
|
+
rsync = "rsync -a -e 'ssh -p #{remote[:port]}' #{remote[:user]}@#{remote[:host]}:#{root_dir}/#{f} #{site[:local]}/#{f}"
|
57
|
+
|
58
|
+
# Get the file using rsync.
|
59
|
+
system rsync
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kate-get
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Evan Boyd Sosenko
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-05-05 00:00:00 -07:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: "\t\tKate-Get takes a space separated list of file paths and checks each one against a list of sources. If a match is found, the file is copied via rsync to a local directory. Options for each source are controlled by a config file.\n"
|
22
|
+
email:
|
23
|
+
executables:
|
24
|
+
- kate-get
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- lib/kate-get.rb
|
31
|
+
- README
|
32
|
+
- LICENCE
|
33
|
+
- bin/kate-get
|
34
|
+
has_rdoc: true
|
35
|
+
homepage:
|
36
|
+
licenses:
|
37
|
+
- MIT
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
segments:
|
49
|
+
- 1
|
50
|
+
- 9
|
51
|
+
- 2
|
52
|
+
version: 1.9.2
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
requirements:
|
62
|
+
- rsync
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.3.7
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: Kate external tool to intelligently copy open remote files to local directories.
|
68
|
+
test_files: []
|
69
|
+
|