user_space 3.0.0 → 5.1.210201
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +74 -0
- data/lib/user_space.rb +49 -68
- metadata +16 -33
- data/README.rdoc +0 -60
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c868edf8d004a22ff97fc912b5562df08524a5b7a0369531758e302ae9b323bf
|
4
|
+
data.tar.gz: f1cd273b38bcb8209128ce601a9165404a287cecf9852678e9a20541c4d949e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbd37a67613e70b2f8490d6c70962cf6e364f5e866b65b576109392c40b820cd84857a2edde91ba5d79e4bedab2ee12a12ba037e717b55e7dde9bc0dd71347f7
|
7
|
+
data.tar.gz: b810e6a240efa6c022045e4b49b9b7de2a6e64fa8c0c9a60cdaf5e767383591441da1aae90781864ef0ad1ba85ff52d350dd6deb9aa701a34e9aa88c48132244
|
data/README.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# UserSpace
|
2
|
+
|
3
|
+
* [VERSION 5.1.210201](https://github.com/carlosjhr64/user_space/releases)
|
4
|
+
* [github](https://www.github.com/carlosjhr64/user_space)
|
5
|
+
* [rubygems](https://rubygems.org/gems/user_space)
|
6
|
+
|
7
|
+
## DESCRIPTION:
|
8
|
+
|
9
|
+
Maintains the user's cache, config, and data directories
|
10
|
+
with the gem-apps cache, config, and data files.
|
11
|
+
|
12
|
+
## SYNOPSIS:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
require 'rbon' # Using RBON(is not JSON!) parser for the config file.
|
16
|
+
require 'user_space'
|
17
|
+
|
18
|
+
module App
|
19
|
+
# ::App::CONFIG is your app's configuration.
|
20
|
+
CONFIG = {:tts=>'espeak', }
|
21
|
+
VERSION = '1.2.3'
|
22
|
+
end
|
23
|
+
|
24
|
+
USERSPACE = UserSpace.new(parser:RBON, appname:'myapp') #~> ^#<UserSpace:
|
25
|
+
# Will maintain these directories:
|
26
|
+
['~/.cache/myapp',
|
27
|
+
'~/.config/myapp',
|
28
|
+
'~/.local/share/myapp'
|
29
|
+
].all?{File.directory? File.expand_path _1} #=> true
|
30
|
+
|
31
|
+
if USERSPACE.config?
|
32
|
+
# Update APP::CONFIG with user's preferences.
|
33
|
+
App::CONFIG.merge! USERSPACE.config
|
34
|
+
else
|
35
|
+
# Write initial configuration with App::CONFIG
|
36
|
+
STDERR.puts "Writting '#{USERSPACE.config_file_name}'"
|
37
|
+
USERSPACE.config = App::CONFIG
|
38
|
+
end
|
39
|
+
# To do the same thing, you can also say:
|
40
|
+
# USERSPACE.configures(App::CONFIG)
|
41
|
+
# We have a config file:
|
42
|
+
File.exist? File.expand_path '~/.config/myapp/config.rbon' #=> true
|
43
|
+
```
|
44
|
+
|
45
|
+
## INSTALL:
|
46
|
+
|
47
|
+
```shell
|
48
|
+
$ gem install user_space
|
49
|
+
```
|
50
|
+
|
51
|
+
## LICENSE:
|
52
|
+
|
53
|
+
(The MIT License)
|
54
|
+
|
55
|
+
Copyright (c) 2021 CarlosJHR64
|
56
|
+
|
57
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
58
|
+
a copy of this software and associated documentation files (the
|
59
|
+
'Software'), to deal in the Software without restriction, including
|
60
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
61
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
62
|
+
permit persons to whom the Software is furnished to do so, subject to
|
63
|
+
the following conditions:
|
64
|
+
|
65
|
+
The above copyright notice and this permission notice shall be
|
66
|
+
included in all copies or substantial portions of the Software.
|
67
|
+
|
68
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
69
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
70
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
71
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
72
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
73
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
74
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/user_space.rb
CHANGED
@@ -1,89 +1,81 @@
|
|
1
1
|
require 'fileutils'
|
2
|
-
require 'xdg'
|
3
2
|
# Requires:
|
4
3
|
#`ruby`
|
5
4
|
|
6
|
-
module FileUtils
|
7
|
-
class << self
|
8
|
-
def user_space_cpr(src, dest)
|
9
|
-
fu_each_src_dest(src, dest) do |s, d|
|
10
|
-
copy_entry(s, d)
|
11
|
-
chmod('u+rwX,go-rwx', d)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
5
|
class UserSpace
|
18
|
-
VERSION = '
|
6
|
+
VERSION = '5.1.210201'
|
7
|
+
XDG = {
|
8
|
+
'cache' => ENV['XDG_CACHE_HOME'] || File.expand_path('~/.cache'),
|
9
|
+
'config' => ENV['XDG_CONFIG_HOME'] || File.expand_path('~/.config'),
|
10
|
+
'data' => ENV['XDG_DATA_HOME'] || File.expand_path('~/.local/share'),
|
11
|
+
}
|
19
12
|
|
20
|
-
def self.appdir
|
21
|
-
|
22
|
-
appdir = File.dirname appdir if File.basename(appdir)=='lib'
|
23
|
-
File.expand_path appdir
|
13
|
+
def self.appdir(lib='/lib')
|
14
|
+
(_ = caller(1..2)[-1]&.split(':',2)&.fetch(0)) and File.dirname(File.dirname(File.expand_path(_)))&.chomp(lib)
|
24
15
|
end
|
25
16
|
|
26
|
-
attr_reader :parser,:ext,:appname,:xdgbases,:appdir,:
|
27
|
-
def initialize(
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
@parser,@ext,@appname,@xdgbases,@appdir,@config = parser,ext,appname,xdgbases,appdir,config
|
36
|
-
install(false) # install with no overwrite
|
17
|
+
attr_reader :parser,:ext,:appname,:xdgbases,:appdir,:cfg
|
18
|
+
def initialize( parser:,
|
19
|
+
appdir: UserSpace.appdir,
|
20
|
+
ext: parser.to_s.downcase,
|
21
|
+
appname: File.basename($0),
|
22
|
+
xdgbases: ['cache', 'config', 'data'],
|
23
|
+
config: 'config')
|
24
|
+
@parser,@ext,@appname,@xdgbases,@appdir,@cfg = parser,ext,appname,xdgbases,appdir,config
|
25
|
+
install
|
37
26
|
end
|
38
27
|
|
39
28
|
def xdg_pairs
|
40
29
|
@xdgbases.each do |base|
|
41
|
-
|
42
|
-
|
43
|
-
basedir = File.join @appdir, base.downcase
|
44
|
-
yield basedir, userdir
|
30
|
+
# yield basedir, userdir
|
31
|
+
yield File.join(@appdir, base), File.join(XDG[base], @appname)
|
45
32
|
end
|
46
33
|
end
|
47
34
|
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
|
52
|
-
def install(overwrite=true)
|
35
|
+
# Will not overwrite anything.
|
36
|
+
# Only copies over missing directories and files.
|
37
|
+
# Verifies directory expectations.
|
38
|
+
def install
|
53
39
|
xdg_pairs do |basedir, userdir|
|
54
40
|
if File.exist?(userdir)
|
55
41
|
# Sanity check
|
56
|
-
|
57
|
-
# Pre-existing directory.
|
58
|
-
# Return unless user wants to overwrite.
|
59
|
-
next unless overwrite
|
42
|
+
assert_directory(userdir)
|
60
43
|
else
|
61
44
|
Dir.mkdir(userdir, 0700)
|
62
45
|
end
|
63
|
-
|
46
|
+
if File.directory? basedir
|
47
|
+
Dir.glob("#{basedir}/**/*").each do |src|
|
48
|
+
dest = src.sub(basedir, userdir)
|
49
|
+
if File.exist? dest
|
50
|
+
# Sanity checks
|
51
|
+
assert_directory(dest) if File.directory? src
|
52
|
+
else
|
53
|
+
if File.directory? src
|
54
|
+
Dir.mkdir dest
|
55
|
+
else
|
56
|
+
FileUtils.cp src, dest
|
57
|
+
end
|
58
|
+
FileUtils.chmod('u+rwX,go-rwx', dest)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
64
62
|
end
|
65
63
|
end
|
66
64
|
|
67
65
|
def cachedir
|
68
|
-
File.join XDG['
|
66
|
+
File.join XDG['cache'], @appname
|
69
67
|
end
|
70
68
|
|
71
69
|
def configdir
|
72
|
-
File.join XDG['
|
70
|
+
File.join XDG['config'], @appname
|
73
71
|
end
|
74
72
|
|
75
73
|
def datadir
|
76
|
-
File.join XDG['
|
74
|
+
File.join XDG['data'], @appname
|
77
75
|
end
|
78
76
|
|
79
|
-
# Not really for public use.
|
80
77
|
def config_file_name
|
81
|
-
File.join XDG['
|
82
|
-
end
|
83
|
-
|
84
|
-
# Not really for public use.
|
85
|
-
def version_file_name
|
86
|
-
File.join XDG['DATA'].to_s, @appname, 'VERSION'
|
78
|
+
File.join XDG['config'], @appname, "#{@cfg}.#{@ext}"
|
87
79
|
end
|
88
80
|
|
89
81
|
def config?
|
@@ -106,28 +98,17 @@ class UserSpace
|
|
106
98
|
end
|
107
99
|
|
108
100
|
def configures(hash)
|
109
|
-
if
|
110
|
-
|
101
|
+
if config? # file exists
|
102
|
+
hash.merge! config
|
111
103
|
else
|
112
104
|
$stderr.puts config_file_name if $VERBOSE
|
113
105
|
self.config = hash
|
114
106
|
end
|
115
107
|
end
|
116
108
|
|
117
|
-
|
118
|
-
File.exist?(version_file_name)
|
119
|
-
end
|
120
|
-
|
121
|
-
# This reads the data directory's version file
|
122
|
-
def version
|
123
|
-
File.read(version_file_name).strip
|
124
|
-
rescue
|
125
|
-
$stderr.puts $!.message if $VERBOSE
|
126
|
-
$stderr.puts $!.backtrace if $DEBUG
|
127
|
-
nil
|
128
|
-
end
|
109
|
+
private
|
129
110
|
|
130
|
-
def
|
131
|
-
|
111
|
+
def assert_directory(dir)
|
112
|
+
raise "Not a directory: #{dir}" unless File.directory?(dir)
|
132
113
|
end
|
133
114
|
end
|
metadata
CHANGED
@@ -1,48 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: user_space
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.1.210201
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- carlosjhr64
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
requirements:
|
17
|
-
- - '='
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 2.2.3
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - '='
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 2.2.3
|
27
|
-
description: 'Maintains the app''s XDG features: app''s cache, config, and data directories.
|
28
|
-
|
29
|
-
'
|
11
|
+
date: 2021-02-01 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: |
|
14
|
+
Maintains the user's cache, config, and data directories
|
15
|
+
with the gem-apps cache, config, and data files.
|
30
16
|
email: carlosjhr64@gmail.com
|
31
17
|
executables: []
|
32
18
|
extensions: []
|
33
|
-
extra_rdoc_files:
|
34
|
-
- README.rdoc
|
19
|
+
extra_rdoc_files: []
|
35
20
|
files:
|
36
|
-
- README.
|
21
|
+
- README.md
|
37
22
|
- lib/user_space.rb
|
38
23
|
homepage: https://github.com/carlosjhr64/user_space
|
39
24
|
licenses:
|
40
25
|
- MIT
|
41
26
|
metadata: {}
|
42
|
-
post_install_message:
|
43
|
-
rdoc_options:
|
44
|
-
- "--main"
|
45
|
-
- README.rdoc
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
46
29
|
require_paths:
|
47
30
|
- lib
|
48
31
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -56,10 +39,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
39
|
- !ruby/object:Gem::Version
|
57
40
|
version: '0'
|
58
41
|
requirements:
|
59
|
-
- 'ruby: ruby
|
60
|
-
|
61
|
-
|
62
|
-
signing_key:
|
42
|
+
- 'ruby: ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]'
|
43
|
+
rubygems_version: 3.2.3
|
44
|
+
signing_key:
|
63
45
|
specification_version: 4
|
64
|
-
summary:
|
46
|
+
summary: Maintains the user's cache, config, and data directories with the gem-apps
|
47
|
+
cache, config, and data files.
|
65
48
|
test_files: []
|
data/README.rdoc
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
= user_space
|
2
|
-
|
3
|
-
github :: https://www.github.com/carlosjhr64/user_space
|
4
|
-
rubygems :: https://rubygems.org/gems/user_space
|
5
|
-
|
6
|
-
== DESCRIPTION:
|
7
|
-
|
8
|
-
Maintains the app's XDG features: app's cache, config, and data directories.
|
9
|
-
|
10
|
-
== SYNOPSIS:
|
11
|
-
|
12
|
-
require 'json' # Using JSON parser for the config file.
|
13
|
-
require 'user_space'
|
14
|
-
# APP::CONFIG is your app's configuration.
|
15
|
-
# Perhaps like...
|
16
|
-
APP::CONFIG = {:tts=>'espeak', }
|
17
|
-
USERSPACE = UserSpace.new(JSON)
|
18
|
-
# Unless this version has been installed,
|
19
|
-
# we copy over our data and cache directories.
|
20
|
-
USERSPACE.install unless USERSPACE.version == APP::VERSION
|
21
|
-
if USERSPACE.config?
|
22
|
-
# Because JSON hashes by String, converting to Symbol.
|
23
|
-
# We pad up APP::CONFIG with user's preferences:
|
24
|
-
USERSPACE.config.each{|opt, value| APP::CONFIG[opt.to_sym] = value}
|
25
|
-
else
|
26
|
-
# We initialize user preferences with our initial APP::CONFIG
|
27
|
-
STDERR.puts "Writting '#{USERSPACE.config_file_name}'"
|
28
|
-
USERSPACE.config = APP::CONFIG
|
29
|
-
end
|
30
|
-
# To do the same thing, you can also say:
|
31
|
-
# USERSPACE.configures(APP::CONFIG)
|
32
|
-
|
33
|
-
== INSTALL:
|
34
|
-
|
35
|
-
sudo gem install user_space
|
36
|
-
|
37
|
-
== LICENSE:
|
38
|
-
|
39
|
-
(The MIT License)
|
40
|
-
|
41
|
-
Copyright (c) 2017 CarlosJHR64
|
42
|
-
|
43
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
44
|
-
a copy of this software and associated documentation files (the
|
45
|
-
'Software'), to deal in the Software without restriction, including
|
46
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
47
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
48
|
-
permit persons to whom the Software is furnished to do so, subject to
|
49
|
-
the following conditions:
|
50
|
-
|
51
|
-
The above copyright notice and this permission notice shall be
|
52
|
-
included in all copies or substantial portions of the Software.
|
53
|
-
|
54
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
55
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
56
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
57
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
58
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
59
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
60
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|