Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
agkyra
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
itminedu
agkyra
Commits
d354ce8b
Commit
d354ce8b
authored
9 years ago
by
Stavros Sachtouris
Committed by
Giorgos Korfiatis
9 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Avoid updating settings if they are not changed
This patch refers to the settings update on closing the settings window.
parent
22d67c7c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
agkyra/agkyra/gui/menu.html
+13
-5
13 additions, 5 deletions
agkyra/agkyra/gui/menu.html
agkyra/agkyra/protocol.py
+44
-11
44 additions, 11 deletions
agkyra/agkyra/protocol.py
with
57 additions
and
16 deletions
agkyra/agkyra/gui/menu.html
+
13
−
5
View file @
d354ce8b
...
...
@@ -85,16 +85,24 @@ var settings_menu = new gui.MenuItem({
click
:
function
()
{
export_settings
(
globals
.
settings
);
if
(
windows
[
'
settings
'
])
windows
[
'
settings
'
].
close
();
var
old_settings
=
{};
$
.
each
(
globals
.
settings
,
function
(
key
,
val
)
{
old_settings
[
key
]
=
val
;});
windows
[
'
settings
'
]
=
gui
.
Window
.
open
(
"
settings.html
"
,
{
toolbar
:
false
,
focus
:
true
,
width
:
841
,
height
:
520
});
windows
[
'
settings
'
].
on
(
'
closed
'
,
function
()
{
new_settings
=
import_settings
();
console
.
log
(
'
Settings windows is closed, PUT
'
);
put_settings
(
socket
,
new_settings
);
get_status
(
socket
);
get_settings
(
socket
);
console
.
log
(
'
Settings windows is closed
'
);
var
new_settings
=
import_settings
();
$
.
each
(
new_settings
,
function
(
key
,
setting
)
{
if
(
old_settings
[
key
]
!==
setting
)
{
console
.
log
(
'
Settings have been modified - updating...
'
);
put_settings
(
socket
,
new_settings
);
get_status
(
socket
);
get_settings
(
socket
);
return
false
;
}
});
});
},
});
...
...
This diff is collapsed.
Click to expand it.
agkyra/agkyra/protocol.py
+
44
−
11
View file @
d354ce8b
...
...
@@ -2,7 +2,7 @@ from ws4py.websocket import WebSocket
import
json
import
logging
from
os.path
import
abspath
from
agkyra.syncer
import
syncer
from
agkyra.syncer
import
syncer
,
setup
,
pithos_client
,
localfs_client
from
agkyra.config
import
AgkyraConfig
...
...
@@ -71,6 +71,7 @@ class WebSocketProtocol(WebSocket):
status
=
dict
(
progress
=
0
,
paused
=
True
,
can_sync
=
False
)
file_syncer
=
None
cnf
=
AgkyraConfig
()
essentials
=
(
'
url
'
,
'
token
'
,
'
container
'
,
'
directory
'
)
def
_get_default_sync
(
self
):
"""
Get global.default_sync or pick the first sync as default
...
...
@@ -154,14 +155,31 @@ class WebSocketProtocol(WebSocket):
def
can_sync
(
self
):
"""
Check if settings are enough to setup a syncing proccess
"""
return
all
([
self
.
settings
.
get
(
key
,
False
)
for
key
in
(
'
url
'
,
'
token
'
,
'
directory
'
,
'
container
'
)])
return
all
([
self
.
settings
[
e
]
for
e
in
self
.
essentials
])
def
_essentials_changed
(
self
,
new_settings
):
"""
Check if essential settings have changed in new_settings
"""
return
all
([
self
.
settings
[
e
]
==
self
.
settings
[
e
]
for
e
in
self
.
essentials
])
def
init_sync
(
self
):
"""
Initialize syncer
"""
sync
=
self
.
_get_default_sync
()
syncer_settings
=
setup
.
SyncerSettings
(
sync
,
self
.
settings
[
'
url
'
],
self
.
settings
[
'
token
'
],
self
.
settings
[
'
container
'
],
self
.
settings
[
'
directory
'
],
ignore_ssl
=
True
)
master
=
pithos_client
.
PithosFileClient
(
syncer_settings
)
slave
=
localfs_client
.
LocalfsFileClient
(
syncer_settings
)
self
.
syncer
=
syncer
.
FileSyncer
(
syncer_settings
,
master
,
slave
)
self
.
syncer_settings
=
syncer_settings
self
.
syncer
.
probe_and_sync_all
()
# Syncer-related methods
def
get_status
(
self
):
from
random
import
randint
if
self
.
status
[
'
progress
'
]
<
100
:
self
.
status
[
'
progress
'
]
+=
0
if
randint
(
0
,
2
)
else
1
self
.
status
[
'
paused
'
]
=
self
.
syncer
.
paused
self
.
status
[
'
progress
'
]
=
50
self
.
status
[
'
can_sync
'
]
=
self
.
can_sync
()
return
self
.
status
...
...
@@ -169,17 +187,29 @@ class WebSocketProtocol(WebSocket):
return
self
.
settings
def
set_settings
(
self
,
new_settings
):
# Prepare setting save
could_sync
=
self
.
can_sync
()
was_active
=
not
self
.
syncer
.
paused
if
could_sync
and
was_active
:
self
.
pause_sync
()
must_reset_syncing
=
self
.
_essentials_changed
(
new_settings
)
# save settings
self
.
settings
=
new_settings
self
.
_dump_settings
()
# Restart
if
self
.
can_sync
():
if
must_reset_syncing
or
not
could_sync
:
self
.
init_sync
()
elif
was_active
:
self
.
start_sync
()
def
pause_sync
(
self
):
self
.
s
tatus
[
'
paused
'
]
=
True
self
.
s
yncer
.
pause_decide
()
def
start_sync
(
self
):
if
self
.
can_sync
():
self
.
status
[
'
paused
'
]
=
False
else
:
self
.
status
[
'
paused
'
]
=
True
self
.
syncer
.
start_decide
()
# WebSocket connection methods
def
opened
(
self
):
...
...
@@ -207,6 +237,9 @@ class WebSocketProtocol(WebSocket):
self
.
send_json
({
'
OK
'
:
200
,
'
action
'
:
'
post %s
'
%
action
})
elif
r
[
'
gui_id
'
]
==
self
.
gui_id
:
self
.
_load_settings
()
if
self
.
can_sync
():
self
.
init_sync
()
self
.
pause_sync
()
self
.
accepted
=
True
self
.
send_json
({
'
ACCEPTED
'
:
202
,
'
action
'
:
'
post gui_id
'
})
else
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment