From 44cd23f16a5a184adb1d8890633a0e432a2e5636 Mon Sep 17 00:00:00 2001 From: "Ira W. Snyder" Date: Tue, 2 Jan 2007 11:43:42 -0800 Subject: [PATCH] Add Copyright / License information + Documentation Add the COPYING file (GPLv2). Add the GPLv2 copyright notice to all files. Add documentation to all modules, classes, and functions. Signed-off-by: Ira W. Snyder --- COPYING | 340 ++++++++++++++++++++++++++++++++++ PAR2Set/Base.py | 82 ++++++-- PAR2Set/ExtractFirstBase.py | 41 ++-- PAR2Set/ExtractFirstNewRAR.py | 63 +++++-- PAR2Set/ExtractFirstOldRAR.py | 64 +++++-- PAR2Set/Join.py | 78 ++++++-- PAR2Set/NewRAR.py | 68 +++++-- PAR2Set/NoExtract.py | 60 ++++-- PAR2Set/OldRAR.py | 70 +++++-- PAR2Set/ZIP.py | 58 +++++- PAR2Set/__init__.py | 15 +- RarslaveDetector.py | 41 +++- rarslave.py | 54 +++++- rsutil/common.py | 27 ++- rsutil/config.py | 26 +++ rsutil/globals.py | 26 +++ rsutil/par2parser.py | 32 +++- 17 files changed, 978 insertions(+), 167 deletions(-) create mode 100644 COPYING diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..d60c31a --- /dev/null +++ b/COPYING @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/PAR2Set/Base.py b/PAR2Set/Base.py index 772e4a5..533ff4f 100644 --- a/PAR2Set/Base.py +++ b/PAR2Set/Base.py @@ -1,12 +1,38 @@ #!/usr/bin/env python # vim: set ts=4 sts=4 sw=4 textwidth=92: -import rsutil.common +""" +Holds the PAR2Set base class +""" + +__author__ = "Ira W. Snyder (devel@irasnyder.com)" +__copyright__ = "Copyright (c) 2006,2007 Ira W. Snyder (devel@irasnyder.com)" +__license__ = "GNU GPL v2 (or, at your option, any later version)" + +# Base.py +# +# Copyright (C) 2006,2007 Ira W. Snyder (devel@irasnyder.com) +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import re import os import logging +import rsutil.common + # This is a fairly generic class which does all of the major things that a PAR2 # set will need to have done to be verified and extracted. For most "normal" types # you won't need to override hardly anything. @@ -14,11 +40,12 @@ import logging # It is ok to override other functions if the need arises, just make sure that you # understand why things are done the way that they are in the original versions. # -# Assumptions made about each of the run*() functions: +# Assumptions made in the runVerifyAndRepair(), runExtract() and runDelete() functions: # ============================================================================== -# The state of self.name_matched_files and self.prot_matched_files will be consistent -# with the real, in-filesystem state at the time that they are called. -# (This is why runAll() calls update_matches() all the time.) +# The state of self.name_matched_files, self.prot_matched_files, and self.all_files +# will be consistent with the real, in-filesystem state at the time that they are +# called. This is the reason that runAll() calls update_matches() after running each +# operation that will possibly change the filesystem. # # Required overrides: # ============================================================================== @@ -27,6 +54,7 @@ import logging # class Base (object): + """Base class for all PAR2Set types""" # Instance Variables # ========================================================================== @@ -38,6 +66,11 @@ class Base (object): # prot_matched_files -- Files in this set, guessed by parsing the PAR2 only def __init__ (self, dir, p2file): + """Default constructor for all PAR2Set types + + dir -- a directory + p2file -- a PAR2 file inside the given directory""" + assert os.path.isdir (dir) assert os.path.isfile (os.path.join (dir, p2file)) @@ -59,18 +92,23 @@ class Base (object): self.all_files = rsutil.common.no_duplicates (self.name_matched_files + self.prot_matched_files) def __eq__ (self, rhs): + """Check for equality between PAR2Set types""" + return (self.dir == rhs.dir) and (self.basename == rhs.basename) and \ rsutil.common.list_eq (self.name_matched_files, rhs.name_matched_files) and \ rsutil.common.list_eq (self.prot_matched_files, rhs.prot_matched_files) def update_matches (self): - """Updates the contents of instance variables which are likely to change after - running an operation, usually one which will create new files.""" + """Updates the contents of instance variables with the current in-filesystem state. + This should be run after any operation which can create or delete files.""" self.name_matched_files = rsutil.common.find_name_matches (self.dir, self.basename) self.all_files = rsutil.common.no_duplicates (self.name_matched_files + self.prot_matched_files) def runVerifyAndRepair (self): + """Verify and Repair a PAR2Set. This is done using the par2repair command by + default""" + PAR2_CMD = rsutil.common.config_get_value ('commands', 'par2repair') # assemble the command @@ -92,13 +130,20 @@ class Base (object): return rsutil.common.SUCCESS def find_deleteable_files (self): + """Find all files which are deletable by using the regular expression from the + configuration file""" + DELETE_REGEX = rsutil.common.config_get_value ('regular expressions', 'delete_regex') dregex = re.compile (DELETE_REGEX, re.IGNORECASE) return [f for f in self.all_files if dregex.match (f)] def delete_list_of_files (self, dir, files, interactive=False): - # Delete a list of files + """Attempt to delete all files given + + dir -- the directory where the files live + files -- the filenames themselves + interactive -- prompt before deleteion""" assert os.path.isdir (dir) @@ -130,6 +175,8 @@ class Base (object): return rsutil.common.SUCCESS def runDelete (self): + """Run the delete operation and return the result""" + deleteable_files = self.find_deleteable_files () ret = self.delete_list_of_files (self.dir, deleteable_files, \ rsutil.common.options_get_value ('interactive')) @@ -137,6 +184,7 @@ class Base (object): return ret def runAll (self): + """Run all of the major sections in the class: repair, extraction, and deletion.""" # Repair Stage ret = self.runVerifyAndRepair () @@ -167,6 +215,10 @@ class Base (object): return rsutil.common.SUCCESS def safe_create_directory (self, dir): + """Safely create a directory, logging the result. + + dir -- the directory to create (None is ignored)""" + if dir == None: return rsutil.common.SUCCESS @@ -183,7 +235,7 @@ class Base (object): return rsutil.common.SUCCESS def runExtract (self, todir=None): - """Extract all heads of this set""" + """Extract all heads of this set and return the result""" # Extract to the head's dir if we don't care where to extract if todir == None: @@ -209,14 +261,16 @@ class Base (object): return rsutil.common.SUCCESS def find_extraction_heads (self): + """Find all extraction heads associated with this set. This must be + overridden for the associated PAR2Set derived class to work.""" + assert False # You MUST override this on a per-type basis def extraction_function (self, file, todir): - # NOTE: Please keep the prototype the same for all overridden functions. - # Doing so will guarantee that your life is made much easier. - # - # Also note that the todir given will always be valid for the current directory - # when the function is called. + """Extract a single head of this PAR2Set's type. + + file -- the full path to the file to be extracted + todir -- the directory to extract to""" assert False # You MUST override this on a per-type basis diff --git a/PAR2Set/ExtractFirstBase.py b/PAR2Set/ExtractFirstBase.py index 909b91d..6b8a661 100644 --- a/PAR2Set/ExtractFirstBase.py +++ b/PAR2Set/ExtractFirstBase.py @@ -1,29 +1,42 @@ #!/usr/bin/env python # vim: set ts=4 sts=4 sw=4 textwidth=92: -import logging -import PAR2Set.Base -import rsutil.common +""" +Holds the ExtractFirstBase class. +""" + +__author__ = "Ira W. Snyder (devel@irasnyder.com)" +__copyright__ = "Copyright (c) 2006,2007 Ira W. Snyder (devel@irasnyder.com)" +__license__ = "GNU GPL v2 (or, at your option, any later version)" +# ExtractFirstBase.py # -# This is another base class for types that must -# run the extraction routine before the repair routine +# Copyright (C) 2006,2007 Ira W. Snyder (devel@irasnyder.com) # -# It will detect sets like the following: -# X.par2 -# X.vol0+1.par2 -# X.vol1+2.par2 -# X.part01.rar -# X.part02.rar -# X.part03.rar +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. # -# Where the PAR2 files protect a file named X.avi, but not the X.part01.rar -# (and other) files. +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. # +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +import logging +import PAR2Set.Base +import rsutil.common class ExtractFirstBase (PAR2Set.Base.Base): + """Base class for PAR2Set types which run the extraction routine before + the repair routine""" def runAll (self): + """Run the extraction, repair, and delete stages""" # Extraction Stage ret = self.runExtract () diff --git a/PAR2Set/ExtractFirstNewRAR.py b/PAR2Set/ExtractFirstNewRAR.py index caed58f..79fb727 100644 --- a/PAR2Set/ExtractFirstNewRAR.py +++ b/PAR2Set/ExtractFirstNewRAR.py @@ -1,32 +1,55 @@ #!/usr/bin/env python # vim: set ts=4 sts=4 sw=4 textwidth=92: -import PAR2Set.ExtractFirstBase -import PAR2Set.NewRAR -import rsutil.common +""" +Holds the ExtractFirstNewRAR class. +This module works with new-style rar sets which need to be extracted +before they are verified. + +It will detect sets like the following: +X.par2 +X.vol0+1.par2 +... + +X.part01.rar +X.part02.rar +... + +Where the PAR2 files do not protect the rar files directly, but instead +protect the files contained inside the rar files. +""" + +__author__ = "Ira W. Snyder (devel@irasnyder.com)" +__copyright__ = "Copyright (c) 2006,2007 Ira W. Snyder (devel@irasnyder.com)" +__license__ = "GNU GPL v2 (or, at your option, any later version)" + +# ExtractFirstNewRAR.py -- detect and work with a new-style rar set # -# This is an old-style rar type -# -# It will detect sets like the following: -# X.par2 -# X.vol0+1.par2 -# X.vol1+2.par2 -# X.rar -# X.r00 -# X.r01 -# -# OR +# Copyright (C) 2006,2007 Ira W. Snyder (devel@irasnyder.com) # -# ABC.rar -# ABC.r00 -# ABC.r01 +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. # -# Where the PAR2 files protect all files that do not match in basename -# with the PAR2 file itself. +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. # +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +import PAR2Set.ExtractFirstBase +import PAR2Set.NewRAR +import rsutil.common + def detector (name_files, prot_files): + """Detects a ExtractFirstNewRAR set""" + return rsutil.common.has_a_match ('^.*\.part0*1\.rar$', name_files) \ and not rsutil.common.has_a_match ('^.*\.part0*1\.rar$', prot_files) @@ -34,6 +57,8 @@ def detector (name_files, prot_files): class ExtractFirstNewRAR (PAR2Set.ExtractFirstBase.ExtractFirstBase, \ PAR2Set.NewRAR.NewRAR): + """Class for new-style rar sets which must be extracted before repair""" + def __repr__ (self): return 'EXTRACTFIRST NEWRAR' diff --git a/PAR2Set/ExtractFirstOldRAR.py b/PAR2Set/ExtractFirstOldRAR.py index 1a45c9e..26ed997 100644 --- a/PAR2Set/ExtractFirstOldRAR.py +++ b/PAR2Set/ExtractFirstOldRAR.py @@ -1,32 +1,56 @@ #!/usr/bin/env python # vim: set ts=4 sts=4 sw=4 textwidth=92: -import PAR2Set.ExtractFirstBase -import PAR2Set.OldRAR -import rsutil.common +""" +Holds the ExtractFirstOldRAR class. +This module works with old-style rar sets which need to be extracted +before they are verified. + +It will detect sets like the following: +X.par2 +X.vol0+1.par2 +... + +X.rar +X.r00 +X.r01 +... + +Where the PAR2 files do not protect the rar files directly, but instead +protect the files contained inside the rar files. +""" + +__author__ = "Ira W. Snyder (devel@irasnyder.com)" +__copyright__ = "Copyright (c) 2006,2007 Ira W. Snyder (devel@irasnyder.com)" +__license__ = "GNU GPL v2 (or, at your option, any later version)" + +# ExtractFirstOldRAR.py -- detect and work with a old-style rar set # -# This is an old-style rar type -# -# It will detect sets like the following: -# X.par2 -# X.vol0+1.par2 -# X.vol1+2.par2 -# X.rar -# X.r00 -# X.r01 -# -# OR +# Copyright (C) 2006,2007 Ira W. Snyder (devel@irasnyder.com) # -# ABC.rar -# ABC.r00 -# ABC.r01 +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. # -# Where the PAR2 files protect all files that do not match in basename -# with the PAR2 file itself. +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. # +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +import PAR2Set.ExtractFirstBase +import PAR2Set.OldRAR +import rsutil.common + def detector (name_files, prot_files): + """Detects a ExtractFirstOldRAR set""" + return rsutil.common.has_a_match ('^.*\.r00$', name_files) \ and not rsutil.common.has_a_match ('^.*\.r00$', prot_files) @@ -34,6 +58,8 @@ def detector (name_files, prot_files): class ExtractFirstOldRAR (PAR2Set.ExtractFirstBase.ExtractFirstBase, \ PAR2Set.OldRAR.OldRAR): + """Class for old-style rar sets which must be extracted before repair""" + def __repr__ (self): return 'EXTRACTFIRST OLDRAR' diff --git a/PAR2Set/Join.py b/PAR2Set/Join.py index 3dd78ce..b764c49 100644 --- a/PAR2Set/Join.py +++ b/PAR2Set/Join.py @@ -1,40 +1,79 @@ #!/usr/bin/env python # vim: set ts=4 sts=4 sw=4 textwidth=92: -import os -import logging -import PAR2Set.Base -import rsutil.common +""" +Holds the Join class. + +This module works with normal joined sets. + +It will detect sets like the following: +X.par2 +X.vol0+1.par2 +... +X.001 +X.002 +... + +Where the PAR2 files protect a file named X.avi, or similar other types. +It will not work where the PAR2 files are protecting the X.001, etc files +directly. +""" + +__author__ = "Ira W. Snyder (devel@irasnyder.com)" +__copyright__ = "Copyright (c) 2006,2007 Ira W. Snyder (devel@irasnyder.com)" +__license__ = "GNU GPL v2 (or, at your option, any later version)" + +# Join.py # -# This is a regular joined file type +# Copyright (C) 2006,2007 Ira W. Snyder (devel@irasnyder.com) # -# It will detect sets like the following: -# X.par2 -# X.vol0+1.par2 -# X.vol1+2.par2 -# X.001 -# X.002 -# X.003 +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. # -# Where the PAR2 files protect a file named X.avi (or similar). It will not -# work where the PAR2 files are protecting the .001, etc files directly. +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. # +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +import os +import logging +import PAR2Set.Base +import rsutil.common + def detector (name_files, prot_files): + """Detects a Join set""" + return rsutil.common.has_a_match ('^.*\.\d\d\d$', name_files) \ and not rsutil.common.has_a_match ('^.*\.\d\d\d$', prot_files) class Join (PAR2Set.Base.Base): + """Class for normal joined-file sets""" + def __repr__ (self): return 'JOIN' def find_joinfiles (self): + """Finds files which contain data to be joined together""" + return rsutil.common.find_matches ('^.*\.\d\d\d$', self.name_matched_files) def runVerifyAndRepair (self): + """Verify and Repair a PAR2Set. This version extends the PAR2Set.Base.Base + version by adding the datafiles to be joined at the end of the command + line. + + This is done using the par2repair command by default""" + PAR2_CMD = rsutil.common.config_get_value ('commands', 'par2repair') # assemble the command @@ -59,10 +98,19 @@ class Join (PAR2Set.Base.Base): return rsutil.common.SUCCESS def find_extraction_heads (self): + """Find the extraction heads. Since this should not be an extractable set, + we return the files which are protected directly by the PAR2 files.""" + return self.prot_matched_files def extraction_function (self, file, todir): - """Extract a single file of this type to the given directory""" + """Extract a single file of the Join type. + + file -- the file to extract + todir -- the directory to extract to + + This command ignores the extraction if file and todir+file are the same + file. This keeps things like mv working smoothly.""" NOEXTRACT_CMD = rsutil.common.config_get_value ('commands', 'noextract') diff --git a/PAR2Set/NewRAR.py b/PAR2Set/NewRAR.py index 408a03a..caefb29 100644 --- a/PAR2Set/NewRAR.py +++ b/PAR2Set/NewRAR.py @@ -1,44 +1,74 @@ #!/usr/bin/env python # vim: set ts=4 sts=4 sw=4 textwidth=92: -import os -import PAR2Set.Base -import rsutil.common +"""Holds the NewRAR class. +This is a new-style rar type. + +It will detect sets like the following: +X.par2 +X.vol0+1.par2 +... + +Y.part01.rar +Y.part02.rar +... + +Where the PAR2 files protect the rar files directly. Y can (but is not required +to be) the same as X. +""" + +__author__ = "Ira W. Snyder (devel@irasnyder.com)" +__copyright__ = "Copyright (c) 2006,2007 Ira W. Snyder (devel@irasnyder.com)" +__license__ = "GNU GPL v2 (or, at your option, any later version)" + +# NewRAR.py -- detect and work with a new-style rar set # -# This is an new-style rar type -# -# It will detect sets like the following: -# X.par2 -# X.vol0+1.par2 -# X.vol1+2.par2 -# X.part01.rar -# X.part02.rar -# X.part03.rar -# -# OR +# Copyright (C) 2006,2007 Ira W. Snyder (devel@irasnyder.com) # -# ABC.part01.rar -# ABC.part02.rar -# ABC.part03.rar +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. # -# Where the PAR2 files protect all files that do not match in basename -# with the PAR2 file itself. +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. # +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +import os +import PAR2Set.Base +import rsutil.common + def detector (name_files, prot_files): + """Detector for the NewRAR type""" + return rsutil.common.has_a_match ('^.*\.part0*1\.rar$', prot_files) class NewRAR (PAR2Set.Base.Base): + """Class for new-style rar sets""" + def __repr__ (self): return 'NEWRAR' def find_extraction_heads (self): + """Find the files to start extraction from. These end in '.part0*1.rar'""" + return rsutil.common.find_matches ('^.*\.part0*1\.rar$', self.all_files) def extraction_function (self, file, todir): + """Extract a single rar file to the directory todir. + + file -- the file to be extracted + todir -- the directory to extract into""" + assert os.path.isfile (file) assert os.path.isdir (todir) diff --git a/PAR2Set/NoExtract.py b/PAR2Set/NoExtract.py index ce2fdfa..c065aa3 100644 --- a/PAR2Set/NoExtract.py +++ b/PAR2Set/NoExtract.py @@ -1,35 +1,71 @@ #!/usr/bin/env python # vim: set ts=4 sts=4 sw=4 textwidth=92: -import logging -import PAR2Set.Base -import rsutil.common +""" +Holds the NoExtract class. + +This module works with sets that only need to repair and delete, and do +not need any extraction. + +It will detect sets like the following: +X.par2 +X.vol0+1.par2 +... + +01.mp3 +02.mp3 +... + +Where the PAR2 files protect the mp3 files directly. + +NOTE: It doesn't just detect mp3's, it will detect any set that does not +NOTE: have any extractable elements in it. +""" +__author__ = "Ira W. Snyder (devel@irasnyder.com)" +__copyright__ = "Copyright (c) 2006,2007 Ira W. Snyder (devel@irasnyder.com)" +__license__ = "GNU GPL v2 (or, at your option, any later version)" + +# NoExtract.py # -# This is a class that will only repair and delete, not extract +# Copyright (C) 2006,2007 Ira W. Snyder (devel@irasnyder.com) # -# It will detect sets like the following: -# X.par2 -# X.vol0+1.par2 -# X.vol1+2.par2 -# 01.mp3 -# 02.mp3 -# 03.mp3 +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. # -# Where the PAR2 files protect the mp3 files. +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. # +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +import logging +import PAR2Set.Base +import rsutil.common + def detector (name_files, prot_files): + """Detector for the NoExtract type""" + EXTRACT_REGEX = rsutil.common.config_get_value ('regular expressions', 'extractable_regex') return not rsutil.common.has_a_match (EXTRACT_REGEX, prot_files) class NoExtract (PAR2Set.Base.Base): + """Class for sets that do not need to be extracted. Note that this is not a + base class, this is a working class.""" + def __repr__ (self): return 'NoExtract' def runAll (self): + """Run the Repair and Deletion stages, omitting the Extraction stage""" # Repair Stage ret = self.runVerifyAndRepair () diff --git a/PAR2Set/OldRAR.py b/PAR2Set/OldRAR.py index 90c7440..f8b5719 100644 --- a/PAR2Set/OldRAR.py +++ b/PAR2Set/OldRAR.py @@ -1,44 +1,76 @@ #!/usr/bin/env python # vim: set ts=4 sts=4 sw=4 textwidth=92: -import os -import PAR2Set.Base -import rsutil.common +""" +Holds the OldRAR class. +This module works with old-style rar sets. + +It will detect sets like the following: +X.par2 +X.vol0+1.par2 +... + +Y.rar +Y.r00 +Y.r01 +... + +Where the PAR2 files protect all of the rar files. Note that Y can be the same +as X, but is not required to be. +""" + +__author__ = "Ira W. Snyder (devel@irasnyder.com)" +__copyright__ = "Copyright (c) 2006,2007 Ira W. Snyder (devel@irasnyder.com)" +__license__ = "GNU GPL v2 (or, at your option, any later version)" + +# OldRAR.py -- detect and work with old-style rar sets # -# This is an old-style rar type -# -# It will detect sets like the following: -# X.par2 -# X.vol0+1.par2 -# X.vol1+2.par2 -# X.rar -# X.r00 -# X.r01 -# -# OR +# Copyright (C) 2006,2007 Ira W. Snyder (devel@irasnyder.com) # -# ABC.rar -# ABC.r00 -# ABC.r01 +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. # -# Where the PAR2 files protect all files that do not match in basename -# with the PAR2 file itself. +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. # +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +import os +import PAR2Set.Base +import rsutil.common + def detector (name_files, prot_files): + """Detect OldRAR sets""" + return rsutil.common.has_a_match ('^.*\.r00$', prot_files) class OldRAR (PAR2Set.Base.Base): + """Class for working with old-style rar sets""" + def __repr__ (self): return 'OLDRAR' def find_extraction_heads (self): + """Find the heads of extraction for an old-style rar set""" + return rsutil.common.find_matches ('^.*\.rar', self.all_files) def extraction_function (self, file, todir): + """Extract a single rar file to the given directory. + + file -- the file to extract + todir -- the directory to extract the file to""" + assert os.path.isfile (file) assert os.path.isdir (todir) diff --git a/PAR2Set/ZIP.py b/PAR2Set/ZIP.py index 6795d0c..36acb74 100644 --- a/PAR2Set/ZIP.py +++ b/PAR2Set/ZIP.py @@ -1,36 +1,74 @@ #!/usr/bin/env python # vim: set ts=4 sts=4 sw=4 textwidth=92: -import PAR2Set.Base -import rsutil.common +""" +Holds the ZIP class. + +This module works with regular zip file sets. + +It will detect sets like the following: +X.par2 +X.vol0+1.par2 +... +Y.zip +... + +Where the PAR2 files protect the Y.zip file(s). Note that Y can be equal to +X, but is not required to be. +""" + +__author__ = "Ira W. Snyder (devel@irasnyder.com)" +__copyright__ = "Copyright (c) 2006,2007 Ira W. Snyder (devel@irasnyder.com)" +__license__ = "GNU GPL v2 (or, at your option, any later version)" + +# ZIP.py -- detect and work with zip sets # -# This is a regular zip file type +# Copyright (C) 2006,2007 Ira W. Snyder (devel@irasnyder.com) # -# It will detect sets like the following: -# X.par2 -# X.vol0+1.par2 -# X.vol1+2.par2 -# X.zip -# ABC.zip +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. # -# Where the PAR2 files protect a file named X.zip and/or ABC.zip. +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. # +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +import PAR2Set.Base +import rsutil.common + def detector (name_files, prot_files): + """Detect a zip set""" + all_files = rsutil.common.no_duplicates (name_files + prot_files) return rsutil.common.has_a_match ('^.*\.zip$', all_files) class ZIP (PAR2Set.Base.Base): + """Class for working with normal zip sets""" + def __repr__ (self): return 'ZIP' def find_extraction_heads (self): + """Find the heads of extraction for a zip set""" + return rsutil.common.find_matches ('^.*\.zip', self.all_files) def extraction_function (self, file, todir): + """Extract a single zip file to the given directory. + + file -- the file to extract + todir -- the directory to extract into""" + ZIP_CMD = rsutil.common.config_get_value ('commands', 'unzip') cmd = ZIP_CMD % (file, todir) diff --git a/PAR2Set/__init__.py b/PAR2Set/__init__.py index 753613e..b900b57 100644 --- a/PAR2Set/__init__.py +++ b/PAR2Set/__init__.py @@ -1,12 +1,18 @@ #!/usr/bin/env python # vim: set ts=4 sts=4 sw=4 textwidth=92: +""" +A package which has many different types of PAR2Sets and their corresponding +detection functions. + +Each (non-base) class in this package is able to repair, extract, and delete +extra files from the corresponding set of files. +""" + __author__ = "Ira W. Snyder (devel@irasnyder.com)" __copyright__ = "Copyright (c) 2006, Ira W. Snyder (devel@irasnyder.com)" __license__ = "GNU GPL v2 (or, at your option, any later version)" -# Module Description Goes Here - import Base import ExtractFirstBase import ExtractFirstNewRAR @@ -20,8 +26,3 @@ import NoExtract __all__ = ['Base', 'ExtractFirstBase', 'ExtractFirstNewRAR', 'ExtractFirstOldRAR', 'Join', 'NewRAR', 'OldRAR', 'ZIP', 'NoExtract'] -def main (): - pass - -if __name__ == '__main__': - main () diff --git a/RarslaveDetector.py b/RarslaveDetector.py index 0895e46..7981836 100644 --- a/RarslaveDetector.py +++ b/RarslaveDetector.py @@ -1,6 +1,33 @@ #!/usr/bin/env python # vim: set ts=4 sts=4 sw=4 textwidth=92: +""" +Class which runs each detector in the PAR2Set classes, and attempts +to run all matches on the current set. +""" + +__author__ = "Ira W. Snyder (devel@irasnyder.com)" +__copyright__ = "Copyright (c) 2006, Ira W. Snyder (devel@irasnyder.com)" +__license__ = "GNU GPL v2 (or, at your option, any later version)" + +# RarslaveDetector.py +# +# Copyright (C) 2006,2007 Ira W. Snyder (devel@irasnyder.com) +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + import rsutil.common # PAR2Set-derived types @@ -16,9 +43,11 @@ import logging class RarslaveDetector (object): - # A tuple of tuples with the following definition: - # (TYPE_NAME, DETECTION_FUNCTION, PAR2Set-derived class) + """A class to detect the type of a set, and then run the appropriate class + on the set.""" + # A tuple of tuples of the following type: + # (type_detection_function, type_working_class) TYPES = ( (PAR2Set.Join.detector, PAR2Set.Join.Join), (PAR2Set.ZIP.detector, PAR2Set.ZIP.ZIP), (PAR2Set.OldRAR.detector, PAR2Set.OldRAR.OldRAR), @@ -29,6 +58,10 @@ class RarslaveDetector (object): ) def __init__ (self, dir, p2file): + """Constructor + + dir -- the directory containing this set + p2file -- a single PAR2 file from this set""" # The real "meat" of the class self.dir = dir @@ -45,8 +78,8 @@ class RarslaveDetector (object): self.prot_matched_files = rsutil.common.parse_all_par2 (self.dir, self.p2file, self.all_p2files) def runMatchingTypes (self): - # Now tries to run every type of PAR2Set-derived class for which the detector - # detects that the class is valid. + """Run all matching PAR2Set types for which the detection function detects that + the class is valid.""" detected = False diff --git a/rarslave.py b/rarslave.py index a27c334..0d6a471 100755 --- a/rarslave.py +++ b/rarslave.py @@ -1,5 +1,35 @@ #!/usr/bin/env python -# vim: set ts=4 sts=4 sw=4 textwidth=112 : +# vim: set ts=4 sts=4 sw=4 textwidth=92: + +""" +The main program of the rarslave project. + +This handles all of the commandline, configuration file, and option +work. It gets the environment set up for a run using the RarslaveDetector +class. +""" + +__author__ = "Ira W. Snyder (devel@irasnyder.com)" +__copyright__ = "Copyright (c) 2006,2007 Ira W. Snyder (devel@irasnyder.com)" +__license__ = "GNU GPL v2 (or, at your option, any later version)" + +# rarslave.py -- a usenet autorepair and autoextract utility +# +# Copyright (C) 2006,2007 Ira W. Snyder (devel@irasnyder.com) +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA VERSION="2.0.0" PROGRAM="rarslave2" @@ -14,6 +44,10 @@ config = rsutil.globals.config # A tiny class to hold logging output until we're finished class DelayedLogger (object): + + """A small class to hold logging output until the program is finished running. + It emulates sys.stdout in the needed ways for the logging module.""" + def __init__ (self, output=sys.stdout.write): self.__messages = [] self.__output = output @@ -38,6 +72,8 @@ class DelayedLogger (object): # A tiny class used to find unique PAR2 sets class CompareSet (object): + """A small class used to find unique PAR2 sets""" + def __init__ (self, dir, p2file): self.dir = dir self.p2file = p2file @@ -52,8 +88,11 @@ class CompareSet (object): def find_all_par2_files (dir): - """Finds all par2 files in a directory""" - # NOTE: does NOT return absolute paths + """Finds all par2 files in the given directory. + + dir -- the directory in which to search for PAR2 files + + NOTE: does not return absolute paths""" if not os.path.isdir (os.path.abspath (dir)): raise ValueError # bad directory given @@ -64,7 +103,9 @@ def find_all_par2_files (dir): return rsutil.common.find_par2_files (files) def generate_all_parsets (dir): - # Generate all parsets in the given directory. + """Generate all parsets in the given directory + + dir -- the directory in which to search""" assert os.path.isdir (dir) # Directory MUST be valid @@ -100,6 +141,8 @@ def check_required_progs(): sys.exit(1) def run_options (options): + """Process all of the commandline options, doing thing such as printing the + version number, etc.""" # Fix directories options.work_dir = rsutil.common.full_abspath (options.work_dir) @@ -129,11 +172,14 @@ def run_options (options): if options.write_def_config: config.write_config (default=True) + sys.exit (0) if options.write_config: config.write_config () + sys.exit (0) def find_loglevel (options): + """Find the log level that should be printed by the logging class""" loglevel = options.verbose - options.quiet diff --git a/rsutil/common.py b/rsutil/common.py index b633171..66b7d02 100644 --- a/rsutil/common.py +++ b/rsutil/common.py @@ -1,11 +1,30 @@ #!/usr/bin/env python # vim: set ts=4 sts=4 sw=4 textwidth=92: +""" +Module holding all of the common functions used throughout the rarslave project +""" + __author__ = "Ira W. Snyder (devel@irasnyder.com)" __copyright__ = "Copyright (c) 2006, Ira W. Snyder (devel@irasnyder.com)" __license__ = "GNU GPL v2 (or, at your option, any later version)" -# This module holds all of the common functions used throughout the rarslave project. +# common.py -- holds all of the common functions used throughout the rarslave project +# +# Copyright (C) 2006,2007 Ira W. Snyder (devel@irasnyder.com) +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software import os import re @@ -140,9 +159,3 @@ def config_get_value (section, name): def options_get_value (name): return getattr (rsutil.globals.options, name) -def main (): - pass - -if __name__ == '__main__': - main () - diff --git a/rsutil/config.py b/rsutil/config.py index e0ab710..5b68757 100644 --- a/rsutil/config.py +++ b/rsutil/config.py @@ -1,6 +1,32 @@ #!/usr/bin/env python # vim: set ts=4 sts=4 sw=4 textwidth=92: +""" +Module holding the config class, to be used by the rarslave project. +""" + +__author__ = "Ira W. Snyder (devel@irasnyder.com)" +__copyright__ = "Copyright (c) 2006,2007 Ira W. Snyder (devel@irasnyder.com)" +__license__ = "GNU GPL v2 (or, at your option, any later version)" + +# config.py -- configuration class for rarslave +# +# Copyright (C) 2006,2007 Ira W. Snyder (devel@irasnyder.com) +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + import os, ConfigParser class config (object): diff --git a/rsutil/globals.py b/rsutil/globals.py index a57fcd0..6287d0d 100644 --- a/rsutil/globals.py +++ b/rsutil/globals.py @@ -1,6 +1,32 @@ #!/usr/bin/env python # vim: set ts=4 sts=4 sw=4 textwidth=92: +""" +Module which holds global variables needed throughout the rarslave project. +""" + +__author__ = "Ira W. Snyder (devel@irasnyder.com)" +__copyright__ = "Copyright (c) 2006,2007 Ira W. Snyder (devel@irasnyder.com)" +__license__ = "GNU GPL v2 (or, at your option, any later version)" + +# globals.py -- global variable storage for the rarslave project +# +# Copyright (C) 2006,2007 Ira W. Snyder (devel@irasnyder.com) +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + import rsutil.config # I know that this sucks majorly, but I kinda need it to keep things diff --git a/rsutil/par2parser.py b/rsutil/par2parser.py index 6940101..572c7b1 100644 --- a/rsutil/par2parser.py +++ b/rsutil/par2parser.py @@ -1,11 +1,35 @@ #!/usr/bin/env python # vim: set ts=4 sts=4 sw=4 textwidth=92: -################################################################################ -# The PAR2 Parser +""" +Module which holds PAR2 file parsing functions. + +Much of this code was borrowed from the excellent cfv project. +See http://cfv.sourceforge.net/ for a copy. +""" + +__author__ = "Ira W. Snyder (devel@irasnyder.com)" +__copyright__ = "Copyright (c) 2006,2007 Ira W. Snyder (devel@irasnyder.com)" +__license__ = "GNU GPL v2 (or, at your option, any later version)" + +# par2parser.py -- PAR2 file parsing utility +# +# Copyright (C) 2006,2007 Ira W. Snyder (devel@irasnyder.com) # -# This was stolen from cfv (see http://cfv.sourceforge.net/ for a copy) -################################################################################ +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + import struct, errno, os, md5 -- 2.25.1