RE_CSS_BLOCKS = re.compile("{(.*?)}", re.DOTALL) def _css_converter(match): rt, lt, pd, e = match.groups() if rt: return "left" if lt: return "right" if pd: a, b, c, d = pd.split() return "%s %s %s %s%s" % (a, d, c, b, e) def flip_css_layout_direction(css_file): print css_file orig = css_file + ".orig" if not orig.isfile(): css_file.copyfile(orig) print css_file, "->", orig orig_css = open(orig).read() process_block = lambda match: RE_CSS_ELEMENTS.sub(_css_converter, match.group(0)) new_css = RE_CSS_BLOCKS.sub(process_block, orig_css) with open(css_file, "w") as f: f.write(new_css) if __name__ == "__main__": for f in sys.argv[1:]: flip_css_layout_direction(path(f))
''' Created on Nov 4, 2012 @author: oferko ''' from path3 import path import re import hashlib import urllib2 import csv import itertools import sys import ast APP_ROOT = path(__file__).parent.parent class TranslatableFile(object): HEADER = "" def __init__(self, f): self.relative_path = APP_ROOT.relpathto(f) self.file_digest = hashlib.md5( self.relative_path).hexdigest()[:DIGEST_LEN] check_collision(self.file_digest) self.path = f self.orig = f + ".orig" source = self.orig if self.orig.isfile() else f with open(source) as opened: self.text = opened.read()
''' Created on Nov 4, 2012 @author: oferko ''' from path3 import path import re import hashlib import urllib2 import csv import itertools import sys import ast APP_ROOT = path(__file__).parent.parent class TranslatableFile(object): HEADER = "" def __init__(self, f): self.relative_path = APP_ROOT.relpathto(f) self.file_digest = hashlib.md5(self.relative_path).hexdigest()[:DIGEST_LEN] check_collision(self.file_digest) self.path = f self.orig = f + ".orig" source = self.orig if self.orig.isfile() else f with open(source) as opened: self.text = opened.read() def __repr__(self): return "%s(%s - %s)" % (self.__class__.__name__, self.file_digest, self.relative_path)