Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
settingsd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etersoft
settingsd
Commits
d78fe289
Commit
d78fe289
authored
Jan 27, 2011
by
Devaev Maxim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Splitted opening of config for read and write
parent
0589180e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
20 deletions
+22
-20
editors.py
settingsd/tools/editors.py
+22
-20
No files found.
settingsd/tools/editors.py
View file @
d78fe289
...
@@ -28,7 +28,7 @@ class PlainEditor(object) :
...
@@ -28,7 +28,7 @@ class PlainEditor(object) :
#####
#####
self
.
__config_file
=
None
self
.
__config_file
_path
=
None
self
.
__config_file_data_list
=
None
self
.
__config_file_data_list
=
None
###
###
...
@@ -42,42 +42,44 @@ class PlainEditor(object) :
...
@@ -42,42 +42,44 @@ class PlainEditor(object) :
### Public ###
### Public ###
def
open
(
self
,
config_file_path
,
config_sample
_file_path
=
None
)
:
def
open
(
self
,
config_file_path
,
sample_config
_file_path
=
None
)
:
if
self
.
__config_file
!=
None
:
if
self
.
__config_file
_path
!=
None
:
raise
AlreadyAssociated
(
"This parser already associated with config
\"
%
s
\"
"
%
self
.
__config_file
.
name
)
raise
AlreadyAssociated
(
"This parser already associated with config
\"
%
s
\"
"
%
self
.
__config_file
_path
)
if
not
os
.
access
(
config_file_path
,
os
.
F_OK
)
:
if
not
os
.
access
(
config_file_path
,
os
.
F_OK
)
:
if
config_sample_file_path
!=
None
and
os
.
access
(
config_sample
_file_path
,
os
.
F_OK
)
:
if
sample_config_file_path
!=
None
and
os
.
access
(
sample_config
_file_path
,
os
.
F_OK
)
:
shutil
.
copy2
(
config_sample
_file_path
,
config_file_path
)
shutil
.
copy2
(
sample_config
_file_path
,
config_file_path
)
else
:
else
:
open
(
config_file_path
,
"w"
)
.
close
()
open
(
config_file_path
,
"w"
)
.
close
()
self
.
__config_file
=
open
(
config_file_path
,
"r+"
)
config_file
=
open
(
config_file_path
,
"r"
)
self
.
__config_file_data_list
=
self
.
__config_file
.
read
()
.
split
(
"
\n
"
)
self
.
__config_file_data_list
=
config_file
.
read
()
.
split
(
"
\n
"
)
self
.
__config_file_path
=
config_file_path
try
:
config_file
.
close
()
except
:
pass
def
save
(
self
)
:
def
save
(
self
)
:
if
self
.
__config_file
==
None
:
if
self
.
__config_file
_path
==
None
:
raise
NotAssociated
(
"This parser is not associated with config"
)
raise
NotAssociated
(
"This parser is not associated with config"
)
self
.
__config_file
.
seek
(
0
)
config_file
=
open
(
self
.
__config_file_path
,
"w"
)
self
.
__config_file
.
truncate
()
config_file
.
write
(
"
\n
"
.
join
(
self
.
__config_file_data_list
))
self
.
__config_file
.
write
(
"
\n
"
.
join
(
self
.
__config_file_data_list
))
try
:
self
.
__config_file
.
flush
()
config_file
.
close
()
except
:
pass
def
close
(
self
)
:
def
close
(
self
)
:
if
self
.
__config_file
==
None
:
if
self
.
__config_file
_path
==
None
:
raise
NotAssociated
(
"This parser is not associated with config"
)
raise
NotAssociated
(
"This parser is not associated with config"
)
try
:
self
.
__config_file
.
close
()
except
:
pass
self
.
__config_file
=
None
self
.
__config_file_data_list
=
None
self
.
__config_file_data_list
=
None
self
.
__config_file_path
=
None
###
###
def
setValue
(
self
,
variable_name
,
values_list
)
:
def
setValue
(
self
,
variable_name
,
values_list
)
:
if
self
.
__config_file
==
None
:
if
self
.
__config_file
_path
==
None
:
raise
NotAssociated
(
"This parser is not associated with config"
)
raise
NotAssociated
(
"This parser is not associated with config"
)
if
not
type
(
values_list
)
.
__name__
in
(
"list"
,
"tuple"
)
:
if
not
type
(
values_list
)
.
__name__
in
(
"list"
,
"tuple"
)
:
...
@@ -103,7 +105,7 @@ class PlainEditor(object) :
...
@@ -103,7 +105,7 @@ class PlainEditor(object) :
self
.
__config_file_data_list
.
insert
(
last_variable_index
+
count
,
variable
)
self
.
__config_file_data_list
.
insert
(
last_variable_index
+
count
,
variable
)
def
value
(
self
,
variable_name
)
:
def
value
(
self
,
variable_name
)
:
if
self
.
__config_file
==
None
:
if
self
.
__config_file
_path
==
None
:
raise
NotAssociated
(
"This parser is not associated with config"
)
raise
NotAssociated
(
"This parser is not associated with config"
)
values_list
=
[]
values_list
=
[]
...
...
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