Ability to have username in init command
[mw] / src / mw / metadir.py
index eb4e56555b63884991093178edcb13794c4820bd..6c6bfeb1e2d45417e132d8dc8e552817353e68f0 100644 (file)
@@ -49,7 +49,7 @@ class Metadir(object):
         else:
             self.config = None
 
-    def create(self, api_url):
+    def create(self, api_url, username=None):
         # create the directory
         if os.path.isdir(self.location):
             print '%s: you are already in a mw repo' % self.me
@@ -64,6 +64,8 @@ class Metadir(object):
         self.config = ConfigParser.RawConfigParser()
         self.config.add_section('remote')
         self.config.set('remote', 'api_url', api_url)
+        if username != None:
+            self.config.set('remote', 'username', username)
         with open(self.config_loc, 'wb') as config_file:
             self.config.write(config_file)
         # create cache/
@@ -147,6 +149,8 @@ class Metadir(object):
                     rvid = self.pages_get_rv_list(pageid)[-1]
                     rv = self.pages_get_rv(pageid, rvid)
                     cur_content = codecs.open(full, 'r', 'utf-8').read()
+                    if cur_content[-1] == '\n':
+                        cur_content = cur_content[:-1]
                     if cur_content != rv['content']:
                         status[os.path.relpath(full, self.root)] = 'U'
         return status
@@ -166,6 +170,8 @@ class Metadir(object):
             old = [i+'\n' for i in oldrv['content'].split('\n')]
             if newrvid == 0:
                 cur_content = codecs.open(filename, 'r', 'utf-8').read()
+                if cur_content[-1] == '\n':
+                    cur_content = cur_content[:-1]
                 newname = 'b/%s (working copy)' % filename
                 new = [i+'\n' for i in cur_content.split('\n')]
             else:
@@ -175,4 +181,7 @@ class Metadir(object):
             diff_fd = StringIO()
             bzrlib.diff.internal_diff(oldname, old, newname, new, diff_fd)
             diff_fd.seek(0)
-            return diff_fd.read()
+            diff = diff_fd.read()
+            if diff[-1] == '\n':
+                diff = diff[:-1]
+            return diff

Benjamin Mako Hill || Want to submit a patch?