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
l-n-s
gajim
Commits
5e4520bd
Commit
5e4520bd
authored
20 years ago
by
Yann Leboulanger
Browse files
Options
Downloads
Patches
Plain Diff
new optparser class that support ; and # in option's value
parent
0ab54164
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
common/optparser.py
+33
-32
33 additions, 32 deletions
common/optparser.py
with
33 additions
and
32 deletions
common/optparser.py
+
33
−
32
View file @
5e4520bd
...
...
@@ -16,44 +16,49 @@
## GNU General Public License for more details.
##
import
ConfigParser
,
logging
,
os
,
string
import
logging
,
os
,
string
log
=
logging
.
getLogger
(
'
common.options
'
)
class
OptionsParser
(
ConfigParser
.
ConfigParser
)
:
class
OptionsParser
:
def
__init__
(
self
,
fname
):
ConfigParser
.
ConfigParser
.
__init__
(
self
)
self
.
__fname
=
os
.
path
.
expanduser
(
fname
)
self
.
tab
=
{}
# END __init__
def
parseCfgFile
(
self
):
try
:
self
.
__
fd
=
open
(
self
.
__fname
)
fd
=
open
(
self
.
__fname
)
except
:
print
'
error cannot open file %s
\n
'
%
(
self
.
__fname
);
return
self
.
readfp
(
self
.
__fd
)
self
.
__sections
=
self
.
sections
()
for
section
in
self
.
__sections
:
self
.
tab
[
section
]
=
{}
for
option
in
self
.
options
(
section
):
value
=
self
.
get
(
section
,
option
,
1
)
#convert to int options than can be
if
string
.
find
(
option
,
'
password
'
)
==
-
1
:
try
:
i
=
string
.
atoi
(
value
)
except
ValueError
:
self
.
tab
[
section
][
option
]
=
value
else
:
self
.
tab
[
section
][
option
]
=
i
else
:
self
.
tab
=
{}
section
=
''
for
line
in
fd
.
readlines
():
if
line
[
0
]
in
"
#;
"
:
continue
if
line
[
0
]
==
'
[
'
:
section
=
line
[
1
:
line
.
find
(
'
]
'
)]
self
.
tab
[
section
]
=
{}
continue
index
=
line
.
find
(
'
=
'
)
if
index
==
-
1
:
continue
option
=
line
[
0
:
index
]
option
=
option
.
strip
()
value
=
line
[
index
+
1
:]
value
=
value
.
strip
()
if
string
.
find
(
option
,
'
password
'
)
==
-
1
:
try
:
i
=
string
.
atoi
(
value
)
except
ValueError
:
self
.
tab
[
section
][
option
]
=
value
# setattr(self, str(section) + '_' + \
# str(option), value)
else
:
self
.
tab
[
section
][
option
]
=
i
else
:
self
.
tab
[
section
][
option
]
=
value
fd
.
close
()
# END parseCfgFile
def
__str__
(
self
):
...
...
@@ -73,19 +78,15 @@ class OptionsParser(ConfigParser.ConfigParser):
# END __getattr__
def
writeCfgFile
(
self
):
#Remove all sections
for
s
in
self
.
sections
():
self
.
remove_section
(
s
)
#recreate sections
for
s
in
self
.
tab
.
keys
():
self
.
add_section
(
s
)
for
o
in
self
.
tab
[
s
].
keys
():
self
.
set
(
s
,
o
,
self
.
tab
[
s
][
o
])
try
:
self
.
write
(
open
(
self
.
__fname
,
'
w
'
)
)
fd
=
open
(
self
.
__fname
,
'
w
'
)
except
:
log
.
debug
(
"
Can
'
t write config %s
"
%
self
.
__fname
)
return
0
for
s
in
self
.
tab
.
keys
():
fd
.
write
(
'
[
'
+
s
+
'
]
\n\n
'
)
for
o
in
self
.
tab
[
s
].
keys
():
fd
.
write
(
o
+
'
=
'
+
str
(
self
.
tab
[
s
][
o
])
+
'
\n
'
)
return
1
# END writeCfgFile
...
...
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