fix recentfile.py to work for both py2/py3
This commit is contained in:
parent
f607cc98ae
commit
238cf389b0
@ -184,23 +184,27 @@ class RecentFiles(object):
|
|||||||
"""
|
"""
|
||||||
Saves the current GRAMPS RecentFiles collection to the associated file.
|
Saves the current GRAMPS RecentFiles collection to the associated file.
|
||||||
"""
|
"""
|
||||||
with io.open(os.path.expanduser(GRAMPS_FILENAME), 'w', encoding='utf8') as xml_file:
|
if sys.version_info[0] < 3:
|
||||||
if use_lock:
|
xml_file = open(os.path.expanduser(GRAMPS_FILENAME), 'w')
|
||||||
fcntl.lockf(xml_file,fcntl.LOCK_EX)
|
else:
|
||||||
xml_file.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
|
xml_file = open(os.path.expanduser(GRAMPS_FILENAME), 'w', encoding='utf8')
|
||||||
xml_file.write('<RecentFiles>\n')
|
if use_lock:
|
||||||
index = 0
|
fcntl.lockf(xml_file,fcntl.LOCK_EX)
|
||||||
for item in self.gramps_recent_files:
|
xml_file.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
|
||||||
index += 1
|
xml_file.write('<RecentFiles>\n')
|
||||||
if index > MAX_GRAMPS_ITEMS:
|
index = 0
|
||||||
break
|
for item in self.gramps_recent_files:
|
||||||
xml_file.write(' <RecentItem>\n')
|
index += 1
|
||||||
xml_file.write(' <Path><![CDATA[%s]]></Path>\n' % item.get_path())
|
if index > MAX_GRAMPS_ITEMS:
|
||||||
xml_file.write(' <Name><![CDATA[%s]]></Name>\n' % item.get_name())
|
break
|
||||||
xml_file.write(' <Timestamp>%d</Timestamp>\n' % item.get_time())
|
xml_file.write(' <RecentItem>\n')
|
||||||
xml_file.write(' </RecentItem>\n')
|
xml_file.write(' <Path><![CDATA[%s]]></Path>\n' % item.get_path())
|
||||||
xml_file.write('</RecentFiles>\n')
|
xml_file.write(' <Name><![CDATA[%s]]></Name>\n' % item.get_name())
|
||||||
# all advisory locks on a file are released on close
|
xml_file.write(' <Timestamp>%d</Timestamp>\n' % item.get_time())
|
||||||
|
xml_file.write(' </RecentItem>\n')
|
||||||
|
xml_file.write('</RecentFiles>\n')
|
||||||
|
xml_file.close()
|
||||||
|
# all advisory locks on a file are released on close
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -222,7 +226,7 @@ class RecentParser(object):
|
|||||||
try:
|
try:
|
||||||
# Python3's expat wants bytes, Python2's wants a string.
|
# Python3's expat wants bytes, Python2's wants a string.
|
||||||
fmode = "r" if sys.version_info[0] < 3 else "rb"
|
fmode = "r" if sys.version_info[0] < 3 else "rb"
|
||||||
with io.open(fname, fmode) as xml_file:
|
with open(fname, fmode) as xml_file:
|
||||||
if use_lock:
|
if use_lock:
|
||||||
fcntl.lockf(xml_file,fcntl.LOCK_SH)
|
fcntl.lockf(xml_file,fcntl.LOCK_SH)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user