[
  {
    "path": ".gitignore",
    "content": "*.pyc\n*.egg-info\n.coverage\nbuild\ndist\n.tox\ndebian/.debhelper/**\ndebian/files\ndebian/pygtail/**\ndebian/tmp/**\ndebian/python-pygtail*\ndebian/python3-pygtail*\n.pybuild/\n"
  },
  {
    "path": ".travis.yml",
    "content": "language: python\npython:\n  - 2.7\n  - pypy\n  - 3.6\n  - 3.7\n  - 3.8\n  - 3.9\n  - 3.10\n  - 3.11\nscript: python setup.py test\n"
  },
  {
    "path": "LICENSE",
    "content": "                    GNU GENERAL PUBLIC LICENSE\n                       Version 2, June 1991\n\n Copyright (C) 1989, 1991 Free Software Foundation, Inc.,\n 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n                            Preamble\n\n  The licenses for most software are designed to take away your\nfreedom to share and change it.  By contrast, the GNU General Public\nLicense is intended to guarantee your freedom to share and change free\nsoftware--to make sure the software is free for all its users.  This\nGeneral Public License applies to most of the Free Software\nFoundation's software and to any other program whose authors commit to\nusing it.  (Some other Free Software Foundation software is covered by\nthe GNU Lesser General Public License instead.)  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthis service if you wish), that you receive source code or can get it\nif you want it, that you can change the software or use pieces of it\nin new free programs; and that you know you can do these things.\n\n  To protect your rights, we need to make restrictions that forbid\nanyone to deny you these rights or to ask you to surrender the rights.\nThese restrictions translate to certain responsibilities for you if you\ndistribute copies of the software, or if you modify it.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must give the recipients all the rights that\nyou have.  You must make sure that they, too, receive or can get the\nsource code.  And you must show them these terms so they know their\nrights.\n\n  We protect your rights with two steps: (1) copyright the software, and\n(2) offer you this license which gives you legal permission to copy,\ndistribute and/or modify the software.\n\n  Also, for each author's protection and ours, we want to make certain\nthat everyone understands that there is no warranty for this free\nsoftware.  If the software is modified by someone else and passed on, we\nwant its recipients to know that what they have is not the original, so\nthat any problems introduced by others will not reflect on the original\nauthors' reputations.\n\n  Finally, any free program is threatened constantly by software\npatents.  We wish to avoid the danger that redistributors of a free\nprogram will individually obtain patent licenses, in effect making the\nprogram proprietary.  To prevent this, we have made it clear that any\npatent must be licensed for everyone's free use or not licensed at all.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\n                    GNU GENERAL PUBLIC LICENSE\n   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n\n  0. This License applies to any program or other work which contains\na notice placed by the copyright holder saying it may be distributed\nunder the terms of this General Public License.  The \"Program\", below,\nrefers to any such program or work, and a \"work based on the Program\"\nmeans either the Program or any derivative work under copyright law:\nthat is to say, a work containing the Program or a portion of it,\neither verbatim or with modifications and/or translated into another\nlanguage.  (Hereinafter, translation is included without limitation in\nthe term \"modification\".)  Each licensee is addressed as \"you\".\n\nActivities other than copying, distribution and modification are not\ncovered by this License; they are outside its scope.  The act of\nrunning the Program is not restricted, and the output from the Program\nis covered only if its contents constitute a work based on the\nProgram (independent of having been made by running the Program).\nWhether that is true depends on what the Program does.\n\n  1. You may copy and distribute verbatim copies of the Program's\nsource code as you receive it, in any medium, provided that you\nconspicuously and appropriately publish on each copy an appropriate\ncopyright notice and disclaimer of warranty; keep intact all the\nnotices that refer to this License and to the absence of any warranty;\nand give any other recipients of the Program a copy of this License\nalong with the Program.\n\nYou may charge a fee for the physical act of transferring a copy, and\nyou may at your option offer warranty protection in exchange for a fee.\n\n  2. You may modify your copy or copies of the Program or any portion\nof it, thus forming a work based on the Program, and copy and\ndistribute such modifications or work under the terms of Section 1\nabove, provided that you also meet all of these conditions:\n\n    a) You must cause the modified files to carry prominent notices\n    stating that you changed the files and the date of any change.\n\n    b) You must cause any work that you distribute or publish, that in\n    whole or in part contains or is derived from the Program or any\n    part thereof, to be licensed as a whole at no charge to all third\n    parties under the terms of this License.\n\n    c) If the modified program normally reads commands interactively\n    when run, you must cause it, when started running for such\n    interactive use in the most ordinary way, to print or display an\n    announcement including an appropriate copyright notice and a\n    notice that there is no warranty (or else, saying that you provide\n    a warranty) and that users may redistribute the program under\n    these conditions, and telling the user how to view a copy of this\n    License.  (Exception: if the Program itself is interactive but\n    does not normally print such an announcement, your work based on\n    the Program is not required to print an announcement.)\n\nThese requirements apply to the modified work as a whole.  If\nidentifiable sections of that work are not derived from the Program,\nand can be reasonably considered independent and separate works in\nthemselves, then this License, and its terms, do not apply to those\nsections when you distribute them as separate works.  But when you\ndistribute the same sections as part of a whole which is a work based\non the Program, the distribution of the whole must be on the terms of\nthis License, whose permissions for other licensees extend to the\nentire whole, and thus to each and every part regardless of who wrote it.\n\nThus, it is not the intent of this section to claim rights or contest\nyour rights to work written entirely by you; rather, the intent is to\nexercise the right to control the distribution of derivative or\ncollective works based on the Program.\n\nIn addition, mere aggregation of another work not based on the Program\nwith the Program (or with a work based on the Program) on a volume of\na storage or distribution medium does not bring the other work under\nthe scope of this License.\n\n  3. You may copy and distribute the Program (or a work based on it,\nunder Section 2) in object code or executable form under the terms of\nSections 1 and 2 above provided that you also do one of the following:\n\n    a) Accompany it with the complete corresponding machine-readable\n    source code, which must be distributed under the terms of Sections\n    1 and 2 above on a medium customarily used for software interchange; or,\n\n    b) Accompany it with a written offer, valid for at least three\n    years, to give any third party, for a charge no more than your\n    cost of physically performing source distribution, a complete\n    machine-readable copy of the corresponding source code, to be\n    distributed under the terms of Sections 1 and 2 above on a medium\n    customarily used for software interchange; or,\n\n    c) Accompany it with the information you received as to the offer\n    to distribute corresponding source code.  (This alternative is\n    allowed only for noncommercial distribution and only if you\n    received the program in object code or executable form with such\n    an offer, in accord with Subsection b above.)\n\nThe source code for a work means the preferred form of the work for\nmaking modifications to it.  For an executable work, complete source\ncode means all the source code for all modules it contains, plus any\nassociated interface definition files, plus the scripts used to\ncontrol compilation and installation of the executable.  However, as a\nspecial exception, the source code distributed need not include\nanything that is normally distributed (in either source or binary\nform) with the major components (compiler, kernel, and so on) of the\noperating system on which the executable runs, unless that component\nitself accompanies the executable.\n\nIf distribution of executable or object code is made by offering\naccess to copy from a designated place, then offering equivalent\naccess to copy the source code from the same place counts as\ndistribution of the source code, even though third parties are not\ncompelled to copy the source along with the object code.\n\n  4. You may not copy, modify, sublicense, or distribute the Program\nexcept as expressly provided under this License.  Any attempt\notherwise to copy, modify, sublicense or distribute the Program is\nvoid, and will automatically terminate your rights under this License.\nHowever, parties who have received copies, or rights, from you under\nthis License will not have their licenses terminated so long as such\nparties remain in full compliance.\n\n  5. You are not required to accept this License, since you have not\nsigned it.  However, nothing else grants you permission to modify or\ndistribute the Program or its derivative works.  These actions are\nprohibited by law if you do not accept this License.  Therefore, by\nmodifying or distributing the Program (or any work based on the\nProgram), you indicate your acceptance of this License to do so, and\nall its terms and conditions for copying, distributing or modifying\nthe Program or works based on it.\n\n  6. Each time you redistribute the Program (or any work based on the\nProgram), the recipient automatically receives a license from the\noriginal licensor to copy, distribute or modify the Program subject to\nthese terms and conditions.  You may not impose any further\nrestrictions on the recipients' exercise of the rights granted herein.\nYou are not responsible for enforcing compliance by third parties to\nthis License.\n\n  7. If, as a consequence of a court judgment or allegation of patent\ninfringement or for any other reason (not limited to patent issues),\nconditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot\ndistribute so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you\nmay not distribute the Program at all.  For example, if a patent\nlicense would not permit royalty-free redistribution of the Program by\nall those who receive copies directly or indirectly through you, then\nthe only way you could satisfy both it and this License would be to\nrefrain entirely from distribution of the Program.\n\nIf any portion of this section is held invalid or unenforceable under\nany particular circumstance, the balance of the section is intended to\napply and the section as a whole is intended to apply in other\ncircumstances.\n\nIt is not the purpose of this section to induce you to infringe any\npatents or other property right claims or to contest validity of any\nsuch claims; this section has the sole purpose of protecting the\nintegrity of the free software distribution system, which is\nimplemented by public license practices.  Many people have made\ngenerous contributions to the wide range of software distributed\nthrough that system in reliance on consistent application of that\nsystem; it is up to the author/donor to decide if he or she is willing\nto distribute software through any other system and a licensee cannot\nimpose that choice.\n\nThis section is intended to make thoroughly clear what is believed to\nbe a consequence of the rest of this License.\n\n  8. If the distribution and/or use of the Program is restricted in\ncertain countries either by patents or by copyrighted interfaces, the\noriginal copyright holder who places the Program under this License\nmay add an explicit geographical distribution limitation excluding\nthose countries, so that distribution is permitted only in or among\ncountries not thus excluded.  In such case, this License incorporates\nthe limitation as if written in the body of this License.\n\n  9. The Free Software Foundation may publish revised and/or new versions\nof the General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\nEach version is given a distinguishing version number.  If the Program\nspecifies a version number of this License which applies to it and \"any\nlater version\", you have the option of following the terms and conditions\neither of that version or of any later version published by the Free\nSoftware Foundation.  If the Program does not specify a version number of\nthis License, you may choose any version ever published by the Free Software\nFoundation.\n\n  10. If you wish to incorporate parts of the Program into other free\nprograms whose distribution conditions are different, write to the author\nto ask for permission.  For software which is copyrighted by the Free\nSoftware Foundation, write to the Free Software Foundation; we sometimes\nmake exceptions for this.  Our decision will be guided by the two goals\nof preserving the free status of all derivatives of our free software and\nof promoting the sharing and reuse of software generally.\n\n                            NO WARRANTY\n\n  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY\nFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN\nOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES\nPROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED\nOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\nMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS\nTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE\nPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,\nREPAIR OR CORRECTION.\n\n  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR\nREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,\nINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING\nOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED\nTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY\nYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER\nPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE\nPOSSIBILITY OF SUCH DAMAGES.\n\n                     END OF TERMS AND CONDITIONS\n\n            How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nconvey the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This program is free software; you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation; either version 2 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License along\n    with this program; if not, write to the Free Software Foundation, Inc.,\n    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n\nAlso add information on how to contact you by electronic and paper mail.\n\nIf the program is interactive, make it output a short notice like this\nwhen it starts in an interactive mode:\n\n    Gnomovision version 69, Copyright (C) year name of author\n    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, the commands you use may\nbe called something other than `show w' and `show c'; they could even be\nmouse-clicks or menu items--whatever suits your program.\n\nYou should also get your employer (if you work as a programmer) or your\nschool, if any, to sign a \"copyright disclaimer\" for the program, if\nnecessary.  Here is a sample; alter the names:\n\n  Yoyodyne, Inc., hereby disclaims all copyright interest in the program\n  `Gnomovision' (which makes passes at compilers) written by James Hacker.\n\n  <signature of Ty Coon>, 1 April 1989\n  Ty Coon, President of Vice\n\nThis General Public License does not permit incorporating your program into\nproprietary programs.  If your program is a subroutine library, you may\nconsider it more useful to permit linking proprietary applications with the\nlibrary.  If this is what you want to do, use the GNU Lesser General\nPublic License instead of this License."
  },
  {
    "path": "README.md",
    "content": "pygtail\n=======\n\nA python \"port\" of [logcheck's logtail2](http://logcheck.org).\n\nPygtail reads log file lines that have not been read. It will even handle log\nfiles that have been rotated.\n\nUsage\n-----\n\nFrom the command line:\n\n    Usage: pygtail.py [options] logfile\n\n    Print log file lines that have not been read.\n\n    Options:\n      -h, --help            show this help message and exit\n      -o OFFSET_FILE, --offset-file=OFFSET_FILE\n                            File to which offset data is written (default:\n                            <logfile>.offset).\n      -p, --paranoid        Update the offset file every time we read a line\n                            (as opposed to only when we reach the end of the\n                            file).\n      -n N, --every-n=N     Update the offset file every N'th time we read a\n                            line (as opposed to only when we reach the end of\n                            the file).\n      --no-copytruncate     Don't support copytruncate-style log rotation.\n                            Instead, if the log file shrinks, print a warning.\n      --read-from-end       Read log file from the end if offset file is\n                            missing. Useful for large files.\n      --log-pattern         Custom log rotation glob pattern. Use %s to\n                            represent the original filename. You may use this\n                            multiple times to provide multiple patterns.\n      --full_lines          Only log when line ends in a newline `\\n`\n                            (default: False)\n      --encoding ENCODING   Encoding to use for reading files (default: system\n                            encoding)\n      --version             Print version and exit.\n\nIn your code:\n\n```python\nfrom pygtail import Pygtail\n\nfor line in Pygtail(\"some.log\"):\n    sys.stdout.write(line)\n```\n\nAn example showing iterating over lines with offsets and manual control over offset updates:\n\n```python\nimport pygtail\n\ntail = pygtail.Pygtail(logfile, save_on_end=False, copytruncate=False)\n\nfor line, offset in tail.with_offsets():\n    # Do someting\n\n # figure out right offset to save\n tail.write_offset_to_file(right_offset)\n```\n\nContributing\n------------\n\nPull requests are very much welcome, but I will not merge your changes if you don't include a test. Run tests with `python setup.py test`.\n\nBuild status\n------------\n\n[![Build Status](https://secure.travis-ci.org/bgreenlee/pygtail.png)](http://travis-ci.org/bgreenlee/pygtail)\n\n\n"
  },
  {
    "path": "README.txt",
    "content": "pygtail\n=======\n\nA python \"port\" of `logcheck's logtail2 <http://logcheck.org>`__.\n\nPygtail reads log file lines that have not been read. It will even\nhandle log files that have been rotated.\n\nUsage\n-----\n\nFrom the command line:\n\n::\n\n    Usage: pygtail.py [options] logfile\n\n    Print log file lines that have not been read.\n\n    Options:\n      -h, --help            show this help message and exit\n      -o OFFSET_FILE, --offset-file=OFFSET_FILE\n                            File to which offset data is written (default:\n                            <logfile>.offset).\n      -p, --paranoid        Update the offset file every time we read a line\n                            (as opposed to only when we reach the end of the\n                            file).\n      -n N, --every-n=N     Update the offset file every N'th time we read a\n                            line (as opposed to only when we reach the end of\n                            the file).\n      --no-copytruncate     Don't support copytruncate-style log rotation.\n                            Instead, if the log file shrinks, print a warning.\n      --read-from-end       Read log file from the end if offset file is\n                            missing. Useful for large files.\n      --log-pattern         Custom log rotation glob pattern. Use %s to\n                            represent the original filename. You may use this\n                            multiple times to provide multiple patterns.\n      --full_lines          Only log when line ends in a newline `\\n`\n                            (default: False)\n      --encoding ENCODING   Encoding to use for reading files (default: system\n                            encoding)\n      --version             Print version and exit.\n\nIn your code:\n\n.. code:: python\n\n    from pygtail import Pygtail\n\n    for line in Pygtail(\"some.log\"):\n        sys.stdout.write(line)\n\n\nAn example showing iterating over lines with offsets and manual control over offset updates:\n\n.. code:: python\n\n    import pygtail\n\n    tail = pygtail.Pygtail(logfile, save_on_end=False, copytruncate=False)\n\n    for line, offset in tail.with_offsets():\n        # Do someting\n\n    # figure out right offset to save\n    tail.write_offset_to_file(right_offset)\n\n\nContributing\n------------\n\nPull requests are very much welcome, but I will not merge your changes if you don't include a test. Run tests with `python setup.py test`.\n\nBuild status\n------------\n\n|Build Status|\n\n.. |Build Status| image:: https://secure.travis-ci.org/bgreenlee/pygtail.png\n   :target: http://travis-ci.org/bgreenlee/pygtail\n"
  },
  {
    "path": "debian/changelog",
    "content": "pygtail (0.14.0) lucid; urgency=low\n\n  * Added with_offsets iterator and write_offset_to_file method. (thanks @pajowu!)\n  * Included LICENSE file in distribution.\n\n -- Brad Greenlee <brad@footle.org>  Sun, 6 Nov 2022 06:48:00 -0800\n\npygtail (0.13.0) lucid; urgency=low\n\n  * Add option to set the file encoding. (thanks @Robert-Lebedeu and @ondrej-bouda!)\n  * Add test for renamecreate when file is rotated to unknown name and pygtail is freshly reading file (thanks @arekm!)\n  * Add support for failing test proposed in #42\n\n -- Brad Greenlee <brad@footle.org>  Sun, 30 Oct 2022 11:48:00 -0700\n\n pygtail (0.12.0) lucid; urgency=low\n\n  * Add option to disable save on end. (thanks @pajowu!)\n\n -- Brad Greenlee <brad@footle.org>  Thu, 14 Apr 2022 08:31:00 -0700\n\npygtail (0.11.1) lucid; urgency=low\n\n  * Update debian packaging\n\n -- Sebastien GALLET <bibi21000@gmail.com>  Mon, 11 Oct 2019 11:30:00 +0100\n\npygtail (0.11.0) lucid; urgency=low\n\n  * Add option to only log lines ending in a newline (thanks @MDunitz!)\n\n -- Brad Greenlee <brad@footle.org>  Tue, 16 Jul 2019 05:12:00 -0700\n\npygtail (0.10.1) lucid; urgency=low\n\n  * Fix keyword argument mismatch (thanks @ushuz!)\n\n -- Brad Greenlee <brad@footle.org>  Mon, 04 Mar 2019 22:18:00 -0800\n\npygtail (0.10.0) lucid; urgency=low\n\n  * Add --log-pattern flag to allow for custom rotated log filename patterns. (thanks @silenben)\n\n -- Brad Greenlee <brad@footle.org> Tue, 20 Nov 2018 04:48:00 -0800\n\npygtail (0.9.0) lucid; urgency=low\n\n  * Add --read-from-end flag to read the log file from the end if the offset file is missing. (thanks Dmitry Sytsko)\n\n -- Brad Greenlee <brad@footle.org> Thu, 02 Aug 2018 16:52:00 -0700\n\npygtail (0.8.0) lucid; urgency=low\n\n  * Add handling for \"renamecreate\" semantics where the currently processed file gets renamed and the\n    original file gets recreated. This is the behavior of certain logfile rollers such as\n    TimeBasedRollingPolicy in Java's Logback library. (thanks @bobtiernay-okta)\n\n -- Brad Greenlee <brad@footle.org>  Sat, 10 Mar 2018 08:39:18 -0800\n\npygtail (0.7.0) lucid; urgency=low\n\n  * Add handling for logrotate dateext dateformat -%Y%m%d-%s log files, with and without\n    delaycompress (thanks @akashawasthi)\n\n -- Brad Greenlee <brad@footle.org>  Thu, 30 Jun 2016 20:25:05 -0700\n\npygtail (0.6.1) lucid; urgency=low\n\n  * Enable line buffering to avoid reading incomplete lines (thanks @olystretch)\n\n -- Brad Greenlee <brad@footle.org>  Thu, 05 Nov 2015 20:13:52 -0800\n\npygtail (0.6.0) lucid; urgency=low\n\n  * Added flag to write offset file only after every n lines, and ability to optionally call a\n    function whenever the offset file is written (thanks @btilly)\n\n -- Brad Greenlee <brad@footle.org>  Thu, 08 Oct 2015 05:19:19 -0700\n\npygtail (0.5.3) lucid; urgency=low\n\n  * Fixed Python 3 compatibility (thanks @sbraz)\n\n -- Brad Greenlee <brad@footle.org>  Thu, 16 Apr 2015 17:30:43 -0700\n\npygtail (0.5.2) lucid; urgency=medium\n\n  * Fixed issue with potentially incorrect offset due to python's read-ahead buffer (thanks @czchen)\n\n -- Brad Greenlee <brad@footle.org>  Thu, 26 Mar 2015 09:10:36 -0400\n\npygtail (0.5.1) lucid; urgency=low\n\n  * Fixed print statement to be Python 3 compatible (thanks @benburry)\n\n -- Brad Greenlee <brad@footle.org>  Fri, 4 Jan 2015 20:36:00 -0800\n\npygtail (0.5.0) lucid; urgency=low\n\n  * Add handling of rotated and immediately compressed files (thanks @NotSqrt)\n\n -- Brad Greenlee <brad@footle.org>  Fri, 17 Oct 2014 09:39:00 -0700\n\npygtail (0.4.0) lucid; urgency=low\n\n  * Make support for copytruncate log rotation the default.\n  * Add --no-copytruncate commandline switch.\n  * Print warning if copytruncate is disabled and the log file shrinks\n\n -- Brad Greenlee <brad@footle.org>  Fri, 9 May 2014 17:31:00 -0700\n\npygtail (0.3.0) lucid; urgency=low\n\n  * Add support for copytruncate style logrotation (contributed by https://github.com/atward)\n\n -- Brad Greenlee <brad@footle.org>  Fri, 9 May 2014 16:00:00 -0700\n\npygtail (0.2.2) lucid; urgency=low\n\n  * Add parsing support for python's TimedRotatingFileHandler (contributed by https://github.com/darknight)\n\n -- Brad Greenlee <brad@footle.org>  Wed, 21 Aug 2013 15:50:00 -0700\n\npygtail (0.2.1) lucid; urgency=low\n\n  * Add ReStructuredText README for PyPi.\n\n -- Brad Greenlee <brad@footle.org>  Wed, 06 Jul 2011 12:37:08 -0700\n\npygtail (0.2) lucid; urgency=low\n\n  * Add setup.py and debianize.\n\n -- Brad Greenlee <brad@footle.org>  Wed, 05 Jul 2011 15:04:42 -0700\n"
  },
  {
    "path": "debian/compat",
    "content": "7\n"
  },
  {
    "path": "debian/control",
    "content": "Source: pygtail\nSection: python\nPriority: optional\nMaintainer: Brad Greenlee <brad@footle.org>\nBuild-Depends: debhelper (>= 7)\nBuild-Depends-Indep: dh-python, python-all, python-setuptools,\n python3-all, python3-setuptools\nStandards-Version: 3.8.3\nHomepage: http://github.com/bgreenlee/pygtail\n\nPackage: python-pygtail\nArchitecture: all\nDepends: ${python:Depends}, ${misc:Depends}\nDescription: Reads log file lines that have not been read. (Python 2)\n Pygtail reads log file lines that have not been read. It will even\n handle log files that have been rotated.\n .\n This package installs the program for Python 2.\n\nPackage: python3-pygtail\nArchitecture: all\nDepends: ${python3:Depends}, ${misc:Depends}\nDescription: Reads log file lines that have not been read. (Python 3)\n Pygtail reads log file lines that have not been read. It will even\n handle log files that have been rotated.\n .\n This package installs the program for Python 3.\n"
  },
  {
    "path": "debian/copyright",
    "content": "Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/\nUpstream-Name: pygtail\nUpstream-Contact: Brad Greenlee <brad@footle.org>\nSource: https://github.com/bgreenlee/pygtail\n\nFiles: *\nCopyright: 2011 Brad Greenlee <brad@footle.org>\nLicense: GPL v2\n http://www.gnu.org/licenses/gpl-2.0.html\n"
  },
  {
    "path": "debian/rules",
    "content": "#!/usr/bin/make -f\n\n#export DH_VERBOSE = 1\nexport PYBUILD_NAME = pygtail\n\n%:\n\tdh $@ --with python2,python3 --buildsystem=pybuild\n\t\t\n#~ override_dh_auto_test:\n#~ \tdh_auto_test\n#~ \tset -ex; cd pygtail && for python in $(PYTHON3_VERSIONS) $(PYTHON2_VERSIONS); do \\\n#~ \t\t\t$$python test/test_pygtail.py; \\\n#~ \tdone\n"
  },
  {
    "path": "debian/source/format",
    "content": "1.0\n"
  },
  {
    "path": "makedoc.sh",
    "content": "#!/bin/bash\n\npandoc -f markdown -t rst -o README.txt README.md\n"
  },
  {
    "path": "pygtail/__init__.py",
    "content": "from pygtail.core import __version__\nfrom pygtail.core import Pygtail\n"
  },
  {
    "path": "pygtail/core.py",
    "content": "#!/usr/bin/python -tt\n# -*- coding: utf-8 -*-\n\n# pygtail - a python \"port\" of logtail2\n# Copyright (C) 2011 Brad Greenlee <brad@footle.org>\n#\n# Derived from logcheck <http://logcheck.org>\n# Copyright (C) 2003 Jonathan Middleton <jjm@ixtab.org.uk>\n# Copyright (C) 2001 Paul Slootman <paul@debian.org>\n#\n# This program is free software; you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation; either version 2 of the License, or\n# (at your option) any later version.\n#\n# This program is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License\n# along with this program; if not, write to the Free Software\n# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n\nfrom __future__ import print_function\nfrom os import fstat, stat\nimport os\nfrom os.path import exists, getsize\nimport sys\nimport glob\nimport gzip\nimport io\nfrom optparse import OptionParser\n\n__version__ = '0.14.0'\n\n\nPY3 = sys.version_info[0] == 3\n\nif PY3:\n    text_type = str\nelse:\n    text_type = unicode\n\n\ndef force_text(s, encoding='utf-8', errors='strict'):\n    if isinstance(s, text_type):\n        return s\n    return s.decode(encoding, errors)\n\n\nclass Offset:\n    \"\"\"Data-class to store file-offsets\"\"\"\n\n    def __init__(self, counter, inode, offset):\n        self.counter = counter\n        self.inode = inode\n        self.offset = offset\n\n    def __eq__(self, other):\n        return self.counter == other.counter and self.offset == other.offset\n\n    def __lt__(self, other):\n        return self.counter < other.counter or (\n            self.counter == other.counter and self.offset < other.offset\n        )\n\n    def __le__(self, other):\n        return self.__lt__(other) or self.__eq__(other)\n\n    def __gt__(self, other):\n        return not self.__le__(other)\n\n    def __ge__(self, other):\n        return not self.__le__(other) or self.__eq__(other)\n\n    def __repr__(self):\n        return \"Offset(counter=%d, inode=%d, offset=%d\" % (\n            self.counter,\n            self.inode,\n            self.offset,\n        )\n\n\nclass PygtailIteratorWithOffsets:\n    def __init__(self, pygtail):\n        self._pygtail = pygtail\n\n    def __next__(self):\n        return self.next()\n\n    def __iter__(self):\n        return self\n\n    def next(self):\n        next_line = self._pygtail.next()\n        offset = self._pygtail._filehandle().tell()\n        inode = fstat(self._pygtail._filehandle().fileno()).st_ino\n        counter = self._pygtail._counter\n        offset_instance = Offset(counter, inode, offset)\n        return next_line, offset_instance\n\n\nclass Pygtail(object):\n    \"\"\"\n    Creates an iterable object that returns only unread lines.\n\n    Keyword arguments:\n    offset_file   File to which offset data is written (default: <logfile>.offset).\n    paranoid      Update the offset file every time we read a line (as opposed to\n                  only when we reach the end of the file (default: False))\n    every_n       Update the offset file every n'th line (as opposed to only when\n                  we reach the end of the file (default: 0))\n    on_update     Execute this function when offset data is written (default False)\n    copytruncate  Support copytruncate-style log rotation (default: True)\n    log_patterns  List of custom rotated log patterns to match (default: None)\n    full_lines    Only log when line ends in a newline `\\n` (default: False)\n    save_on_end   Automatically save the offset once the end of the file is reached (default: True)\n    \"\"\"\n    def __init__(self, filename, offset_file=None, paranoid=False, copytruncate=True,\n                 every_n=0, on_update=False, read_from_end=False, log_patterns=None, full_lines=False,\n                 save_on_end=True, encoding=None):\n        self.filename = filename\n        self.paranoid = paranoid\n        self.every_n = every_n\n        self.on_update = on_update\n        self.copytruncate = copytruncate\n        self.read_from_end = read_from_end\n        self.log_patterns = log_patterns\n        self.full_lines = full_lines\n        self.save_on_end = save_on_end\n        self.encoding = encoding\n        self.offset_file = offset_file or \"%s.offset\" % self.filename\n        self.offset_file_inode = 0\n        self.offset = 0\n        self.since_update = 0\n        self.fh = None\n        self.rotated_logfile = None\n        self._counter = 0\n\n        # if offset file exists and non-empty, open and parse it\n        if exists(self.offset_file) and getsize(self.offset_file):\n            offset_fh = open(self.offset_file, \"r\")\n            (self.offset_file_inode, self.offset) = \\\n                [int(line.strip()) for line in offset_fh]\n            offset_fh.close()\n            if self.offset_file_inode != stat(self.filename).st_ino or \\\n                    stat(self.filename).st_size < self.offset:\n                # The inode has changed or filesize has reduced so the file\n                # might have been rotated.\n                # Look for the rotated file and process that if we find it.\n                self.rotated_logfile = self._determine_rotated_logfile()\n                # If copytruncate is enabled and we can't find the rotated logfile, all we can do is reset.\n                if self.copytruncate and self.rotated_logfile is None:\n                    sys.stderr.write(\"[pygtail] [WARN] log file was rotated to unknown location. Resetting.\\n\")\n                    self.offset = 0\n                    self.update_offset_file()\n\n\n    def __del__(self):\n        if self._filehandle():\n            self._filehandle().close()\n\n    def __iter__(self):\n        return self\n\n    def next(self):\n        \"\"\"\n        Return the next line in the file, updating the offset.\n        \"\"\"\n        try:\n            line = self._get_next_line()\n        except StopIteration:\n            # we've reached the end of the file; if we're processing the\n            # rotated log file or the file has been renamed, we can continue with the actual file; otherwise\n            # update the offset file\n            if self._is_new_file():\n                self.rotated_logfile = None\n                self.fh.close()\n                self.offset = 0\n                # open up current logfile and continue\n                try:\n                    line = self._get_next_line()\n                except StopIteration:  # oops, empty file\n                    if self.save_on_end:\n                        self.update_offset_file()\n                    raise\n            else:\n                if self.save_on_end:\n                    self.update_offset_file()\n                raise\n\n        if self.paranoid:\n            self.update_offset_file()\n        elif self.every_n and self.every_n <= self.since_update:\n            self.update_offset_file()\n\n        return line\n\n    def with_offsets(self):\n        \"\"\"Returns an iterator that yields lines with their internal offset state\"\"\"\n        return PygtailIteratorWithOffsets(self)\n\n    def __next__(self):\n        \"\"\"`__next__` is the Python 3 version of `next`\"\"\"\n        return self.next()\n\n    def readlines(self):\n        \"\"\"\n        Read in all unread lines and return them as a list.\n        \"\"\"\n        return [line for line in self]\n\n    def read(self):\n        \"\"\"\n        Read in all unread lines and return them as a single string.\n        \"\"\"\n        lines = self.readlines()\n        if lines:\n            try:\n                return ''.join(lines)\n            except TypeError:\n                return ''.join(force_text(line) for line in lines)\n        else:\n            return None\n\n    def _is_closed(self):\n        if not self.fh:\n            return True\n        try:\n            return self.fh.closed\n        except AttributeError:\n            if isinstance(self.fh, gzip.GzipFile):\n                # python 2.6\n                return self.fh.fileobj is None\n            else:\n                raise\n\n    def _filehandle(self):\n        \"\"\"\n        Return a filehandle to the file being tailed, with the position set\n        to the current offset.\n        \"\"\"\n        if not self.fh or self._is_closed():\n            self._counter += 1\n            filename = self.rotated_logfile or self.filename\n            if filename.endswith('.gz'):\n                self.fh = gzip.open(filename, 'r')\n            elif PY3:\n                self.fh = open(filename, \"r\", 1, encoding=self.encoding)\n            else:\n                self.fh = io.open(filename, \"r\", 1, encoding=self.encoding)\n            if self.read_from_end and not exists(self.offset_file):\n                self.fh.seek(0, os.SEEK_END)\n            else:\n                self.fh.seek(self.offset)\n\n        return self.fh\n\n    def update_offset_file(self):\n        \"\"\"\n        Update the offset file with the current inode and offset.\n        \"\"\"\n        if self.on_update:\n            self.on_update()\n        tmp_filename = self.offset_file + \".tmp\"\n        offset = self._filehandle().tell()\n        inode = fstat(self._filehandle().fileno()).st_ino\n        fh = open(tmp_filename, \"w\")\n        fh.write(\"%s\\n%s\\n\" % (inode, offset))\n        fh.close()\n        os.rename(tmp_filename, self.offset_file)  # atomic file update, safer\n        self.since_update = 0\n\n    def write_offset_to_file(self, offset):\n        \"\"\"Writes an `Offset` to the offset file\"\"\"\n        if self.on_update:\n            self.on_update()\n        fh = open(self.offset_file, \"w\")\n        fh.write(\"%s\\n%s\\n\" % (offset.inode, offset.offset))\n        fh.close()\n\n    def _determine_rotated_logfile(self):\n        \"\"\"\n        We suspect the logfile has been rotated, so try to guess what the\n        rotated filename is, and return it.\n        \"\"\"\n        rotated_filename = self._check_rotated_filename_candidates()\n        if rotated_filename and exists(rotated_filename):\n            if stat(rotated_filename).st_ino == self.offset_file_inode:\n                return rotated_filename\n\n            # if the inode hasn't changed, then the file shrank; this is expected with copytruncate,\n            # otherwise print a warning\n            if stat(self.filename).st_ino == self.offset_file_inode:\n                if self.copytruncate:\n                    return rotated_filename\n                else:\n                    sys.stderr.write(\n                        \"[pygtail] [WARN] file size of %s shrank, and copytruncate support is \"\n                        \"disabled (expected at least %d bytes, was %d bytes).\\n\" %\n                        (self.filename, self.offset, stat(self.filename).st_size))\n\n        return None\n\n    def _check_rotated_filename_candidates(self):\n        \"\"\"\n        Check for various rotated logfile filename patterns and return the first\n        match we find.\n        \"\"\"\n        # savelog(8)\n        candidate = \"%s.0\" % self.filename\n        if (exists(candidate) and exists(\"%s.1.gz\" % self.filename) and\n            (stat(candidate).st_mtime > stat(\"%s.1.gz\" % self.filename).st_mtime)):\n            return candidate\n\n        # logrotate(8)\n        # with delaycompress\n        candidate = \"%s.1\" % self.filename\n        if exists(candidate):\n            return candidate\n\n        # without delaycompress\n        candidate = \"%s.1.gz\" % self.filename\n        if exists(candidate):\n            return candidate\n\n        rotated_filename_patterns = [\n            # logrotate dateext rotation scheme - `dateformat -%Y%m%d` + with `delaycompress`\n            \"%s-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\",\n            # logrotate dateext rotation scheme - `dateformat -%Y%m%d` + without `delaycompress`\n            \"%s-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].gz\",\n            # logrotate dateext rotation scheme - `dateformat -%Y%m%d-%s` + with `delaycompress`\n            \"%s-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\",\n            # logrotate dateext rotation scheme - `dateformat -%Y%m%d-%s` + without `delaycompress`\n            \"%s-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].gz\",\n            # for TimedRotatingFileHandler\n            \"%s.[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]\",\n        ]\n        if self.log_patterns:\n            rotated_filename_patterns.extend(self.log_patterns)\n\n        # break into directory and filename components to support cases where the\n        # the file is prepended as part of rotation\n        file_dir, rel_filename = os.path.split(self.filename)\n        for rotated_filename_pattern in rotated_filename_patterns:\n            candidates = glob.glob(os.path.join(file_dir, rotated_filename_pattern % rel_filename))\n            if candidates:\n                candidates.sort()\n                return candidates[-1]  # return most recent\n\n        # no match\n        return None\n\n    def _is_new_file(self):\n        # Processing rotated logfile or at the end of current file which has been renamed\n        return self.rotated_logfile or \\\n               self._filehandle().tell() == fstat(self._filehandle().fileno()).st_size and \\\n               fstat(self._filehandle().fileno()).st_ino != stat(self.filename).st_ino\n\n    def _get_next_line(self):\n        curr_offset = self._filehandle().tell()\n        line = self._filehandle().readline()\n        if self.full_lines:\n            if not line.endswith('\\n'):\n                self._filehandle().seek(curr_offset)\n                raise StopIteration\n        if not line:\n            raise StopIteration\n        self.since_update += 1\n        return line\n\n\ndef main():\n    # command-line parsing\n    cmdline = OptionParser(usage=\"usage: %prog [options] logfile\",\n        description=\"Print log file lines that have not been read.\")\n    cmdline.add_option(\"--offset-file\", \"-o\", action=\"store\",\n        help=\"File to which offset data is written (default: <logfile>.offset).\")\n    cmdline.add_option(\"--paranoid\", \"-p\", action=\"store_true\",\n        help=\"Update the offset file every time we read a line (as opposed to\"\n             \" only when we reach the end of the file).\")\n    cmdline.add_option(\"--every-n\", \"-n\", action=\"store\",\n        help=\"Update the offset file every n'th time we read a line (as opposed to\"\n             \" only when we reach the end of the file).\")\n    cmdline.add_option(\"--no-copytruncate\", action=\"store_true\",\n        help=\"Don't support copytruncate-style log rotation. Instead, if the log file\"\n             \" shrinks, print a warning.\")\n    cmdline.add_option(\"--read-from-end\", action=\"store_true\",\n        help=\"Read log file from the end if offset file is missing. Useful for large files.\")\n    cmdline.add_option(\"--log-pattern\", action=\"append\",\n        help=\"Custom log rotation glob pattern. Use %s to represent the original filename.\"\n             \" You may use this multiple times to provide multiple patterns.\")\n    cmdline.add_option(\"--full_lines\", action=\"store_true\",\n                       help=\"Only log when line ends in a newline (\\\\n)\")\n    cmdline.add_option(\"--encoding\", action=\"store\",\n        help=\"Encoding to use for reading files (default: system encoding)\")\n    cmdline.add_option(\"--version\", action=\"store_true\",\n        help=\"Print version and exit.\")\n\n    options, args = cmdline.parse_args()\n\n    if options.version:\n        print(\"pygtail version\", __version__)\n        sys.exit(0)\n\n    if (len(args) != 1):\n        cmdline.error(\"Please provide a logfile to read.\")\n\n    if options.every_n:\n        options.every_n = int(options.every_n)\n    pygtail = Pygtail(args[0],\n                      offset_file=options.offset_file,\n                      paranoid=options.paranoid,\n                      every_n=options.every_n,\n                      copytruncate=not options.no_copytruncate,\n                      read_from_end=options.read_from_end,\n                      log_patterns=options.log_pattern,\n                      full_lines=options.full_lines,\n                      encoding=options.encoding)\n\n    for line in pygtail:\n        sys.stdout.write(line)\n\n\nif __name__ == \"__main__\":\n    main()\n"
  },
  {
    "path": "pygtail/test/__init__.py",
    "content": "#"
  },
  {
    "path": "pygtail/test/test_pygtail.py",
    "content": "import os\nimport sys\n\ntry:\n    # python 2.6\n    import unittest2 as unittest\nexcept ImportError:\n    import unittest\nimport shutil\nimport tempfile\nimport gzip\nimport io\n\nfrom pygtail import Pygtail\n\n\nPY2 = sys.version_info[0] == 2\n\n\nclass PygtailTest(unittest.TestCase):\n    # TODO:\n    # - test for non-default offset file\n    # - test for savelog and datext rotation schemes\n\n    def setUp(self):\n        self.test_lines = [\"1\\n\", \"2\\n\", \"3\\n\"]\n        self.test_str = ''.join(self.test_lines)\n        self.logfile = tempfile.NamedTemporaryFile(delete=False)\n        self.logfile.write(self.test_str.encode('utf-8'))\n        self.logfile.close()\n\n    def append(self, str):\n        # append the give string to the temp logfile\n        fh = open(self.logfile.name, \"a\")\n        fh.write(str)\n        fh.close()\n\n    def copytruncate(self):\n        shutil.copyfile(self.logfile.name, \"%s.1\" % self.logfile.name)\n        fh = open(self.logfile.name, \"w\")\n        fh.close()\n\n    def tearDown(self):\n        filename = self.logfile.name\n        for tmpfile in [filename, filename + \".offset\", filename + \".1\", filename + \".1.gz\"]:\n            if os.path.exists(tmpfile):\n                os.remove(tmpfile)\n\n    def test_read(self):\n        pygtail = Pygtail(self.logfile.name)\n        self.assertEqual(pygtail.read(), self.test_str)\n\n    def test_readlines(self):\n        pygtail = Pygtail(self.logfile.name)\n        self.assertEqual(pygtail.readlines(), self.test_lines)\n\n    def test_subsequent_read_with_no_new_data(self):\n        pygtail = Pygtail(self.logfile.name)\n        self.assertEqual(pygtail.read(), self.test_str)\n        self.assertEqual(pygtail.read(), None)\n\n    def test_subsequent_read_with_new_data(self):\n        pygtail = Pygtail(self.logfile.name)\n        self.assertEqual(pygtail.read(), self.test_str)\n        new_lines = \"4\\n5\\n\"\n        self.append(new_lines)\n        new_pygtail = Pygtail(self.logfile.name)\n        self.assertEqual(new_pygtail.read(), new_lines)\n\n    def test_read_from_the_file_end(self):\n        pygtail = Pygtail(self.logfile.name, read_from_end=True)\n        self.assertEqual(pygtail.read(), None)\n        new_lines = \"4\\n5\\n\"\n        self.append(new_lines)\n        new_pygtail = Pygtail(self.logfile.name, read_from_end=True)\n        self.assertEqual(new_pygtail.read(), new_lines)\n\n    def test_logrotate_without_delay_compress(self):\n        new_lines = [\"4\\n5\\n\", \"6\\n7\\n\"]\n        pygtail = Pygtail(self.logfile.name)\n        pygtail.read()\n        self.append(new_lines[0])\n\n        # put content to gzip file\n        gzip_handle = gzip.open(\"%s.1.gz\" % self.logfile.name, 'wb')\n        with open(self.logfile.name, 'rb') as logfile:\n            gzip_handle.write(logfile.read())\n        gzip_handle.close()\n\n        with open(self.logfile.name, 'w'):\n            # truncate file\n            pass\n\n        self.append(new_lines[1])\n        pygtail = Pygtail(self.logfile.name)\n        self.assertEqual(pygtail.read(), ''.join(new_lines))\n\n    def test_logrotate_with_delay_compress(self):\n        new_lines = [\"4\\n5\\n\", \"6\\n7\\n\"]\n        pygtail = Pygtail(self.logfile.name)\n        pygtail.read()\n        self.append(new_lines[0])\n        os.rename(self.logfile.name, \"%s.1\" % self.logfile.name)\n        self.append(new_lines[1])\n        pygtail = Pygtail(self.logfile.name)\n        self.assertEqual(pygtail.read(), ''.join(new_lines))\n\n    def test_logrotate_with_dateext_with_delaycompress(self):\n        new_lines = [\"4\\n5\\n\", \"6\\n7\\n\"]\n        pygtail = Pygtail(self.logfile.name)\n        pygtail.read()\n        self.append(new_lines[0])\n        os.rename(self.logfile.name, \"%s-20160616\" % self.logfile.name)\n        self.append(new_lines[1])\n        pygtail = Pygtail(self.logfile.name)\n        self.assertEqual(pygtail.read(), ''.join(new_lines))\n\n    def test_logrotate_with_dateext_without_delaycompress(self):\n        new_lines = [\"4\\n5\\n\", \"6\\n7\\n\"]\n        pygtail = Pygtail(self.logfile.name)\n        pygtail.read()\n        self.append(new_lines[0])\n\n        # put content to gzip file\n        gzip_handle = gzip.open(\"%s-20160616.gz\" % self.logfile.name, 'wb')\n        with open(self.logfile.name, 'rb') as logfile:\n            gzip_handle.write(logfile.read())\n        gzip_handle.close()\n\n        with open(self.logfile.name, 'w'):\n            # truncate file\n            pass\n\n        self.append(new_lines[1])\n        pygtail = Pygtail(self.logfile.name)\n        self.assertEqual(pygtail.read(), ''.join(new_lines))\n\n    def test_logrotate_with_dateext2_with_delaycompress(self):\n        new_lines = [\"4\\n5\\n\", \"6\\n7\\n\"]\n        pygtail = Pygtail(self.logfile.name)\n        pygtail.read()\n        self.append(new_lines[0])\n        os.rename(self.logfile.name, \"%s-20160616-1466093571\" % self.logfile.name)\n        self.append(new_lines[1])\n        pygtail = Pygtail(self.logfile.name)\n        self.assertEqual(pygtail.read(), ''.join(new_lines))\n\n    def test_logrotate_with_dateext2_without_delaycompress(self):\n        new_lines = [\"4\\n5\\n\", \"6\\n7\\n\"]\n        pygtail = Pygtail(self.logfile.name)\n        pygtail.read()\n        self.append(new_lines[0])\n\n        # put content to gzip file\n        gzip_handle = gzip.open(\"%s-20160616-1466093571.gz\" % self.logfile.name, 'wb')\n        with open(self.logfile.name, 'rb') as logfile:\n            gzip_handle.write(logfile.read())\n        gzip_handle.close()\n\n        with open(self.logfile.name, 'w'):\n            # truncate file\n            pass\n\n        self.append(new_lines[1])\n        pygtail = Pygtail(self.logfile.name)\n        self.assertEqual(pygtail.read(), ''.join(new_lines))\n\n    def test_timed_rotating_file_handler(self):\n        new_lines = [\"4\\n5\\n\", \"6\\n7\\n\"]\n        pygtail = Pygtail(self.logfile.name)\n        pygtail.read()\n        self.append(new_lines[0])\n        os.rename(self.logfile.name, \"%s.2016-06-16\" % self.logfile.name)\n        self.append(new_lines[1])\n        pygtail = Pygtail(self.logfile.name)\n        self.assertEqual(pygtail.read(), ''.join(new_lines))\n\n    def test_custom_rotating_file_handler_with_prepend(self):\n        new_lines = [\"4\\n5\\n\", \"6\\n7\\n\"]\n        pygtail = Pygtail(self.logfile.name)\n        pygtail.read()\n        self.append(new_lines[0])\n        file_dir, rel_filename = os.path.split(self.logfile.name)\n        os.rename(self.logfile.name, os.path.join(file_dir, \"custom_log_pattern.%s\" % rel_filename))\n        self.append(new_lines[1])\n        pygtail = Pygtail(self.logfile.name, log_patterns=[\"custom_log_pattern.%s\"])\n        self.assertEqual(pygtail.read(), ''.join(new_lines))\n\n    def test_copytruncate_off_smaller(self):\n        self.test_readlines()\n        self.copytruncate()\n        new_lines = \"4\\n5\\n\"\n        self.append(new_lines)\n\n        sys.stderr = captured = io.BytesIO() if PY2 else io.StringIO()\n        pygtail = Pygtail(self.logfile.name, copytruncate=False)\n        captured_value = captured.getvalue()\n        sys.stderr = sys.__stderr__\n\n        assert_class = self.assertRegex if sys.version_info >= (3, 1) else self.assertRegexpMatches\n        assert_class(captured_value, r\".*?\\bWARN\\b.*?\\bshrank\\b.*\")\n        self.assertEqual(pygtail.read(), None)\n\n    def test_copytruncate_on_smaller(self):\n        self.test_readlines()\n        self.copytruncate()\n        new_lines = \"4\\n5\\n\"\n        self.append(new_lines)\n        pygtail = Pygtail(self.logfile.name, copytruncate=True)\n        self.assertEqual(pygtail.read(), new_lines)\n\n    def _test_copytruncate_larger(self, onoff):\n        self.test_readlines()\n        self.copytruncate()\n        self.append(self.test_str)\n        new_lines = \"4\\n5\\n\"\n        self.append(new_lines)\n        pygtail = Pygtail(self.logfile.name, copytruncate=onoff)\n        self.assertEqual(pygtail.read(), new_lines)\n\n    def test_copytruncate_larger_off(self):\n        self._test_copytruncate_larger(False)\n\n    def test_copytruncate_larger_on(self):\n        self._test_copytruncate_larger(True)\n\n    def test_offset_file(self):\n        pygtail = Pygtail(self.logfile.name, paranoid=True)\n\n        log_inode = os.stat(self.logfile.name).st_ino\n\n        next(pygtail)\n        with open(self.logfile.name + '.offset', 'r') as f:\n            inode, offset = int(next(f)), int(next(f))\n        self.assertEqual(inode, log_inode)\n        self.assertEqual(offset, 2)\n\n        next(pygtail)\n        with open(self.logfile.name + '.offset', 'r') as f:\n            inode, offset = int(next(f)), int(next(f))\n        self.assertEqual(inode, log_inode)\n        self.assertEqual(offset, 4)\n\n        next(pygtail)\n        with open(self.logfile.name + '.offset', 'r') as f:\n            inode, offset = int(next(f)), int(next(f))\n        self.assertEqual(inode, log_inode)\n        self.assertEqual(offset, 6)\n\n    def test_on_update_with_paranoid(self):\n        updates = [0]\n\n        def record_update():\n            updates[0] += 1\n\n        pygtail = Pygtail(self.logfile.name, paranoid=True,\n                          on_update=record_update)\n\n        self.assertEqual(updates[0], 0)\n        next(pygtail)\n        self.assertEqual(updates[0], 1)\n        next(pygtail)\n        self.assertEqual(updates[0], 2)\n        next(pygtail)\n        self.assertEqual(updates[0], 3)\n\n    def test_on_update_without_paranoid(self):\n        updates = [0]\n\n        def record_update():\n            updates[0] += 1\n\n        pygtail = Pygtail(self.logfile.name, on_update=record_update)\n\n        self.assertEqual(updates[0], 0)\n        for line in pygtail:\n            self.assertEqual(updates[0], 0)\n        self.assertEqual(updates[0], 1)\n\n    def test_every_n(self):\n        updates = [0]\n        # We save before returning the second line.\n        # We save at the end of the file with all 3 recorded.\n        expected = [1, 3]\n        previous_lines = 0\n\n        def record_update():\n            self.assertEqual(previous_lines, expected[updates[0]])\n            updates[0] += 1\n\n        pygtail = Pygtail(self.logfile.name, every_n=2, on_update=record_update)\n\n        self.assertEqual(updates[0], 0)\n        for line in pygtail:\n            previous_lines += 1\n\n    def test_renamecreate(self):\n        \"\"\"\n        Tests \"renamecreate\" semantics where the currently processed file gets renamed and the\n        original file gets recreated. This is the behavior of certain logfile rollers such as\n        TimeBasedRollingPolicy in Java's Logback library.\n        \"\"\"\n        new_lines = [\"4\\n5\\n\", \"6\\n7\\n\"]\n        pygtail = Pygtail(self.logfile.name)\n        pygtail.read()\n        os.rename(self.logfile.name, \"%s.2018-03-10\" % self.logfile.name)\n        # append will recreate the original log file\n        self.append(new_lines[0])\n        self.append(new_lines[1])\n        self.assertEqual(pygtail.read(), ''.join(new_lines))\n\n    def test_renamecreate_unknown_rotated_name(self):\n        \"\"\"\n        Tests \"renamecreate\" semantics where the currently processed file gets renamed and the\n        original file gets recreated. Rolled file has unknown name to pygtail. logrotate from\n        Linux has this behaviour when rotating into separate directory.\n        \"\"\"\n        new_lines = [\"4\\n5\\n\", \"6\\n7\\n\"]\n        pygtail = Pygtail(self.logfile.name)\n        pygtail.read()\n        os.rename(self.logfile.name, \"%s.unknown-name\" % self.logfile.name)\n        # append will recreate the original log file\n        self.append(new_lines[0])\n        self.append(new_lines[1])\n        # reopen using Pytgail\n        sys.stderr = captured = io.BytesIO() if PY2 else io.StringIO()\n        pygtail = Pygtail(self.logfile.name)\n        captured_value = captured.getvalue()\n        sys.stderr = sys.__stderr__\n        assert_class = self.assertRegex if sys.version_info >= (3, 1) else self.assertRegexpMatches\n        assert_class(captured_value, r\".*?\\bWARN\\b.*?\\bResetting\\b.*\")\n        self.assertEqual(pygtail.read(), ''.join(new_lines))\n\n\n    def test_full_lines(self):\n        \"\"\"\n        Tests lines are logged only when they have a new line at the end. This is useful to ensure that log lines\n        aren't unintentionally split up.\n        \"\"\"\n        pygtail = Pygtail(self.logfile.name, full_lines=True)\n        new_lines = \"4\\n5,\"\n        last_line = \"5.5\\n6\\n\"\n\n        self.append(new_lines)\n        pygtail.read()\n        self.append(last_line)\n        self.assertEqual(pygtail.read(), \"5,5.5\\n6\\n\")\n\n\n    def test_save_on_end(self):\n        \"\"\"\n        Test save offset is not automatically saved once the end of the file is reached\n        \"\"\"\n        updates = [0]\n\n        def record_update():\n            updates[0] += 1\n\n        pygtail = Pygtail(self.logfile.name, save_on_end=False, on_update=record_update)\n\n        self.assertEqual(updates[0], 0)\n        for line in pygtail:\n            self.assertEqual(updates[0], 0)\n        self.assertEqual(updates[0], 0)\n        pygtail.update_offset_file()\n        self.assertEqual(updates[0], 1)\n\n\n    def test_iterator_with_offsets(self):\n        \"\"\"\n        Test save offset is not automatically saved once the end of the file is reached\n        \"\"\"\n        updates = [0]\n\n        def record_update():\n            updates[0] += 1\n\n        pygtail = Pygtail(self.logfile.name, save_on_end=False, on_update=record_update, copytruncate=False,)\n\n        self.assertEqual(updates[0], 0)\n        lines, offsets = list(zip(*pygtail.with_offsets()))\n        self.assertEqual(len(lines), 3)\n        self.assertEqual(updates[0], 0)\n        pygtail.write_offset_to_file(offsets[1])\n        self.assertEqual(updates[0], 1)\n\n        for i in range(len(offsets)-1):\n            self.assertLess(offsets[i], offsets[i+1])\n\n        pygtail = Pygtail(self.logfile.name, save_on_end=False, on_update=record_update, copytruncate=False,)\n        lines_new, offsets_new = list(zip(*pygtail.with_offsets()))\n        self.assertEqual(len(lines_new), 1)\n        self.assertEqual(updates[0], 1)\n        self.assertEqual(offsets_new, offsets[2:])\n\n    def test_offset_comparisons(self):\n        \"\"\"Test comparison operators of the Offset dataclass\"\"\"\n        pygtail = Pygtail(self.logfile.name)\n        _, offsets = list(zip(*pygtail.with_offsets()))\n        for i in range(len(offsets)-1, ):\n            self.assertLess(offsets[i], offsets[i+1])\n            self.assertLessEqual(offsets[i], offsets[i+1])\n            self.assertLessEqual(offsets[i], offsets[i])\n            self.assertGreater(offsets[i+1], offsets[i])\n            self.assertGreaterEqual(offsets[i], offsets[i])\n            self.assertGreaterEqual(offsets[i+1], offsets[i])\n\ndef main():\n    unittest.main(buffer=True)\n\n\nif __name__ == \"__main__\":\n    main()\n"
  },
  {
    "path": "pypi.txt",
    "content": "To update the version on PyPi:\n\n1. Update __version__ in pygtail/core.py\n2. Update debian/changelog\n3. rm dist/*\n4. python3 setup.py sdist bdist_wheel\n5. twine --repository pygtail upload dist/* # if ~/.pypirc is setup, otherwise username: __token__, password: <pygtail API token>\n"
  },
  {
    "path": "setup.py",
    "content": "import os\nfrom setuptools import setup\n\nfrom pygtail import __version__\n\n\ndef main():\n    cwd = os.path.dirname(os.path.abspath(__file__))\n    path = os.path.join(cwd, 'README.txt')\n    readme = open(path, 'r').read()\n\n    setup(\n        name = 'pygtail',\n        version = __version__,\n        description = 'Reads log file lines that have not been read.',\n        license = 'GPL v2',\n        author = 'Brad Greenlee',\n        author_email = 'brad@footle.org',\n        keywords = ['logging', 'tail', 'logtail2'],\n        url = 'http://github.com/bgreenlee/pygtail',\n        packages = ['pygtail'],\n        entry_points = {\n            'console_scripts': ['pygtail=pygtail.core:main']\n            },\n        test_suite='pygtail.test',\n        classifiers = [\n            \"Development Status :: 4 - Beta\",\n            \"Intended Audience :: Developers\",\n            \"License :: OSI Approved :: GNU General Public License (GPL)\",\n            \"Operating System :: MacOS :: MacOS X\",\n            \"Operating System :: POSIX :: Linux\",\n            \"Operating System :: Unix\",\n            \"Programming Language :: Python\",\n            \"Programming Language :: Python :: 2.6\",\n            \"Programming Language :: Python :: 2.7\",\n            \"Programming Language :: Python :: 3\",\n            \"Topic :: Software Development :: Libraries :: Python Modules\",\n            \"Topic :: System :: Logging\"\n            ],\n        long_description = readme\n        )\n\n\nif __name__ == '__main__':\n    main()\n"
  },
  {
    "path": "tox.ini",
    "content": "# Tox (http://codespeak.net/~hpk/tox/) is a tool for running tests\n# in multiple virtualenvs. This configuration file will run the\n# test suite on all supported python versions. To use it, \"pip install tox\"\n# and then run \"tox\" from this directory.\n\n[tox]\nminversion=1.8.0\nenvlist = py{26,27,36,37,38,39,310,311}, pypy\n\n[testenv]\ncommands = python setup.py test\ndeps =\n\tpy26: unittest2\n"
  }
]