diff mbox

[07/10] Report if a patch is delagated and to whom

Message ID 1448712886-3221-8-git-send-email-mchehab@osg.samsung.com
State Accepted
Delegated to: Stephen Finucane
Headers show

Commit Message

Mauro Carvalho Chehab Nov. 28, 2015, 12:14 p.m. UTC
When a patch is delegated, it can be important to report it via
pwclient, as handing delegated patches may be different. So, add
an optional field at the email's body if this is happening.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
---
 patchwork/models.py | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

Comments

Stephen Finucane Dec. 24, 2015, 1:57 p.m. UTC | #1
On 28 Nov 10:14, Mauro Carvalho Chehab wrote:
> When a patch is delegated, it can be important to report it via
> pwclient, as handing delegated patches may be different. So, add
> an optional field at the email's body if this is happening.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> ---
>  patchwork/models.py | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 54 insertions(+)
> 
> diff --git a/patchwork/models.py b/patchwork/models.py
> index e552217a3cbc..024ff4d8d5e1 100644
> --- a/patchwork/models.py
> +++ b/patchwork/models.py
> @@ -323,6 +323,60 @@ class Patch(models.Model):
>          str = fname_re.sub('-', self.name)
>          return str.strip('-') + '.patch'
>  
> +    def mbox(self):
> +        postscript_re = re.compile('\n-{2,3} ?\n')
> +
> +        comment = None
> +        try:
> +            comment = Comment.objects.get(patch = self, msgid = self.msgid)
> +        except Exception:
> +            pass
> +
> +        body = ''
> +        if comment:
> +            body = comment.content.strip() + "\n"
> +
> +        parts = postscript_re.split(body, 1)
> +        if len(parts) == 2:
> +            (body, postscript) = parts
> +            body = body.strip() + "\n"
> +            postscript = postscript.strip() + "\n"
> +        else:
> +            postscript = ''
> +
> +        for comment in Comment.objects.filter(patch = self) \
> +                .exclude(msgid = self.msgid):
> +            body += comment.patch_responses()
> +
> +        if body:
> +            body += '\n'
> +
> +        if postscript:
> +            body += '---\n' + postscript.strip() + '\n'
> +
> +        if self.content:
> +            body += '\n' + self.content
> +
> +        mail = PatchMbox(body)
> +        mail['Subject'] = self.name
> +        mail['Date'] = email.utils.formatdate(
> +                        time.mktime(self.date.utctimetuple()))
> +        mail['From'] = unicode(self.submitter)
> +        mail['X-Patchwork-Id'] = str(self.id)
> +	if self.delegate:
> +            mail['X-Patchwork-Delegate'] = str(self.delegate.email)

[snip]

You seem to be missing a couple of dependencies here: it fails to run
because of missing imports and the code looks like a minor modification
of functionality found in 'patchwork/views/__init__.py'. Is there any
reason we can't just include the above 'X-Patchwork-Delegate' lines in
the 'patch_to_mbox' function found in the aforementioned file?

Stephen
Mauro Carvalho Chehab Dec. 24, 2015, 8:31 p.m. UTC | #2
Em Thu, 24 Dec 2015 13:57:08 +0000
"Finucane, Stephen" <stephen.finucane@intel.com> escreveu:

> On 28 Nov 10:14, Mauro Carvalho Chehab wrote:
> > When a patch is delegated, it can be important to report it via
> > pwclient, as handing delegated patches may be different. So, add
> > an optional field at the email's body if this is happening.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > ---
> >  patchwork/models.py | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 54 insertions(+)
> > 
> > diff --git a/patchwork/models.py b/patchwork/models.py
> > index e552217a3cbc..024ff4d8d5e1 100644
> > --- a/patchwork/models.py
> > +++ b/patchwork/models.py
> > @@ -323,6 +323,60 @@ class Patch(models.Model):
> >          str = fname_re.sub('-', self.name)
> >          return str.strip('-') + '.patch'
> >  
> > +    def mbox(self):
> > +        postscript_re = re.compile('\n-{2,3} ?\n')
> > +
> > +        comment = None
> > +        try:
> > +            comment = Comment.objects.get(patch = self, msgid = self.msgid)
> > +        except Exception:
> > +            pass
> > +
> > +        body = ''
> > +        if comment:
> > +            body = comment.content.strip() + "\n"
> > +
> > +        parts = postscript_re.split(body, 1)
> > +        if len(parts) == 2:
> > +            (body, postscript) = parts
> > +            body = body.strip() + "\n"
> > +            postscript = postscript.strip() + "\n"
> > +        else:
> > +            postscript = ''
> > +
> > +        for comment in Comment.objects.filter(patch = self) \
> > +                .exclude(msgid = self.msgid):
> > +            body += comment.patch_responses()
> > +
> > +        if body:
> > +            body += '\n'
> > +
> > +        if postscript:
> > +            body += '---\n' + postscript.strip() + '\n'
> > +
> > +        if self.content:
> > +            body += '\n' + self.content
> > +
> > +        mail = PatchMbox(body)
> > +        mail['Subject'] = self.name
> > +        mail['Date'] = email.utils.formatdate(
> > +                        time.mktime(self.date.utctimetuple()))
> > +        mail['From'] = unicode(self.submitter)
> > +        mail['X-Patchwork-Id'] = str(self.id)
> > +	if self.delegate:
> > +            mail['X-Patchwork-Delegate'] = str(self.delegate.email)
> 
> [snip]
> 
> You seem to be missing a couple of dependencies here: it fails to run
> because of missing imports and the code looks like a minor modification
> of functionality found in 'patchwork/views/__init__.py'. 

Hmm.. it runs fine at patchwork, but perhaps due to some other
locale changes I did there, for patchwork to find the dependencies.

> Is there any
> reason we can't just include the above 'X-Patchwork-Delegate' lines in
> the 'patch_to_mbox' function found in the aforementioned file?

I remember I tried to add it on some other place (don't remember where
anymore, as it was done several years ago). It didn't work when the
patch were obtained via XMLRPC.

I need to receive this tag via pwclient, as my local scripts use it
to remove patches delegated to other developers from my own work
queue.

Anyway, feel free to either modify this patch or do to something else
that would provide the same functionality. I'm not a Pyhton expert.
So, I'm probably not taking the best approach ;)

> 
> Stephen
> _______________________________________________
> Patchwork mailing list
> Patchwork@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/patchwork
Stephen Finucane Jan. 6, 2016, 5:19 p.m. UTC | #3
On 24 Dec 18:31, Mauro Carvalho Chehab wrote:

[snip]

> > You seem to be missing a couple of dependencies here: it fails to run
> > because of missing imports and the code looks like a minor modification
> > of functionality found in 'patchwork/views/__init__.py'. 
> 
> Hmm.. it runs fine at patchwork, but perhaps due to some other
> locale changes I did there, for patchwork to find the dependencies.
> 
> > Is there any
> > reason we can't just include the above 'X-Patchwork-Delegate' lines in
> > the 'patch_to_mbox' function found in the aforementioned file?
> 
> I remember I tried to add it on some other place (don't remember where
> anymore, as it was done several years ago). It didn't work when the
> patch were obtained via XMLRPC.
> 
> I need to receive this tag via pwclient, as my local scripts use it
> to remove patches delegated to other developers from my own work
> queue.
> 
> Anyway, feel free to either modify this patch or do to something else
> that would provide the same functionality. I'm not a Pyhton expert.
> So, I'm probably not taking the best approach ;)

OK, I have it merged into the existing file and it's working for me.
I also have unit tests added. As such, I'm rejecting this one but
will merge a modified version. That OK? :)

Stephen
Stephen Finucane Jan. 19, 2016, 9:26 p.m. UTC | #4
On 06 Jan 17:19, Finucane, Stephen wrote:
> On 24 Dec 18:31, Mauro Carvalho Chehab wrote:
> 
> [snip]
> 
> > > You seem to be missing a couple of dependencies here: it fails to run
> > > because of missing imports and the code looks like a minor modification
> > > of functionality found in 'patchwork/views/__init__.py'. 
> > 
> > Hmm.. it runs fine at patchwork, but perhaps due to some other
> > locale changes I did there, for patchwork to find the dependencies.
> > 
> > > Is there any
> > > reason we can't just include the above 'X-Patchwork-Delegate' lines in
> > > the 'patch_to_mbox' function found in the aforementioned file?
> > 
> > I remember I tried to add it on some other place (don't remember where
> > anymore, as it was done several years ago). It didn't work when the
> > patch were obtained via XMLRPC.
> > 
> > I need to receive this tag via pwclient, as my local scripts use it
> > to remove patches delegated to other developers from my own work
> > queue.
> > 
> > Anyway, feel free to either modify this patch or do to something else
> > that would provide the same functionality. I'm not a Pyhton expert.
> > So, I'm probably not taking the best approach ;)
> 
> OK, I have it merged into the existing file and it's working for me.
> I also have unit tests added. As such, I'm rejecting this one but
> will merge a modified version. That OK? :)
> 
> Stephen

Dropped in favour of patch 11.
diff mbox

Patch

diff --git a/patchwork/models.py b/patchwork/models.py
index e552217a3cbc..024ff4d8d5e1 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -323,6 +323,60 @@  class Patch(models.Model):
         str = fname_re.sub('-', self.name)
         return str.strip('-') + '.patch'
 
+    def mbox(self):
+        postscript_re = re.compile('\n-{2,3} ?\n')
+
+        comment = None
+        try:
+            comment = Comment.objects.get(patch = self, msgid = self.msgid)
+        except Exception:
+            pass
+
+        body = ''
+        if comment:
+            body = comment.content.strip() + "\n"
+
+        parts = postscript_re.split(body, 1)
+        if len(parts) == 2:
+            (body, postscript) = parts
+            body = body.strip() + "\n"
+            postscript = postscript.strip() + "\n"
+        else:
+            postscript = ''
+
+        for comment in Comment.objects.filter(patch = self) \
+                .exclude(msgid = self.msgid):
+            body += comment.patch_responses()
+
+        if body:
+            body += '\n'
+
+        if postscript:
+            body += '---\n' + postscript.strip() + '\n'
+
+        if self.content:
+            body += '\n' + self.content
+
+        mail = PatchMbox(body)
+        mail['Subject'] = self.name
+        mail['Date'] = email.utils.formatdate(
+                        time.mktime(self.date.utctimetuple()))
+        mail['From'] = unicode(self.submitter)
+        mail['X-Patchwork-Id'] = str(self.id)
+	if self.delegate:
+            mail['X-Patchwork-Delegate'] = str(self.delegate.email)
+        mail['Message-Id'] = self.msgid
+        mail.set_unixfrom('From patchwork ' + self.date.ctime())
+
+
+        copied_headers = ['To', 'Cc']
+        orig_headers = HeaderParser().parsestr(str(self.headers))
+        for header in copied_headers:
+            if header in orig_headers:
+                mail[header] = orig_headers[header]
+
+        return mail
+
     @models.permalink
     def get_absolute_url(self):
         return ('patchwork.views.patch.patch', (), {'patch_id': self.id})