<html><body><p>Yes, you are right Viswa! PEP8 recommends to have spaces(in multiples of 4), here is the link for PEP8 standards which talks about the standards need to follow for the code.<br><br>Going forward it is really nice idea to use <a href="https://pypi.python.org/pypi/pep8">pep8 </a>tool to check the coding standard for python code.<br><br>Thanks,<br>Manjunath.<br><br><img width="16" height="16" src="cid:1__=EABBF5DADFB61B278f9e8a93df938690918cEAB@" border="0" alt="Inactive hide details for Vishwanatha Subbanna---01/29/2016 11:47:53 AM---In the earlier phases of OpenBMC development, I was t"><font color="#424282">Vishwanatha Subbanna---01/29/2016 11:47:53 AM---In the earlier phases of OpenBMC development, I was told to use spaces instead of tabs and I switche</font><br><br><font size="2" color="#5F5F5F">From:        </font><font size="2">Vishwanatha Subbanna/India/IBM@IBMIN</font><br><font size="2" color="#5F5F5F">To:        </font><font size="2">"Peng Fei BG Gou" <shgoupf@cn.ibm.com></font><br><font size="2" color="#5F5F5F">Cc:        </font><font size="2">openbmc@lists.ozlabs.org, openbmc-patches@stwcx.xyz, cyrilbur@gmail.com</font><br><font size="2" color="#5F5F5F">Date:        </font><font size="2">01/29/2016 11:47 AM</font><br><font size="2" color="#5F5F5F">Subject:        </font><font size="2">Re: 回复:回复:[PATCH phosphor-rest-server] The streaming support for obmc-rest.</font><br><font size="2" color="#5F5F5F">Sent by:        </font><font size="2">"openbmc" <openbmc-bounces+mkumatag=in.ibm.com@lists.ozlabs.org></font><br><hr width="100%" size="2" align="left" noshade style="color:#8091A5; "><br><br><br><font size="4">In the earlier phases of OpenBMC development, I was told to use spaces instead of tabs and I switched to using spaces since then.<br><br>So all my code is now "4 space" indented ( with VI auto converting my tab to 4 spaces. )<br><br>Thanks<br><br>-------------------------------------------------------------------------------------<br>Thanks and Regards,<br>Vishwanath.<br>Advisory Software Engineer,<br>Power Firmware Development, <br>Systems &Technology Lab,<br>MG2-6F-255 , Manyata Embassy Business Park, <br>Bangalore , KA , 560045<br>Ph: +91-80-46678255<br>E-mail: vishwanath@in.ibm.com<br>----------------------------------------------------------------------------------<br><br></font><img src="cid:1__=EABBF5DADFB61B278f9e8a93df938690918cEAB@" width="16" height="16" alt="Inactive hide details for "Peng Fei BG Gou" ---29/01/2016 09:54:28 am---Yes Cyril, your suggestion is fair, we should keep it c"><font size="4" color="#424282">"Peng Fei BG Gou" ---29/01/2016 09:54:28 am---Yes Cyril, your suggestion is fair, we should keep it consistent across all files in a project. Ther</font><font size="4"><br></font><font color="#5F5F5F"><br>From: </font>"Peng Fei BG Gou" <shgoupf@cn.ibm.com><font color="#5F5F5F"><br>To: </font>cyrilbur@gmail.com<font color="#5F5F5F"><br>Cc: </font>openbmc@lists.ozlabs.org, openbmc-patches@stwcx.xyz<font color="#5F5F5F"><br>Date: </font>29/01/2016 09:54 am<font color="#5F5F5F"><br>Subject: </font>Re: 回复:回复:[PATCH phosphor-rest-server] The streaming support for obmc-rest.<font color="#5F5F5F"><br>Sent by: </font>"openbmc" <openbmc-bounces+vishwanath=in.ibm.com@lists.ozlabs.org><font size="4"><br></font><hr width="100%" size="2" align="left" noshade><font size="4"><br><br></font><font size="4" face="Arial"><br>Yes Cyril, your suggestion is fair, we should keep it consistent across all files in a project. There is always debating between tabs and whitespaces. Even though personally I prefer white spaces (that's why my editor automatically convert tab to whitespace for me), I agree that for this project, I should use tabs. Will make an update soon. </font><font size="4"><br></font><font size="4" face="Arial"><br>GOU, Peng Fei (苟鹏飞), Ph.D.<br>OpenPOWER Enablement.<br>+86-21-609-28631</font><font size="4"><br><br></font><font size="4" face="Arial"><br>----- Original message -----<br>From: Cyril Bur <cyrilbur@gmail.com><br>To: Peng Fei BG Gou/China/IBM@IBMCN<br>Cc: "openbmc" <openbmc@lists.ozlabs.org>, "OpenBMC Patches" <openbmc-patches@stwcx.xyz><br>Subject: Re: 回复:回复:[PATCH phosphor-rest-server] The streaming support for obmc-rest.<br>Date: Fri, Jan 29, 2016 10:09 AM</font><font size="4"><br></font><tt><font size="4"><br>On Fri, 29 Jan 2016 00:49:39 +0000<br>"Peng Fei BG Gou" <shgoupf@cn.ibm.com> wrote:<br><br>> And the white space you saw in the email thread and coding is probably caused by the mixing use of tab and white space. The original code uses tab for indent, while I prefer to use 4 white spaces for indent. I will discuss with Brad regarding the indent convention for our code. Will fix it up if we strictly need tab in our project.<br><br>In a world where we all have to read each others code, we should make an effort<br>to not make it hard for everyone. What you have done here is mix different<br>indenting styles which only makes it harder to read for everyone to read the<br>code. Imagine a world where I preferred 8 space indenting and I went through<br>and my additions to the file were 8 space indented, this would be impossible to<br>read.<br><br>Typically when a file has been written in one way, it is left that way unless<br>that particular way is absolutely abhorrent (5 space indenting...). Tabs are a<br>perfectly valid way of indenting, I don't see the issue here.<br><br>Futhurmore, I know this isn't really for python, if in doubt we should probably<br>be falling back to the openbmc/docs/contributing file and I quote:<br><br>Components of the OpenBMC sources should have consistent style.<br><br>For C code, we typically use the Linux coding style, which is<br>documented at:</font></tt><tt><u><font size="4" color="#0000FF"><br></font></u></tt><u><font size="4" color="#0000FF"><br></font></u><a href="http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/CodingStyle" target="_blank"><tt><u><font size="4" color="#0000FF">http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/CodingStyle</font></u></tt></a><tt><font size="4"><br><br>(unless you want to write a completely separate Python document, and change all<br>the python in this project, I suggest we follow this one where appropriate)<br><br>Indent with tabs instead of spaces, set at 8 columns<br><br>tl;dr<br><br>Don't mix indenting styles, way too hard to read the code.<br><br>>  <br>>  <br>>  <br>>  在 2016年1月29日,上午8:38:15,"Peng Fei BG Gou" <shgoupf@cn.ibm.com> 写道:<br>>  <br>>       Python is indent based languang, so the function will fail if we have<br>> incorrect indenting. I have tested this in real bmc machine so I believe the<br>> indenting should be fine for now. Please let Brad review this change since he<br>> is familiar with Python.<br>>    在 2016年1月29日,上午8:24:58,"Cyril Bur" <cyrilbur@gmail.com> 写道:<br>>    <br>>        On Thu, 28 Jan 2016 02:00:37 -0600<br>>     OpenBMC Patches  wrote:<br>>     > From: shgoupf<br>>     >  <br>>     Hi Peng,<br>>     So I'm don't really know python all that well but I do believe this<br>> language is white space sensitive... I'll let a pythoner respond about the<br>> rest...<br>>     > Changes:<br>>     > 1) The main idea of this change is to have a streaming path as below:<br>>     >     dbus signal -> obmc-rest capture the dbus signal -> obmc-rest<br>>     > notify the client of the signal receiving. 2) Replace rocket with<br>>     > gevent WSGI server to support multiple async accesses. 3) Use gevent<br>>     > queue to notify the dbus signal receiving. 4) The uri to the streaming<br>>     > should be in the form as below: </font></tt><a href="https:////stream/" target="_blank"><tt><u><font size="4" color="#0000FF">https:////stream/</font></u></tt></a><tt><font size="4"><br>>     > ---<br>>     >  obmc-rest | 115<br>>     > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file<br>>     > changed, 104 insertions(+), 11 deletions(-) mode change 100644 =><br>>     > 100755 obmc-rest<br>>     ><br>>     > diff --git a/obmc-rest b/obmc-rest<br>>     > old mode 100644<br>>     > new mode 100755<br>>     > index c6d2949..481dafa<br>>     > --- a/obmc-rest<br>>     > +++ b/obmc-rest<br>>     > @@ -3,7 +3,9 @@<br>>     >  import os<br>>     >  import sys<br>>     >  import dbus<br>>     > +import gobject<br>>     >  import dbus.exceptions<br>>     > +import dbus.mainloop.glib<br>>     >  import json<br>>     >  import logging<br>>     >  from xml.etree import ElementTree<br>>     > @@ -14,6 +16,10 @@ from OpenBMCMapper import Mapper, PathTree,<br>>     > IntrospectionNodeParser, ListMatch import spwd<br>>     >  import grp<br>>     >  import crypt<br>>     > +import threading<br>>     > +import gevent<br>>     > +from gevent.pywsgi import WSGIServer<br>>     > +from gevent.queue import Queue<br>>     >  <br>>     >  DBUS_UNKNOWN_INTERFACE = 'org.freedesktop.UnknownInterface'<br>>     >  DBUS_UNKNOWN_METHOD = 'org.freedesktop.DBus.Error.UnknownMethod'<br>>     > @@ -59,12 +65,13 @@ def makelist(data):<br>>     >  <br>>     >  class RouteHandler(object):<br>>     >   _require_auth = makelist(valid_user)<br>>     > - def __init__(self, app, bus, verbs, rules):<br>>     > + def __init__(self, app, bus, verbs, rules, skips = []):<br>>     >   self.app = app<br>>     >   self.bus = bus<br>>     >   self.mapper = Mapper(bus)<br>>     >   self._verbs = makelist(verbs)<br>>     >   self._rules = rules<br>>     > +                self._skips = skips<br>>     >  <br>>     >   def _setup(self, **kw):<br>>     >   request.route_data = {}<br>>     > @@ -79,7 +86,7 @@ class RouteHandler(object):<br>>     >   return getattr(self, 'do_' + request.method.lower())(**kw)<br>>     >  <br>>     >   def install(self):<br>>     > - self.app.route(self._rules, callback = self,<br>>     > + self.app.route(self._rules, callback = self, skip = self._skips,<br>>     >   method = ['GET', 'PUT', 'PATCH', 'POST', 'DELETE'])<br>>     >  <br>>     >   @staticmethod<br>>     > @@ -108,6 +115,58 @@ class RouteHandler(object):<br>>     >   return None<br>>     >   raise<br>>     >  <br>>     > +class SignalHandler(RouteHandler):<br>>     > + verbs = ['GET']<br>>     > + rules = '/stream/'<br>>     > +<br>>     > + def __init__(self, app, bus):<br>>     > + super(SignalHandler, self).__init__(<br>>     > + app, bus, self.verbs, self.rules)<br>>     > +<br>>     > + def find(self, path, signal):<br>>     > + busses = self.try_mapper_call(self.mapper.get_object,<br>>     > + path = path)<br>>     > + for items in busses.iteritems():<br>>     > + s = self.find_signal_on_bus(path, signal, *items)<br>>     > + if s:<br>>     > + return s<br>>     > +<br>>     > + abort(404, _4034_msg %('signal', 'found', signal))<br>>     > +<br>>     > + def setup(self, path, signal):<br>>     > + request.route_data['map'] = self.find(path, signal)<br>>     > +<br>>     > + def do_get(self, path, signal):<br>>     > +                body = Queue()<br>>     > +                dsignal = DbusSignal(bus, request.route_data['map'][0],<br>>     > +                                     request.route_data['map'][1],<br>>     > path)<br>>     > +                dsignal.onData(body.put)<br>>     > +                dsignal.onFinish(lambda: body.put(StopIteration))<br>>     > +                dsignal.signalSnooping()<br>>     > +                return body<br>>     > +<br>>     > + @staticmethod<br>>     > + def find_signal(signal, signals):<br>>     > + if signals is None:<br>>     > + return None<br>>     > +<br>>     > + signal = find_case_insensitive(signal, signals.keys())<br>>     > + if signal is not None:<br>>     > +                        return signal<br>>     > +<br>>     > + def find_signal_on_bus(self, path, signal, bus, interfaces):<br>>     > + obj = self.bus.get_object(bus, path, introspect = False)<br>>     > + iface = dbus.Interface(obj, dbus.INTROSPECTABLE_IFACE)<br>>     > + data = iface.Introspect()<br>>     > + parser = IntrospectionNodeParser(<br>>     > + ElementTree.fromstring(data),<br>>     > + intf_match = ListMatch(interfaces))<br>>     > + for x,y in parser.get_interfaces().iteritems():<br>>     > + s = self.find_signal(signal,<br>>     > +                                             y.get('signal'))<br>>     > + if s:<br>>     > + return (x,s)<br>>     > +<br>>     >  class DirectoryHandler(RouteHandler):<br>>     >   verbs = 'GET'<br>>     >   rules = '/'<br>>     > @@ -715,7 +774,8 @@ class RestApp(Bottle):<br>>     >   self.install(JSONPlugin(**json_kw))<br>>     >   self.install(JsonApiErrorsPlugin(**json_kw))<br>>     >   self.install(AuthorizationPlugin())<br>>     > - self.install(JsonApiResponsePlugin())<br>>     > +                self.json_response_plugin = JsonApiResponsePlugin()  <br>>     Indenting?<br>>     > + self.install(self.json_response_plugin)<br>>     >   self.install(JsonApiRequestPlugin())<br>>     >   self.install(JsonApiRequestTypePlugin())<br>>     >  <br>>     > @@ -726,6 +786,7 @@ class RestApp(Bottle):<br>>     >  <br>>     >   def create_handlers(self):<br>>     >   # create route handlers<br>>     > + self.signal_handler = SignalHandler(self, self.bus)<br>>     >   self.session_handler = SessionHandler(self, self.bus)<br>>     >   self.directory_handler = DirectoryHandler(self, self.bus)<br>>     >   self.list_names_handler = ListNamesHandler(self, self.bus)<br>>     > @@ -736,6 +797,11 @@ class RestApp(Bottle):<br>>     >   self.instance_handler = InstanceHandler(self, self.bus)<br>>     >  <br>>     >   def install_handlers(self):<br>>     > +                # Skip json response for signal handler because it<br>>     > requires to<br>>     > +                # return a gevent iterable which cannot be handled by<br>>     > json<br>>     > +                # response plugin<br>>     > +                self.signal_handler._skips =<br>>     > [self.json_response_plugin]  <br>>     Indenting?<br>>     > + self.signal_handler.install()<br>>     >   self.session_handler.install()<br>>     >   self.directory_handler.install()<br>>     >   self.list_names_handler.install()<br>>     > @@ -766,21 +832,48 @@ class RestApp(Bottle):<br>>     >   parts = filter(bool, path.split('/'))<br>>     >   request.environ['PATH_INFO'] = '/' + '/'.join(parts) + trailing<br>>     >  <br>>     > +class DbusSignal():<br>>     > +    def __init__(self, bus, dbus_interface, signal_name, path):<br>>     > +        # Register the dbus recieve handler<br>>     > +        bus.add_signal_receiver(self.signalReciever,<br>>     > +                                dbus_interface = dbus_interface,<br>>     > +                                signal_name = signal_name,<br>>     > +                                path = path)<br>>     > +<br>>     > +        self.snooping = True<br>>     > +<br>>     > +    def signalReciever(self, msg):<br>>     > +        self.send("Recieved message: %s" % msg)<br>>     > +        self.snooping = False<br>>     > +<br>>     > +    def onData(self, send):<br>>     > +        self.send = send<br>>     > +<br>>     > +    def onFinish(self, f):<br>>     > +        self.finish = f<br>>     > +<br>>     > +    def signalSnooping(self):<br>>     > +        while self.snooping:<br>>     > +            mainloop = gobject.MainLoop()<br>>     > +            gevent.sleep(1)<br>>     > +            gobject.timeout_add(1, mainloop.quit)<br>>     > +            mainloop.run()<br>>     > +<br>>     > +        self.finish()<br>>     > +<br>>     >  if __name__ == '__main__':<br>>     >   log = logging.getLogger('Rocket.Errors')<br>>     >   log.setLevel(logging.INFO)<br>>     >   log.addHandler(logging.StreamHandler(sys.stdout))<br>>     >  <br>>     > +        dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)  <br>>     Indenting?<br>>     >   bus = dbus.SystemBus()<br>>     >   app = RestApp(bus)<br>>     > +  <br>>     ?<br>>     >   default_cert = os.path.join(sys.prefix, 'share',<br>>     >   os.path.basename(__file__), 'cert.pem')<br>>     >  <br>>     > - server = Rocket(('0.0.0.0',<br>>     > - 443,<br>>     > - default_cert,<br>>     > - default_cert),<br>>     > - 'wsgi', {'wsgi_app': app},<br>>     > - min_threads = 1,<br>>     > - max_threads = 1)<br>>     > - server.start()<br>>     > +        server = WSGIServer(("0.0.0.0", 443), app, keyfile =<br>>     > default_cert,<br>>     > +                            certfile = default_cert)<br>>     > +<br>>     > +        server.serve_forever()  <br>>     Indenting?</font></tt><font size="4"><br><br></font><tt><font size="4"><br>_______________________________________________<br>openbmc mailing list<br>openbmc@lists.ozlabs.org</font></tt><tt><u><font size="4" color="#0000FF"><br></font></u></tt><a href="https://lists.ozlabs.org/listinfo/openbmc"><tt><u><font size="4" color="#0000FF">https://lists.ozlabs.org/listinfo/openbmc</font></u></tt></a><font size="4"><br><br><br></font><tt>_______________________________________________<br>openbmc mailing list<br>openbmc@lists.ozlabs.org<br></tt><tt><a href="https://lists.ozlabs.org/listinfo/openbmc">https://lists.ozlabs.org/listinfo/openbmc</a></tt><tt><br></tt><br><br><BR>
</body></html>