user_space 1.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.rdoc +1 -1
- data/lib/user_space/user_space.rb +122 -110
- data/lib/user_space/version.rb +2 -2
- data/lib/user_space.rb +0 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad4946e7879c8d5182a601dca296fec845c37785
|
4
|
+
data.tar.gz: b7844d0201b7a83e4e9987bdcf94e714a7c7139b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab588bdaff70c0fa820c9ab243867a0c28fdc84a96cf9bbac240fbf1b3e50ca9d3daead487548c21939950161dce225cddef928882a7213f423605bc70225596
|
7
|
+
data.tar.gz: b113e412b3c652622502535402c64092f11ee2e5ecb72819820d18f1cea6c53a103763323f8e567a3340f4da71164c448509835ee82f3321d0fc0c61a95932b7
|
data/README.rdoc
CHANGED
@@ -14,7 +14,7 @@ Automates certain XDG features.
|
|
14
14
|
# Perhaps like...
|
15
15
|
APP::CONFIG = {:tts=>'espeak', }
|
16
16
|
# By default, UserSpace works with the JSON parser.
|
17
|
-
USERSPACE =
|
17
|
+
USERSPACE = UserSpace.new
|
18
18
|
# Unless this version has been installed,
|
19
19
|
# we copy over our data and cache directories.
|
20
20
|
USERSPACE.install unless USERSPACE.version == APP::VERSION
|
@@ -1,132 +1,144 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
@appname = parameters[:appname] || PARAMETERS[:appname]
|
18
|
-
@appdir = parameters[:appdir] || PARAMETERS[:appdir]
|
19
|
-
@xdgbases = parameters[:xdgbases] || PARAMETERS[:xdgbases]
|
20
|
-
@options = OPTIONS
|
21
|
-
|
22
|
-
unless @appdir
|
23
|
-
appdir = File.dirname File.dirname caller_locations(1,1)[0].path
|
24
|
-
appdir = File.dirname appdir if File.basename(appdir)=='lib'
|
25
|
-
@appdir = File.expand_path appdir
|
26
|
-
verbose.puts "Warning: UserSpace#appdir heuristics used" if verbose
|
27
|
-
end
|
1
|
+
class UserSpace
|
2
|
+
OPTIONS = {
|
3
|
+
config: 'config',
|
4
|
+
version: 'VERSION',
|
5
|
+
ext: nil,
|
6
|
+
parser: nil,
|
7
|
+
}
|
8
|
+
['JSON','YAML','Marshal'].each do |parser|
|
9
|
+
begin
|
10
|
+
OPTIONS[:parser] = Object.const_get parser
|
11
|
+
$stderr.puts "USER_SPACE will use #{parser} by default." if $VERBOSE
|
12
|
+
break
|
13
|
+
rescue NameError
|
14
|
+
$stderr.puts "#{parser} was not available for USER_SPACE." if $DEBUG
|
15
|
+
end
|
16
|
+
end
|
28
17
|
|
29
|
-
|
30
|
-
|
18
|
+
PARAMETERS = {
|
19
|
+
appname: File.basename($0),
|
20
|
+
appdir: nil, # Can't guess at this point yet?
|
21
|
+
xdgbases: ['CACHE', 'CONFIG', 'DATA'],
|
22
|
+
}
|
23
|
+
|
24
|
+
attr_reader :appname, :appdir, :xdgbases, :options
|
25
|
+
def initialize(parameters=PARAMETERS)
|
26
|
+
|
27
|
+
@appname = parameters[:appname] || PARAMETERS[:appname]
|
28
|
+
@appdir = parameters[:appdir] || PARAMETERS[:appdir]
|
29
|
+
@xdgbases = parameters[:xdgbases] || PARAMETERS[:xdgbases]
|
30
|
+
@options = OPTIONS.dup
|
31
|
+
|
32
|
+
unless @appdir
|
33
|
+
appdir = File.dirname File.dirname caller_locations(1,1)[0].path
|
34
|
+
appdir = File.dirname appdir if File.basename(appdir)=='lib'
|
35
|
+
@appdir = File.expand_path appdir
|
36
|
+
$stderr.puts "UserSpace#appdir=\"#{@appdir}\" # heuristics used" if $VERBOSE
|
31
37
|
end
|
32
38
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
39
|
+
# install with no overwrite
|
40
|
+
install(false)
|
41
|
+
end
|
42
|
+
|
43
|
+
def xdg_pairs
|
44
|
+
@xdgbases.each do |base|
|
45
|
+
xdg = XDG[base].to_s
|
46
|
+
userdir = File.join(xdg, @appname)
|
47
|
+
basedir = File.join @appdir, base.downcase
|
48
|
+
yield basedir, userdir
|
40
49
|
end
|
50
|
+
end
|
41
51
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
57
|
-
FileUtils.cp_r(Dir.glob("#{basedir}/*"), userdir) if File.directory? basedir
|
58
|
-
FileUtils.chmod_R 'og-rwx', userdir
|
59
|
-
FileUtils.chmod_R 'u+rwX', userdir
|
52
|
+
# Note that initialize will not overwrite anything.
|
53
|
+
# This overwrites the user's data directory with a fresh install.
|
54
|
+
# App should consider being nice about this,
|
55
|
+
# like warn the user or something.
|
56
|
+
def install(overwrite=true)
|
57
|
+
xdg_pairs do |basedir, userdir|
|
58
|
+
if File.exist?(userdir)
|
59
|
+
# Sanity check
|
60
|
+
raise "Not a directory: #{userdir}" unless File.directory?(userdir)
|
61
|
+
# Pre-existing directory.
|
62
|
+
# Return unless user wants to overwrite.
|
63
|
+
next unless overwrite
|
64
|
+
else
|
65
|
+
Dir.mkdir(userdir, 0700)
|
60
66
|
end
|
67
|
+
FileUtils.cp_r(Dir.glob("#{basedir}/*"), userdir) if File.directory? basedir
|
68
|
+
FileUtils.chmod_R 'og-rwx', userdir
|
69
|
+
FileUtils.chmod_R 'u+rwX', userdir
|
61
70
|
end
|
71
|
+
end
|
62
72
|
|
63
|
-
|
64
|
-
|
65
|
-
|
73
|
+
def cachedir
|
74
|
+
File.join XDG['CACHE'].to_s, @appname
|
75
|
+
end
|
66
76
|
|
67
|
-
|
68
|
-
|
69
|
-
|
77
|
+
def configdir
|
78
|
+
File.join XDG['CONFIG'].to_s, @appname
|
79
|
+
end
|
70
80
|
|
71
|
-
|
72
|
-
|
73
|
-
|
81
|
+
def datadir
|
82
|
+
File.join XDG['DATA'].to_s, @appname
|
83
|
+
end
|
74
84
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
85
|
+
# Not really for public use.
|
86
|
+
def config_file_name
|
87
|
+
parser = @options[:parser]
|
88
|
+
ext = @options[:ext] || parser.to_s.downcase
|
89
|
+
basename = "#{@options[:config]}.#{ext}"
|
90
|
+
File.join XDG['CONFIG'].to_s, @appname, basename
|
91
|
+
end
|
82
92
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
93
|
+
# Not really for public use.
|
94
|
+
def version_file_name
|
95
|
+
File.join XDG['DATA'].to_s, @appname, @options[:version]
|
96
|
+
end
|
87
97
|
|
88
|
-
|
89
|
-
|
90
|
-
|
98
|
+
def config?
|
99
|
+
File.exist?(config_file_name)
|
100
|
+
end
|
91
101
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
102
|
+
# Reads config
|
103
|
+
def config
|
104
|
+
p, d = @options[:parser], File.read(config_file_name)
|
105
|
+
p.load(d)
|
106
|
+
rescue
|
107
|
+
$stderr.puts $!.message if $VERBOSE
|
108
|
+
$stderr.puts $!.backtrace if $DEBUG
|
109
|
+
nil
|
110
|
+
end
|
100
111
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
112
|
+
# Saves config
|
113
|
+
def config=(obj)
|
114
|
+
p = @options[:parser]
|
115
|
+
d = (p.respond_to?(:pretty_generate))? p.pretty_generate(obj) : p.dump(obj)
|
116
|
+
File.open(config_file_name, 'w', 0600){|fh| fh.puts d}
|
117
|
+
end
|
105
118
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
end
|
119
|
+
def configures(hash)
|
120
|
+
if self.config? # file exists
|
121
|
+
self.config.each{|opt, value| hash[opt.to_sym] = value}
|
122
|
+
else
|
123
|
+
$stderr.puts config_file_name if $VERBOSE
|
124
|
+
self.config = hash
|
113
125
|
end
|
126
|
+
end
|
114
127
|
|
115
|
-
|
116
|
-
|
117
|
-
|
128
|
+
def version?
|
129
|
+
File.exist?(version_file_name)
|
130
|
+
end
|
118
131
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
132
|
+
# This reads the data directory's version file
|
133
|
+
def version
|
134
|
+
File.read(version_file_name).strip
|
135
|
+
rescue
|
136
|
+
$stderr.puts $!.message if $VERBOSE
|
137
|
+
$stderr.puts $!.backtrace if $DEBUG
|
138
|
+
nil
|
139
|
+
end
|
127
140
|
|
128
|
-
|
129
|
-
|
130
|
-
end
|
141
|
+
def version=(v)
|
142
|
+
File.open(version_file_name, 'w', 0600){|fh| fh.puts v}
|
131
143
|
end
|
132
144
|
end
|
data/lib/user_space/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = '
|
1
|
+
class UserSpace
|
2
|
+
VERSION = '2.0.1'
|
3
3
|
end
|
data/lib/user_space.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: user_space
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- carlosjhr64
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: xdg
|