Home | History | Annotate | Download | only in talk
      1 # libjingle
      2 # Copyright 2013 Google Inc.
      3 #
      4 # Redistribution and use in source and binary forms, with or without
      5 # modification, are permitted provided that the following conditions are met:
      6 #
      7 #  1. Redistributions of source code must retain the above copyright notice,
      8 #     this list of conditions and the following disclaimer.
      9 #  2. Redistributions in binary form must reproduce the above copyright notice,
     10 #     this list of conditions and the following disclaimer in the documentation
     11 #     and/or other materials provided with the distribution.
     12 #  3. The name of the author may not be used to endorse or promote products
     13 #     derived from this software without specific prior written permission.
     14 #
     15 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     16 # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     17 # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
     18 # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     19 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     20 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     21 # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     22 # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     23 # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     24 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25 
     26 def _LicenseHeader(input_api):
     27   """Returns the license header regexp."""
     28   # Accept any year number from start of project to the current year
     29   current_year = int(input_api.time.strftime('%Y'))
     30   allowed_years = (str(s) for s in reversed(xrange(2004, current_year + 1)))
     31   years_re = '(' + '|'.join(allowed_years) + ')'
     32   years_re = '%s(--%s)?' % (years_re, years_re)
     33   license_header = (
     34       r'.*? libjingle\n'
     35       r'.*? Copyright %(year)s Google Inc\..*\n'
     36       r'.*?\n'
     37       r'.*? Redistribution and use in source and binary forms, with or without'
     38         r'\n'
     39       r'.*? modification, are permitted provided that the following conditions '
     40         r'are met:\n'
     41       r'.*?\n'
     42       r'.*? 1\. Redistributions of source code must retain the above copyright '
     43         r'notice,\n'
     44       r'.*?    this list of conditions and the following disclaimer\.\n'
     45       r'.*? 2\. Redistributions in binary form must reproduce the above '
     46         r'copyright notice,\n'
     47       r'.*?    this list of conditions and the following disclaimer in the '
     48         r'documentation\n'
     49       r'.*?    and/or other materials provided with the distribution\.\n'
     50       r'.*? 3\. The name of the author may not be used to endorse or promote '
     51         r'products\n'
     52       r'.*?    derived from this software without specific prior written '
     53         r'permission\.\n'
     54       r'.*?\n'
     55       r'.*? THIS SOFTWARE IS PROVIDED BY THE AUTHOR \`\`AS IS\'\' AND ANY '
     56         r'EXPRESS OR IMPLIED\n'
     57       r'.*? WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES '
     58         r'OF\n'
     59       r'.*? MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE '
     60         r'DISCLAIMED\. IN NO\n'
     61       r'.*? EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, '
     62         r'INCIDENTAL,\n'
     63       r'.*? SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES \(INCLUDING, '
     64         r'BUT NOT LIMITED TO,\n'
     65       r'.*? PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR '
     66         r'PROFITS;\n'
     67       r'.*? OR BUSINESS INTERRUPTION\) HOWEVER CAUSED AND ON ANY THEORY OF '
     68         r'LIABILITY,\n'
     69       r'.*? WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \(INCLUDING '
     70         r'NEGLIGENCE OR\n'
     71       r'.*? OTHERWISE\) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, '
     72         r'EVEN IF\n'
     73       r'.*? ADVISED OF THE POSSIBILITY OF SUCH DAMAGE\.\n'
     74   ) % {
     75       'year': years_re,
     76   }
     77   return license_header
     78 
     79 def _CommonChecks(input_api, output_api):
     80   """Checks common to both upload and commit."""
     81   results = []
     82   results.extend(input_api.canned_checks.CheckLicense(
     83       input_api, output_api, _LicenseHeader(input_api)))
     84   return results
     85 
     86 def CheckChangeOnUpload(input_api, output_api):
     87   results = []
     88   results.extend(_CommonChecks(input_api, output_api))
     89   return results
     90 
     91 def CheckChangeOnCommit(input_api, output_api):
     92   results = []
     93   results.extend(_CommonChecks(input_api, output_api))
     94   return results
     95