-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload-wiki.rb
executable file
·69 lines (57 loc) · 1.33 KB
/
upload-wiki.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/local/bin/ruby
# = upload-wiki.rb
#
# Author:: Dirk Meyer
# Copyright:: Copyright (c) 2018-2023 Dirk Meyer
# License:: Distributes under the same terms as Ruby
#
$: << '.'
require 'yaml'
require 'netrc'
require 'dokuwiki'
# wiki config file
CONFIG_FILE = 'wiki-config.yml'.freeze
def read_yaml( filename, default = {} )
config = default
return config unless File.exist?( filename )
config.merge!( YAML.load_file( filename ) )
end
$config = read_yaml( CONFIG_FILE )
user, pass = NetRc.login_data( $config[ 'host' ] )
exit if user.nil?
dokuwiki = DokuWiki::DokuWikiAccess.new( $config[ 'host' ] )
dokuwiki.login( $config[ 'qspath' ], user, pass )
dokuwiki.upload_dir = 'UPLOAD'
old = Dir.getwd
unless ARGV.empty?
ARGV.each do |filename|
path = $config[ 'qspath' ].to_s.dup
if filename.include?( '/' )
dir = filename.split( '/' ).first
path << ':'
path << dir
filename = filename.split( '/' ).last
Dir.chdir( dir )
end
dokuwiki.upload_file( path, filename )
Dir.chdir( old )
end
exit 0
end
[
'qscript.txt',
'numbered-qscript.txt',
'out.html',
'out.txt',
'all.wiki',
'plain.wiki',
'clothes.pdf',
'all.pdf',
'todo-list.csv',
'assignment-list.csv',
'availability.html'
].each do |filename|
dokuwiki.upload_file( $config[ 'qspath' ], filename )
end
exit 0
# eof