bbmb 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e02656cc3440640de1d6e399c82e5b32d96410b1
4
+ data.tar.gz: 8555ca02ab11577f19a2b89383b0cba8053d3a6e
5
+ SHA512:
6
+ metadata.gz: 73ab4bfa38b7f6812735a7e2ef8731c9d04ff9966a430e27e21796d1d7c35d619315b5e3dddf0f4cec33fc1aa4f62f05b5138ab417467fce96ddaa94d886986c
7
+ data.tar.gz: a53ab0144bbc19b0a24e37957c4a991f9a274d824de930602aa961ea86faa23fc741f5263a634e8daa37101e8a78f8a156494e43923f3b687921c017a403e8db
@@ -0,0 +1,7 @@
1
+ vendor/
2
+ coverage/
3
+ pkg/
4
+ test/data/
5
+ .bundle
6
+ .ruby-version
7
+ Gemfile.lock
@@ -0,0 +1,26 @@
1
+ language: ruby
2
+
3
+ bundler_args: --without debugger
4
+
5
+ cache: bundler
6
+ sudo: false
7
+
8
+ before_install:
9
+ - gem --version
10
+
11
+ script: bundle exec test/suite.rb
12
+
13
+ rvm:
14
+ - 2.1
15
+ - 2.2
16
+ - 2.3.0
17
+ - ruby-head
18
+
19
+ matrix:
20
+ allow_failures:
21
+ - rvm: ruby-head
22
+
23
+ notifications:
24
+ email:
25
+ recipients:
26
+ - ngiger@ywesee.com
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+ group :debugger do
5
+ if RUBY_VERSION.match(/^1/)
6
+ gem 'pry-debugger'
7
+ else
8
+ gem 'pry-byebug'
9
+ gem 'pry-doc'
10
+ end
11
+ end
@@ -0,0 +1,129 @@
1
+ =How to setup bbmb on your localhost or on a server
2
+
3
+ == Getting started
4
+
5
+ * http://dev.ywesee.com/wiki.php/Masa/20101109-setup-eshop
6
+
7
+ == Gems you will need
8
+
9
+ * ruby-json
10
+ * sbsm
11
+ * htmlgrid
12
+ * yus
13
+
14
+ == Look and Feel dependencies
15
+
16
+ * lib/bbmb/util/csv_importer.rb
17
+
18
+ == Using daemontools
19
+
20
+ I makes sense to run bbmb with deamontools once everything is ready for
21
+ production.
22
+
23
+ /service/bbmb $ cat run
24
+ #!/bin/sh
25
+ DIR=/var/.../bbmb/
26
+ exec 2>&1
27
+ exec sudo -u xxx /usr/bin/ruby -rubygems $DIR/bin/bbmbd
28
+ config=$DIR/etc/config.yml
29
+
30
+ == Setup config.yml in /var/www/bbmb/etc/ directory
31
+
32
+ See
33
+
34
+ * http://dev.ywesee.com/wiki.php/Masa/20101109-setup-eshop#configyaml
35
+
36
+ this is an example config
37
+
38
+ ---
39
+ error_recipients:
40
+ - mhatakeyama@ywesee.com
41
+ bbmb_dir: /home/masa/ywesee/bbmb
42
+ db_name: sanxxx_bbmb
43
+ db_user: sanxxx
44
+ db_pass: sanxxx
45
+ log_level: DEBUG
46
+ mail_order_to: mhatakeyama@ywesee.com
47
+ mail_order_from: mhatakeyama@ywesee.com
48
+ name: "Bbmb(Masa)"
49
+ smtp_server: mail.ywesee.com
50
+ smtp_authtype: :plain
51
+ smtp_user: 'mhatakeyama@ywesee.com'
52
+ smtp_pass: xxxx
53
+ target_format: csv
54
+ inject_error_body: |
55
+ inject_error_body
56
+ inject_error_subject: 'Bestellung "%s" mit fehlendem Kunden: "%s"'
57
+ inject_error_from: 'mhatakeyama@ywesee.com'
58
+ inject_error_to: 'mhatakeyama@ywesee.com'
59
+ mail_confirm_from: 'mhatakeyama@ywesee.com'
60
+ mail_confirm_reply_to: 'mhatakeyama@ywesee.com'
61
+ mail_confirm_subject: "Masa: Auftragsbestätigung %s"
62
+ mail_confirm_lines:
63
+ - "%3i x %-40s à %6.2f, total %7.2f"
64
+ - "%3i x %-40s à %6.2f, total %7.2f"
65
+ - "%3i x %-40s a %6.2f, totale %7.2f"
66
+ mail_confirm_body: |
67
+ mail_confirm_body
68
+ confirm_error_body: |
69
+ confirm_error_body
70
+ confirm_error_subject: Kunde "%s" ohne hinterlegte Email-Adresse im Sandoz
71
+ E-shop
72
+ confirm_error_from: 'mhatakeyama@ywesee.com'
73
+ confirm_error_to: 'mhatakeyama@ywesee.com'
74
+
75
+ == Setup /etc/apache2/vhosts.d/04_bbmb_vhost.conf
76
+
77
+ <Directory /home/masa/ywesee/bbmb/doc>
78
+ Options ExecCGI FollowSymlinks Indexes
79
+ AllowOverride None
80
+ Order allow,deny
81
+ Allow from all
82
+ # SSLRequireSSL
83
+ # ErrorDocument 403 https://masa.bbmb.ch
84
+ </Directory>
85
+
86
+ <VirtualHost *:80>
87
+ DocumentRoot /home/masa/ywesee/bbmb/doc
88
+ ServerName bbmb.masa.ch
89
+ DirectoryIndex index.rbx
90
+ RubyAddPath /home/masa/ywesee/bbmb/src
91
+ RubyRequire 'sbsm/trans_handler'
92
+ SetHandler ruby-object
93
+ RubyTransHandler SBSM::TransHandler.instance
94
+ # ErrorLog "|/usr/sbin/cronolog -l /home/masa/ywesee/bbmb/log/error_log
95
+ # /home/masa/ywesee/bbmb/log/%Y/%m/%d/error_log"
96
+ # CustomLog "|/usr/sbin/cronolog -l /home/masa/ywesee/bbmb/log/access_log
97
+ # /home/masa/ywesee/bbmb/log/%Y/%m/%d/access_log" combined
98
+ # SetEnv DEFAULT_FLAVOR masa_bbmb
99
+ SetEnv DRB_SERVER druby://localhost:12000
100
+ </VirtualHost>
101
+
102
+ == Installing the database in Postgresql
103
+
104
+ sudo -u postgres createdb -E UTF8 -T template0 bbmb
105
+ su
106
+ su postgres
107
+ createuser bbmb
108
+
109
+ psql bbmb
110
+ \password bbmb
111
+ enter the password
112
+
113
+ Also see this if Postgresql drives you nuts:
114
+
115
+ * https://help.ubuntu.com/community/PostgreSQL
116
+
117
+ checking your local DB's
118
+
119
+ psql -U postgres
120
+ postgres=# \l
121
+
122
+ == Setting up and configuring yus server
123
+
124
+ * yus_grant --server_url="druby://localhost:12001" zrr@ywesee.com login ch.bbmb.Admin
125
+ * yus_grant --server_url="druby://localhost:12001" zrr@ywesee.com login ch.bbmb.Customer
126
+
127
+ See this link:
128
+
129
+ * http://dev.ywesee.com/wiki.php/Masa/20101111-setup-eshopUpdate-customer-data#yus
@@ -1,3 +1,12 @@
1
+ === 2.0.1 / 17.05.2016
2
+
3
+ * Update for ruby 2.3.1
4
+ ** Some utf-8 issues
5
+ ** Use new minitest syntax
6
+ ** remove encodings
7
+ * Moved from using hoe to rubygems
8
+ * Prepared for travis-ci
9
+
1
10
  === 2.0.0 / 17.12.2010
2
11
 
3
12
  * gem package for bbmb is ready.
@@ -1,3 +1,4 @@
1
+ Guide.txt
1
2
  History.txt
2
3
  LICENSE.txt
3
4
  Manifest.txt
@@ -70,6 +71,7 @@ lib/bbmb/util/numbers.rb
70
71
  lib/bbmb/util/password_generator.rb
71
72
  lib/bbmb/util/polling_manager.rb
72
73
  lib/bbmb/util/server.rb
74
+ lib/bbmb/util/smtp_tls.rb
73
75
  lib/bbmb/util/target_dir.rb
74
76
  lib/bbmb/util/transfer_dat.rb
75
77
  lib/bbmb/util/updater.rb
data/Rakefile CHANGED
@@ -1,28 +1,21 @@
1
- # -*- ruby -*-
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'bbmb/version'
6
+ require "bundler/gem_tasks"
7
+ require 'rspec/core/rake_task'
2
8
 
3
- require 'rubygems'
4
- require 'hoe'
9
+ RSpec::Core::RakeTask.new(:spec)
5
10
 
6
- # Hoe.plugin :compiler
7
- # Hoe.plugin :cucumberfeatures
8
- # Hoe.plugin :gem_prelude_sucks
9
- # Hoe.plugin :inline
10
- # Hoe.plugin :inline
11
- # Hoe.plugin :manifest
12
- # Hoe.plugin :newgem
13
- # Hoe.plugin :racc
14
- # Hoe.plugin :rubyforge
15
- # Hoe.plugin :rubyforge
16
- # Hoe.plugin :website
11
+ # dependencies are now declared in bbmb.gemspec
17
12
 
18
- Hoe.spec 'bbmb' do
19
- # HEY! If you fill these out in ~/.hoe_template/Rakefile.erb then
20
- # you'll never have to touch them again!
21
- # (delete this comment too, of course)
22
-
23
- developer('Masaomi Hatakeyama, Zeno R.R. Davatz', 'mhatakeyama@ywesee.com, zdavatz@ywesee.com')
24
-
25
- # self.rubyforge_name = 'bbmbx' # if different than 'bbmb'
13
+ desc 'Offer a gem task like hoe'
14
+ task :gem => :build do
15
+ Rake::Task[:build].invoke
26
16
  end
27
17
 
28
- # vim: syntax=ruby
18
+ task :spec => :clean
19
+
20
+ require 'rake/clean'
21
+ CLEAN.include FileList['pkg/*.gem']
@@ -0,0 +1,45 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bbmb/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bbmb"
8
+ spec.version = BBMB::VERSION
9
+ spec.author = "Masaomi Hatakeyama, Zeno R.R. Davatz, Niklaus Giger"
10
+ spec.email = "mhatakeyama@ywesee.com, zdavatz@ywesee.com, ngiger@ywesee.com"
11
+ spec.description = "ywesee distributed invoice manager. A Ruby gem"
12
+ spec.summary = "ywesee distributed invoice manager"
13
+ spec.homepage = "https://github.com/zdavatz/bbmb"
14
+ spec.license = "GPL-v2"
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "odba", '>= 1.1.2'
21
+ spec.add_dependency "ydbd-pg", '>= 0.5.2'
22
+ spec.add_dependency "ydbi", '>= 0.5.3'
23
+ spec.add_dependency "json"
24
+ spec.add_dependency "sbsm"
25
+ spec.add_dependency "htmlgrid"
26
+ spec.add_dependency "ydim", '>= 0.5.1'
27
+ spec.add_dependency "syck"
28
+ spec.add_dependency "rmail"
29
+ spec.add_dependency "rclconf"
30
+ spec.add_dependency "needle"
31
+ spec.add_dependency "ypdf-writer"
32
+ spec.add_dependency "hpricot"
33
+ spec.add_runtime_dependency 'deprecated', '= 2.0.1'
34
+
35
+ spec.add_runtime_dependency "yus"
36
+
37
+ spec.add_development_dependency "bundler"
38
+ spec.add_development_dependency "simplecov"
39
+ spec.add_development_dependency "rake"
40
+ spec.add_development_dependency "flexmock"
41
+ spec.add_development_dependency "test-unit"
42
+ spec.add_development_dependency "minitest"
43
+ spec.add_development_dependency "rspec"
44
+ end
45
+
Binary file
data/bin/bbmbd CHANGED
@@ -8,7 +8,6 @@ require 'drb'
8
8
  require 'logger'
9
9
  require 'bbmb/config'
10
10
  require 'bbmb/util/server'
11
- require 'encoding/character/utf-8'
12
11
  require 'pp'
13
12
 
14
13
  module BBMB
@@ -0,0 +1,244 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ puts "#{Time.now}: Loading #{__FILE__}"
4
+ STDOUT.sync = true
5
+
6
+ require 'syck'
7
+
8
+
9
+ begin
10
+ require 'pry'
11
+ rescue LoadError
12
+ end
13
+
14
+ here = File.expand_path(File.join(File.dirname(File.dirname(__FILE__)), 'lib'))
15
+ $: << here
16
+ require 'logger'
17
+ require 'needle'
18
+ require 'odba/id_server'
19
+ require 'rrba/server'
20
+ require 'yus/entity'
21
+ require 'yus/privilege'
22
+ require 'ydim/autoinvoicer'
23
+ require 'ydim/client'
24
+ require 'ydim/currency_converter'
25
+ require 'ydim/currency_updater'
26
+ require 'ydim/factory'
27
+ require 'ydim/root_user'
28
+ require 'ydim/server'
29
+ require 'ydim/util'
30
+ require 'odba/connection_pool'
31
+ require 'odba/drbwrapper'
32
+ require 'ydim/odba'
33
+ require 'ydim/root_session'
34
+ require 'ydim/root_user'
35
+
36
+ require File.join(here, 'bbmb/persistence/odba.rb')
37
+
38
+ module YDIM
39
+ class Server
40
+ # http://stackoverflow.com/questions/2982677/ruby-1-9-invalid-byte-sequence-in-utf-8
41
+ # https://robots.thoughtbot.com/fight-back-utf-8-invalid-byte-sequences
42
+ def sanitize_utf8(string)
43
+ return nil if string.nil?
44
+ # return string.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
45
+ return string if string.valid_encoding?
46
+ if string.force_encoding(Encoding::ISO_8859_1).valid_encoding?
47
+ string.force_encoding(Encoding::ISO_8859_1).clone.encode(Encoding::UTF_8)
48
+ else
49
+ string.chars.select { |c| c.valid_encoding? }.join
50
+ end
51
+ end
52
+ def _migrate_to_utf8 queue, table, opts={}
53
+ while obj = queue.shift do
54
+ if obj.is_a?(Numeric)
55
+ begin
56
+ obj = ODBA.cache.fetch obj
57
+ rescue ODBA::OdbaError
58
+ return
59
+ end
60
+ else
61
+ obj = obj.odba_instance
62
+ end
63
+ puts " #{__LINE__}: Migrating #{obj.class} #{obj.to_s}" if $VERBOSE
64
+ return unless obj
65
+ _migrate_obj_to_utf8 obj, queue, table, opts
66
+ obj.odba_store unless obj.odba_unsaved?
67
+ end
68
+ end
69
+ def _migrate_obj_to_utf8 obj, queue, table, opts={}
70
+ obj.instance_variables.each do |name|
71
+ child = obj.instance_variable_get name
72
+ if child.respond_to?(:odba_unsaved?) && !child.odba_unsaved? \
73
+ && obj.respond_to?(:odba_serializables) \
74
+ && obj.odba_serializables.include?(name)
75
+ child.instance_variable_set '@odba_persistent', nil
76
+ end
77
+ child = _migrate_child_to_utf8 child, queue, table, opts
78
+ obj.instance_variable_set name, child
79
+ end
80
+ if obj.is_a?(Array)
81
+ obj.collect! do |child|
82
+ _migrate_child_to_utf8 child, queue, table, opts
83
+ end
84
+ end
85
+ if obj.is_a?(Hash)
86
+ obj.dup.each do |key, child|
87
+ obj.store key, _migrate_child_to_utf8(child, queue, table, opts)
88
+ end
89
+ end
90
+ obj
91
+ end
92
+ def _migrate_child_to_utf8 child, queue, table, opts={}
93
+ @serialized ||= {}
94
+ case child
95
+ when ODBA::Persistable, ODBA::Stub
96
+ if child = child.odba_instance
97
+ if child.odba_unsaved?
98
+ _migrate_to_utf8 [child], table, opts
99
+ elsif opts[:all]
100
+ odba_id = child.odba_id
101
+ unless table[odba_id]
102
+ table.store odba_id, true
103
+ queue.push odba_id
104
+ end
105
+ end
106
+ end
107
+ when String
108
+ old = child.encoding
109
+ if ( child.encoding != Encoding::UTF_8 && child.force_encoding(Encoding::ISO_8859_1).valid_encoding? ) ||
110
+ ( child.encoding == Encoding::UTF_8 && !child.valid_encoding? )
111
+ child = child.force_encoding(Encoding::ISO_8859_1).clone.encode(Encoding::UTF_8)
112
+ puts "force_encoding from ISO_8859_1 #{old}. is now #{child}"
113
+ end
114
+ binding.pry unless child.valid_encoding?
115
+ case child.encoding.to_s
116
+ when /ASCII-8BIT|US-ASCII/
117
+ # nothing todo
118
+ when /UTF-8/
119
+ puts "UTF-8: for #{child.to_s}" if $VERBOSE
120
+ child = sanitize_utf8(child)
121
+ when /ISO-8859-1/i
122
+ child = sanitize_utf8(child)
123
+ # child = child.force_encoding('UTF-8')
124
+ puts "force_encoding from #{old}. is now #{child}"
125
+ else
126
+ puts "Unhandeled encoding #{child.encoding}"
127
+ # require 'pry'; binding.pry
128
+ # child = child.force_encoding
129
+ end
130
+ when
131
+ Yus::Entity,
132
+ Yus::Privilege,
133
+ YDIM::AutoInvoice,
134
+ YDIM::Debitor,
135
+ YDIM::Debitor,
136
+ YDIM::Invoice,
137
+ YDIM::Invoice::Info,
138
+ YDIM::Item
139
+ child = _migrate_obj_to_utf8 child, queue, table, opts
140
+ when Float, Fixnum, TrueClass, FalseClass, NilClass,
141
+ Symbol, Time, Date, DateTime,
142
+ YDIM::Factory,
143
+ YDIM::CurrencyConverter,
144
+ YDIM::MobileCurrencyConverter
145
+ # do nothing
146
+ else
147
+ @ignored ||= {}
148
+ unless @ignored[child.class]
149
+ @ignored.store child.class, true
150
+ warn "ignoring #{child.class}"
151
+ end
152
+ end
153
+ child
154
+ rescue SystemStackError
155
+ puts child.class
156
+ raise
157
+ end
158
+ end
159
+ end
160
+
161
+ @logger = Logger.new('/tmp/ migrate_to_utf8.log')
162
+ @logger.level = Logger::DEBUG
163
+ config = YDIM::Server.config
164
+ module Yus
165
+ class Entity
166
+ include ODBA::Persistable
167
+ class << self
168
+ alias :all :odba_extent
169
+ end
170
+ end
171
+ class Privilege
172
+ include ODBA::Persistable
173
+ class << self
174
+ alias :all :odba_extent
175
+ end
176
+ end
177
+ end
178
+ module BBMB
179
+ module Model
180
+ class Order
181
+ include ODBA::Persistable
182
+ class << self
183
+ alias :all :odba_extent
184
+ end
185
+ end
186
+ class ProductInfo
187
+ include ODBA::Persistable
188
+ class << self
189
+ alias :all :odba_extent
190
+ end
191
+ end
192
+ class Customer
193
+ include ODBA::Persistable
194
+ class << self
195
+ alias :all :odba_extent
196
+ end
197
+ end
198
+ class Promotion
199
+ include ODBA::Persistable
200
+ class << self
201
+ alias :all :odba_extent
202
+ end
203
+ end
204
+ class Quota
205
+ include ODBA::Persistable
206
+ class << self
207
+ alias :all :odba_extent
208
+ end
209
+ end
210
+ class Subject
211
+ include ODBA::Persistable
212
+ class << self
213
+ alias :all :odba_extent
214
+ end
215
+ end
216
+ end
217
+ end
218
+
219
+ ODBA.storage.dbi = ODBA::ConnectionPool.new(config.db_driver_url,
220
+ config.db_user, config.db_auth, :client_encoding => 'LATIN1')
221
+ ODBA.cache.setup
222
+ DRb.install_id_conv ODBA::DRbIdConv.new
223
+
224
+ @server = YDIM::Server.new(config, @logger)
225
+ puts "DB used is #{config.db_name} user: #{config.db_user} auth: #{config.db_auth}"
226
+ @server.extend(DRbUndumped)
227
+ session = YDIM::RootSession.new(YDIM::RootUser.new(1))
228
+ session.serv = @server
229
+ { # :orders => BBMB::Model::Order.odba_extent,
230
+ # :products => BBMB::Model::ProductInfo.odba_extent,
231
+ # :customers => BBMB::Model::Customer.odba_extent,
232
+ # :promotions => BBMB::Model::Promotion.odba_extent,
233
+ # :quota => BBMB::Model::Quota.odba_extent,
234
+ # :subject => BBMB::Model::Subject.odba_extent,
235
+ :entitites => Yus::Entity.odba_extent,
236
+ :privileges => Yus::Privilege.odba_extent,
237
+ :debitors => YDIM::Debitor.odba_extent,
238
+ :invoices => YDIM::Invoice.odba_extent,
239
+ :autoinvoices => YDIM::AutoInvoice.odba_extent,
240
+ }.each do |name, to_migrate|
241
+ puts "#{Time.now}: Start migrating #{to_migrate.size} #{name}"
242
+ @server._migrate_to_utf8(to_migrate, {})
243
+ end
244
+ puts "#{Time.now}: Finished migrate_to_utf8"