Skip to content

Commit

Permalink
Use io.open for <=2.7 support
Browse files Browse the repository at this point in the history
  • Loading branch information
evanpurkhiser committed Nov 11, 2015
1 parent d252369 commit f0d4aaa
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions bin/dots
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ from __future__ import print_function

import sys
import os
import io
import shutil
import subprocess
import glob
Expand Down Expand Up @@ -219,7 +220,7 @@ class Configuration(object):
exist in the source tree (meaning it's considered an 'invalid group'"""
if not os.path.exists(self.group_file): return

with open(self.group_file, 'r') as f:
with io.open(self.group_file, 'r') as f:
self.groups = f.read().splitlines()

if not self.groups:
Expand All @@ -234,7 +235,7 @@ class Configuration(object):
if not os.path.exists(directory):
os.makedirs(directory)

with open(self.group_file, 'w+') as f:
with io.open(self.group_file, 'w+') as f:
f.write('\n'.join(self.groups))

def files(self, path_filters=None):
Expand Down Expand Up @@ -375,7 +376,7 @@ class ConfigFile(object):
append_points = set()

for path in self.real_paths():
with open(path, 'r') as file:
with io.open(path, 'r') as file:
for line in file:
line = line.strip()
if line.startswith(AP_IDENTIFIER):
Expand Down Expand Up @@ -421,7 +422,7 @@ class ConfigFile(object):
# Read all file paths into arrays
# This may be memory inefficient and may have to be changed later
for path in self.real_paths():
with open(path, 'r') as file:
with io.open(path, 'r') as file:
contents = file.readlines()

# Replace front and back empty lines with None
Expand Down Expand Up @@ -521,15 +522,15 @@ class ConfigFile(object):
compiled = ''.join(self.compiled).encode('utf-8')
compiled = hashlib.md5(compiled).digest()

with open(path, 'r', encoding='utf-8') as installed_file:
with io.open(path, 'r', encoding='utf-8') as installed_file:
installed = installed_file.read().encode('utf-8')
installed = hashlib.md5(installed).digest()

if installed == compiled and os.stat(path).st_mode == self.mode():
return

# Write the file
with open(path, 'w') as file:
with io.open(path, 'w') as file:
file.writelines(self.compiled)

# Set the file's mode
Expand Down

0 comments on commit f0d4aaa

Please sign in to comment.