Class: AssUpdater

Inherits:
Object
  • Object
show all
Defined in:
lib/ass_updater.rb,
lib/ass_updater/http.rb,
lib/ass_updater/version.rb,
lib/ass_updater/ass_version.rb,
lib/ass_updater/update_info.rb,
lib/ass_updater/update_distrib.rb,
lib/ass_updater/update_history.rb,
lib/ass_updater/update_info_service.rb

Overview

– encoding utf-8

Defined Under Namespace

Classes: AssVersion, Error, HTTP, UpdateDistrib, UpdateHistory, UpdateInfo, UpdateInfoService

Constant Summary collapse

PLATFORM_VERSIONS =
{ :"8.2" => '8.2', :"8.3" => '8.3' }
KNOWN_CONF_CODENAME =
{ HRM: 'Зарплата и управление персоналом',
Accounting: 'Бухгалтерия предприятия',
AccountingKz: 'Бухгалтерия для Казахстана' }
UPDATEREPO_BASE =
'http://downloads.v8.1c.ru/tmplts/'
UPDATEINFO_BASE =
'http://downloads.1c.ru/ipp/ITSREPV/V8Update/Configs/'
UPD11_ZIP =
'v8upd11.zip'
VERSION =
'0.1.1'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conf_code_name, conf_redaction, platform_version = PLATFORM_VERSIONS.keys.last) { ... } ⇒ AssUpdater

Returns a new instance of AssUpdater.

Parameters:

  • conf_code_name (String)

    code name of configuration

  • conf_redaction (String)

    redaction is major version nuber of configuration. See AssUpdater::AssVersion#redaction

  • platform_version (String) (defaults to: PLATFORM_VERSIONS.keys.last)

    major version namber of target platform 1C:Enterprese.

Yields:

  • self. It’s good place for configure http object. See HTTP

Raises:



43
44
45
46
47
48
49
50
51
52
# File 'lib/ass_updater.rb', line 43

def initialize(conf_code_name,
               conf_redaction,
               platform_version = PLATFORM_VERSIONS.keys.last
              )
  @conf_code_name = conf_code_name
  @http = AssUpdater::HTTP.new
  @conf_redaction = AssUpdater.valid_redaction(conf_redaction)
  @platform_version = AssUpdater.valid_platform_version(platform_version)
  yield self if block_given?
end

Instance Attribute Details

#conf_code_nameString (readonly)

See arguments of #initialize

Returns:

  • (String)


29
30
31
# File 'lib/ass_updater.rb', line 29

def conf_code_name
  @conf_code_name
end

#conf_redactionString (readonly)

See arguments of #initialize

Returns:

  • (String)


29
30
31
# File 'lib/ass_updater.rb', line 29

def conf_redaction
  @conf_redaction
end

#httpAssUpdater::HTTP

Object for access to 1C services. It’s public for configure http connection.

Returns:



32
33
34
# File 'lib/ass_updater.rb', line 32

def http
  @http
end

#platform_versionString (readonly)

See arguments of #initialize

Returns:

  • (String)


29
30
31
# File 'lib/ass_updater.rb', line 29

def platform_version
  @platform_version
end

Instance Method Details

#get_update(user, password, version, tmplt_root) ⇒ AssUpdater::UpdateDistrib

Note:

Require authorization.

Note:

Service downloads.v8.1c.ru often unavailable and it fail on timeout. Don’t worry and try again.

Implement work with distributives of configuration update

Parameters:

  • user (String)

    authorization user name

  • password (String)

    authorization password

  • version (String AssUpdater::AssVersion)
  • tmplt_root (String)

    path to 1C update templates

Returns:



103
104
105
106
# File 'lib/ass_updater.rb', line 103

def get_update(user, password, version, tmplt_root)
  distrib = new_update_distrib(version, tmplt_root)
  distrib.get(user, password)
end

#get_updates(user, password, versions, tmplt_root) {|AssUpdater::UpdateDistrib| ... } ⇒ Array<AssUpdater::UpdateDistrib>

Get updates included in array <versions>. See #get_update

Parameters:

  • versions (Array<String,AssUpdater::AssVersion>)
  • user (String)

    authorization user name

  • password (String)

    authorization password

  • tmplt_root (String)

    path to 1C update templates

Yields:

Returns:



115
116
117
118
119
120
121
122
# File 'lib/ass_updater.rb', line 115

def get_updates(user, password, versions, tmplt_root)
  r = []
  versions.each do |version|
    r << get_update(user, password, version, tmplt_root)
    yield r.last if block_given?
  end
  r
end

#instaled_distribs(tmplt_root) ⇒ Array<AssUpdater::UpdateDistrib>

Note:

return distirbs present in #update_history only

Return all instaled updates findet in 1C templates directory

Parameters:

  • tmplt_root (String)

    path to 1C update templates

Returns:



144
145
146
147
148
149
150
151
152
# File 'lib/ass_updater.rb', line 144

def instaled_distribs(tmplt_root)
  instaled_versions(tmplt_root).map do |v|
    begin
      new_update_distrib(v, tmplt_root)
    rescue AssUpdater::Error
      nil
    end
  end.compact
end

#instaled_versions(tmplt_root) ⇒ Array<AssUpdater::AssVersion>

Return versions all instaled updates finded in 1C templates directory <tmplt_root>

Parameters:

  • tmplt_root (String)

    path to 1C update templates

Returns:



128
129
130
131
132
133
134
135
136
137
138
# File 'lib/ass_updater.rb', line 128

def instaled_versions(tmplt_root)
  (Dir.entries(conf_distribs_local_path(tmplt_root)).map do |e|
    next if e == '.' || e == '..'
    begin
      v = AssUpdater::AssVersion.new(e.split('_').join('.'))
      v if v.redaction == conf_redaction
    rescue ArgumentError
      nil
    end
  end).compact
end

#new_update_distrib(version, tmplt_root) ⇒ AssUpdater::UpdateDistrib

Wrapper return UpdateDistrib object

Parameters:

Returns:



158
159
160
# File 'lib/ass_updater.rb', line 158

def new_update_distrib(version, tmplt_root)
  AssUpdater::UpdateDistrib.new(version, tmplt_root, self)
end

#required_versions_for_update(from_ver = nil, to_ver = nil) ⇒ Array<AssUpdater::AssVersion>

Evaluate versions required for update configuration from version <from_ver> to version <to_ver>. Return array iclude <to_ver> and exclude <from_ver> If called whithout arguments return versions required for update from version ‘0.0.0.0’ to last release.

Parameters:

Returns:

Raises:

  • (ArgumentError)

    if <from_ver> more then <to_ver>



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/ass_updater.rb', line 79

def required_versions_for_update(from_ver = nil, to_ver = nil)
  from_ver = AssUpdater::AssVersion.new(from_ver)
  to_ver = AssUpdater::AssVersion.new(to_ver || update_history.max_version)
  if from_ver >= to_ver
    fail ArgumentError, 'from_ver must be less than to_ver'
  end
  r = []
  c_ver = to_ver
  loop do
    r << c_ver
    targets = update_history.target c_ver
    break if targets.size == 0 || targets.index(from_ver)
    c_ver = targets.min
  end
  r
end

#update_historyHash

Note:

Service downloads.1c.ru often unavailable and initialize fail on timeout. Don’t worry and try again.

Return updates history from v8upd11.xml

Returns:

  • (Hash)


64
65
66
# File 'lib/ass_updater.rb', line 64

def update_history
  @update_history ||= AssUpdater::UpdateHistory.new(self)
end

#update_infoAssUpdater::UpdateInfo

Return info about last configuration release from file UpdInfo.txt



57
58
59
# File 'lib/ass_updater.rb', line 57

def update_info
  @update_info ||= AssUpdater::UpdateInfo.new(self)
end