Code cleanup.
This commit is contained in:
parent
5e518f5037
commit
6d6779caf7
2 changed files with 90 additions and 90 deletions
|
@ -19,7 +19,7 @@ class Index extends App.ControllerContent
|
||||||
url: "#{@apiPath}/packages",
|
url: "#{@apiPath}/packages",
|
||||||
processData: true,
|
processData: true,
|
||||||
success: (data) =>
|
success: (data) =>
|
||||||
@packages = data
|
@packages = data.packages
|
||||||
@render()
|
@render()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ class Index extends App.ControllerContent
|
||||||
id: 'packages'
|
id: 'packages'
|
||||||
type: httpType
|
type: httpType
|
||||||
url: "#{@apiPath}/packages",
|
url: "#{@apiPath}/packages",
|
||||||
data: JSON.stringify( { id: id } )
|
data: JSON.stringify(id: id)
|
||||||
processData: false
|
processData: false
|
||||||
success: =>
|
success: =>
|
||||||
@load()
|
@load()
|
||||||
|
|
|
@ -6,9 +6,9 @@ class Package < ApplicationModel
|
||||||
|
|
||||||
# build package based on .szpm
|
# build package based on .szpm
|
||||||
# Package.build(
|
# Package.build(
|
||||||
# :file => 'package.szpm',
|
# file: 'package.szpm',
|
||||||
# :root => '/path/to/src/extention/',
|
# root: '/path/to/src/extention/',
|
||||||
# :output => '/path/to/package_location/'
|
# output: '/path/to/package_location/'
|
||||||
# )
|
# )
|
||||||
def self.build(data)
|
def self.build(data)
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ class Package < ApplicationModel
|
||||||
element.text = base64
|
element.text = base64
|
||||||
end
|
end
|
||||||
if data[:output]
|
if data[:output]
|
||||||
location = data[:output] + '/' + package.elements['zpm/name'].text + '-' + package.elements['zpm/version'].text + '.zpm'
|
location = "#{data[:output]}/#{package.elements['zpm/name'].text}-#{package.elements['zpm/version'].text}.zpm"
|
||||||
logger.info "NOTICE: writting package to '#{location}'"
|
logger.info "NOTICE: writting package to '#{location}'"
|
||||||
file = File.new(location, 'wb')
|
file = File.new(location, 'wb')
|
||||||
file.write(package.to_s)
|
file.write(package.to_s)
|
||||||
|
@ -46,7 +46,7 @@ class Package < ApplicationModel
|
||||||
# Package.auto_install
|
# Package.auto_install
|
||||||
# install all packages located under auto_install/*.zpm
|
# install all packages located under auto_install/*.zpm
|
||||||
def self.auto_install
|
def self.auto_install
|
||||||
path = @@root + '/auto_install/'
|
path = "#{@@root}/auto_install/"
|
||||||
return if !File.exist?(path)
|
return if !File.exist?(path)
|
||||||
data = []
|
data = []
|
||||||
Dir.foreach(path) do |entry|
|
Dir.foreach(path) do |entry|
|
||||||
|
@ -55,7 +55,7 @@ class Package < ApplicationModel
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
data.each {|file|
|
data.each {|file|
|
||||||
install( file: path + '/' + file )
|
install(file: "#{path}/#{file}")
|
||||||
}
|
}
|
||||||
data
|
data
|
||||||
end
|
end
|
||||||
|
@ -65,7 +65,7 @@ class Package < ApplicationModel
|
||||||
# note: will not take down package migrations, use Package.unlink instead
|
# note: will not take down package migrations, use Package.unlink instead
|
||||||
def self.unlink_all
|
def self.unlink_all
|
||||||
# link files
|
# link files
|
||||||
Dir.glob( @@root + '/**/*' ) do |entry|
|
Dir.glob("#{@@root}/**/*") do |entry|
|
||||||
if File.symlink?(entry)
|
if File.symlink?(entry)
|
||||||
logger.info "unlink: #{entry}"
|
logger.info "unlink: #{entry}"
|
||||||
File.delete(entry)
|
File.delete(entry)
|
||||||
|
@ -174,8 +174,8 @@ class Package < ApplicationModel
|
||||||
Package::Migration.migrate(package)
|
Package::Migration.migrate(package)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Package.install( :file => '/path/to/package.zpm' )
|
# Package.install(file: '/path/to/package.zpm')
|
||||||
# Package.install( :string => zpm_as_string )
|
# Package.install(string: zpm_as_string)
|
||||||
def self.install(data)
|
def self.install(data)
|
||||||
if data[:file]
|
if data[:file]
|
||||||
xml = _read_file(data[:file], true)
|
xml = _read_file(data[:file], true)
|
||||||
|
@ -221,7 +221,7 @@ class Package < ApplicationModel
|
||||||
object: 'Package',
|
object: 'Package',
|
||||||
o_id: record.id,
|
o_id: record.id,
|
||||||
data: package.to_s,
|
data: package.to_s,
|
||||||
filename: meta[:name] + '-' + meta[:version] + '.zpm',
|
filename: "#{meta[:name]}-#{meta[:version]}.zpm",
|
||||||
preferences: {},
|
preferences: {},
|
||||||
created_by_id: UserInfo.current_user_id || 1,
|
created_by_id: UserInfo.current_user_id || 1,
|
||||||
)
|
)
|
||||||
|
@ -259,8 +259,8 @@ class Package < ApplicationModel
|
||||||
install(string: file, reinstall: true)
|
install(string: file, reinstall: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Package.uninstall( :name => 'package', :version => '0.1.1' )
|
# Package.uninstall(name: 'package', version: '0.1.1')
|
||||||
# Package.uninstall( :string => zpm_as_string )
|
# Package.uninstall(string: zpm_as_string)
|
||||||
def self.uninstall(data)
|
def self.uninstall(data)
|
||||||
|
|
||||||
if data[:string]
|
if data[:string]
|
||||||
|
@ -355,7 +355,7 @@ class Package < ApplicationModel
|
||||||
end
|
end
|
||||||
|
|
||||||
def self._write_file(file, permission, data)
|
def self._write_file(file, permission, data)
|
||||||
location = @@root + '/' + file
|
location = "#{@@root}/#{file}"
|
||||||
|
|
||||||
# rename existing file
|
# rename existing file
|
||||||
if File.exist?(location)
|
if File.exist?(location)
|
||||||
|
@ -369,7 +369,7 @@ class Package < ApplicationModel
|
||||||
(0..(directories.length - 2) ).each {|position|
|
(0..(directories.length - 2) ).each {|position|
|
||||||
tmp_path = ''
|
tmp_path = ''
|
||||||
(1..position).each {|count|
|
(1..position).each {|count|
|
||||||
tmp_path = tmp_path + '/' + directories[count].to_s
|
tmp_path = "#{tmp_path}/#{directories[count]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
next if tmp_path == ''
|
next if tmp_path == ''
|
||||||
|
@ -392,7 +392,7 @@ class Package < ApplicationModel
|
||||||
end
|
end
|
||||||
|
|
||||||
def self._delete_file(file, _permission, _data)
|
def self._delete_file(file, _permission, _data)
|
||||||
location = @@root + '/' + file
|
location = "#{@@root}/#{file}"
|
||||||
|
|
||||||
# install file
|
# install file
|
||||||
logger.info "NOTICE: uninstall '#{location}'"
|
logger.info "NOTICE: uninstall '#{location}'"
|
||||||
|
@ -414,7 +414,7 @@ class Package < ApplicationModel
|
||||||
@@root = Rails.root.to_s # rubocop:disable Style/ClassVars
|
@@root = Rails.root.to_s # rubocop:disable Style/ClassVars
|
||||||
|
|
||||||
def self.migrate(package, direction = 'normal')
|
def self.migrate(package, direction = 'normal')
|
||||||
location = @@root + '/db/addon/' + package.underscore
|
location = "#{@@root}/db/addon/#{package.underscore}"
|
||||||
|
|
||||||
return true if !File.exist?(location)
|
return true if !File.exist?(location)
|
||||||
migrations_done = Package::Migration.where(name: package.underscore)
|
migrations_done = Package::Migration.where(name: package.underscore)
|
||||||
|
|
Loading…
Reference in a new issue