PublicanCreators   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 211
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 211
rs 10
wmc 2
1
#!/usr/bin/env ruby
2
# @author Sascha Manns
3
# @abstract Main Class for PublicanCreators
4
#
5
# Copyright (C) 2015-2017  Sascha Manns <[email protected]>
6
# License: MIT
7
8
# Dependencies
9
require 'publican_creators/checker'
10
require 'publican_creators/get'
11
require 'publican_creators/change'
12
require 'publican_creators/export'
13
require 'publican_creators/prepare'
14
require 'publican_creators/notifier'
15
require 'fileutils'
16
require 'nokogiri'
17
require 'rainbow/ext/string'
18
require 'bundler/setup'
19
require 'manns_shared'
20
21
# Main Class of PublicanCreators
22
# @return [String] true or false
23
class PublicanCreators
24
  # Versionizing
25
  VERSION = '1.1.2'
26
27
  my_name = File.basename($PROGRAM_NAME)
28
29
  puts "Script: #{my_name}"
30
  puts "Version: #{VERSION}"
31
  puts
32
  puts 'Copyright (C) 2015-2016 Sascha Manns <[email protected]>'
33
  puts 'Description: This script creates a article or book set with'
34
  puts 'Publican. Then it modifies it for your needs.'
35
  puts 'License: GPL-3'
36
  puts 'Bugs: Please file bugs on https://gitlab.com/saigkill/publican_creators/issues'
37
38
  puts 'Reading the config file in publicancreators.cfg'
39
  # @note Run config method who reads in the config file and puts the variables
40
  # in an array
41
  # name, email, language, use_brand, title_logo, legal, brand, company_name,
42
  #     company_division, email_business, brand_dir, glob_entities,
43
  #     articles_dir_business, reports_dir_business, books_dir_business,
44
  #     articles_dir_private, homework_dir_private, books_dir_private,
45
  #     brand_private, brand_homework, db5, conf_ver, xfc_brand_dir,
46
  #     pdfview = PublicanCreatorsGet.config
47
48
  home = Dir.home
49
  config = ParseConfig.new("#{home}/.publican_creators/publicancreators.cfg")
50
  conf_ver = config['conf_ver']
51
  name = config['name']
52
  email = config['email_private']
53
  language = config['language']
54
  use_brand = config['use_brand']
55
  title_logo = config['title_logo']
56
  legal = config['legal']
57
  brand = config['brand']
58
  company_name = config['company_name']
59
  company_division = config['company_division']
60
  email_business = config['email_business']
61
  brand_dir = config['brand_dir']
62
  glob_entities = config['globalentities']
63
  articles_dir_business = config['articles_dir']
64
  reports_dir_business = config['reports_dir']
65
  books_dir_business = config['books_dir']
66
  articles_dir_private = config['articles_dir_priv']
67
  homework_dir_private = config['homework_dir']
68
  books_dir_private = config['books_dir_priv']
69
  brand_private = config['brand_private']
70
  brand_homework = config['brand_homework']
71
  db5 = config['db5']
72
  xfc_brand_dir = config['xfc_brand_dir']
73
  pdfview = config['pdfview']
74
75
  puts 'Your configuration is:'
76
  puts "Your Name: #{name}"
77
  puts "Your private emailaddress: #{email}"
78
  puts "Your choosen language: #{language}"
79
  puts "Using an own brand: #{use_brand}"
80
  puts "Leave title_logo: #{title_logo}"
81
  puts "Leave legalnotice in article: #{legal}"
82
  puts "Choosen brand: #{brand}"
83
  puts "Your company name: #{company_name}"
84
  puts "Your company division: #{company_division}"
85
  puts "Your business email address: #{email_business}"
86
  puts "Your brand dir: #{brand_dir}"
87
  puts "Your global entities: #{glob_entities}"
88
  puts "Your business articles dir: #{articles_dir_business}"
89
  puts "Your business reports dir: #{reports_dir_business}"
90
  puts "Your business books dir: #{books_dir_business}"
91
  puts "Your private articles dir: #{articles_dir_private}"
92
  puts "Your homework dir: #{homework_dir_private}"
93
  puts "Your private books dir: #{books_dir_private}"
94
  puts "Your private brand: #{brand_private}"
95
  puts "Your homework brand: #{brand_homework}"
96
  puts "DocBook5 as default: #{db5}"
97
  puts "Config version: #{conf_ver}"
98
  puts "XFC brand dir: #{xfc_brand_dir}"
99
  puts "Your prefered PDF-Viewer: #{pdfview}"
100
101
  global_entities = "#{brand_dir}/#{glob_entities}"
102
  puts "Your global entities file is there: #{global_entities}"
103
104
  # @note Ask for the title and other settings via yad and put them into a array
105
  environment, type, opt, title = PublicanCreatorsGet.title
106
107
  puts "Environment: #{environment}"
108
  puts "Type: #{type}"
109
  puts "Optional: #{opt}"
110
  puts "Title: #{title}"
111
112
  # This method sets the default value for report
113
  # @param [String] opt Can be Report or Homework or Normal
114
  # @return [String] report
115
116
  report = 'FALSE'
117
  homework = 'FALSE'
118
  report = 'TRUE' if opt == 'Report'
119
  homework = 'TRUE' if opt == 'Homework'
120
121
  # @note Hardcoded variables
122
  artinfo = "#{title}/#{language}/Article_Info.xml"
123
  bookinfo = "#{title}/#{language}/Book_Info.xml"
124
  revhist = "#{title}/#{language}/Revision_History.xml"
125
  agroup = "#{title}/#{language}/Author_Group.xml"
126
  ent = "#{title}/#{language}/#{title}.ent"
127
  builds = "#{title}/#{language}/Rakefile"
128
129
  # @note Run one of the both methods to get the variable targetdir
130
  # @param [String] type Book or Article
131
  # @param [String] reports_dir_business path to that dir where you store your
132
  #                 reports
133
  # @param [String] articles_dir_business path to that dir where you store
134
  #                 business articles
135
  # @param [String] report true or false
136
  # @param [String] books_dir_business path to that dir where you store your
137
  #                 business books
138
  # @param [String] true or false
139
  # @param [String] articles_dir_private path to your private articles directory
140
  # @param [String] homework path to your homework directory
141
  # @param [String] books_dir_private path to your private books directory
142
  targetdir = PublicanCreatorsPrepare.targetdir(environment, type, report,
143
                                                reports_dir_business,
144
                                                articles_dir_business,
145
                                                books_dir_business, homework,
146
                                                articles_dir_private,
147
                                                homework_dir_private,
148
                                                books_dir_private)
149
150
  # @note Checks if the needed directory targetdir is available. Otherwise it
151
  # creates one.
152
  puts "Creating directory #{targetdir}"
153
  # @param [String] targetdir comes from PublicanCreatorsPrepare.prepare_work or
154
  # .prepare_private
155
  MannsShared.check_dir(targetdir)
156
157
  # @note Change to target directory
158
  puts 'Change to this directory'
159
  # @param [String] targetdir comes from PublicanCreatorsPrepare.prepare_work or
160
  # .prepare_private
161
  FileUtils.cd(targetdir) do
162
    # @param [String] title comes from titleget[3]
163
    # @param [String] type Book or Article
164
    # @param [String] language comes from config file in format de-DE
165
    # @param [String] brand e.g. Debian or nothing for using publicans default
166
    #                 brand (config file)
167
    # @param [String] db5 DocBook5 as default? (config file)
168
    # @param [String] homework true or false
169
    # @param [String] brand_homework e.g. ils (config file)
170
    # @param [String] brand_private e.g. manns (config file)
171
    PublicanCreatorsChange.check_environment(environment, title, type, language,
172
                                             brand, db5, homework,
173
                                             brand_homework, brand_private)
174
175
    # @param [String] title comes from titleget[3]
176
    # @param [String] environment Work or Private
177
    # @param [String] global_entities path to a global entities file
178
    #                 (config file)
179
    # @param [String] brand e.g. Debian or nothing for using publicans default
180
    #                 brand (config file)
181
    PublicanCreatorsChange.add_entity(environment, global_entities, ent)
182
183
    # @param [String] title comes from titleget[3]
184
    # @param [String] environment Work or Private
185
    # @param [String] name your name (config file)
186
    # @param [String] company_name (config file)
187
    PublicanCreatorsChange.change_holder(title, environment, name, company_name,
188
                                         ent)
189
190
    # @param [String] title comes from titleget[3]
191
    # @param [String] environment Work or Private
192
    # @param [String] type Book or Article
193
    # @param [String] legal remove legalnotice from article? (config file)
194
    PublicanCreatorsChange.remove_legal(environment, type, legal, artinfo)
195
196
    # @param [String] artinfo path to Article_Info (hardcoded)
197
    # @param [String] bookinfo path to Book_Info (hardcoded)
198
    # @param [String] title_logo remove titlelogo from articlepage (config file)
199
    # @param [String] type Book or Article
200
    PublicanCreatorsChange.remove_orgname_prepare(bookinfo, artinfo, title_logo,
201
                                                  type)
202
203
    # @param [String] environment Work or Private
204
    # @param [String] name your name (config file)
205
    # @param [String] email_business business email address (config file)
206
    # @param [String] title comes from titleget[3]
207
    PublicanCreatorsChange.fix_revhist(environment, name, email_business, email,
208
                                       revhist)
209
210
    # @param [String] title comes from titleget[3]
211
    # @param [String] name your name (config file)
212
    # @param [String] email_business business email address (config file)
213
    # @param [String] company_name your company's name (config file)
214
    # @param [String] company_division your companiy's division
215
    # @param [String] email your private email address
216
    PublicanCreatorsChange.fix_authorgroup(name, email_business, company_name,
217
                                           company_division, email, environment,
218
                                           agroup)
219
220
    # @param [String] title comes from titleget[3]
221
    # @param [String] builds path to buildscript (hardcoded)
222
    # @param [String] language comes from config file in format de-DE
223
    # @param [String] xfc_brand_dir if present the path to your branded xfc
224
    #                 stylesheets (config file)
225
    # @param [String] pdfview your prefered PDF-Viewer (config file)
226
    PublicanCreatorsExport.export_buildscript(title, builds, language,
227
                                              xfc_brand_dir, pdfview)
228
229
    puts "Now you can find your documentation there: #{targetdir}/#{title}"
230
    Notifier.run
231
    puts "Thanks for using: #{my_name} #{VERSION}"
232
  end
233
end
234