Module: QooxView

Defined in:
lib/qooxview/qooxview.rb

Class Method Summary collapse

Class Method Details

.do_opts(dir_entities, dir_views) ⇒ Object

Reads options from the command-line:

  • -h shows the help screen

  • -(t|i18n) scans for translation-variables and writes .po

  • -p converts .po to .mo

  • -a call Accounts.archive (should be moved to Africompta)



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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/qooxview/qooxview.rb', line 39

def self.do_opts(dir_entities, dir_views)
  opts = GetoptLong.new(
      ['--help', '-h', GetoptLong::NO_ARGUMENT],
      ['--i18n', '-t', GetoptLong::OPTIONAL_ARGUMENT],
      ['--po', '-p', GetoptLong::NO_ARGUMENT],
      ['--archive', '-a', GetoptLong::OPTIONAL_ARGUMENT]
  )
  opts.each { |o, a|
    case o
      when '--help'
        puts "Usage: #{$0} [-t] [--help]"
        puts "\t-t [lang]\tUpdate translations - takes an optional language-argument"
        puts "\t-p\tCreate .mo-files"
        puts "\t--help\tShow this help"
        raise 'PrintHelp'
      when '--i18n'
        potfile = "po/#{$name}.pot"
        %x[ mkdir -p po; rm -f #{potfile} ]
        paths = ["#{dir_entities}/*.rb", "#{dir_views}/*.rb", "#{dir_views}/*/*.rb"]
        dputs(2) { "potfile is #{potfile.inspect}, paths is #{paths.collect { |p| Dir[p] }}" }
        #GetText::Tools::XGetText.run( paths.collect{|p| Dir[p] }.flatten.concat( [ "-o", "#{potfile}" ] ) )
        GetText::Tools::XGetText.run(*paths.collect { |p| Dir[p] }.concat(
                                         %W(-o #{potfile})).flatten)
        if a.length > 0
          pofile = "po/#{$name}-#{a}.po"
          if File.exists? pofile
            %x[ mv #{pofile} #{pofile}.tmp ]
            #%x[ msgmerge #{pofile}.tmp #{potfile} -o #{pofile} ]
            # Should be possible with rmsgmerge, but it didn't work :(
            GetText::Tools::MsgMerge.run("#{pofile}.tmp", potfile, '-o', pofile)
            %x[ rm #{pofile}.tmp ]
          else
            %x[ cp #{potfile} #{pofile} ]
          end
        end
        raise 'UpdatePot'
      when '--po'
        dputs(2) { 'Making mo-files' }
        Dir.glob("po/#{$name}-*.po").each { |po|
          lang = po.match(/.*#{$name}-(.*).po/)[1]
          path = "po/#{lang}/LC_MESSAGES"
          dputs(2) { "Doing po-file #{po} for language #{lang} with path #{path}" }
          if not %x[ mkdir -p #{path}] or not GetText::Tools::MsgFmt.run(po, "-o#{path}/#{$name}.mo")
            dputs(0) { "Error: can't make mo-files, exiting" }
            exit
          end
        }
        raise 'MakeMo'
      when '--archive'
        dputs(2) { 'Going to archive AfriCompta' }
        $qooxview_cmds.push [:archive, a]
    end
  }
end

.init(dir_entities = nil, dir_views = nil) ⇒ Object

Read in all entities and vies, load data of entities, but don’t start web-server yet



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/qooxview/qooxview.rb', line 111

def self.init(dir_entities = nil, dir_views = nil)
  #dputs_func
  # If we're in test-mode, don't interpret arguments
  if !Module.constants.index(:Test)
    dputs(2) { 'Doing options' }
    self.do_opts(dir_entities, dir_views)
  end

  # Include all modules in the dir_entities and dir_views
  # directories
  dputs(2) { "Starting init with entities:views = #{[dir_entities, dir_views].join(':')}" }
  QooxView.load_dirs( dir_entities, dir_views )

  if not Permission.list.index('default')
    Permission.add('default', '.*')
  end

  dputs(2) { 'Starting RPCQooxdooServices' }
  # We want to load an eventual ConfigBase first, so that other modules can
  # read the configuration
  rpcqooxdoo = RPCQooxdooService.new('Entities.ConfigBase')
  if true
    ConfigBases.init_load
  else
    Entities.ConfigBases.load
    ConfigBases.singleton
    Entities.ConfigBases.migrate
  end
  # Everything will be loaded just after, so make sure we have everything done
  # when there is a migration
  Entities.save_all

  GetText.bindtextdomain($name, :path => 'po')
  if ConfigBase.locale_force
    dputs(3) { "Forcing locale to #{ConfigBase.locale_force}" }
    GetText.locale = ConfigBase.locale_force
  end
  GetText::TextDomainManager.cached = false

  # Get an instance of all Qooxdoo-services
  rpcqooxdoo.get_services('^Entities.*')
  Entities.load_all
  rpcqooxdoo.get_services('^View.*')

  $qooxview_cmds.each { |qv|
    qv_cmd = qv.class == Array ? qv[0] : qv
    dputs(2) { "Doing #{qv.inspect}" }
    case qv_cmd
      when :archive
        month = qv[1] == '' ? 1 : qv[1]
        dputs(2) { "Archiving with starting month #{month}" }
        Accounts.archive(month)
        exit
    end
  }
end

.load_dirs(*dirs) ⇒ Object

require all files in the directories dirs - one or more arguments to scan for .rb-files



96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/qooxview/qooxview.rb', line 96

def self.load_dirs( *dirs )
  #dputs_func
  dirs.flatten.each{|dir|
    if dir
      dputs(2) { "Initializing directory #{dir}" }
      Dir[File.join(dir, '**', '*.rb')].each { |f|
        dputs(3) { "Requiring file #{f}" }
        require(f)
      }
    end
  }
end

.startWeb(port = 3302, duration = nil) ⇒ Object

The main function, used to start it all



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/qooxview/qooxview.rb', line 169

def self.startWeb(port = 3302, duration = nil)
  dputs(2) { "Configuring port for #{port}" }
  # Suppose we've not being initialized when there are no permissions
  if Permission.list.size == 0
    self.init
  end

  # And start the webrick-server
  # First check whether QooxDoo is running in source- or buid-mode
  dir_html = File.exist?(QOOXVIEW_DIR + '/frontend/build/script/frontend.js') ?
      'build' : 'source'
  dputs(2) { "Directory for Frontend is: #{dir_html}" }

  log_msg('main', 'Starting up')
  if cmd = get_config(false, :startupCmd)
    %x[ #{cmd} ]
  end
  RPCQooxdooHandler.webrick(port, QOOXVIEW_DIR + "/frontend/#{dir_html}/",
                            duration)
end