Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
debomatic-webui
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
debomatic-webui-admins
debomatic-webui
Commits
fadf0818
Commit
fadf0818
authored
Jul 20, 2014
by
Leo Iannacone
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactory on client
parent
159e0294
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
142 deletions
+86
-142
debomatic-webui/lib/broadcaster.coffee
debomatic-webui/lib/broadcaster.coffee
+5
-5
debomatic-webui/lib/client.coffee
debomatic-webui/lib/client.coffee
+79
-128
debomatic-webui/lib/utils.coffee
debomatic-webui/lib/utils.coffee
+2
-9
No files found.
debomatic-webui/lib/broadcaster.coffee
View file @
fadf0818
config
=
require
(
"./config"
)
fs
=
require
(
"fs"
)
utils
=
require
(
"./utils"
)
Tail
=
require
(
"./tail"
)
__watch_status_check_same_obj
=
(
obj1
,
obj2
)
->
__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
...
@@ -84,9 +89,4 @@ Broadcaster = (sockets, status) ->
...
@@ -84,9 +89,4 @@ Broadcaster = (sockets, status) ->
__watch_distributions
(
sockets
)
__watch_distributions
(
sockets
)
__watch_pidfile
(
sockets
)
__watch_pidfile
(
sockets
)
"use strict"
config
=
require
(
"./config"
)
fs
=
require
(
"fs"
)
utils
=
require
(
"./utils"
)
Tail
=
require
(
"./tail"
)
module
.
exports
=
Broadcaster
module
.
exports
=
Broadcaster
debomatic-webui/lib/client.coffee
View file @
fadf0818
__get_files_list_from_package
=
(
data
,
callback
)
->
fs
=
require
(
"fs"
)
path
=
require
(
"path"
)
config
=
require
(
"./config"
)
utils
=
require
(
"./utils"
)
e
=
config
.
events
.
client
get_files_list_from_package
=
(
data
,
callback
)
->
package_path
=
utils
.
get_package_path
(
data
)
package_path
=
utils
.
get_package_path
(
data
)
utils
.
get_files_list
package_path
,
false
,
(
files
)
->
utils
.
get_files_list
package_path
,
false
,
(
files
)
->
data
.
package
.
files
=
[]
data
.
package
.
files
=
[]
...
@@ -28,165 +34,110 @@ __get_files_list_from_package = (data, callback) ->
...
@@ -28,165 +34,110 @@ __get_files_list_from_package = (data, callback) ->
callback
(
data
)
callback
(
data
)
__send_package_files_list
=
(
event_name
,
socket
,
data
)
->
read_package_status
=
(
data
,
cb
)
->
__get_files_list_from_package
data
,
(
new_data
)
->
socket
.
emit
event_name
,
new_data
return
return
__read_package_status
=
(
data
,
cb
)
->
package_path
=
utils
.
get_package_path
(
data
)
package_path
=
utils
.
get_package_path
(
data
)
package_json
=
path
.
join
(
package_path
,
data
.
package
.
orig_name
+
".json"
)
package_json
=
path
.
join
(
package_path
,
data
.
package
.
orig_name
+
".json"
)
fs
.
readFile
package_json
,
{
encoding
:
"utf8"
},
(
err
,
content
)
->
fs
.
readFile
package_json
,
{
encoding
:
"utf8"
},
(
err
,
content
)
->
if
err
if
err
utils
.
errors_handler
"Client:
__
read_package_status:"
,
err
utils
.
errors_handler
"Client:read_package_status:"
,
err
return
return
try
try
content
=
JSON
.
parse
(
content
)
content
=
JSON
.
parse
(
content
)
catch
parse
_
err
catch
parseerr
utils
.
errors_handler
(
"Client:"
+
utils
.
errors_handler
(
"Client:"
+
"
__read_package_status:parse_
err:"
,
"
read_package_status:parse
err:"
,
parse
_
err
)
parseerr
)
return
return
cb
content
cb
content
return
return
__send_package_info
=
(
socket
,
data
)
->
__read_package_status
data
,
(
content
)
->
socket
.
emit
_e
.
package_info
,
content
return
return
__send_package_status
=
(
socket
,
data
)
->
__read_package_status
data
,
(
content
)
->
socket
.
emit
_e
.
distribution_packages_status
,
content
return
return
__send_distribution_packages
=
(
event_name
,
socket
,
data
)
->
distro_path
=
utils
.
get_distribution_pool_path
(
data
)
utils
.
get_files_list
distro_path
,
true
,
(
packages
)
->
data
.
distribution
.
packages
=
[]
packages
.
forEach
(
p
)
->
pack
=
{}
info
=
p
.
split
(
"_"
)
pack
.
name
=
info
[
0
]
pack
.
version
=
info
[
1
]
pack
.
orig_name
=
p
__send_package_status
socket
,
distribution
:
data
.
distribution
package
:
pack
data
.
distribution
.
packages
.
push
pack
return
socket
.
emit
event_name
,
data
class
Client
return
constructor
:
(
@
socket
)
->
send_package_files_list
:
(
data
)
->
get_files_list_from_package
data
,
(
new_data
)
=>
@
socket
.
emit
e
.
package_files_list
,
new_data
send_distribution_packages
:
(
data
)
->
distro_path
=
utils
.
get_distribution_pool_path
(
data
)
utils
.
get_files_list
distro_path
,
true
,
(
packages
)
=>
data
.
distribution
.
packages
=
[]
for
p
in
packages
pack
=
{}
info
=
p
.
split
(
"_"
)
pack
.
name
=
info
[
0
]
pack
.
version
=
info
[
1
]
pack
.
orig_name
=
p
read_package_status
{
distribution
:
data
.
distribution
,
package
:
pack
},
(
content
)
=>
@
socket
.
emit
e
.
distribution_packages_status
,
content
data
.
distribution
.
packages
.
push
pack
@
socket
.
emit
e
.
distribution_packages
,
data
send_file
:
(
data
)
->
file_path
=
utils
.
get_file_path
(
data
)
get_preview
=
data
.
file
.
name
in
config
.
web
.
file
.
preview
and
not
data
.
file
.
force
fs
.
readFile
file_path
,
"utf8"
,
(
err
,
content
)
=>
if
err
utils
.
errors_handler
(
"client:send_file"
,
err
,
@
socket
)
return
data
.
file
.
orig_name
=
file_path
.
split
(
"/"
).
pop
()
if
get_preview
and
config
.
web
.
file
.
num_lines
>
0
last_lines
=
config
.
web
.
file
.
num_lines
data
.
file
.
content
=
content
.
split
(
"
\n
"
)[
-
last_lines
..].
join
(
"
\n
"
)
else
data
.
file
.
content
=
content
data
.
file
.
path
=
file_path
.
replace
(
config
.
debomatic
.
path
,
config
.
routes
.
debomatic
)
@
socket
.
emit
e
.
file
,
data
return
send_status
:
(
status
)
->
__send_file
=
(
event_name
,
socket
,
data
,
last_lines
)
->
@
socket
.
emit
e
.
status
,
status
file_path
=
utils
.
get_file_path
(
data
)
fs
.
readFile
file_path
,
"utf8"
,
(
err
,
content
)
->
if
err
utils
.
errors_handler
(
"client:__send_file"
,
err
,
socket
)
return
data
.
file
.
orig_name
=
file_path
.
split
(
"/"
).
pop
()
if
last_lines
>
0
data
.
file
.
content
=
content
.
split
(
"
\n
"
)[
-
last_lines
..].
join
(
"
\n
"
)
else
data
.
file
.
content
=
content
data
.
file
.
path
=
file_path
.
replace
(
config
.
debomatic
.
path
,
config
.
routes
.
debomatic
)
socket
.
emit
event_name
,
data
return
return
__handler_get_file
=
(
socket
,
data
)
->
file_path
=
utils
.
get_file_path
(
data
)
send
=
(
event_name
,
socket
,
data
)
->
data
.
file
.
content
=
null
socket
.
emit
(
event_name
,
data
)
utils
.
watch_path_onsocket
(
_e
.
file_newcontent
,
socket
,
data
,
file_path
,
send
)
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
)
else
__send_file
(
_e
.
file
,
socket
,
data
)
return
Client
=
(
socket
)
->
@
start
=
->
send_status_debomatic
:
->
fs
.
exists
config
.
debomatic
.
pidfile
,
(
exists
)
=>
@
socket
.
emit
config
.
events
.
broadcast
.
status_debomatic
,
running
:
exists
start
:
->
# init send distributions
# init send distributions
utils
.
send_distributions
socket
utils
.
send_distributions
@
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
=
utils
.
get_distribution_pool_path
(
data
)
distribution_path
=
utils
.
get_distribution_pool_path
(
data
)
utils
.
generic_handler_watcher
(
_e
.
distribution_packages
,
@
send_distribution_packages
(
data
)
socket
,
utils
.
watch_path_onsocket
e
.
distribution_packages
,
@
socket
,
data
,
distribution_path
,
(
new_data
)
=>
data
,
@
send_distribution_packages
(
new_data
)
distribution_path
,
__send_distribution_packages
)
data
=
null
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
,
@
send_package_files_list
(
data
)
socket
,
utils
.
watch_path_onsocket
e
.
package_files_list
,
@
socket
,
data
,
package_path
,
(
new_data
)
=>
data
,
@
send_package_files_list
(
new_data
)
package_path
,
__send_package_files_list
)
data
=
null
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
file_path
=
utils
.
get_file_path
(
data
)
data
=
null
data
.
file
.
content
=
null
return
@
send_file
(
data
)
utils
.
watch_path_onsocket
e
.
file_newcontent
,
@
socket
,
data
,
file_path
,
(
new_data
)
=>
@
socket
.
emit
(
e
.
file_newcontent
,
new_data
)
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
read_package_status
data
,
(
content
)
=>
data
=
null
@
socket
.
emit
e
.
package_info
,
content
return
# 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
()
catch
error_watch
catch
error_watch
utils
.
errors_handler
"client:disconnect"
,
error_watch
utils
.
errors_handler
"client:disconnect"
,
error_watch
return
return
@
send_status
=
(
status
)
->
socket
.
emit
_e
.
status
,
status
return
@
send_status_debomatic
=
->
fs
.
exists
config
.
debomatic
.
pidfile
,
(
exists
)
->
socket
.
emit
config
.
events
.
broadcast
.
status_debomatic
,
running
:
exists
return
return
return
"use strict"
fs
=
require
(
"fs"
)
path
=
require
(
"path"
)
config
=
require
(
"./config"
)
utils
=
require
(
"./utils"
)
_e
=
config
.
events
.
client
module
.
exports
=
Client
module
.
exports
=
Client
debomatic-webui/lib/utils.coffee
View file @
fadf0818
...
@@ -75,13 +75,13 @@ watch_path_onsocket = (event_name, socket, data, watch_path, callback) ->
...
@@ -75,13 +75,13 @@ watch_path_onsocket = (event_name, socket, data, watch_path, callback) ->
persistent
:
true
,
persistent
:
true
,
(
event
,
fileName
)
->
(
event
,
fileName
)
->
if
event
is
"rename"
if
event
is
"rename"
callback
(
event_name
,
socket
,
data
))
callback
(
data
))
else
if
stats
.
isFile
()
else
if
stats
.
isFile
()
watcher
=
new
Tail
(
watch_path
)
watcher
=
new
Tail
(
watch_path
)
watcher
.
on
"line"
,
(
new_content
,
tailInfo
)
->
watcher
.
on
"line"
,
(
new_content
,
tailInfo
)
->
data
.
file
.
new_content
=
new_content
+
"
\n
"
data
.
file
.
new_content
=
new_content
+
"
\n
"
callback
(
event_name
,
socket
,
data
)
callback
(
data
)
watcher
.
on
"error"
,
(
msg
)
->
watcher
.
on
"error"
,
(
msg
)
->
socket
.
emit
config
.
events
.
error
,
msg
socket
.
emit
config
.
events
.
error
,
msg
...
@@ -95,12 +95,6 @@ watch_path_onsocket = (event_name, socket, data, watch_path, callback) ->
...
@@ -95,12 +95,6 @@ watch_path_onsocket = (event_name, socket, data, watch_path, callback) ->
err
,
socket
)
err
,
socket
)
return
return
generic_handler_watcher
=
(
event_name
,
socket
,
data
,
watch_path
,
callback
)
->
callback
event_name
,
socket
,
data
watch_path_onsocket
event_name
,
socket
,
data
,
watch_path
,
callback
send_distributions
=
(
socket
)
->
send_distributions
=
(
socket
)
->
get_files_list
config
.
debomatic
.
path
,
true
,
(
directories
)
->
get_files_list
config
.
debomatic
.
path
,
true
,
(
directories
)
->
distributions
=
[]
distributions
=
[]
...
@@ -128,6 +122,5 @@ module.exports.get_package_path = get_package_path
...
@@ -128,6 +122,5 @@ module.exports.get_package_path = get_package_path
module
.
exports
.
get_file_path
=
get_file_path
module
.
exports
.
get_file_path
=
get_file_path
module
.
exports
.
get_files_list
=
get_files_list
module
.
exports
.
get_files_list
=
get_files_list
module
.
exports
.
watch_path_onsocket
=
watch_path_onsocket
module
.
exports
.
watch_path_onsocket
=
watch_path_onsocket
module
.
exports
.
generic_handler_watcher
=
generic_handler_watcher
module
.
exports
.
send_distributions
=
send_distributions
module
.
exports
.
send_distributions
=
send_distributions
module
.
exports
.
errors_handler
=
errors_handler
module
.
exports
.
errors_handler
=
errors_handler
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment