Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

make sure there's a yaml loader avail. *sigh*

  • Loading branch information...
commit 3c005cb55f92e328f7d4371553f150b281edec11 1 parent 10a53eb
@jensck authored
View
12 fluidity/defs.py
@@ -57,6 +57,17 @@ def _get_read_review_path():
return path
+def _get_yaml_loader_dumper():
+ # WTF? How can a Fedora install NOT have the YAML C dumper?!
+ # I can't wait for the day when Android is usable as a full workstation.
+ # Desktop Linux: the only things that suck even harder than this are
+ # the alternatives.
+ try:
+ return yaml.CLoader, yaml.CDumper
+ except AttributeError:
+ return yaml.Loader, yaml.Dumper
+
+
APP_NAME = 'Fluidity'
DBUS_BUS_NAME = 'org.solemnsilence.Fluidity'
DBUS_OBJECT_PATH = '/org/solemnsilence/Fluidity'
@@ -69,6 +80,7 @@ def _get_read_review_path():
FAKE_CONTEXT_UUID = uuid.UUID(
bytes='\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xDE\xAD\xBE\xEF')
+YAML_LOADER, YAML_DUMPER = _get_yaml_loader_dumper()
### NOTES APP STUFF ###
# FIXME: this is lame. Figure out /real/ Tomboy vs. Gnote handling later
View
3  fluidity/first_time.py
@@ -63,4 +63,5 @@ def _create_initial_recurrence_file(self, full_path):
'last_run': datetime.date.today()}
print("Creating initial recurrence file...")
with open(full_path, 'w') as yfile:
- yaml.dump(data, yfile, Dumper=yaml.CDumper, default_flow_style=False)
+ yaml.dump(data, yfile, Dumper=defs.YAML_DUMPER, default_flow_style=False)
+
View
4 fluidity/managers.py
@@ -779,13 +779,13 @@ def _save_data(self, data_file_path):
#FIXME: create a backup copy?
with open(data_file_path, 'w') as yfile:
print("Saving recurrence data")
- yaml.dump(self._recur_data, yfile, Dumper=yaml.CDumper,
+ yaml.dump(self._recur_data, yfile, Dumper=defs.YAML_DUMPER,
default_flow_style=False)
def _yloader(self, yfile_path):
with open(yfile_path, 'r') as yfile:
print("calling yaml.load()")
- ycontent = yaml.load(yfile, Loader=yaml.CLoader)
+ ycontent = yaml.load(yfile, Loader=defs.YAML_LOADER)
return ycontent
View
5 tools/fity_data_conversion_helper.py
@@ -21,6 +21,7 @@
import fluidity
from collections import namedtuple
+from fluidity import defs
GTD_NT = namedtuple("GTDDefaults", "default proper_type convert_func")
@@ -59,7 +60,7 @@ def dump(data, path, overwrite=False):
"""Format should be a string, either 'yaml' or 'pkl'."""
ext = os.path.splitext(path)[1].strip('.')
dumpers = {
- 'yaml': lambda d, s: yaml.dump(d, s, yaml.CDumper, default_flow_style=False),
+ 'yaml': lambda d, s: yaml.dump(d, s, defs.YAML_DUMPER, default_flow_style=False),
'pkl': lambda d, s: pickle.dump(d, s, protocol=pickle.HIGHEST_PROTOCOL)}
if not overwrite and os.path.exists(path):
raise IOError("File already exists; cowardly refusing to overwrite")
@@ -76,7 +77,7 @@ def get_dump_path(orig_path):
def load(path):
"""Format should be either 'yaml' or 'pkl'."""
ext = os.path.splitext(path)[1].strip('.')
- loaders = {'yaml': lambda stream: yaml.load(stream, Loader=yaml.CLoader),
+ loaders = {'yaml': lambda stream: yaml.load(stream, Loader=defs.YAML_LOADER),
'pkl': lambda stream: pickle.load(stream)}
with open(path, 'r') as lfile:
data = loaders[ext](lfile)
View
6 tools/fity_data_debug_converter.py
@@ -73,14 +73,14 @@ def convert_fity_data_file(orig_path, new_path, delete_original=False):
# print "well, we got this far...."
if orig_path.endswith('.yaml') and new_path.endswith('.pkl'):
with open(orig_path, 'r') as orig_file:
- fity_data = yaml.load(orig_file, Loader=yaml.CLoader)
+ fity_data = yaml.load(orig_file, Loader=defs.YAML_LOADER)
with open(new_path, 'w') as new_file:
pickle.dump(fity_data, new_file, protocol=pickle.HIGHEST_PROTOCOL)
elif orig_path.endswith('.pkl') and new_path.endswith('.yaml'):
with open(orig_path, 'r') as orig_file:
fity_data = pickle.load(orig_file)
with open(new_path, 'w') as new_file:
- yaml.dump(fity_data, new_file, Dumper=yaml.CDumper,
+ yaml.dump(fity_data, new_file, Dumper=defs.YAML_DUMPER,
default_flow_style=False)
else:
fail()
@@ -123,4 +123,4 @@ def main():
if __name__ == '__main__':
- main()
+ main()
Please sign in to comment.
Something went wrong with that request. Please try again.