Commits

sodas tsai  committed 9961f40

0.1

  • Participants
  • Parent commits 1f4c7e6

Comments (0)

Files changed (6)

File ground_soil/__init__.py

-__version__ = '0.1.5'
+__version__ = '0.1.12'
 VERSION = tuple(map(lambda x: int(x), __version__.split('.')))

File ground_soil/console/color.py

     @staticmethod
     def c(text, *attributes):
         for attribute in attributes:
-            text = '\033[%dm' % attribute + text
+            text = '\033[{attr:d}m'.format(attr=attribute) + text
         return text + '\033[0m'
 
 

File ground_soil/datastucture/settings_dict.py

             except KeyError:
                 return args[1]
         else:
-            raise TypeError('get() takes exactly 1 or 2 arguments (%s given)' % len(args))
+            raise TypeError('get() takes exactly 1 or 2 arguments ({0} given)'.format(len(args)))
 
     def __getattr__(self, item):
         return self[item]
     def __getitem__(self, item):
         if item in self:
             target = super(SettingsDict, self).__getitem__(item)
-            return target() if callable(target) else target
+            return target(self) if callable(target) else target
         else:
             raise KeyError(item)

File ground_soil/fabric/__init__.py

 import ast
 import json
 from fabric.api import local, prefix
+from fabric.main import _escape_split
+
+escape_split = _escape_split
 
 
 def lsudo(command, capture=False):
-    return local('sudo %s' % command, capture=capture)
+    return local('sudo {command}'.format(command=command), capture=capture)
 
 
 def virtual_env(venv_path):
-    return prefix('source %s/bin/activate' % venv_path)
+    return prefix('source {path}/bin/activate'.format(path=venv_path))
 
 
 def eval_arg(raw_value, is_json=False):

File ground_soil/filesystem.py

     try:
         yield path
     finally:
-        os.system('rm -rf %s' % path)
+        os.system('rm -rf {path}'.format(path=path))
+
+
+def sed(sed_command, file_path, sed_argument=''):
+    return 'sed {arg} -i.bak -e "{command}" {path} && rm -rf {path}.bak'.format(
+        arg=sed_argument, path=file_path, command=sed_command)
 
 
 def rsync(source, destination, rsync_schema=None, rsync_argument='-rlpctzD', expand_to_destination=False):
     :return
         composed rsync command
     """
-    rsync = 'rsync %s' % rsync_argument
+    rsync = 'rsync {argument}'.format(argument=rsync_argument)
 
     if source.startswith('localhost:'):
         source = source.replace('localhost:', '')
         rsync_schema = 'ssh'
 
     if rsync_schema:
-        rsync += ' -e "%s"' % rsync_schema
+        rsync += ' -e "{schema}"'.format(schema=rsync_schema)
 
-    rsync += ' %s %s' % (source, destination)
+    rsync += ' {src} {dest}'.format(src=source, dest=destination)
 
     return rsync
 
 
-def render_file(file_path, context, optimize=False):
+def render_file(file_path, context=None, optimize=False, **extend_context):
     """
     Render Jinja2-compatible templates with context
     :param file_path: The path of template file
     :param optimize: Reduce empty line and strip
     :return: Rendered result
     """
+    if context is None:
+        context = {}
+    else:
+        context = dict(context)  # copy it
+    context.update(extend_context)
+
     templates_folder, template_filename = os.path.split(file_path)
-    env = Environment(loader=FileSystemLoader(templates_folder))
-    t = env.get_template(template_filename)
+    environmemnt = Environment(loader=FileSystemLoader(templates_folder))
+    t = environmemnt.get_template(template_filename)
+
     result = t.render(**context)
     if optimize:
         result = re.sub(r'( *\n){2,}', '\n\n', result.strip()) + '\n'
 
     content = editor(content)
 
-    tmp_file = '%s.bak' % file_path
+    tmp_file = '{path}.bak'.format(path=file_path)
     with open(tmp_file, 'w') as f:
         f.write(writer(content))
 
-    os.system('/bin/mv -f %s %s' % (tmp_file, file_path))
+    os.system('/bin/mv -f {src} {dest}'.format(src=tmp_file, dest=file_path))

File ground_soil/package.py

                 pypi_version = tuple(map(lambda x: int(x), version_string.split('.')))
                 local_version = tuple(map(lambda x: int(x), local_version_string.split('.')))
                 if pypi_version > local_version:
-                    msg = '%s %s has been released, please update it.' % (app_name, version_string)
+                    msg = '{name} {ver} has been released, please update it.'.format(name=app_name, ver=version_string)
                     print color(msg, Colors.YELLOW)
                     print ''
                     return 1
                 pass
 
     if not quiet:
-        print color('Beanstalk-Stack is update to date. (version=%s)' % local_version_string, Colors.GREEN)
+        print color(
+            '{name} is update to date. (version={ver})'.format(name=app_name, ver=local_version_string), Colors.GREEN)
     return 0