view · edit · sidebar · attach · print · history

20101108-sample-ebook-setup-eshop

<< Masa.20101109-setup-eshop | 2010 | Masa.20101105-create-patinfo-ebook >>


  1. Small sample test (ebps)
  2. Set up E-Shop
  3. Test daemon starting
  4. Focus on starting bbmbd

Goal
  • Setup E-Shop / 50%
Milestones
  1. Sample Ebook 11:00
  2. Update README 11:20
  3. Setup E-Shop
    • Install libraries
    • Read source code
    • Test run bbmbd
Summary
Commits
ToDo Tomorrow
  • Set up virtual host
  • Set up yus account
Keep in Mind
Attached Files

Small sample test (ebps)

Files necessary to run a converter example (from yaml data to epub file)

  1. Converter (main Ruby script)
  2. Configuration file (yaml)
  3. Data file (yaml)
  4. Import module (Ruby script)
  5. Export module (Ruby script)
  6. Ebps library (ywesee project)

Test 1. Converter script (converter_for_firefox.rb)

#!/usr/bin/env ruby19

$: << File.expand_path('../lib', File.dirname(__FILE__))

require 'ebps'
require 'ebps/util/mail'

def identify_module namespace, name
  module_name = name.gsub /(^|_)./ do |match| match.upcase.delete '_' end
  namespace.const_get module_name
end

begin

  log = []

  # Read modules
  import_from = EBPS.config.import_from
  export_to = EBPS.config.export_to
  require "ebps/conversion/#{import_from}"
  require "ebps/conversion/#{export_to}"

  importer = identify_module EBPS::Conversion, import_from
  exporter = identify_module EBPS::Conversion, export_to

  # Import process
  model = []
  source_path = EBPS.config.source
  inputs = ""
  if File.ftype(source_path) == 'directory'
    inputs << "Input files for conversion:"
    Dir.foreach(source_path) do |name|
      path = File.join source_path, name
      if File.ftype(path) == 'file'
        inputs << "\n" << path
        File.open(path) do |fh|
          model.concat importer.import(fh, path)
        end
      end
    end
  else
    inputs << "Input file for conversion: " << source_path
    source = File.open(source_path)
    model = importer.import source, source_path
  end
  log.push inputs

  # Export process
  target = EBPS.config.target
  exporter.export model, target

  log.push sprintf("The Ebook %s was generated and stored in %s",
                   File.basename(target), File.dirname(target))

rescue StandardError => err
  log.push err
ensure
  EBPS::Util::Mail.notify log
end

2. Configuration file (config.yml)

---
smtp_server: smtp_server
smtp_user: username@domain
smtp_pass: 'password'
report_to:
 - email_address
source: ./data.yml
target: ./sample.epub
import_from: import_module_sample
export_to: epub
language: de
title: Firmenliste Schweiz

3. Data file (data.yml)

--- !ywesee,2010/CompanyInfo
oid: 123456789
descriptions: !ywesee,2010/SimpleLanguage::Descriptions
  de: !ywesee,2010/CompanyInfo2010
    name: ywesee GmbH
    short_description: !ywesee,2010/Text::Chapter
      heading: ywesee - intellectual capital connected
      sections: []

    general_information: !ywesee,2010/Text::Chapter
      heading: About ywesee GmbH
      sections:
      - !ywesee,2010/Text::Section
        subheading: ""
        paragraphs:
        - !ywesee,2010/Text::Paragraph
          formats:
          - !ywesee,2010/Text::Format
            values:
            - :italic
            start: 0
            end: 9
          - !ywesee,2010/Text::Format
            values: []

            start: 10
            end: -1
          text: "ywesee GmbH is an OpenSource Software company with a bias for OpenStandards and a dedicated focus on the HealthCare industry."
          preformatted: false
        - !ywesee,2010/Text::Paragraph
          formats:
          - !ywesee,2010/Text::Format
            values:
            - :italic
            start: 0
            end: 11
          - !ywesee,2010/Text::Format
            values: []

            start: 12
            end: -1
          text: "Web site: http://www.ywesee.com"
          preformatted: false
    address_form: !ywesee,2010/Text::Chapter
      heading: Kontakt zu ywesee
      sections:
      - !ywesee,2010/Text::Section
        subheading: "Address"
        paragraphs:
        - !ywesee,2010/Text::Paragraph
          formats:
          - !ywesee,2010/Text::Format
            values: []

            start: 0
            end: -1
          text: "Winterthurerstrasse 52, 8006 Zürich, Schweiz."
          preformatted: false

4. Import module (import_module_sample.rb)

require 'ebps/text/document'
require 'yaml'

module EBPS

  YAML.add_domain_type 'ywesee,2010', 'CompanyInfo' do |type, val|
    if descr = val.delete('descriptions')
      doc = descr[EBPS.config.language]
      doc.metadata.update val
      doc
    end
  end
  YAML.add_domain_type 'ywesee,2010', 'CompanyInfo2010' do |type, val|
    chapters = %w{short_description general_information address_form}
    Conversion::ImportModuleSample.assemble_document chapters, val
  end
  YAML.add_domain_type 'ywesee,2010', 'Text::Chapter' do |type, val|
    chp = Text::Chapter.new
    chp.heading << val['heading']
    Conversion::ImportModuleSample.encode chp.heading
    chp.paragraphs.concat val['sections'].flatten.compact
    chp
  end
  YAML.add_domain_type 'ywesee,2010', 'Text::Section' do |type, val|
    paragraphs = []
    if (txt = val['subheading']) && !txt.empty?
      sh = Text::Subheading.new
      sh << txt
      Conversion::ImportModuleSample.encode sh.text
      paragraphs << sh
    end
    paragraphs.concat val['paragraphs']
    paragraphs
  end
  YAML.add_domain_type 'ywesee,2010', 'Text::Paragraph' do |type, val|
    par = Text::Paragraph.new
    par << val['text']
    Conversion::ImportModuleSample.encode par.text
    par.formats.replace val['formats']
    if val['preformatted']
      par.formats.each do |fmt|
        fmt.values << 'pre'
      end
    end
    par
  end
  YAML.add_domain_type 'ywesee,2010', 'Text::Format' do |type, val|
    fmt = Text::Format.new
    fmt.values = val['values']
    fmt.start = val['start']
    fmt.end = val['end']
    fmt
  end
  YAML.add_domain_type 'ywesee,2010', 'SimpleLanguage::Descriptions' do |type, val|
    val
  end

  module Conversion
    module ImportModuleSample
      def self.import string_or_io, path=nil
        collection = {}
        YAML.each_document string_or_io do |doc|
          if doc
            collection.store Digest::MD5.hexdigest(doc.to_s), doc
          end
        end
        ## apparently we have some nil-values here (?)
        collection.values.compact
      end
      def self.assemble_document chapters, yaml_value
        doc = Text::Document.new
        doc.title = Conversion::ImportModuleSample.encode(yaml_value['name'])
        chapters.each do |name|
          if chapter = yaml_value[name]
            doc.add_chapter chapter
          end
        end
        doc
      end
      def self.encode txt
        txt.force_encoding 'UTF-8'
        txt
      end
    end
  end
end

5. Export module (lib/ebps/convertion/epub.rb)

Run

masa@masa ~/ywesee/ebps/example $ ruby1.9 ./converter_for_firefox.rb config="./config.yml"

Result

Commit

Set up E-Shop

Emails

References

Install and test log

masa@masa ~/ywesee/bbmb $ sudo ruby setup.rb 
Passwort: 

- - CONFIGURE - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

/usr/lib64/ruby/1.8/yaml/rubytypes.rb:147:in `is_binary_data?': undefined method `>' for nil:NilClass (NoMethodError)
        from /usr/lib64/ruby/1.8/yaml/rubytypes.rb:166:in `to_yaml'
        from /usr/lib64/ruby/1.8/yaml.rb:391:in `call'
        from /usr/lib64/ruby/1.8/yaml.rb:391:in `emit'
        from /usr/lib64/ruby/1.8/yaml.rb:391:in `quick_emit'
        from /usr/lib64/ruby/1.8/yaml/rubytypes.rb:165:in `to_yaml'
        from /usr/lib64/ruby/1.8/yaml/rubytypes.rb:41:in `node_export'
        from /usr/lib64/ruby/1.8/yaml/rubytypes.rb:41:in `add'
        from /usr/lib64/ruby/1.8/yaml/rubytypes.rb:41:in `to_yaml'
         ... 12 levels...
        from setup.rb:1245:in `__send__'
        from setup.rb:1245:in `run'
        from setup.rb:1193:in `run'
        from setup.rb:1345

Notes

  • Installing by Ruby1.8 failed
masa@masa ~/ywesee/bbmb $ sudo ruby1.9 setup.rb 

- - CONFIGURE - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

Configuration saved.

- - INSTALL - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

* bin -> /usr/bin
* lib -> /usr/lib64/ruby/site_ruby/1.9.1

masa@masa ~/ywesee/bbmb $ ls
bin  InstalledFiles  lib  LICENSE  SetupConfig  setup.rb  test
masa@masa ~/ywesee/bbmb $ ruby1.9 test/suite.rb 
test/suite.rb:10:in `require': no such file to load -- test/model/test_customer.rb (LoadError)
        from test/suite.rb:10:in `block in <main>'
        from /usr/lib64/ruby/1.9.1/find.rb:41:in `block in find'
        from /usr/lib64/ruby/1.9.1/find.rb:40:in `catch'
        from /usr/lib64/ruby/1.9.1/find.rb:40:in `find'
        from test/suite.rb:8:in `<main>'

Notes

  • Installing by Ruby1.9 succeeded but tests failed.
masa@masa ~/ywesee/xmlconv $ sudo ruby1.9 setup.rb 

- - CONFIGURE - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

Configuration saved.

- - INSTALL - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

* bin -> /usr/bin
* lib -> /usr/lib64/ruby/site_ruby/1.9.1
* data -> /usr/share
masa@masa ~/ywesee/xmlconv $ ruby1.9 test/suite.rb 
/home/masa/ywesee/xmlconv/test/mock.rb:19:in `require': no such file to load -- runit/error (LoadError)
        from /home/masa/ywesee/xmlconv/test/mock.rb:19:in `<top (required)>'
        from /home/masa/ywesee/xmlconv/test/test_i2/document.rb:9:in `require'
        from /home/masa/ywesee/xmlconv/test/test_i2/document.rb:9:in `<top (required)>'
        from test/suite.rb:12:in `require'
        from test/suite.rb:12:in `block (2 levels) in <main>'
        from test/suite.rb:10:in `foreach'
        from test/suite.rb:10:in `block in <main>'
        from test/suite.rb:7:in `foreach'
        from test/suite.rb:7:in `<main>'

Notes

  • Installing xmlconv succeeded but test failed
masa@masa ~/ywesee/xmlconv $ cd ../xmlconv2/
masa@masa ~/ywesee/xmlconv2 $ sudo ruby1.9 setup.rb 

- - CONFIGURE - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

Configuration saved.

- - INSTALL - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

* bin -> /usr/bin
* data -> /usr/share

masa@masa ~/ywesee/xmlconv2 $ ruby1.9 test/suite.rb 
/home/masa/ywesee/xmlconv2/test/mock.rb:19:in `require': no such file to load -- runit/error (LoadError)
        from /home/masa/ywesee/xmlconv2/test/mock.rb:19:in `<top (required)>'
        from /home/masa/ywesee/xmlconv2/test/test_conversion/bdd_geh.rb:11:in `require'
        from /home/masa/ywesee/xmlconv2/test/test_conversion/bdd_geh.rb:11:in `<top (required)>'
        from test/suite.rb:12:in `require'
        from test/suite.rb:12:in `block (2 levels) in <main>'
        from test/suite.rb:10:in `foreach'
        from test/suite.rb:10:in `block in <main>'
        from test/suite.rb:7:in `foreach'
        from test/suite.rb:7:in `<main>'

Notes

  • Installing xmlconv2 also succeeded but tests failed

Test daemon starting

Log

masa@masa ~/ywesee/bbmb $ ruby1.9 bin/bbmbd 
bin/bbmbd:3: warning: variable $KCODE is no longer effective; ignored
/usr/lib64/ruby/site_ruby/1.9.1/bbmb/html/util/known_user.rb:4:in `require': no such file to load -- sbsm/user (LoadError)
        from /usr/lib64/ruby/site_ruby/1.9.1/bbmb/html/util/known_user.rb:4:in `<top (required)>'
        from /usr/lib64/ruby/site_ruby/1.9.1/bbmb/util/server.rb:5:in `require'
        from /usr/lib64/ruby/site_ruby/1.9.1/bbmb/util/server.rb:5:in `<top (required)>'
        from bin/bbmbd:10:in `require'
        from bin/bbmbd:10:in `<main>'

Install sbsm

masa@masa ~/ywesee/ruby19/sbsm $ sudo ruby1.9 setup.rb 

- - CONFIGURE - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

Configuration saved.

- - INSTALL - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

* lib -> /usr/lib64/ruby/site_ruby/1.9.1
* data -> /usr/share

Run bbmbd again

masa@masa ~/ywesee/ruby19/bbmb $ ruby1.9 bin/bbmbd 
bin/bbmbd:3: warning: variable $KCODE is no longer effective; ignored
/usr/lib64/ruby/gems/1.9.1/gems/character-encodings-0.4.1/lib/encoding/character/utf-8.rb:5:in `require': no such file to load -- encoding/character/utf-8/utf8 (LoadError)

Install character-encodings => failed

masa@masa ~/ywesee/ruby19/bbmb $ sudo ruby1.9 /usr/bin/gem install character-encodings
Building native extensions.  This could take a while...
ERROR:  Error installing character-encodings:
        ERROR: Failed to build gem native extension.

/usr/bin/ruby1.9 extconf.rb
extconf.rb:4: invalid multibyte char (US-ASCII)
extconf.rb:4: invalid multibyte char (US-ASCII)
extconf.rb:4: syntax error, unexpected $end, expecting keyword_end
  checking_for "‘#{opt}’ option to compiler" do
                  ^


Gem files will remain installed in /usr/lib64/ruby/gems/1.9.1/gems/character-encodings-0.4.1 for inspection.
Results logged to /usr/lib64/ruby/gems/1.9.1/gems/character-encodings-0.4.1/ext/encoding/character/utf-8/gem_make.out

Focus on starting bbmbd

Try to run by Ruby1.8

masa@masa ~/ywesee/bbmb $ bin/bbmbd 
/usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- json/objects (LoadError)
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from /home/masa/ywesee/bbmb/lib/bbmb/html/view/json.rb:5
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from /home/masa/ywesee/bbmb/lib/bbmb/html/state/json.rb:4
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from /home/masa/ywesee/bbmb/lib/bbmb/html/state/current_order.rb:6
         ... 11 levels...
        from /home/masa/ywesee/bbmb/lib/bbmb/util/server.rb:6
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from bin/bbmbd:10

Check libraries

masa@masa ~/ywesee/bbmb $ gem search json

*** LOCAL GEMS ***

json (1.4.3)
json_pure (1.4.3)

Install ruby-json

masa@masa ~/ywesee/bbmb $ sudo gem install ruby-json
Successfully installed ruby-json-1.1.2
1 gem installed
Installing ri documentation for ruby-json-1.1.2...
ERROR:  While executing gem ... (NoMethodError)
    undefined method `>' for nil:NilClass

Run again

masa@masa ~/ywesee/bbmb $ gem search json 

*** LOCAL GEMS ***

json (1.4.3)
json_pure (1.4.3)
ruby-json (1.1.2)
masa@masa ~/ywesee/bbmb $ bin/bbmbd 
/usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- bbmb/util/csv_importer (LoadError)
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from bin/bbmbd:16
        from bin/bbmbd:15:in `each'
        from bin/bbmbd:15

Check csv_importer

masa@masa ~/ywesee/bbmb/lib/bbmb/util $ ls
invoicer.rb  mail.rb  multilingual.rb  numbers.rb  password_generator.rb  polling_manager.rb  server.rb  target_dir.rb  transfer_dat.rb  updater.rb

Notes

Copy csv_importer.rb and run

masa@masa ~/ywesee/bbmb $ cp ~/ywesee/sandoz.bbmb.ch/lib/bbmb/util/csv_importer.rb lib/bbmb/util/
masa@masa ~/ywesee/bbmb $ bin/bbmbd 
/usr/lib64/ruby/site_ruby/1.8/DBD/Pg/Pg.rb:118:in `initialize': FATAL:  database "bbmb" does not exist (DBI::OperationalError)
        from /usr/lib64/ruby/site_ruby/1.8/DBD/Pg/Pg.rb:62:in `new'
        from /usr/lib64/ruby/site_ruby/1.8/DBD/Pg/Pg.rb:62:in `connect'
        from /usr/lib64/ruby/site_ruby/1.8/dbi.rb:448:in `connect'
        from /usr/lib64/ruby/site_ruby/1.8/dbi.rb:221:in `connect'
        from /usr/lib64/ruby/site_ruby/1.8/odba/connection_pool.rb:60:in `_connect'
        from /usr/lib64/ruby/site_ruby/1.8/odba/connection_pool.rb:59:in `times'
        from /usr/lib64/ruby/site_ruby/1.8/odba/connection_pool.rb:59:in `_connect'
        from /usr/lib64/ruby/site_ruby/1.8/odba/connection_pool.rb:56:in `connect'
        from /usr/lib64/ruby/site_ruby/1.8/odba/connection_pool.rb:56:in `synchronize'
        from /usr/lib64/ruby/site_ruby/1.8/odba/connection_pool.rb:56:in `connect'
        from /usr/lib64/ruby/site_ruby/1.8/odba/connection_pool.rb:19:in `initialize'
        from /home/masa/ywesee/bbmb/lib/bbmb/persistence/odba.rb:38:in `new'
        from /home/masa/ywesee/bbmb/lib/bbmb/persistence/odba.rb:38
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from bin/bbmbd:18

Notes

  • The DB is necessary
  • Create user, db
  • Download backup file from the production server
masa@masa ~/ywesee/bbmb $ createuser sandxx -P
Geben Sie das Passwort der neuen Rolle ein: 
Geben Sie es noch einmal ein: 
Soll die neue Rolle ein Superuser sein? (j/n) j

masa@masa ~/ywesee/bbmb $ sudo -u postgres createdb -E UTF8 -T template0 sandxx_bbmb
masa@masa ~/ywesee/bbmb $ cd src/
masa@masa ~/ywesee/bbmb/src $ scp xxx@$WHITIE:/var/.../postgresql_database-sandxx_bbmb-backup.gz .
masa@masa ~/ywesee/bbmb/src $ zcat postgresql_database-sandxx_bbmb-backup.gz | psql -U sandxx sandxx_bbmb

Change default configuration parameters

lib/bbmb/config.rb

...
#    'db_name'                         => 'bbmb',
#    'db_user'                         => 'bbmb',
#    'db_auth'                         => 'bbmb',
    'db_name'                         => 'sandxx_bbmb',
    'db_user'                         => 'sandxx',
    'db_auth'                         => 'sandxx',
...
#    'mail_order_to'                   => 'orders.test@bbmb.ch',
    'mail_order_to'                   => 'mhatakeyama@ywesee.com',
...
    #'smtp_server'                     => 'mail.bbmb.ch',
    'smtp_server'                     => 'smtp.gmail.com',
    #'smtp_user'                       => nil,
    'smtp_user'                       => 'mhatakeyama@ywesee.com',
...

Test run

masa@masa ~/ywesee/bbmb $ bin/bbmbd 
ERROR:  relation "object" already exists

ERROR:  relation "prefetchable_index" already exists

ERROR:  relation "extent_index" already exists

ERROR:  relation "object_connection" already exists

ERROR:  relation "target_id_index" already exists

ERROR:  relation "collection" already exists

ERROR:  relation "target_id_bbmb_model_product_pcode" already exists

ERROR:  relation "target_id_bbmb_model_customer_customer_id" already exists

ERROR:  relation "target_id_bbmb_model_product_description" already exists

ERROR:  relation "target_id_bbmb_model_product_article_number" already exists

ERROR:  relation "target_id_bbmb_model_product_catalogue1" already exists

ERROR:  relation "target_id_bbmb_model_product_catalogue2" already exists

ERROR:  relation "target_id_bbmb_model_customer_ean13" already exists

ERROR:  relation "target_id_bbmb_model_product_ean13" already exists

ERROR:  relation "target_id_bbmb_model_customer_email" already exists

/usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31: command not found: cg-object-id
I, [2010-11-08T16:37:55.968987 #1459]  INFO -- start: starting bbmb-server on druby://localhost:12000

Notes

  • There are errors but it looks running

Next

  • Set up virtual host
  • Refer to oddb.org vhost setting /etc/apache2/vhosts.d/01_oddb_vhost.conf
view · edit · sidebar · attach · print · history
Page last modified on July 13, 2011, at 11:56 AM