winprofile 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +53 -0
- data/TODO +7 -0
- data/VERSION +1 -0
- data/bin/redirect_folders.rb +120 -0
- data/lib/winprofile.rb +146 -0
- data/lib/winreg.rb +83 -0
- data/test/helper.rb +10 -0
- data/test/test_winprofile.rb +110 -0
- data/test/test_winreg.rb +27 -0
- metadata +96 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Miguel Armas
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= winprofile
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 Miguel Armas. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "winprofile"
|
8
|
+
gem.summary = %Q{Manage Windows Profiles}
|
9
|
+
gem.description = %Q{This Gem allows you to manage Windows roving profiles stored on your servers}
|
10
|
+
gem.email = "kuko@canarytek.com"
|
11
|
+
gem.homepage = "http://github.com/kukoarmas/winprofile"
|
12
|
+
gem.authors = ["Miguel Armas"]
|
13
|
+
gem.add_development_dependency "shoulda", ">= 0"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake/testtask'
|
22
|
+
Rake::TestTask.new(:test) do |test|
|
23
|
+
test.libs << 'lib' << 'test'
|
24
|
+
test.pattern = 'test/**/test_*.rb'
|
25
|
+
test.verbose = true
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
require 'rcov/rcovtask'
|
30
|
+
Rcov::RcovTask.new do |test|
|
31
|
+
test.libs << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
task :rcov do
|
37
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
task :test => :check_dependencies
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "winprofile #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/TODO
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.2
|
@@ -0,0 +1,120 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
#
|
3
|
+
# Redirect a user profile's folders
|
4
|
+
#
|
5
|
+
# We use the following defaults
|
6
|
+
# Personal -> U:/Mis Documentos
|
7
|
+
# ALL THE REST -> U:\.windows_settings\
|
8
|
+
|
9
|
+
|
10
|
+
require 'rubygems'
|
11
|
+
require 'winprofile'
|
12
|
+
|
13
|
+
require 'optparse'
|
14
|
+
require 'fileutils'
|
15
|
+
|
16
|
+
# Samba profiles defaults
|
17
|
+
@profiles="/home/samba/profiles"
|
18
|
+
# User homes default
|
19
|
+
@homes="/home"
|
20
|
+
|
21
|
+
@verbose=false
|
22
|
+
@debug=false
|
23
|
+
|
24
|
+
# Command
|
25
|
+
@cmd="show"
|
26
|
+
|
27
|
+
def redirect
|
28
|
+
p=WinProfile.new(@user,@profiles,@homes)
|
29
|
+
p.debug=@debug
|
30
|
+
p.verbose=@verbose
|
31
|
+
|
32
|
+
puts "Redirecting Desktop"
|
33
|
+
p.redirect_folder('Desktop','U:\\.windows_settings\\Escritorio')
|
34
|
+
puts "Redirecting AppData"
|
35
|
+
p.redirect_folder('AppData','U:\\.windows_settings\\Datos de programa')
|
36
|
+
puts "Redirecting Personal"
|
37
|
+
p.redirect_folder('Personal','U:\\Mis documentos')
|
38
|
+
end
|
39
|
+
|
40
|
+
def move
|
41
|
+
puts "Creating #{@homes}/#{@user}/.windows_settings"
|
42
|
+
FileUtils.makedirs "#{@homes}/#{@user}/.windows_settings"
|
43
|
+
puts "Moving dirs"
|
44
|
+
puts "#{@homes}/samba/profiles/#{@user}/Mis\ documentos -> #{@homes}/#{@user}/Mis\ documentos"
|
45
|
+
FileUtils.mv "#{@homes}/samba/profiles/#{@user}/Mis\ documentos","#{@homes}/#{@user}/Mis\ documentos"
|
46
|
+
|
47
|
+
puts "#{@homes}/samba/profiles/#{@user}/Escritorio -> #{@homes}/#{@user}/.windows_settings/Escritorio"
|
48
|
+
FileUtils.mv "#{@homes}/samba/profiles/#{@user}/Escritorio","#{@homes}/#{@user}/.windows_settings/Escritorio"
|
49
|
+
|
50
|
+
puts "#{@homes}/samba/profiles/#{@user}/Datos de programa -> #{@homes}/#{@user}/.windows_settings/Datos de programa"
|
51
|
+
FileUtils.mv "#{@homes}/samba/profiles/#{@user}/Datos de programa","#{@homes}/#{@user}/.windows_settings/Datos de programa"
|
52
|
+
end
|
53
|
+
|
54
|
+
app = Hash.new
|
55
|
+
|
56
|
+
options = OptionParser.new do |opts|
|
57
|
+
opts.on("--debug", "Debug. No action. (verbose=true)") do |opt|
|
58
|
+
@noop=true
|
59
|
+
@verbose=true
|
60
|
+
@debug=true
|
61
|
+
end
|
62
|
+
opts.on("--verbose", "Be verbose") do |opt|
|
63
|
+
@verbose=true
|
64
|
+
end
|
65
|
+
opts.on("--user [ARG]", "User profile to change") do |opt|
|
66
|
+
@user=opt
|
67
|
+
end
|
68
|
+
opts.on("--profiles [ARG]", "User profiles directory (default: /home/samba/profiles)") do |opt|
|
69
|
+
@profiles=opt
|
70
|
+
end
|
71
|
+
opts.on("--homes [ARG]", "User homes (default: /home)") do |opt|
|
72
|
+
@homes=opt
|
73
|
+
end
|
74
|
+
opts.on("--version", "Print version and exit") do |opt|
|
75
|
+
puts "version #{winprofile::VERSION}"
|
76
|
+
exit 0
|
77
|
+
end
|
78
|
+
end
|
79
|
+
options.parse!(ARGV)
|
80
|
+
if ARGV.length != 1
|
81
|
+
puts "Missing command argument"
|
82
|
+
puts "Available commands"
|
83
|
+
puts " show: show folder status"
|
84
|
+
puts " redirect: redirect folders (only in registry)"
|
85
|
+
puts " move: move folders"
|
86
|
+
exit 1
|
87
|
+
end
|
88
|
+
@cmd=ARGV.shift
|
89
|
+
|
90
|
+
if ! @user
|
91
|
+
puts "ERROR: You need to specify e user with --user option"
|
92
|
+
exit 1
|
93
|
+
end
|
94
|
+
|
95
|
+
case @cmd
|
96
|
+
when "show"
|
97
|
+
p=WinProfile.new(@user,@profiles,@homes)
|
98
|
+
puts "Personal Folders for #{@user}"
|
99
|
+
#p.verbose=@verbose
|
100
|
+
p.verbose=true
|
101
|
+
p.debug=@debug
|
102
|
+
p.show_folders
|
103
|
+
when "redirect"
|
104
|
+
redirect
|
105
|
+
when "move"
|
106
|
+
move
|
107
|
+
else
|
108
|
+
puts "Unknown command: #{@cmd}"
|
109
|
+
end
|
110
|
+
|
111
|
+
#FileUtils.cp_r "#{@profiles}/#{@user}","#{@home}/#{@user}/.windows_settings", :preserve=>true
|
112
|
+
|
113
|
+
# FIXME: Move Mis Documentos
|
114
|
+
|
115
|
+
#p=WinProfile.new("#{@home}/#{@user}/.windows_settings/NTUSER.DAT")
|
116
|
+
#p.show_folders
|
117
|
+
#p.redirect_folders('U:\\.windows_settings')
|
118
|
+
#p.redirect_folders('U:\\.windows_settings')
|
119
|
+
#p.redirect_folder('Personal','U:\\Mis documentos')
|
120
|
+
|
data/lib/winprofile.rb
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
|
2
|
+
require 'rubygems'
|
3
|
+
require 'winreg'
|
4
|
+
|
5
|
+
#
|
6
|
+
# WinProfile
|
7
|
+
#
|
8
|
+
class WinProfile
|
9
|
+
attr_accessor :file, :debug, :verbose, :homes, :profiles
|
10
|
+
attr_reader :folders
|
11
|
+
|
12
|
+
# Base regkey for folder redirection
|
13
|
+
FOLDERS_BASE='Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders'
|
14
|
+
|
15
|
+
# List of user folder redirection regkeys
|
16
|
+
FOLDER_DEFAULTS=[
|
17
|
+
{:name => "AppData", :dir => 'Datos de programa' },
|
18
|
+
{:name => "Desktop", :dir => 'Escritorio' },
|
19
|
+
{:name => "Favorites", :dir => 'Favoritos' },
|
20
|
+
{:name => "NetHood", :dir => 'Entorno de red' },
|
21
|
+
{:name => "Personal", :dir => 'Mis documentos' },
|
22
|
+
{:name => "PrintHood", :dir => 'Impresoras' },
|
23
|
+
{:name => "Programs", :dir => 'Menú Inicio\Programas' },
|
24
|
+
{:name => "SendTo", :dir => 'SendTo' },
|
25
|
+
{:name => "Start Menu", :dir => 'Menú Inicio' },
|
26
|
+
{:name => "Startup", :dir => 'Menú Inicio\Programas\Inicio' },
|
27
|
+
{:name => "Templates", :dir => 'Plantillas' },
|
28
|
+
{:name => "Local Settings", :dir => 'Configuración Local' },
|
29
|
+
{:name => "Local AppData", :dir => 'Configuración Local\Datos de programa' },
|
30
|
+
{:name => "Cache", :dir => 'Configuración Local\Archivos temporales de Internet' },
|
31
|
+
{:name => "Cookies", :dir => 'Cookies' },
|
32
|
+
{:name => "Recent", :dir => 'Reciente' },
|
33
|
+
{:name => "History", :dir => 'Configuración Local\Historial' },
|
34
|
+
]
|
35
|
+
|
36
|
+
|
37
|
+
def initialize(user=nil,profiles="/home/samba/profiles",homes="/home")
|
38
|
+
# Defaults
|
39
|
+
@profiles = profiles
|
40
|
+
@homes = homes
|
41
|
+
@folders = FOLDER_DEFAULTS
|
42
|
+
|
43
|
+
# If user=nil don't check existence, late initialization
|
44
|
+
if user != nil
|
45
|
+
# HKLU hive file
|
46
|
+
@file = "#{@profiles}/#{user}/NTUSER.DAT"
|
47
|
+
raise "Invalid profile: #{@file}" unless File.exists? @file
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Set the user whose profile we want to change
|
52
|
+
def user=(user)
|
53
|
+
# HKLU hive file
|
54
|
+
@file = "#{@profiles}/#{user}/NTUSER.DAT"
|
55
|
+
|
56
|
+
raise "Invalid profile: #{@file}" unless File.exists? @file
|
57
|
+
end
|
58
|
+
|
59
|
+
# Show folder redirection status for a given folder
|
60
|
+
def show_folder(folder)
|
61
|
+
@location=nil
|
62
|
+
|
63
|
+
w=WinReg.new(@file)
|
64
|
+
w.debug=@debug
|
65
|
+
|
66
|
+
FOLDER_DEFAULTS.each do |key|
|
67
|
+
if key[:name] == folder
|
68
|
+
@location = w.read_key(FOLDERS_BASE+'\\'+key[:name])
|
69
|
+
puts "#{key[:name]} -> #{@location}" if @verbose
|
70
|
+
end
|
71
|
+
end
|
72
|
+
@location
|
73
|
+
end
|
74
|
+
|
75
|
+
# Show folder redirection status for all folders
|
76
|
+
def show_folders
|
77
|
+
|
78
|
+
w=WinReg.new(@file)
|
79
|
+
w.debug=@debug
|
80
|
+
|
81
|
+
FOLDER_DEFAULTS.each do |key|
|
82
|
+
@location = w.read_key(FOLDERS_BASE+'\\'+key[:name])
|
83
|
+
puts "#{key[:name]} -> #{@location}" if @verbose
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# Redirects a given user folders to a dir
|
88
|
+
def redirect_folder(folder,dir)
|
89
|
+
|
90
|
+
w=WinReg.new(@file)
|
91
|
+
w.debug=@debug
|
92
|
+
|
93
|
+
w.write_key(FOLDERS_BASE+'\\'+folder,dir)
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
# Redirects all user folders to given dir
|
98
|
+
def redirect_folders(dir)
|
99
|
+
|
100
|
+
w=WinReg.new(@file)
|
101
|
+
w.debug=@debug
|
102
|
+
FOLDER_DEFAULTS.each do |key|
|
103
|
+
w.write_key(FOLDERS_BASE+'\\'+key[:name],dir+'\\'+key[:dir])
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# Initialize a roving profile directory structure in the given directory
|
108
|
+
def init_folders(dir)
|
109
|
+
|
110
|
+
FOLDER_DEFAULTS.each do |key|
|
111
|
+
@folder=dir+"/"+key[:dir]
|
112
|
+
@folder.gsub!('\\','/')
|
113
|
+
if not File.directory? @folder
|
114
|
+
File.makedirs @folder
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
# Move ALL profile folders to a new destination
|
121
|
+
def move_folders(orig,dest)
|
122
|
+
|
123
|
+
puts "Moving #{orig} -> #{dest}" if @verbose
|
124
|
+
FileUtils.mv orig,dest
|
125
|
+
end
|
126
|
+
|
127
|
+
# Move a given profile folder to a new destination
|
128
|
+
def move_folder(folder,orig,dest)
|
129
|
+
|
130
|
+
puts "Moving #{orig}/#{key[:dir]} -> #{dest}/#{key[:dir]}" if @verbose
|
131
|
+
FileUtils.mv "#{orig}/#{key[:dir]}", "#{dest}/#{key[:dir]}"
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
# Reset profile to default folders
|
136
|
+
def reset_default
|
137
|
+
|
138
|
+
w=WinReg.new(@file)
|
139
|
+
w.debug=@debug
|
140
|
+
FOLDER_DEFAULTS.each do |key|
|
141
|
+
w.write_key(FOLDERS_BASE+'\\'+key[:name],'%USERPROFILE%\\'+key[:dir])
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
|
data/lib/winreg.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
|
2
|
+
require 'expect'
|
3
|
+
require 'pty'
|
4
|
+
|
5
|
+
$expect_verbose = false
|
6
|
+
|
7
|
+
class WinReg
|
8
|
+
attr_accessor :file, :debug, :verbose
|
9
|
+
|
10
|
+
def initialize(file)
|
11
|
+
@file = file
|
12
|
+
# Check that file exists
|
13
|
+
if not File.exists? @file
|
14
|
+
puts "ERROR: File #{@file} does not exist"
|
15
|
+
return nil
|
16
|
+
end
|
17
|
+
# FIXME: Check that we have the chntpw command
|
18
|
+
end
|
19
|
+
|
20
|
+
def read_key(key)
|
21
|
+
@value = nil
|
22
|
+
|
23
|
+
PTY.spawn("chntpw -e #{@file}") do |read,write,pid|
|
24
|
+
$expect_verbose = @debug
|
25
|
+
write.sync = true
|
26
|
+
|
27
|
+
# If 30 seconds pass and the expected text is not found, the
|
28
|
+
# response object will be nil.
|
29
|
+
read.expect(/^>/, 5) do |response|
|
30
|
+
raise unless response
|
31
|
+
write.print "cat " + key + "\n" if response
|
32
|
+
end
|
33
|
+
|
34
|
+
read.expect(/^>/, 5) do |response|
|
35
|
+
raise unless response
|
36
|
+
write.print "q" + "\n" if response
|
37
|
+
# response is a string array
|
38
|
+
@found=false
|
39
|
+
response[0].split(/\r\n/).each do |line|
|
40
|
+
if @found
|
41
|
+
@value=line
|
42
|
+
break
|
43
|
+
end
|
44
|
+
@found = true if line =~ /^Value/
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
return @value
|
50
|
+
end
|
51
|
+
|
52
|
+
def write_key(key,value)
|
53
|
+
|
54
|
+
PTY.spawn("chntpw -e #{@file}") do |read,write,pid|
|
55
|
+
$expect_verbose = @debug
|
56
|
+
write.sync = true
|
57
|
+
|
58
|
+
# If 30 seconds pass and the expected text is not found, the
|
59
|
+
# response object will be nil.
|
60
|
+
read.expect(/^>/, 5) do |response|
|
61
|
+
raise unless response
|
62
|
+
write.print "ed " + key + "\n" if response
|
63
|
+
end
|
64
|
+
|
65
|
+
read.expect(/^->/, 5) do |response|
|
66
|
+
raise unless response
|
67
|
+
write.print value + "\n" if response
|
68
|
+
end
|
69
|
+
|
70
|
+
read.expect(/^>/, 5) do |response|
|
71
|
+
raise unless response
|
72
|
+
write.print "q" + "\n" if response
|
73
|
+
end
|
74
|
+
|
75
|
+
read.expect(/^Write hive files?/, 5) do |response|
|
76
|
+
raise unless response
|
77
|
+
write.print "y" + "\n" if response
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
class TestWinProfile < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context "WinProfile" do
|
7
|
+
should 'raise exception when invalid profile given' do
|
8
|
+
assert_raise RuntimeError do
|
9
|
+
@winprofile=WinProfile.new("test")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
should 'raise exception when invalid profile given in late initialization' do
|
13
|
+
assert_raise RuntimeError do
|
14
|
+
@winprofile=WinProfile.new()
|
15
|
+
@winprofile.user="NONEXISTENT"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
should 'return WinProfile object when valid profile given' do
|
19
|
+
@winprofile=WinProfile.new("sample_profile","test")
|
20
|
+
assert_instance_of WinProfile, @winprofile
|
21
|
+
end
|
22
|
+
should "be able to set profile after object created" do
|
23
|
+
@winprofile=WinProfile.new()
|
24
|
+
@winprofile.profiles="test"
|
25
|
+
@winprofile.user="sample_profile"
|
26
|
+
assert_equal "test/sample_profile/NTUSER.DAT",@winprofile.file
|
27
|
+
end
|
28
|
+
should "return same object when both initialize methods are used with same parameters" do
|
29
|
+
@winprofile=WinProfile.new()
|
30
|
+
@winprofile.profiles="test"
|
31
|
+
@winprofile.user="sample_profile"
|
32
|
+
@winprofile2=WinProfile.new("sample_profile","test")
|
33
|
+
assert @winprofile2.file == @winprofile.file
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "a WinProfile instance" do
|
38
|
+
|
39
|
+
setup do
|
40
|
+
File.copy "test/sample_profile/NTUSER.DAT","test/NTUSER.DAT"
|
41
|
+
@winprofile=WinProfile.new("sample_profile","test")
|
42
|
+
@winprofile.verbose=false
|
43
|
+
end
|
44
|
+
|
45
|
+
should "initialize folders same as FOLDER_DEFAULTS" do
|
46
|
+
assert_same_elements WinProfile::FOLDER_DEFAULTS,@winprofile.folders
|
47
|
+
end
|
48
|
+
|
49
|
+
context "when asked for the 'Personal' folder key" do
|
50
|
+
should 'return "%USERPROFILE%\Mis documentos"' do
|
51
|
+
assert_equal '%USERPROFILE%\Mis documentos',@winprofile.show_folder('Personal')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "when asked for a non_existent folder" do
|
56
|
+
should "return nil" do
|
57
|
+
assert_nil @winprofile.show_folder('non-existent')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "when reset to defaults" do
|
62
|
+
setup do
|
63
|
+
@winprofile.reset_default
|
64
|
+
end
|
65
|
+
context "reading the 'Personal' folder" do
|
66
|
+
should 'return "%USERPROFILE%\Mis documentos"' do
|
67
|
+
assert_equal '%USERPROFILE%\Mis documentos',@winprofile.show_folder('Personal')
|
68
|
+
end
|
69
|
+
end
|
70
|
+
context "reading all folders" do
|
71
|
+
should "return DEFAULT_FOLDERS constant" do
|
72
|
+
@winprofile.show_folders
|
73
|
+
assert_equal WinProfile::FOLDER_DEFAULTS,@winprofile.show_folders
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
#context "when initializing profile folders" do
|
79
|
+
# setup do
|
80
|
+
# FileUtils.rm_rf("test/tmp/sample_profile")
|
81
|
+
# end
|
82
|
+
|
83
|
+
#should "get correct folders" do
|
84
|
+
# @winprofile.init_folders("test/tmp/sample_profile")
|
85
|
+
# Dir.chdir("test/sample_profile")
|
86
|
+
# @sample_profile=Dir.glob("*/")
|
87
|
+
# Dir.chdir("../..")
|
88
|
+
# assert_same_elements @sample_profile,Dir.entries("test/tmp/sample_profile")
|
89
|
+
#end
|
90
|
+
#end
|
91
|
+
|
92
|
+
context "when moving profile folders" do
|
93
|
+
setup do
|
94
|
+
# Remove orig
|
95
|
+
FileUtils.rm_rf("test/tmp/orig_profile")
|
96
|
+
# Remove dest
|
97
|
+
FileUtils.rm_rf("test/tmp/dest_profile")
|
98
|
+
# Copy test profile
|
99
|
+
FileUtils.cp_r("test/sample_profile","test/tmp/orig_profile")
|
100
|
+
end
|
101
|
+
|
102
|
+
should "get same directories" do
|
103
|
+
@before=Dir.entries("test/tmp/orig_profile")
|
104
|
+
@winprofile.move_folders("test/tmp/orig_profile","test/tmp/dest_profile")
|
105
|
+
assert_same_elements @before,Dir.entries("test/tmp/dest_profile")
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
data/test/test_winreg.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'ftools'
|
3
|
+
|
4
|
+
class TestWinReg < Test::Unit::TestCase
|
5
|
+
FOLDERS_BASE='Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders'
|
6
|
+
|
7
|
+
context "A WinReg instance" do
|
8
|
+
setup do
|
9
|
+
File.copy "test/NTUSER.DAT.SAFE","test/NTUSER.DAT"
|
10
|
+
@winreg=WinReg.new("test/NTUSER.DAT")
|
11
|
+
end
|
12
|
+
|
13
|
+
context "when reading the 'Personal' folder key" do
|
14
|
+
should 'return "%USERPROFILE%\Mis Documentos"' do
|
15
|
+
assert_equal '%USERPROFILE%\Mis Documentos',@winreg.read_key(FOLDERS_BASE+'\\'+'Personal')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'when writing the "Personal" folder key with "SOME_DATA"' do
|
20
|
+
should 'return "SOME_DATA"' do
|
21
|
+
@winreg.write_key(FOLDERS_BASE+'\\'+'Personal','SOME_DATA')
|
22
|
+
assert_equal 'SOME_DATA',@winreg.read_key(FOLDERS_BASE+'\\'+'Personal')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: winprofile
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Miguel Armas
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-06-16 00:00:00 +01:00
|
19
|
+
default_executable: redirect_folders.rb
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: shoulda
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
description: This Gem allows you to manage Windows roving profiles stored on your servers
|
36
|
+
email: kuko@canarytek.com
|
37
|
+
executables:
|
38
|
+
- redirect_folders.rb
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- LICENSE
|
43
|
+
- README.rdoc
|
44
|
+
- TODO
|
45
|
+
files:
|
46
|
+
- .document
|
47
|
+
- .gitignore
|
48
|
+
- LICENSE
|
49
|
+
- README.rdoc
|
50
|
+
- Rakefile
|
51
|
+
- VERSION
|
52
|
+
- bin/redirect_folders.rb
|
53
|
+
- lib/winprofile.rb
|
54
|
+
- lib/winreg.rb
|
55
|
+
- test/helper.rb
|
56
|
+
- test/test_winprofile.rb
|
57
|
+
- test/test_winreg.rb
|
58
|
+
- TODO
|
59
|
+
has_rdoc: true
|
60
|
+
homepage: http://github.com/kukoarmas/winprofile
|
61
|
+
licenses: []
|
62
|
+
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options:
|
65
|
+
- --charset=UTF-8
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 3
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
version: "0"
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
hash: 3
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
version: "0"
|
86
|
+
requirements: []
|
87
|
+
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 1.3.7
|
90
|
+
signing_key:
|
91
|
+
specification_version: 3
|
92
|
+
summary: Manage Windows Profiles
|
93
|
+
test_files:
|
94
|
+
- test/test_winprofile.rb
|
95
|
+
- test/test_winreg.rb
|
96
|
+
- test/helper.rb
|