Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
migre-ptx-2-3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
primtux-eole
Grenoble
migre-ptx-2-3
Commits
9149b30b
Commit
9149b30b
authored
6 years ago
by
Philippe Dpt35
Browse files
Options
Downloads
Patches
Plain Diff
Ajout des scripts de conversion des fichiers de configuration des handymenus
parent
44ce1790
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
handymenuMigration.py
+151
-0
151 additions, 0 deletions
handymenuMigration.py
pickleToYaml.py
+72
-0
72 additions, 0 deletions
pickleToYaml.py
with
223 additions
and
0 deletions
handymenuMigration.py
0 → 100755
+
151
−
0
View file @
9149b30b
#!/usr/bin/python
# -*- coding:Utf-8 -*-
import
sys
import
os
import
traceback
import
pickle
import
io
import
yaml
from
shutil
import
copyfile
def
coloring
(
message
,
ok
=
False
):
color
=
'
\033
[91m
'
if
ok
:
color
=
'
\033
[92m
'
print
(
color
+
message
+
'
\033
[0m
'
)
def
convert_config
(
in_path
,
out_path
,
skel_path
=
None
,
verbose
=
False
):
"""
1. Convertis les fichiers .conv provenant des 4 sessions par défaut
2. Enregistre le résultat dans /etc/handymenu/handymenu-{lasession}.yaml
3. Enregistre le résultat dans le squelette de la session soit dans /etc/skel/handymenu.yaml (par exemple pour le prof)
"""
try
:
with
open
(
in_path
,
'
rb
'
)
as
pkl
:
try
:
config
=
pickle
.
load
(
pkl
)
except
:
try
:
config
=
pickle
.
load
(
pkl
,
encoding
=
"
utf-8
"
)
except
:
coloring
(
"
Impossible de décoder le fichier %s
"
%
in_path
)
if
verbose
:
traceback
.
print_exc
()
return
except
:
coloring
(
"
Impossible d
'
ouvrir fichier %s
"
%
in_path
)
if
verbose
:
traceback
.
print_exc
()
return
try
:
with
io
.
open
(
out_path
,
'
w
'
,
encoding
=
'
utf8
'
)
as
outfile
:
try
:
yaml
.
safe_dump
(
config
,
outfile
,
default_flow_style
=
False
,
allow_unicode
=
True
)
coloring
(
"
%s créé.
"
%
out_path
,
True
)
except
:
coloring
(
"
Impossible d
'
encoder le fichier %s
"
%
out_path
)
if
verbose
:
traceback
.
print_exc
()
return
except
:
coloring
(
"
Impossible d
'
enregistrer le fichier %s
"
%
out_path
)
if
verbose
:
traceback
.
print_exc
()
if
skel_path
==
None
:
return
try
:
with
io
.
open
(
skel_path
,
'
w
'
,
encoding
=
'
utf8
'
)
as
outfile
:
try
:
yaml
.
safe_dump
(
config
,
outfile
,
default_flow_style
=
False
,
allow_unicode
=
True
)
coloring
(
"
%s créé.
"
%
skel_path
,
True
)
except
:
coloring
(
"
Impossible d
'
encoder le fichier %s
"
%
skel_path
)
if
verbose
:
traceback
.
print_exc
()
return
except
:
coloring
(
"
Impossible d
'
enregistrer le fichier %s
"
%
skel_path
)
if
verbose
:
traceback
.
print_exc
()
if
__name__
==
"
__main__
"
:
verbose
=
False
if
(
len
(
sys
.
argv
)
>
1
and
(
sys
.
argv
[
1
]
==
"
-v
"
or
sys
.
argv
[
1
]
==
"
--verbose
"
)
):
verbose
=
True
coloring
(
"
Etape 1 : Migration des sessions mini, super, maxi et prof
"
,
True
)
sessions
=
[
'
01-mini
'
,
'
02-super
'
,
'
03-maxi
'
,
'
administrateur
'
]
for
session
in
sessions
:
skel_session
=
session
.
replace
(
'
01
'
,
''
).
replace
(
'
02
'
,
''
).
replace
(
'
03
'
,
''
).
replace
(
'
administrateur
'
,
''
)
if
session
==
'
administrateur
'
:
session
=
'
prof
'
convert_config
(
"
/home/
"
+
session
+
"
/handymenu.conf
"
,
"
/etc/handymenu/handymenu-
"
+
session
+
"
.yaml
"
,
"
/etc/skel
"
+
skel_session
+
"
/.handymenu.conf
"
,
verbose
)
coloring
(
"
Etape 2 : Migration des comptes personnalisés
"
,
True
)
custom_sessions
=
list
(
set
(
os
.
listdir
(
"
/home/
"
))
-
set
(
sessions
)
-
set
([
'
lost+found
'
])
)
for
custom_session
in
custom_sessions
:
convert_config
(
"
/home/
"
+
custom_session
+
"
/.handymenu.conf
"
,
"
/home/
"
+
custom_session
+
"
/.config/handymenu/conf.yaml
"
,
None
,
verbose
)
icon_path
=
"
/usr/share/handymenu/icons/primtuxmenu_icon-prof.png
"
custom_icon_path
=
"
/home/
"
+
custom_session
+
"
/.config/handymenu/menu.png
"
try
:
copyfile
(
icon_path
,
custom_icon_path
)
coloring
(
"
Copie du fichier {0} dans {1} !
"
.
format
(
icon_path
,
custom_icon_path
),
True
)
except
:
if
verbose
:
traceback
.
print_exc
()
coloring
(
"
Impossible de copier le fichier {0} dans {1} !
"
.
format
(
icon_path
,
custom_icon_path
)
)
coloring
(
"
Migration terminée !
"
,
True
)
This diff is collapsed.
Click to expand it.
pickleToYaml.py
0 → 100644
+
72
−
0
View file @
9149b30b
#!/usr/bin/python
# -*- coding:Utf-8 -*-
import
sys
import
traceback
import
pickle
import
io
import
yaml
def
coloring
(
message
,
ok
=
False
):
color
=
'
\033
[91m
'
if
ok
:
color
=
'
\033
[92m
'
print
(
color
+
message
+
'
\033
[0m
'
)
def
convert_config
(
in_path
,
out_path
):
try
:
with
open
(
in_path
,
'
rb
'
)
as
pkl
:
try
:
config
=
pickle
.
load
(
pkl
)
except
:
try
:
config
=
pickle
.
load
(
pkl
,
encoding
=
"
utf-8
"
)
except
:
coloring
(
"
Impossible de décoder le fichier %s
"
%
in_path
)
traceback
.
print_exc
()
exit
(
0
)
except
:
coloring
(
"
Impossible d
'
ouvrir fichier %s
"
%
in_path
)
traceback
.
print_exc
()
exit
(
0
)
try
:
with
io
.
open
(
out_path
,
'
w
'
,
encoding
=
'
utf8
'
)
as
outfile
:
try
:
yaml
.
safe_dump
(
config
,
outfile
,
default_flow_style
=
False
,
allow_unicode
=
True
)
except
:
coloring
(
"
Impossible d
'
encoder le fichier %s
"
%
out_path
)
traceback
.
print_exc
()
exit
(
0
)
except
:
coloring
(
"
Impossible d
'
enregistrer le fichier %s
"
%
out_path
)
if
verbose
:
traceback
.
print_exc
()
if
__name__
==
"
__main__
"
:
if
len
(
sys
.
argv
)
<
2
:
coloring
(
"
Il vous manque un fichier d
'
entrée
"
)
exit
(
0
)
if
len
(
sys
.
argv
)
<
3
:
coloring
(
"
Il vous manque un fichier de sortie
"
)
exit
(
0
)
convert_config
(
sys
.
argv
[
1
],
sys
.
argv
[
2
])
coloring
(
"
Votre fichier de configuration a bien été converti !
"
,
True
)
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