860faee7cf7fd2a7598d29395560ff619d535f95
[software/sisu] / lib / sisu / develop / se_version.rb
1 # encoding: utf-8
2 =begin
3
4 * Name: SiSU
5
6 ** Description: documents, structuring, processing, publishing, search
7 *** system environment, resource control and configuration details
8
9 ** Author: Ralph Amissah
10 <ralph@amissah.com>
11 <ralph.amissah@gmail.com>
12
13 ** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
14 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Ralph Amissah,
15 All Rights Reserved.
16
17 ** License: GPL 3 or later:
18
19 SiSU, a framework for document structuring, publishing and search
20
21 Copyright (C) Ralph Amissah
22
23 This program is free software: you can redistribute it and/or modify it
24 under the terms of the GNU General Public License as published by the Free
25 Software Foundation, either version 3 of the License, or (at your option)
26 any later version.
27
28 This program is distributed in the hope that it will be useful, but WITHOUT
29 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
30 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
31 more details.
32
33 You should have received a copy of the GNU General Public License along with
34 this program. If not, see <http://www.gnu.org/licenses/>.
35
36 If you have Internet connection, the latest version of the GPL should be
37 available at these locations:
38 <http://www.fsf.org/licensing/licenses/gpl.html>
39 <http://www.gnu.org/licenses/gpl.html>
40
41 <http://www.sisudoc.org/sisu/en/manifest/gpl.fsf.html>
42
43 ** SiSU uses:
44 * Standard SiSU markup syntax,
45 * Standard SiSU meta-markup syntax, and the
46 * Standard SiSU object citation numbering and system
47
48 ** Hompages:
49 <http://www.jus.uio.no/sisu>
50 <http://www.sisudoc.org>
51
52 ** Git
53 <http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=summary>
54 <http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=blob;f=lib/sisu/develop/se_version.rb;hb=HEAD>
55
56 =end
57 module SiSU_Info_Version
58 require_relative 'constants' # constants.rb
59 require_relative 'utils' # utils.rb
60 require_relative 'se_info_env' # se_info_env.rb
61 begin
62 require 'singleton'
63 rescue LoadError
64 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
65 error('singleton NOT FOUND (LoadError)')
66 end
67 class InfoVersion < SiSU_Info_Env::InfoEnv # se_info_env.rb
68 include Singleton
69 begin
70 require 'rbconfig'
71 require 'yaml'
72 rescue LoadError
73 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
74 error('rbconfig or yaml NOT FOUND (LoadError)')
75 end
76 @@lib_path=nil
77 def get_version
78 version={}
79 @pwd=ENV['PWD']
80 lib_path=
81 @@lib_path \
82 ? @@lib_path
83 : `echo $RUBYLIB`.split(':')
84 @@lib_path ||=lib_path
85 if File.exist?(SiSU_is.version_info_path?)
86 version=YAML::load(File::open(SiSU_is.version_info_path?))
87 end
88 version[:branch_version]=SiSU_is.branch_version?
89 version[:branch_number]=/^v([0-9]+)/.match(version[:branch_version])[1]
90 version[:branch_name]=SiSU_is.branch_name?
91 version[:install_method]=if SiSU_is.run_from? ==:gem_install
92 spec = Gem::Specification.find_by_name("sisu")
93 gem_root = spec.gem_dir
94 (File.dirname(__FILE__.gsub(/\/lib\/sisu\/#{SiSU_is.branch_name?}/,'')) == gem_root) \
95 ? ' (ruby gem install)' : ''
96 else ''
97 end
98 @version=version
99 def version_details_hash
100 @version
101 end
102 def project
103 version_details_hash[:project]
104 end
105 def date
106 version_details_hash[:date]
107 end
108 def date_stamp
109 version_details_hash[:date_stamp]
110 end
111 def version
112 version_details_hash[:version]
113 end
114 def branch_version
115 version_details_hash[:branch_version]
116 end
117 def branch_number
118 version_details_hash[:branch_number]
119 end
120 def branch_name
121 version_details_hash[:branch_name]
122 end
123 def install_method
124 version_details_hash[:install_method]
125 end
126 self
127 end
128 def rbversion
129 %x{ruby -v}.strip
130 end
131 end
132 end
133 module SiSU_Info_About
134 require_relative 'constants' # constants.rb
135 require_relative 'utils' # utils.rb
136 begin
137 require 'singleton'
138 rescue LoadError
139 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
140 error('singleton NOT FOUND (LoadError)')
141 end
142 class InfoAbout
143 def initialize(color='')
144 @color=color
145 end
146 def sisu_version
147 version=SiSU_Env::InfoVersion.instance.get_version
148 rb_ver=SiSU_Env::InfoVersion.instance.rbversion
149 if version.version
150 opt_cmd=if defined? @color.cmd \
151 and @color.cmd =~/[ck]/
152 @color.cmd
153 else '-v'
154 end
155 SiSU_Screen::Ansi.new(
156 opt_cmd,
157 version.project,
158 version.version,
159 version.date_stamp,
160 version.date,
161 version.install_method,
162 rb_ver
163 ).version
164 else puts 'SiSU (version information not available)'
165 end
166 end
167 def sisu_about
168 puts <<-WOK
169 sisu: documents; markup, structuring, publishing in multiple standard formats, & search
170 most (not all) useful commands (are made in a directory containing a sisu markup file &) take the form:
171 sisu [action(s)] [filename(s)]
172 where filename refers to a valid sisu marked up file, e.g.:
173 cd /usr/share/doc/sisu/markup-samples/sisu_manual
174 sisu --html --verbose sisu_commands.sst
175 sisu --txt --html --epub --odt --pdf --sqlite --manpage --texinfo --concordance --qrcode --verbose sisu.ssm
176 cd -
177 See output produced, or see man pages: man sisu
178 <http://www.sisudoc.org/> <http://www.jus.uio.no/sisu/>
179 WOK
180 end
181 end
182 end
183 __END__