user_space 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 964e9a54183227b621f7fa093cc644b25eb59055
4
+ data.tar.gz: 81ad79c904d9bdfba3c3c604223bba5da8ab323b
5
+ SHA512:
6
+ metadata.gz: 0af919b9206d6a386dc68ce5a3a180e7afaa3991dde99a2fca2c545ee868488eb8f232c614cb4a364690d6cc9fc53615b4e3e51141828f2bda0c0eb24f301c8b
7
+ data.tar.gz: 28d1d0a93e1368808cb3c03c5bc486e02356bde12d83a70a683d089289d7765e78975343daf6643c5546434deb97a3b1d68d366033b688c2b4a9d50d29c76822
@@ -0,0 +1 @@
1
+ === 0.0.0 / 2013-12-21 09:33:10 -0800
@@ -0,0 +1,12 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.rdoc
4
+ TODO.txt
5
+ data/VERSION
6
+ features/main.feature
7
+ features/step_definitions/main_steps.rb
8
+ lib/user_space.rb
9
+ lib/user_space/user_space.rb
10
+ lib/user_space/version.rb
11
+ test/user_space.rb
12
+ user_space.gemspec
@@ -0,0 +1,59 @@
1
+ = user_space
2
+
3
+ == DESCRIPTION:
4
+
5
+ Automates certain XDG features.
6
+
7
+ == SYNOPSIS:
8
+
9
+ require 'user_space'
10
+ # APP::CONFIG is your app's configuration.
11
+ # Perhaps like...
12
+ APP::CONFIG = {:tts=>'espeak', }
13
+ # By default, UserSpace works with the JSON parser.
14
+ USERSPACE = USER_SPACE::UserSpace.new
15
+ # Unless this version has been installed,
16
+ # we copy over our data and cache directories.
17
+ USERSPACE.install unless USERSPACE.version == APP::VERSION
18
+ if USERSPACE.config?
19
+ # Because JSON hashes by String, converting to Symbol.
20
+ # We pad up APP::CONFIG with user's preferences:
21
+ USERSPACE.config.each{|opt, value| APP::CONFIG[opt.to_sym] = value}
22
+ else
23
+ # We initialize user preferences with our initial APP::CONFIG
24
+ STDERR.puts "Writting '#{USERSPACE.config_file_name}'"
25
+ USERSPACE.config = APP::CONFIG
26
+ end
27
+
28
+ == FEATURES/PROBLEMS:
29
+
30
+ * Still in alpha, have not publish to ruby gems yet.
31
+
32
+ == INSTALL:
33
+
34
+ Not yet available.
35
+
36
+ == LICENSE:
37
+
38
+ (The MIT License)
39
+
40
+ Copyright (c) 2013 CarlosJHR64
41
+
42
+ Permission is hereby granted, free of charge, to any person obtaining
43
+ a copy of this software and associated documentation files (the
44
+ 'Software'), to deal in the Software without restriction, including
45
+ without limitation the rights to use, copy, modify, merge, publish,
46
+ distribute, sublicense, and/or sell copies of the Software, and to
47
+ permit persons to whom the Software is furnished to do so, subject to
48
+ the following conditions:
49
+
50
+ The above copyright notice and this permission notice shall be
51
+ included in all copies or substantial portions of the Software.
52
+
53
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
54
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
55
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
56
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
57
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
58
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
59
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,5 @@
1
+ == File List
2
+
3
+ TODO: Come up with some good cucumber tests.
4
+ features/step_definitions/main_steps.rb, #2
5
+
@@ -0,0 +1 @@
1
+ 1.20.300
@@ -0,0 +1,9 @@
1
+ @main
2
+ Feature: Main Feature
3
+
4
+ Background:
5
+ * Given main feature
6
+
7
+ Scenario:
8
+ * When main feature
9
+ * Then main feature
@@ -0,0 +1,18 @@
1
+ require 'rainbow'
2
+ # TODO: Come up with some good cucumber tests.
3
+ Given /^(\w+) (.*)$/ do |given, condition|
4
+ condition.strip!
5
+ case given
6
+ when 'Given'
7
+ #raise "'Given' form not defined."
8
+ STDERR.puts "Need to come up with some cucumber tests".color(:blue)
9
+ when 'When'
10
+ #raise "'When' form not defined."
11
+ STDERR.puts "Need to come up with some cucumber tests".color(:blue)
12
+ when 'Then'
13
+ #raise "'Then' form not defined."
14
+ STDERR.puts "Need to come up with some cucumber tests".color(:blue)
15
+ else
16
+ raise "'#{given}' form not defined."
17
+ end
18
+ end
@@ -0,0 +1,8 @@
1
+ require 'English'
2
+ require 'fileutils'
3
+ require 'json' # default parser
4
+ require 'xdg'
5
+ require 'user_space/version.rb'
6
+ require 'user_space/user_space.rb'
7
+ # Requires:
8
+ #`ruby`
@@ -0,0 +1,105 @@
1
+ module USER_SPACE
2
+ class UserSpace
3
+
4
+ OPTIONS = {:config => 'config',
5
+ :parser => JSON,
6
+ :ext => nil,
7
+ :version => 'VERSION'}
8
+
9
+ PARAMETERS = {:appname => File.basename($PROGRAM_NAME),
10
+ :appdir => nil, # Can't guess at this point yet?
11
+ :xdgbases => ['CACHE', 'CONFIG', 'DATA']}
12
+
13
+ attr_reader :appname, :appdir, :xdgbases, :options
14
+ def initialize(parameters=PARAMETERS)
15
+
16
+ @appname = parameters[:appname] || PARAMETERS[:appname]
17
+ @appdir = parameters[:appdir] || PARAMETERS[:appdir]
18
+ @xdgbases = parameters[:xdgbases] || PARAMETERS[:xdgbases]
19
+ @options = OPTIONS
20
+
21
+ unless @appdir
22
+ appdir = File.dirname File.dirname caller.first.split(/:/,2).first
23
+ @appdir = File.expand_path appdir
24
+ end
25
+
26
+ # install with no overwrite
27
+ install(false)
28
+ end
29
+
30
+ def xdg_pairs
31
+ @xdgbases.each do |base|
32
+ xdg = XDG[base].to_s
33
+ userdir = File.join(xdg, @appname)
34
+ basedir = File.join @appdir, base.downcase
35
+ yield basedir, userdir
36
+ end
37
+ end
38
+
39
+ # Note that initialize will not overwrite anything.
40
+ # This overwrites the user's data directory with a fresh install.
41
+ # App should consider being nice about this,
42
+ # like warn the user or something.
43
+ def install(overwrite=true)
44
+ xdg_pairs do |basedir, userdir|
45
+ if File.exist?(userdir)
46
+ # Sanity check
47
+ raise "Not a directory: #{userdir}" unless File.directory?(userdir)
48
+ # Pre-existing directory.
49
+ # Return unless user wants to overwrite.
50
+ return unless overwrite
51
+ else
52
+ Dir.mkdir(userdir, 0700)
53
+ end
54
+ FileUtils.cp_r(Dir.glob("#{basedir}/*"), userdir) if File.directory? basedir
55
+ end
56
+ end
57
+
58
+ def cachedir
59
+ File.join XDG['CACHE'].to_s, @appname
60
+ end
61
+
62
+ def configdir
63
+ File.join XDG['CONFIG'].to_s, @appname
64
+ end
65
+
66
+ def datadir
67
+ File.join XDG['DATA'].to_s, @appname
68
+ end
69
+
70
+ # Not really for public use.
71
+ def config_file_name(options=@options)
72
+ parser = options[:parser]
73
+ ext = options[:ext] || parser.to_s.downcase
74
+ basename = "#{options[:config]}.#{ext}"
75
+ File.join XDG['CONFIG'].to_s, @appname, basename
76
+ end
77
+
78
+ # Not really for public use.
79
+ def version_file_name
80
+ File.join XDG['DATA'].to_s, @appname, @options[:version]
81
+ end
82
+
83
+ def config?(options=@options)
84
+ File.exist?(config_file_name(options))
85
+ end
86
+
87
+ # Reads config
88
+ def config(options=@options)
89
+ options[:parser].parse File.read(config_file_name(options))
90
+ end
91
+
92
+ # Saves config
93
+ def config=(obj, options=@options)
94
+ File.open(config_file_name, 'w', 0600){|fh| fh.puts options[:parser].pretty_generate obj}
95
+ end
96
+
97
+ # This reads the data directory's version file
98
+ def version
99
+ fn = version_file_name
100
+ return nil unless File.exist? fn
101
+ File.read(version_file_name).strip
102
+ end
103
+
104
+ end
105
+ end
@@ -0,0 +1,3 @@
1
+ module USER_SPACE
2
+ VERSION = '0.0.0'
3
+ end
@@ -0,0 +1,93 @@
1
+ require 'test/unit'
2
+ require 'tmpdir'
3
+ TMPDIR = Dir.mktmpdir
4
+ Dir.mkdir File.join TMPDIR, '.cache'
5
+ Dir.mkdir File.join TMPDIR, '.config'
6
+ Dir.mkdir File.join TMPDIR, '.local'
7
+ Dir.mkdir File.join TMPDIR, '.local', 'share'
8
+ APPNAME = 'ima2awesome'
9
+
10
+ ENV['HOME'] = TMPDIR
11
+ $0 = APPNAME
12
+
13
+ # Needed to setup the enviroment first, now...
14
+ require 'user_space'
15
+
16
+ class TestUserSpace < Test::Unit::TestCase
17
+
18
+ include USER_SPACE
19
+
20
+ def test_user_space_version
21
+ assert_equal('0.0.0', VERSION)
22
+ end
23
+
24
+ def test_user_space_constants
25
+ assert_equal 'config', UserSpace::OPTIONS[:config]
26
+ assert_equal JSON, UserSpace::OPTIONS[:parser]
27
+ assert_equal 'VERSION', UserSpace::OPTIONS[:version]
28
+ assert_nil UserSpace::OPTIONS[:ext]
29
+
30
+ assert_equal 'ima2awesome', UserSpace::PARAMETERS[:appname]
31
+
32
+ xdgbases = UserSpace::PARAMETERS[:xdgbases]
33
+ assert xdgbases.include? 'CACHE'
34
+ assert xdgbases.include? 'CONFIG'
35
+ assert xdgbases.include? 'DATA'
36
+ end
37
+
38
+ def test_user_space_new
39
+ userspace = nil
40
+ assert_nothing_raised(Exception){userspace = UserSpace.new}
41
+
42
+ assert_equal(APPNAME, userspace.appname)
43
+
44
+ dirname = File.dirname File.dirname File.expand_path __FILE__
45
+ assert_equal(dirname, userspace.appdir)
46
+
47
+ xdgbases = userspace.xdgbases
48
+ assert(userspace.xdgbases.include?('CACHE'))
49
+ assert(userspace.xdgbases.include?('CONFIG'))
50
+ assert(userspace.xdgbases.include?('DATA'))
51
+
52
+ count = 0
53
+ userspace.xdg_pairs do |basedir, userdir|
54
+ count += 1
55
+ assert(File.directory?(userdir))
56
+ refute_nil(userdir=~/\/ima2awesome$/)
57
+ refute_nil(basedir=~/user_space\/((data)|(config)|(cache))$/)
58
+ end
59
+ assert_equal(3, count)
60
+
61
+ options = userspace.options
62
+ assert_equal('config', options[:config])
63
+ assert_equal('VERSION', options[:version])
64
+ assert_equal(JSON, options[:parser])
65
+ assert_nil(options[:ext])
66
+
67
+ assert File.exist? userspace.cachedir
68
+ assert File.exist? userspace.configdir
69
+ assert File.exist? userspace.datadir
70
+
71
+ version = File.read('data/VERSION').strip
72
+ assert_equal version, userspace.version
73
+
74
+ refute File.exist? userspace.config_file_name
75
+ config1 = {'a'=>"A", 'b'=>"B"}
76
+ userspace.config = config1
77
+ assert File.exist? userspace.config_file_name
78
+ config2 = JSON.parse File.read userspace.config_file_name
79
+ assert_equal config1, config2
80
+
81
+ # Overwrite version file...
82
+ File.open(userspace.version_file_name, 'w'){|fh|fh.puts 'A.B.C'}
83
+ # Now we get the version given to the file:
84
+ assert_equal 'A.B.C', userspace.version
85
+ # Which is different from the initial version
86
+ refute version == 'A.B.C'
87
+
88
+ # But we can re-fresh our install
89
+ assert_nothing_raised(Exception){userspace.install}
90
+ # Now we have our initial version back
91
+ assert_equal version, userspace.version
92
+ end
93
+ end
@@ -0,0 +1,46 @@
1
+ Gem::Specification.new do |s|
2
+
3
+ s.name = 'user_space'
4
+ s.version = '0.0.0'
5
+
6
+ s.homepage = 'https://github.com/carlosjhr64/user_space'
7
+
8
+ s.author = 'CarlosJHR64'
9
+ s.email = 'carlosjhr64@gmail.com'
10
+
11
+ s.date = '2013-12-22'
12
+ s.licenses = ['MIT']
13
+
14
+ s.description = <<DESCRIPTION
15
+ Automates certain XDG features.
16
+ DESCRIPTION
17
+
18
+ s.summary = <<SUMMARY
19
+ Automates certain XDG features.
20
+ SUMMARY
21
+
22
+ s.extra_rdoc_files = ['README.rdoc']
23
+ s.rdoc_options = ["--main", "README.rdoc"]
24
+
25
+ s.require_paths = ["lib"]
26
+ s.files = %w(
27
+ History.txt
28
+ Manifest.txt
29
+ README.rdoc
30
+ TODO.txt
31
+ data/VERSION
32
+ features/main.feature
33
+ features/step_definitions/main_steps.rb
34
+ lib/user_space.rb
35
+ lib/user_space/user_space.rb
36
+ lib/user_space/version.rb
37
+ test/user_space.rb
38
+ user_space.gemspec
39
+ )
40
+
41
+ s.add_runtime_dependency 'xdg', '~> 2.2', '>= 2.2.3'
42
+ s.add_development_dependency 'rainbow', '~> 1.1', '>= 1.1.4'
43
+ s.add_development_dependency 'test-unit', '~> 2.5', '>= 2.5.5'
44
+ s.requirements << 'ruby: ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]'
45
+
46
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: user_space
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - CarlosJHR64
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: xdg
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.2'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.2.3
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '2.2'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.2.3
33
+ - !ruby/object:Gem::Dependency
34
+ name: rainbow
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.1'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 1.1.4
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.1'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 1.1.4
53
+ - !ruby/object:Gem::Dependency
54
+ name: test-unit
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '2.5'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 2.5.5
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '2.5'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 2.5.5
73
+ description: |
74
+ Automates certain XDG features.
75
+ email: carlosjhr64@gmail.com
76
+ executables: []
77
+ extensions: []
78
+ extra_rdoc_files:
79
+ - README.rdoc
80
+ files:
81
+ - History.txt
82
+ - Manifest.txt
83
+ - README.rdoc
84
+ - TODO.txt
85
+ - data/VERSION
86
+ - features/main.feature
87
+ - features/step_definitions/main_steps.rb
88
+ - lib/user_space.rb
89
+ - lib/user_space/user_space.rb
90
+ - lib/user_space/version.rb
91
+ - test/user_space.rb
92
+ - user_space.gemspec
93
+ homepage: https://github.com/carlosjhr64/user_space
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options:
99
+ - "--main"
100
+ - README.rdoc
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements:
114
+ - 'ruby: ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]'
115
+ rubyforge_project:
116
+ rubygems_version: 2.0.3
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Automates certain XDG features.
120
+ test_files: []