Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gajim
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
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
Weblate
gajim
Commits
573ddce6
Commit
573ddce6
authored
16 years ago
by
Yann Leboulanger
Browse files
Options
Downloads
Patches
Plain Diff
use regex to parse config file. See #4457
parent
2603ee19
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/common/optparser.py
+15
-20
15 additions, 20 deletions
src/common/optparser.py
with
15 additions
and
20 deletions
src/common/optparser.py
+
15
−
20
View file @
573ddce6
...
@@ -28,6 +28,7 @@
...
@@ -28,6 +28,7 @@
import
os
import
os
import
locale
import
locale
import
re
from
common
import
gajim
from
common
import
gajim
import
exceptions
import
exceptions
...
@@ -46,24 +47,6 @@ class OptionsParser:
...
@@ -46,24 +47,6 @@ class OptionsParser:
self
.
old_values
=
{}
# values that are saved in the file and maybe
self
.
old_values
=
{}
# values that are saved in the file and maybe
# no longer valid
# no longer valid
def
read_line
(
self
,
line
):
index
=
line
.
find
(
'
=
'
)
var_str
=
line
[
0
:
index
]
value_str
=
line
[
index
+
3
:
-
1
]
i_start
=
var_str
.
find
(
'
.
'
)
i_end
=
var_str
.
rfind
(
'
.
'
)
if
i_start
==
-
1
:
self
.
old_values
[
var_str
]
=
value_str
gajim
.
config
.
set
(
var_str
,
value_str
)
else
:
optname
=
var_str
[
0
:
i_start
]
key
=
var_str
[
i_start
+
1
:
i_end
]
subname
=
var_str
[
i_end
+
1
:]
gajim
.
config
.
add_per
(
optname
,
key
)
gajim
.
config
.
set_per
(
optname
,
key
,
subname
,
value_str
)
def
read
(
self
):
def
read
(
self
):
try
:
try
:
fd
=
open
(
self
.
__filename
)
fd
=
open
(
self
.
__filename
)
...
@@ -75,12 +58,24 @@ class OptionsParser:
...
@@ -75,12 +58,24 @@ class OptionsParser:
new_version
=
gajim
.
config
.
get
(
'
version
'
)
new_version
=
gajim
.
config
.
get
(
'
version
'
)
new_version
=
new_version
.
split
(
'
-
'
,
1
)[
0
]
new_version
=
new_version
.
split
(
'
-
'
,
1
)[
0
]
for
line
in
fd
.
readlines
():
seen
=
set
()
regex
=
re
.
compile
(
r
"
(?P<optname>[^.]+)(?:(?:\.(?P<key>.+))?\.(?P<subname>[^.]+))?\s=\s(?P<value>.*)
"
)
for
line
in
fd
:
try
:
try
:
line
=
line
.
decode
(
'
utf-8
'
)
line
=
line
.
decode
(
'
utf-8
'
)
except
UnicodeDecodeError
:
except
UnicodeDecodeError
:
line
=
line
.
decode
(
locale
.
getpreferredencoding
())
line
=
line
.
decode
(
locale
.
getpreferredencoding
())
self
.
read_line
(
line
)
optname
,
key
,
subname
,
value
=
regex
.
match
(
line
).
groups
()
if
key
is
None
:
self
.
old_values
[
optname
]
=
value
gajim
.
config
.
set
(
optname
,
value
)
else
:
if
(
optname
,
key
)
not
in
seen
:
gajim
.
config
.
add_per
(
optname
,
key
)
seen
.
add
((
optname
,
key
))
gajim
.
config
.
set_per
(
optname
,
key
,
subname
,
value
)
old_version
=
gajim
.
config
.
get
(
'
version
'
)
old_version
=
gajim
.
config
.
get
(
'
version
'
)
old_version
=
old_version
.
split
(
'
-
'
,
1
)[
0
]
old_version
=
old_version
.
split
(
'
-
'
,
1
)[
0
]
...
...
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