Code cleanup.

This commit is contained in:
Martin Edenhofer 2016-01-21 23:25:05 +01:00
parent 5e518f5037
commit 6d6779caf7
2 changed files with 90 additions and 90 deletions

View file

@ -19,7 +19,7 @@ class Index extends App.ControllerContent
url: "#{@apiPath}/packages",
processData: true,
success: (data) =>
@packages = data
@packages = data.packages
@render()
)
@ -52,7 +52,7 @@ class Index extends App.ControllerContent
id: 'packages'
type: httpType
url: "#{@apiPath}/packages",
data: JSON.stringify( { id: id } )
data: JSON.stringify(id: id)
processData: false
success: =>
@load()

View file

@ -6,9 +6,9 @@ class Package < ApplicationModel
# build package based on .szpm
# Package.build(
# :file => 'package.szpm',
# :root => '/path/to/src/extention/',
# :output => '/path/to/package_location/'
# file: 'package.szpm',
# root: '/path/to/src/extention/',
# output: '/path/to/package_location/'
# )
def self.build(data)
@ -33,7 +33,7 @@ class Package < ApplicationModel
element.text = base64
end
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}'"
file = File.new(location, 'wb')
file.write(package.to_s)
@ -46,7 +46,7 @@ class Package < ApplicationModel
# Package.auto_install
# install all packages located under auto_install/*.zpm
def self.auto_install
path = @@root + '/auto_install/'
path = "#{@@root}/auto_install/"
return if !File.exist?(path)
data = []
Dir.foreach(path) do |entry|
@ -55,7 +55,7 @@ class Package < ApplicationModel
end
end
data.each {|file|
install( file: path + '/' + file )
install(file: "#{path}/#{file}")
}
data
end
@ -65,7 +65,7 @@ class Package < ApplicationModel
# note: will not take down package migrations, use Package.unlink instead
def self.unlink_all
# link files
Dir.glob( @@root + '/**/*' ) do |entry|
Dir.glob("#{@@root}/**/*") do |entry|
if File.symlink?(entry)
logger.info "unlink: #{entry}"
File.delete(entry)
@ -174,8 +174,8 @@ class Package < ApplicationModel
Package::Migration.migrate(package)
end
# Package.install( :file => '/path/to/package.zpm' )
# Package.install( :string => zpm_as_string )
# Package.install(file: '/path/to/package.zpm')
# Package.install(string: zpm_as_string)
def self.install(data)
if data[:file]
xml = _read_file(data[:file], true)
@ -221,7 +221,7 @@ class Package < ApplicationModel
object: 'Package',
o_id: record.id,
data: package.to_s,
filename: meta[:name] + '-' + meta[:version] + '.zpm',
filename: "#{meta[:name]}-#{meta[:version]}.zpm",
preferences: {},
created_by_id: UserInfo.current_user_id || 1,
)
@ -259,8 +259,8 @@ class Package < ApplicationModel
install(string: file, reinstall: true)
end
# Package.uninstall( :name => 'package', :version => '0.1.1' )
# Package.uninstall( :string => zpm_as_string )
# Package.uninstall(name: 'package', version: '0.1.1')
# Package.uninstall(string: zpm_as_string)
def self.uninstall(data)
if data[:string]
@ -355,7 +355,7 @@ class Package < ApplicationModel
end
def self._write_file(file, permission, data)
location = @@root + '/' + file
location = "#{@@root}/#{file}"
# rename existing file
if File.exist?(location)
@ -369,7 +369,7 @@ class Package < ApplicationModel
(0..(directories.length - 2) ).each {|position|
tmp_path = ''
(1..position).each {|count|
tmp_path = tmp_path + '/' + directories[count].to_s
tmp_path = "#{tmp_path}/#{directories[count]}"
}
next if tmp_path == ''
@ -392,7 +392,7 @@ class Package < ApplicationModel
end
def self._delete_file(file, _permission, _data)
location = @@root + '/' + file
location = "#{@@root}/#{file}"
# install file
logger.info "NOTICE: uninstall '#{location}'"
@ -414,7 +414,7 @@ class Package < ApplicationModel
@@root = Rails.root.to_s # rubocop:disable Style/ClassVars
def self.migrate(package, direction = 'normal')
location = @@root + '/db/addon/' + package.underscore
location = "#{@@root}/db/addon/#{package.underscore}"
return true if !File.exist?(location)
migrations_done = Package::Migration.where(name: package.underscore)