Commit 70646bc3 authored by Leo Iannacone's avatar Leo Iannacone

check code style

parent 18c0c552
...@@ -33,10 +33,11 @@ app.get "/", routes.index ...@@ -33,10 +33,11 @@ app.get "/", routes.index
app.get config.routes.distribution, routes.distribution app.get config.routes.distribution, routes.distribution
# parefernces page # parefernces page
app.get config.routes.preferences, routes.preferences if config.routes.preferences if config.routes.preferences
app.get config.routes.preferences, routes.preferences
# commands page # commands page
app.get config.routes.commands, routes.commands if config.routes.commands app.get config.routes.commands, routes.commands if config.routes.commands
# debomatic static page # debomatic static page
if config.routes.debomatic if config.routes.debomatic
...@@ -50,8 +51,10 @@ if config.routes.debomatic ...@@ -50,8 +51,10 @@ if config.routes.debomatic
base += (if base[base.length - 1] isnt "/" then "/" else "") # append / base += (if base[base.length - 1] isnt "/" then "/" else "") # append /
match = req.url.replace(base, "").split("/") match = req.url.replace(base, "").split("/")
match.pop() if match[match.length - 1] is "" match.pop() if match[match.length - 1] is ""
# case unstable/unstable
if match.length >= 2 and ((match[0] is match[1]) or (match[1] is "build" and match.length > 2)) # case unstable/build/* if match.length >= 2 and
((match[0] is match[1]) or # case unstable/unstable
(match[1] is "build" and match.length > 2)) # case unstable/build/*
res.status(403).send "<h1>403 Forbidden</h1>" res.status(403).send "<h1>403 Forbidden</h1>"
else # call next() here to move on to next middleware/router else # call next() here to move on to next middleware/router
next() next()
...@@ -77,7 +80,8 @@ server.listen config.port, config.host, null, (err) -> ...@@ -77,7 +80,8 @@ server.listen config.port, config.host, null, (err) ->
# and set his user id # and set his user id
uid = parseInt(process.env.SUDO_UID) uid = parseInt(process.env.SUDO_UID)
if uid if uid
console.log "Please do not run nodejs with sudo. Changing user to %d", uid console.log "Please do not run nodejs with sudo. " +
"Changing user to %d", uid
process.setgid uid process.setgid uid
process.setuid uid process.setuid uid
...@@ -87,11 +91,14 @@ server.listen config.port, config.host, null, (err) -> ...@@ -87,11 +91,14 @@ server.listen config.port, config.host, null, (err) ->
io.sockets.on "connection", (socket) -> io.sockets.on "connection", (socket) ->
client = new Client(socket) client = new Client(socket)
client.start() client.start()
client.send_status status if status.length > 0 client.send_status status if status.length > 0
client.send_status_debomatic() client.send_status_debomatic()
return return
console.log "Debomatic-webui listening on %s:%d in %s mode", server.address().address, server.address().port, app.settings.env console.log "Debomatic-webui listening on %s:%d in %s mode",
server.address().address,
server.address().port,
app.settings.env
return return
server.on "error", (e) -> server.on "error", (e) ->
......
...@@ -2,7 +2,7 @@ __watch_status_check_same_obj = (obj1, obj2) -> ...@@ -2,7 +2,7 @@ __watch_status_check_same_obj = (obj1, obj2) ->
if obj1.status is obj2.status if obj1.status is obj2.status
if obj1.distribution is obj2.distribution if obj1.distribution is obj2.distribution
if obj1.hasOwnProperty("package") and obj2.hasOwnProperty("package") if obj1.hasOwnProperty("package") and obj2.hasOwnProperty("package")
return true if obj1.package is obj2.package return true if obj1.package is obj2.package
return false return false
return true return true
false false
...@@ -15,7 +15,9 @@ __watch_status = (socket, status) -> ...@@ -15,7 +15,9 @@ __watch_status = (socket, status) ->
try try
data = JSON.parse(new_content) data = JSON.parse(new_content)
catch err catch err
utils.errors_handler "Broadcaster:__watch_status:JSON.parse(new_content) - ", err, socket utils.errors_handler "Broadcaster:" +
"__watch_status:JSON.parse(new_content) - ",
err, socket
return return
# looking for same status already in statuses lists # looking for same status already in statuses lists
...@@ -55,21 +57,26 @@ __watch_distributions = (socket) -> ...@@ -55,21 +57,26 @@ __watch_distributions = (socket) ->
return return
__watch_pidfile = (socket) -> __watch_pidfile = (socket) ->
fs.watchFile config.debomatic.pidfile, fs.watchFile config.debomatic.pidfile, {
persistent: false persistent: false
interval: 1007 interval: 1007
}
, (curr, prev) -> , (curr, prev) ->
status_debomatic = running: curr.ino isnt 0 # if === 0 means pidfile does not exists # if === 0 means pidfile does not exists
status_debomatic = running: curr.ino isnt 0
try try
socket.emit socket.emit(config.events.broadcast.status_debomatic, status_debomatic) socket.emit socket.emit(
config.events.broadcast.status_debomatic,
status_debomatic)
return return
return return
Broadcaster = (sockets, status) -> Broadcaster = (sockets, status) ->
__watch_status sockets, status __watch_status(sockets, status)
__watch_distributions sockets __watch_distributions(sockets)
__watch_pidfile sockets __watch_pidfile(sockets)
{}
"use strict" "use strict"
config = require("./config") config = require("./config")
fs = require("fs") fs = require("fs")
......
...@@ -6,22 +6,26 @@ __get_files_list_from_package = (data, callback) -> ...@@ -6,22 +6,26 @@ __get_files_list_from_package = (data, callback) ->
data.package.sources = [] data.package.sources = []
files.forEach (f) -> files.forEach (f) ->
file = {} file = {}
file.path = path.join(package_path, f).replace(config.debomatic.path, config.routes.debomatic) file.path = path.join(package_path, f)
.replace(config.debomatic.path,
config.routes.debomatic)
file.orig_name = f file.orig_name = f
file.name = f.split("_")[0] file.name = f.split("_")[0]
file.extension = f.split(".").pop() file.extension = f.split(".").pop()
return if config.debomatic.excluded_files.indexOf(file.extension) >= 0 return if file.extension in config.debomatic.excluded_files
if file.extension is "deb" or file.extension is "ddeb" or file.extension is "udeb" if file.extension in ["deb", "ddeb", "udeb"]
data.package.debs.push file data.package.debs.push(file)
else if f.indexOf(".tar") >= 0 or file.extension is "changes" or file.extension is "dsc" else if file.extension in ["changes", "dsc"] or
file.name = f.replace(data.package.name + "_" + data.package.version + ".", "") f.indexOf('.tar') > 0
file.name = f.replace(data.package.orig_name + ".", "")
if file.extension is "changes" if file.extension is "changes"
file.name = file.extension file.name = file.extension
else file.name = "orig." + f.split(".orig.").pop() if f.indexOf(".tar") >= 0 and f.indexOf(".orig.") > 0 else if f.indexOf('.orig.tar') > 0
data.package.sources.push file file.name = "orig." + f.split(".orig.").pop()
data.package.sources.push(file)
else else
file.name = file.extension file.name = file.extension
data.package.files.push file data.package.files.push(file)
return return
callback data callback data
...@@ -46,7 +50,9 @@ __read_package_status = (data, cb) -> ...@@ -46,7 +50,9 @@ __read_package_status = (data, cb) ->
try try
content = JSON.parse(content) content = JSON.parse(content)
catch parse_err catch parse_err
utils.errors_handler "Client:__read_package_status:parse_err:", parse_err utils.errors_handler("Client:" +
"__read_package_status:parse_err:",
parse_err)
return return
cb content cb content
return return
...@@ -93,26 +99,30 @@ __send_file = (event_name, socket, data, last_lines) -> ...@@ -93,26 +99,30 @@ __send_file = (event_name, socket, data, last_lines) ->
return return
data.file.orig_name = file_path.split("/").pop() data.file.orig_name = file_path.split("/").pop()
if last_lines > 0 if last_lines > 0
data.file.content = content.split("\n").slice(-last_lines).join("\n") data.file.content = content.split("\n")[-last_lines..].join("\n")
else else
data.file.content = content data.file.content = content
data.file.path = file_path.replace(config.debomatic.path, config.routes.debomatic) data.file.path = file_path.replace(config.debomatic.path,
config.routes.debomatic)
socket.emit event_name, data socket.emit event_name, data
return return
return return
__handler_get_file = (socket, data) -> __handler_get_file = (socket, data) ->
file_path = utils.get_file_path(data) file_path = utils.get_file_path(data)
utils.watch_path_onsocket _e.file_newcontent, socket, data, file_path, (event_name, socket, data) -> send = (event_name, socket, data) ->
data.file.content = null data.file.content = null
socket.emit event_name, data socket.emit event_name, data
return utils.watch_path_onsocket _e.file_newcontent, socket, data, file_path, send
if config.web.file.preview.indexOf(data.file.name) >= 0 and not data.file.force if data.file.name in config.web.file.preview and not data.file.force
__send_file _e.file, socket, data, config.web.file.num_lines __send_file(_e.file, socket, data, config.web.file.num_lines)
else else
__send_file _e.file, socket, data __send_file(_e.file, socket, data)
return return
Client = (socket) -> Client = (socket) ->
@start = -> @start = ->
...@@ -121,27 +131,37 @@ Client = (socket) -> ...@@ -121,27 +131,37 @@ Client = (socket) ->
# init events # init events
socket.on _e.distribution_packages, (data) -> socket.on _e.distribution_packages, (data) ->
return unless utils.check_data_distribution(data) return unless utils.check_data_distribution(data)
distribution_path = path.join(config.debomatic.path, data.distribution.name, "pool") distribution_path = path.join(config.debomatic.path,
utils.generic_handler_watcher _e.distribution_packages, socket, data, distribution_path, __send_distribution_packages data.distribution.name,
"pool")
utils.generic_handler_watcher(_e.distribution_packages,
socket,
data,
distribution_path,
__send_distribution_packages)
data = null data = null
return return
socket.on _e.package_files_list, (data) -> socket.on _e.package_files_list, (data) ->
return unless utils.check_data_package(data) return unless utils.check_data_package(data)
package_path = utils.get_package_path(data) package_path = utils.get_package_path(data)
utils.generic_handler_watcher _e.package_files_list, socket, data, package_path, __send_package_files_list utils.generic_handler_watcher(_e.package_files_list,
socket,
data,
package_path,
__send_package_files_list)
data = null data = null
return return
socket.on _e.file, (data) -> socket.on _e.file, (data) ->
return unless utils.check_data_file(data) return unless utils.check_data_file(data)
__handler_get_file socket, data __handler_get_file socket, data
data = null data = null
return return
socket.on _e.package_info, (data) -> socket.on _e.package_info, (data) ->
return unless utils.check_data_package(data) return unless utils.check_data_package(data)
__send_package_info socket, data __send_package_info socket, data
data = null data = null
return return
...@@ -150,7 +170,7 @@ Client = (socket) -> ...@@ -150,7 +170,7 @@ Client = (socket) ->
# on client disconnection close all watchers # on client disconnection close all watchers
socket.on "disconnect", -> socket.on "disconnect", ->
socket_watchers = socket.watchers socket_watchers = socket.watchers
return unless socket_watchers return unless socket_watchers
for key of socket_watchers for key of socket_watchers
try try
socket_watchers[key].close() socket_watchers[key].close()
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
Parser = -> Parser = ->
args = process.argv.slice(2) args = process.argv.slice(2)
help = -> help = ->
console.log "Usage: %s [-c config]\n -h print this help \n -c set user configuration file", process.argv[1].split("/").pop() console.log "Usage: %s [-c config]\n -h print this help \n -c set user configuration file", process.argv[1].split("/").pop()
process.exit 0 process.exit 0
return return
......
...@@ -8,14 +8,14 @@ Tail::watchEvent = (e) -> ...@@ -8,14 +8,14 @@ Tail::watchEvent = (e) ->
if err if err
_this.emit "error", err _this.emit "error", err
return return
_this.pos = stats.size if stats.size < _this.pos _this.pos = stats.size if stats.size < _this.pos
if stats.size > _this.pos if stats.size > _this.pos
_this.queue.push _this.queue.push
start: _this.pos start: _this.pos
end: stats.size end: stats.size
_this.pos = stats.size _this.pos = stats.size
_this.internalDispatcher.emit "next" if _this.queue.length is 1 _this.internalDispatcher.emit "next" if _this.queue.length is 1
else if e is "rename" else if e is "rename"
@unwatch() @unwatch()
......
__errors_handler = (from, err, socket) -> __errors_handler = (from, err, socket) ->
from = "NO SOCKET: " + from unless socket from = "NO SOCKET: " + from unless socket
console.error from, err.message console.error from, err.message
socket.emit config.events.error, err.message if socket socket.emit config.events.error, err.message if socket
return return
__check_no_backward = (backward_path) -> __check_no_backward = (backward_path) ->
try try
return backward_path.indexOf("..") < 0 return backward_path.indexOf("..") < 0
catch err catch err
return true return true
return return
__check_data_distribution = (data) -> __check_data_distribution = (data) ->
__check_no_backward(data) and __check_no_backward(data.distribution) and __check_no_backward(data.distribution.name) __check_no_backward(data) and
__check_no_backward(data.distribution) and
__check_no_backward(data.distribution.name)
__check_data_package = (data) -> __check_data_package = (data) ->
__check_data_distribution(data) and __check_no_backward(data.package) and __check_no_backward(data.package.name) and __check_no_backward(data.package.version) __check_data_distribution(data) and
__check_no_backward(data.package) and
__check_no_backward(data.package.name) and
__check_no_backward(data.package.version)
__check_data_file = (data) -> __check_data_file = (data) ->
__check_data_package(data) and __check_no_backward(data.file) and __check_no_backward(data.file.name) __check_data_package(data) and
__check_no_backward(data.file) and
__check_no_backward(data.file.name)
__get_distribution_pool_path = (data) -> __get_distribution_pool_path = (data) ->
path.join config.debomatic.path, data.distribution.name, "pool" path.join(config.debomatic.path, data.distribution.name, "pool")
__get_package_path = (data) -> __get_package_path = (data) ->
path.join __get_distribution_pool_path(data), data.package.name + "_" + data.package.version path.join(__get_distribution_pool_path(data), data.package.orig_name)
__get_file_path = (data) -> __get_file_path = (data) ->
path.join __get_package_path(data), data.package.name + "_" + data.package.version + "." + data.file.name path.join(__get_package_path(data),
data.package.orig_name + "." + data.file.name)
__get_files_list = (dir, onlyDirectories, callback) -> __get_files_list = (dir, onlyDirectories, callback) ->
fs.readdir dir, (err, files) -> fs.readdir dir, (err, files) ->
result = [] result = []
...@@ -32,9 +48,9 @@ __get_files_list = (dir, onlyDirectories, callback) -> ...@@ -32,9 +48,9 @@ __get_files_list = (dir, onlyDirectories, callback) ->
complete_path = path.join(dir, f) complete_path = path.join(dir, f)
stat = fs.statSync(complete_path) stat = fs.statSync(complete_path)
if onlyDirectories if onlyDirectories
result.push f if stat.isDirectory() result.push f if stat.isDirectory()
else else
result.push f if stat.isFile() result.push f if stat.isFile()
catch fs_error catch fs_error
__errors_handler "__get_files_list:forEach", fs_error __errors_handler "__get_files_list:forEach", fs_error
return return
...@@ -57,7 +73,7 @@ __watch_path_onsocket = (event_name, socket, data, watch_path, updater) -> ...@@ -57,7 +73,7 @@ __watch_path_onsocket = (event_name, socket, data, watch_path, updater) ->
watcher = fs.watch(watch_path, watcher = fs.watch(watch_path,
persistent: true persistent: true
, (event, fileName) -> , (event, fileName) ->
updater event_name, socket, data if event is "rename" updater event_name, socket, data if event is "rename"
return return
) )
else if stats.isFile() else if stats.isFile()
...@@ -76,7 +92,10 @@ __watch_path_onsocket = (event_name, socket, data, watch_path, updater) -> ...@@ -76,7 +92,10 @@ __watch_path_onsocket = (event_name, socket, data, watch_path, updater) ->
return return
catch err catch err
__errors_handler "__watch_path_onsocket <- " + arguments_.callee.caller.name, err, socket __errors_handler("__watch_path_onsocket <- " +
arguments_.callee.caller.name,
err,
socket)
return return
return return
__generic_handler_watcher = (event_name, socket, data, watch_path, callback) -> __generic_handler_watcher = (event_name, socket, data, watch_path, callback) ->
...@@ -91,18 +110,18 @@ __send_distributions = (socket) -> ...@@ -91,18 +110,18 @@ __send_distributions = (socket) ->
data.distribution = {} data.distribution = {}
data.distribution.name = dir data.distribution.name = dir
pool_path = __get_distribution_pool_path(data) pool_path = __get_distribution_pool_path(data)
distributions.push dir if fs.existsSync(pool_path) distributions.push dir if fs.existsSync(pool_path)
return return
socket.emit config.events.broadcast.distributions, distributions socket.emit config.events.broadcast.distributions, distributions
return return
return return
"use strict"
path = require("path") path = require("path")
fs = require("fs") fs = require("fs")
config = require("./config") config = require("./config")
Tail = require("./tail") Tail = require("./tail")
utils = utils =
check_data_distribution: (data) -> check_data_distribution: (data) ->
__check_data_distribution data __check_data_distribution data
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment