From: Łukasz Rekucki Date: Sat, 27 Mar 2010 18:28:54 +0000 (+0100) Subject: Cleanup. X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/aa021ad04c81969c58558343fb1ff2409c82563e?ds=inline;hp=42faac096df5479bd7747d9068eb88d1410d6d34 Cleanup. --- diff --git a/AUTHORS.md b/AUTHORS.md new file mode 100644 index 00000000..b48559cd --- /dev/null +++ b/AUTHORS.md @@ -0,0 +1,5 @@ +Authors +------- + +* Łukasz Rekucki +* Marek Stępniowski diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..2def0e88 --- /dev/null +++ b/LICENSE @@ -0,0 +1,661 @@ + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. + + 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 +them 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. + + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU Affero General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey 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; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If 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 convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU Affero 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 that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + 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. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +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. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + 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 +state 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 Affero General Public License as published by + the Free Software Foundation, either version 3 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 Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU AGPL, see +. \ No newline at end of file diff --git a/NOTICE b/NOTICE new file mode 100644 index 00000000..ff69f4ac --- /dev/null +++ b/NOTICE @@ -0,0 +1,19 @@ + + FNP Librarian + + Copyright © 2010 Fundacja Nowoczesna Polska + + For full list of contributors see AUTHORS file. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 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 Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . \ No newline at end of file diff --git a/apps/maintenancemode/._middleware.py b/apps/maintenancemode/._middleware.py deleted file mode 100644 index d25f019d..00000000 Binary files a/apps/maintenancemode/._middleware.py and /dev/null differ diff --git a/apps/maintenancemode/__init__.py b/apps/maintenancemode/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/apps/maintenancemode/conf/._settings.py b/apps/maintenancemode/conf/._settings.py deleted file mode 100644 index a8981627..00000000 Binary files a/apps/maintenancemode/conf/._settings.py and /dev/null differ diff --git a/apps/maintenancemode/conf/__init__.py b/apps/maintenancemode/conf/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/apps/maintenancemode/conf/settings.py b/apps/maintenancemode/conf/settings.py deleted file mode 100644 index 4d0b1a51..00000000 --- a/apps/maintenancemode/conf/settings.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.conf import settings - -MAINTENANCE_MODE = getattr(settings, 'MAINTENANCE_MODE', False) \ No newline at end of file diff --git a/apps/maintenancemode/conf/urls/__init__.py b/apps/maintenancemode/conf/urls/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/apps/maintenancemode/conf/urls/defaults.py b/apps/maintenancemode/conf/urls/defaults.py deleted file mode 100644 index 20029db5..00000000 --- a/apps/maintenancemode/conf/urls/defaults.py +++ /dev/null @@ -1,3 +0,0 @@ -__all__ = ['handler503'] - -handler503 = 'maintenancemode.views.defaults.temporary_unavailable' \ No newline at end of file diff --git a/apps/maintenancemode/http.py b/apps/maintenancemode/http.py deleted file mode 100644 index 4b3023b6..00000000 --- a/apps/maintenancemode/http.py +++ /dev/null @@ -1,4 +0,0 @@ -from django.http import HttpResponse - -class HttpResponseTemporaryUnavailable(HttpResponse): - status_code = 503 diff --git a/apps/maintenancemode/middleware.py b/apps/maintenancemode/middleware.py deleted file mode 100644 index 35346c8c..00000000 --- a/apps/maintenancemode/middleware.py +++ /dev/null @@ -1,37 +0,0 @@ -from django.conf import settings -from django.core import urlresolvers - -# This is django-maintancemode v. 0.9.2 - -from django.conf.urls import defaults -defaults.handler503 = 'maintenancemode.views.defaults.temporary_unavailable' -defaults.__all__.append('handler503') - -from maintenancemode.conf.settings import MAINTENANCE_MODE -import traceback - -class MaintenanceModeMiddleware(object): - def process_request(self, request): - # Allow access if middleware is not activated - if not MAINTENANCE_MODE: - return None - - # Allow access if remote ip is in INTERNAL_IPS - if request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS: - return None - - # Allow acess if the user doing the request is logged in and a - # staff member. - if hasattr(request, 'user') and request.user.is_staff: - return None - - # Otherwise show the user the 503 page - resolver = urlresolvers.get_resolver(None) - - callback, param_dict = resolver._resolve_special('503') - return callback(request, **param_dict) - - def process_exception(self, request, exception): - tb_text = traceback.format_exc() - url = request.build_absolute_uri() - request.META['wsgi.errors'].write(url + '\n' + str(tb_text) + '\n') diff --git a/apps/maintenancemode/views/__init__.py b/apps/maintenancemode/views/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/apps/maintenancemode/views/defaults.py b/apps/maintenancemode/views/defaults.py deleted file mode 100644 index f0bf48fe..00000000 --- a/apps/maintenancemode/views/defaults.py +++ /dev/null @@ -1,16 +0,0 @@ -from django.template import Context, loader - -from maintenancemode import http - -def temporary_unavailable(request, template_name='503.html'): - """ - Default 503 handler, which looks for the requested URL in the redirects - table, redirects if found, and displays 404 page if not redirected. - - Templates: `503.html` - Context: - request_path - The path of the requested URL (e.g., '/app/pages/bad_page/') - """ - t = loader.get_template(template_name) # You need to create a 503.html template. - return http.HttpResponseTemporaryUnavailable(t.render(Context({}))) \ No newline at end of file diff --git a/apps/sorl/__init__.py b/apps/sorl/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/apps/sorl/thumbnail/__init__.py b/apps/sorl/thumbnail/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/apps/sorl/thumbnail/base.py b/apps/sorl/thumbnail/base.py deleted file mode 100644 index 24f4d973..00000000 --- a/apps/sorl/thumbnail/base.py +++ /dev/null @@ -1,285 +0,0 @@ -import os -from os.path import isfile, isdir, getmtime, dirname, splitext, getsize -from tempfile import mkstemp -from shutil import copyfile - -from PIL import Image - -from sorl.thumbnail import defaults -from sorl.thumbnail.processors import get_valid_options, dynamic_import - - -class ThumbnailException(Exception): - # Stop Django templates from choking if something goes wrong. - silent_variable_failure = True - - -class Thumbnail(object): - imagemagick_file_types = defaults.IMAGEMAGICK_FILE_TYPES - - def __init__(self, source, requested_size, opts=None, quality=85, - dest=None, convert_path=defaults.CONVERT, - wvps_path=defaults.WVPS, processors=None): - # Paths to external commands - self.convert_path = convert_path - self.wvps_path = wvps_path - # Absolute paths to files - self.source = source - self.dest = dest - - # Thumbnail settings - try: - x, y = [int(v) for v in requested_size] - except (TypeError, ValueError): - raise TypeError('Thumbnail received invalid value for size ' - 'argument: %s' % repr(requested_size)) - else: - self.requested_size = (x, y) - try: - self.quality = int(quality) - if not 0 < quality <= 100: - raise ValueError - except (TypeError, ValueError): - raise TypeError('Thumbnail received invalid value for quality ' - 'argument: %r' % quality) - - # Processors - if processors is None: - processors = dynamic_import(defaults.PROCESSORS) - self.processors = processors - - # Handle old list format for opts. - opts = opts or {} - if isinstance(opts, (list, tuple)): - opts = dict([(opt, None) for opt in opts]) - - # Set Thumbnail opt(ion)s - VALID_OPTIONS = get_valid_options(processors) - for opt in opts: - if not opt in VALID_OPTIONS: - raise TypeError('Thumbnail received an invalid option: %s' - % opt) - self.opts = opts - - if self.dest is not None: - self.generate() - - def generate(self): - """ - Generates the thumbnail if it doesn't exist or if the file date of the - source file is newer than that of the thumbnail. - """ - # Ensure dest(ination) attribute is set - if not self.dest: - raise ThumbnailException("No destination filename set.") - - if not isinstance(self.dest, basestring): - # We'll assume dest is a file-like instance if it exists but isn't - # a string. - self._do_generate() - elif not isfile(self.dest) or (self.source_exists and - getmtime(self.source) > getmtime(self.dest)): - - # Ensure the directory exists - directory = dirname(self.dest) - if directory and not isdir(directory): - os.makedirs(directory) - - self._do_generate() - - def _check_source_exists(self): - """ - Ensure the source file exists. If source is not a string then it is - assumed to be a file-like instance which "exists". - """ - if not hasattr(self, '_source_exists'): - self._source_exists = (self.source and - (not isinstance(self.source, basestring) or - isfile(self.source))) - return self._source_exists - source_exists = property(_check_source_exists) - - def _get_source_filetype(self): - """ - Set the source filetype. First it tries to use magic and - if import error it will just use the extension - """ - if not hasattr(self, '_source_filetype'): - if not isinstance(self.source, basestring): - # Assuming a file-like object - we won't know it's type. - return None - try: - import magic - except ImportError: - self._source_filetype = splitext(self.source)[1].lower().\ - replace('.', '').replace('jpeg', 'jpg') - else: - m = magic.open(magic.MAGIC_NONE) - m.load() - ftype = m.file(self.source) - if ftype.find('Microsoft Office Document') != -1: - self._source_filetype = 'doc' - elif ftype.find('PDF document') != -1: - self._source_filetype = 'pdf' - elif ftype.find('JPEG') != -1: - self._source_filetype = 'jpg' - else: - self._source_filetype = ftype - return self._source_filetype - source_filetype = property(_get_source_filetype) - - # data property is the image data of the (generated) thumbnail - def _get_data(self): - if not hasattr(self, '_data'): - try: - self._data = Image.open(self.dest) - except IOError, detail: - raise ThumbnailException(detail) - return self._data - - def _set_data(self, im): - self._data = im - data = property(_get_data, _set_data) - - # source_data property is the image data from the source file - def _get_source_data(self): - if not hasattr(self, '_source_data'): - if not self.source_exists: - raise ThumbnailException("Source file: '%s' does not exist." % - self.source) - if self.source_filetype == 'doc': - self._convert_wvps(self.source) - elif self.source_filetype in self.imagemagick_file_types: - self._convert_imagemagick(self.source) - else: - self.source_data = self.source - return self._source_data - - def _set_source_data(self, image): - if isinstance(image, Image.Image): - self._source_data = image - else: - try: - self._source_data = Image.open(image) - except IOError, detail: - raise ThumbnailException("%s: %s" % (detail, image)) - except MemoryError: - raise ThumbnailException("Memory Error: %s" % image) - source_data = property(_get_source_data, _set_source_data) - - def _convert_wvps(self, filename): - try: - import subprocess - except ImportError: - raise ThumbnailException('wvps requires the Python 2.4 subprocess ' - 'package.') - tmp = mkstemp('.ps')[1] - try: - p = subprocess.Popen((self.wvps_path, filename, tmp), - stdout=subprocess.PIPE) - p.wait() - except OSError, detail: - os.remove(tmp) - raise ThumbnailException('wvPS error: %s' % detail) - self._convert_imagemagick(tmp) - os.remove(tmp) - - def _convert_imagemagick(self, filename): - try: - import subprocess - except ImportError: - raise ThumbnailException('imagemagick requires the Python 2.4 ' - 'subprocess package.') - tmp = mkstemp('.png')[1] - if 'crop' in self.opts or 'autocrop' in self.opts: - x, y = [d * 3 for d in self.requested_size] - else: - x, y = self.requested_size - try: - p = subprocess.Popen((self.convert_path, '-size', '%sx%s' % (x, y), - '-antialias', '-colorspace', 'rgb', '-format', 'PNG24', - '%s[0]' % filename, tmp), stdout=subprocess.PIPE) - p.wait() - except OSError, detail: - os.remove(tmp) - raise ThumbnailException('ImageMagick error: %s' % detail) - self.source_data = tmp - os.remove(tmp) - - def _do_generate(self): - """ - Generates the thumbnail image. - - This a semi-private method so it isn't directly available to template - authors if this object is passed to the template context. - """ - im = self.source_data - - for processor in self.processors: - im = processor(im, self.requested_size, self.opts) - - self.data = im - - filelike = not isinstance(self.dest, basestring) - if not filelike: - dest_extension = os.path.splitext(self.dest)[1][1:] - format = None - else: - dest_extension = None - format = 'JPEG' - if (self.source_filetype and self.source_filetype == dest_extension and - self.source_data == self.data): - copyfile(self.source, self.dest) - else: - try: - im.save(self.dest, format=format, quality=self.quality, - optimize=1) - except IOError: - # Try again, without optimization (PIL can't optimize an image - # larger than ImageFile.MAXBLOCK, which is 64k by default) - try: - im.save(self.dest, format=format, quality=self.quality) - except IOError, detail: - raise ThumbnailException(detail) - - if filelike: - self.dest.seek(0) - - # Some helpful methods - - def _dimension(self, axis): - if self.dest is None: - return None - return self.data.size[axis] - - def width(self): - return self._dimension(0) - - def height(self): - return self._dimension(1) - - def _get_filesize(self): - if self.dest is None: - return None - if not hasattr(self, '_filesize'): - self._filesize = getsize(self.dest) - return self._filesize - filesize = property(_get_filesize) - - def _source_dimension(self, axis): - if self.source_filetype in ['pdf', 'doc']: - return None - else: - return self.source_data.size[axis] - - def source_width(self): - return self._source_dimension(0) - - def source_height(self): - return self._source_dimension(1) - - def _get_source_filesize(self): - if not hasattr(self, '_source_filesize'): - self._source_filesize = getsize(self.source) - return self._source_filesize - source_filesize = property(_get_source_filesize) diff --git a/apps/sorl/thumbnail/defaults.py b/apps/sorl/thumbnail/defaults.py deleted file mode 100644 index b4ae142b..00000000 --- a/apps/sorl/thumbnail/defaults.py +++ /dev/null @@ -1,15 +0,0 @@ -DEBUG = False -BASEDIR = '' -SUBDIR = '' -PREFIX = '' -QUALITY = 85 -CONVERT = '/usr/bin/convert' -WVPS = '/usr/bin/wvPS' -EXTENSION = 'jpg' -PROCESSORS = ( - 'sorl.thumbnail.processors.colorspace', - 'sorl.thumbnail.processors.autocrop', - 'sorl.thumbnail.processors.scale_and_crop', - 'sorl.thumbnail.processors.filters', -) -IMAGEMAGICK_FILE_TYPES = ('eps', 'pdf', 'psd') diff --git a/apps/sorl/thumbnail/fields.py b/apps/sorl/thumbnail/fields.py deleted file mode 100644 index 1b527434..00000000 --- a/apps/sorl/thumbnail/fields.py +++ /dev/null @@ -1,228 +0,0 @@ -from UserDict import DictMixin -try: - from cStringIO import StringIO -except ImportError: - from StringIO import StringIO - -from django.db.models.fields.files import ImageField, ImageFieldFile -from django.core.files.base import ContentFile -from django.utils.safestring import mark_safe -from django.utils.html import escape - -from sorl.thumbnail.base import Thumbnail -from sorl.thumbnail.main import DjangoThumbnail, build_thumbnail_name -from sorl.thumbnail.utils import delete_thumbnails - - -REQUIRED_ARGS = ('size',) -ALL_ARGS = { - 'size': 'requested_size', - 'options': 'opts', - 'quality': 'quality', - 'basedir': 'basedir', - 'subdir': 'subdir', - 'prefix': 'prefix', - 'extension': 'extension', -} -BASE_ARGS = { - 'size': 'requested_size', - 'options': 'opts', - 'quality': 'quality', -} -TAG_HTML = '' - - -class ThumbsDict(object, DictMixin): - def __init__(self, descriptor): - super(ThumbsDict, self).__init__() - self.descriptor = descriptor - - def keys(self): - return self.descriptor.field.extra_thumbnails.keys() - - -class LazyThumbs(ThumbsDict): - def __init__(self, *args, **kwargs): - super(LazyThumbs, self).__init__(*args, **kwargs) - self.cached = {} - - def __getitem__(self, key): - thumb = self.cached.get(key) - if not thumb: - args = self.descriptor.field.extra_thumbnails[key] - thumb = self.descriptor._build_thumbnail(args) - self.cached[key] = thumb - return thumb - - def keys(self): - return self.descriptor.field.extra_thumbnails.keys() - - -class ThumbTags(ThumbsDict): - def __getitem__(self, key): - thumb = self.descriptor.extra_thumbnails[key] - return self.descriptor._build_thumbnail_tag(thumb) - - -class BaseThumbnailFieldFile(ImageFieldFile): - def _build_thumbnail(self, args): - # Build the DjangoThumbnail kwargs. - kwargs = {} - for k, v in args.items(): - kwargs[ALL_ARGS[k]] = v - # Build the destination filename and return the thumbnail. - name_kwargs = {} - for key in ['size', 'options', 'quality', 'basedir', 'subdir', - 'prefix', 'extension']: - name_kwargs[key] = args.get(key) - source = getattr(self.instance, self.field.name) - dest = build_thumbnail_name(source.name, **name_kwargs) - return DjangoThumbnail(source, relative_dest=dest, **kwargs) - - def _build_thumbnail_tag(self, thumb): - opts = dict(src=escape(thumb), width=thumb.width(), - height=thumb.height()) - return mark_safe(self.field.thumbnail_tag % opts) - - def _get_extra_thumbnails(self): - if self.field.extra_thumbnails is None: - return None - if not hasattr(self, '_extra_thumbnails'): - self._extra_thumbnails = LazyThumbs(self) - return self._extra_thumbnails - extra_thumbnails = property(_get_extra_thumbnails) - - def _get_extra_thumbnails_tag(self): - if self.field.extra_thumbnails is None: - return None - return ThumbTags(self) - extra_thumbnails_tag = property(_get_extra_thumbnails_tag) - - def save(self, *args, **kwargs): - # Optionally generate the thumbnails after the image is saved. - super(BaseThumbnailFieldFile, self).save(*args, **kwargs) - if self.field.generate_on_save: - self.generate_thumbnails() - - def delete(self, *args, **kwargs): - # Delete any thumbnails too (and not just ones defined here in case - # the {% thumbnail %} tag was used or the thumbnail sizes changed). - relative_source_path = getattr(self.instance, self.field.name).name - delete_thumbnails(relative_source_path) - super(BaseThumbnailFieldFile, self).delete(*args, **kwargs) - - def generate_thumbnails(self): - # Getting the thumbs generates them. - if self.extra_thumbnails: - self.extra_thumbnails.values() - - -class ImageWithThumbnailsFieldFile(BaseThumbnailFieldFile): - def _get_thumbnail(self): - return self._build_thumbnail(self.field.thumbnail) - thumbnail = property(_get_thumbnail) - - def _get_thumbnail_tag(self): - return self._build_thumbnail_tag(self.thumbnail) - thumbnail_tag = property(_get_thumbnail_tag) - - def generate_thumbnails(self, *args, **kwargs): - self.thumbnail.generate() - Super = super(ImageWithThumbnailsFieldFile, self) - return Super.generate_thumbnails(*args, **kwargs) - - -class ThumbnailFieldFile(BaseThumbnailFieldFile): - def save(self, name, content, *args, **kwargs): - new_content = StringIO() - # Build the Thumbnail kwargs. - thumbnail_kwargs = {} - for k, argk in BASE_ARGS.items(): - if not k in self.field.thumbnail: - continue - thumbnail_kwargs[argk] = self.field.thumbnail[k] - Thumbnail(source=content, dest=new_content, **thumbnail_kwargs) - new_content = ContentFile(new_content.read()) - super(ThumbnailFieldFile, self).save(name, new_content, *args, - **kwargs) - - def _get_thumbnail_tag(self): - opts = dict(src=escape(self.url), width=self.width, - height=self.height) - return mark_safe(self.field.thumbnail_tag % opts) - thumbnail_tag = property(_get_thumbnail_tag) - - -class BaseThumbnailField(ImageField): - def __init__(self, *args, **kwargs): - # The new arguments for this field aren't explicitly defined so that - # users can still use normal ImageField positional arguments. - self.extra_thumbnails = kwargs.pop('extra_thumbnails', None) - self.thumbnail_tag = kwargs.pop('thumbnail_tag', TAG_HTML) - self.generate_on_save = kwargs.pop('generate_on_save', False) - - super(BaseThumbnailField, self).__init__(*args, **kwargs) - _verify_thumbnail_attrs(self.thumbnail) - if self.extra_thumbnails: - for extra, attrs in self.extra_thumbnails.items(): - name = "%r of 'extra_thumbnails'" - _verify_thumbnail_attrs(attrs, name) - - def south_field_triple(self): - """ - Return a suitable description of this field for South. - """ - # We'll just introspect ourselves, since we inherit. - from south.modelsinspector import introspector - field_class = "django.db.models.fields.files.ImageField" - args, kwargs = introspector(self) - # That's our definition! - return (field_class, args, kwargs) - - -class ImageWithThumbnailsField(BaseThumbnailField): - """ - photo = ImageWithThumbnailsField( - upload_to='uploads', - thumbnail={'size': (80, 80), 'options': ('crop', 'upscale'), - 'extension': 'png'}, - extra_thumbnails={ - 'admin': {'size': (70, 50), 'options': ('sharpen',)}, - } - ) - """ - attr_class = ImageWithThumbnailsFieldFile - - def __init__(self, *args, **kwargs): - self.thumbnail = kwargs.pop('thumbnail', None) - super(ImageWithThumbnailsField, self).__init__(*args, **kwargs) - - -class ThumbnailField(BaseThumbnailField): - """ - avatar = ThumbnailField( - upload_to='uploads', - size=(200, 200), - options=('crop',), - extra_thumbnails={ - 'admin': {'size': (70, 50), 'options': (crop, 'sharpen')}, - } - ) - """ - attr_class = ThumbnailFieldFile - - def __init__(self, *args, **kwargs): - self.thumbnail = {} - for attr in ALL_ARGS: - if attr in kwargs: - self.thumbnail[attr] = kwargs.pop(attr) - super(ThumbnailField, self).__init__(*args, **kwargs) - - -def _verify_thumbnail_attrs(attrs, name="'thumbnail'"): - for arg in REQUIRED_ARGS: - if arg not in attrs: - raise TypeError('Required attr %r missing in %s arg' % (arg, name)) - for attr in attrs: - if attr not in ALL_ARGS: - raise TypeError('Invalid attr %r found in %s arg' % (arg, name)) diff --git a/apps/sorl/thumbnail/main.py b/apps/sorl/thumbnail/main.py deleted file mode 100644 index a59b64f1..00000000 --- a/apps/sorl/thumbnail/main.py +++ /dev/null @@ -1,115 +0,0 @@ -import os - -from django.conf import settings -from django.utils.encoding import iri_to_uri, force_unicode - -from sorl.thumbnail.base import Thumbnail -from sorl.thumbnail.processors import dynamic_import -from sorl.thumbnail import defaults - - -def get_thumbnail_setting(setting, override=None): - """ - Get a thumbnail setting from Django settings module, falling back to the - default. - - If override is not None, it will be used instead of the setting. - """ - if override is not None: - return override - if hasattr(settings, 'THUMBNAIL_%s' % setting): - return getattr(settings, 'THUMBNAIL_%s' % setting) - else: - return getattr(defaults, setting) - - -def build_thumbnail_name(source_name, size, options=None, - quality=None, basedir=None, subdir=None, prefix=None, - extension=None): - quality = get_thumbnail_setting('QUALITY', quality) - basedir = get_thumbnail_setting('BASEDIR', basedir) - subdir = get_thumbnail_setting('SUBDIR', subdir) - prefix = get_thumbnail_setting('PREFIX', prefix) - extension = get_thumbnail_setting('EXTENSION', extension) - path, filename = os.path.split(source_name) - basename, ext = os.path.splitext(filename) - name = '%s%s' % (basename, ext.replace(os.extsep, '_')) - size = '%sx%s' % tuple(size) - - # Handle old list format for opts. - options = options or {} - if isinstance(options, (list, tuple)): - options = dict([(opt, None) for opt in options]) - - opts = options.items() - opts.sort() # options are sorted so the filename is consistent - opts = ['%s_' % (v is not None and '%s-%s' % (k, v) or k) - for k, v in opts] - opts = ''.join(opts) - extension = extension and '.%s' % extension - thumbnail_filename = '%s%s_%s_%sq%s%s' % (prefix, name, size, opts, - quality, extension) - return os.path.join(basedir, path, subdir, thumbnail_filename) - - -class DjangoThumbnail(Thumbnail): - imagemagick_file_types = get_thumbnail_setting('IMAGEMAGICK_FILE_TYPES') - - def __init__(self, relative_source, requested_size, opts=None, - quality=None, basedir=None, subdir=None, prefix=None, - relative_dest=None, processors=None, extension=None): - relative_source = force_unicode(relative_source) - # Set the absolute filename for the source file - source = self._absolute_path(relative_source) - - quality = get_thumbnail_setting('QUALITY', quality) - convert_path = get_thumbnail_setting('CONVERT') - wvps_path = get_thumbnail_setting('WVPS') - if processors is None: - processors = dynamic_import(get_thumbnail_setting('PROCESSORS')) - - # Call super().__init__ now to set the opts attribute. generate() won't - # get called because we are not setting the dest attribute yet. - super(DjangoThumbnail, self).__init__(source, requested_size, - opts=opts, quality=quality, convert_path=convert_path, - wvps_path=wvps_path, processors=processors) - - # Get the relative filename for the thumbnail image, then set the - # destination filename - if relative_dest is None: - relative_dest = \ - self._get_relative_thumbnail(relative_source, basedir=basedir, - subdir=subdir, prefix=prefix, - extension=extension) - filelike = not isinstance(relative_dest, basestring) - if filelike: - self.dest = relative_dest - else: - self.dest = self._absolute_path(relative_dest) - - # Call generate now that the dest attribute has been set - self.generate() - - # Set the relative & absolute url to the thumbnail - if not filelike: - self.relative_url = \ - iri_to_uri('/'.join(relative_dest.split(os.sep))) - self.absolute_url = '%s%s' % (settings.MEDIA_URL, - self.relative_url) - - def _get_relative_thumbnail(self, relative_source, - basedir=None, subdir=None, prefix=None, - extension=None): - """ - Returns the thumbnail filename including relative path. - """ - return build_thumbnail_name(relative_source, self.requested_size, - self.opts, self.quality, basedir, subdir, - prefix, extension) - - def _absolute_path(self, filename): - absolute_filename = os.path.join(settings.MEDIA_ROOT, filename) - return absolute_filename.encode(settings.FILE_CHARSET) - - def __unicode__(self): - return self.absolute_url diff --git a/apps/sorl/thumbnail/management/__init__.py b/apps/sorl/thumbnail/management/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/apps/sorl/thumbnail/management/commands/__init__.py b/apps/sorl/thumbnail/management/commands/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/apps/sorl/thumbnail/management/commands/thumbnail_cleanup.py b/apps/sorl/thumbnail/management/commands/thumbnail_cleanup.py deleted file mode 100644 index 690c42c7..00000000 --- a/apps/sorl/thumbnail/management/commands/thumbnail_cleanup.py +++ /dev/null @@ -1,75 +0,0 @@ -import os -import re -from django.db import models -from django.conf import settings -from django.core.management.base import NoArgsCommand -from sorl.thumbnail.main import get_thumbnail_setting - - -try: - set -except NameError: - from sets import Set as set # For Python 2.3 - -thumb_re = re.compile(r'^%s(.*)_\d{1,}x\d{1,}_[-\w]*q([1-9]\d?|100)\.jpg' % - get_thumbnail_setting('PREFIX')) - - -def get_thumbnail_path(path): - basedir = get_thumbnail_setting('BASEDIR') - subdir = get_thumbnail_setting('SUBDIR') - return os.path.join(basedir, path, subdir) - - -def clean_up(): - paths = set() - for app in models.get_apps(): - model_list = models.get_models(app) - for model in model_list: - for field in model._meta.fields: - if isinstance(field, models.ImageField): - #TODO: take care of date formatted and callable upload_to. - if (not callable(field.upload_to) and - field.upload_to.find("%") == -1): - paths = paths.union((field.upload_to,)) - paths = list(paths) - for path in paths: - thumbnail_path = get_thumbnail_path(path) - try: - file_list = os.listdir(os.path.join(settings.MEDIA_ROOT, - thumbnail_path)) - except OSError: - continue # Dir doesn't exists, no thumbnails here. - for fn in file_list: - m = thumb_re.match(fn) - if m: - # Due to that the naming of thumbnails replaces the dot before - # extension with an underscore we have 2 possibilities for the - # original filename. If either present we do not delete - # suspected thumbnail. - # org_fn is the expected original filename w/o extension - # org_fn_alt is the expected original filename with extension - org_fn = m.group(1) - org_fn_exists = os.path.isfile( - os.path.join(settings.MEDIA_ROOT, path, org_fn)) - - usc_pos = org_fn.rfind("_") - if usc_pos != -1: - org_fn_alt = "%s.%s" % (org_fn[0:usc_pos], - org_fn[usc_pos+1:]) - org_fn_alt_exists = os.path.isfile( - os.path.join(settings.MEDIA_ROOT, path, org_fn_alt)) - else: - org_fn_alt_exists = False - if not org_fn_exists and not org_fn_alt_exists: - del_me = os.path.join(settings.MEDIA_ROOT, - thumbnail_path, fn) - os.remove(del_me) - - -class Command(NoArgsCommand): - help = "Deletes thumbnails that no longer have an original file." - requires_model_validation = False - - def handle_noargs(self, **options): - clean_up() diff --git a/apps/sorl/thumbnail/models.py b/apps/sorl/thumbnail/models.py deleted file mode 100644 index ec325fd5..00000000 --- a/apps/sorl/thumbnail/models.py +++ /dev/null @@ -1 +0,0 @@ -# Needs a models.py file so that tests are picked up. diff --git a/apps/sorl/thumbnail/processors.py b/apps/sorl/thumbnail/processors.py deleted file mode 100644 index a6c17416..00000000 --- a/apps/sorl/thumbnail/processors.py +++ /dev/null @@ -1,130 +0,0 @@ -from PIL import Image, ImageFilter, ImageChops -from sorl.thumbnail import utils -import re - - -def dynamic_import(names): - imported = [] - for name in names: - # Use rfind rather than rsplit for Python 2.3 compatibility. - lastdot = name.rfind('.') - modname, attrname = name[:lastdot], name[lastdot + 1:] - mod = __import__(modname, {}, {}, ['']) - imported.append(getattr(mod, attrname)) - return imported - - -def get_valid_options(processors): - """ - Returns a list containing unique valid options from a list of processors - in correct order. - """ - valid_options = [] - for processor in processors: - if hasattr(processor, 'valid_options'): - valid_options.extend([opt for opt in processor.valid_options - if opt not in valid_options]) - return valid_options - - -def colorspace(im, requested_size, opts): - if 'bw' in opts and im.mode != "L": - im = im.convert("L") - elif im.mode not in ("L", "RGB", "RGBA"): - im = im.convert("RGB") - return im -colorspace.valid_options = ('bw',) - - -def autocrop(im, requested_size, opts): - if 'autocrop' in opts: - bw = im.convert("1") - bw = bw.filter(ImageFilter.MedianFilter) - # white bg - bg = Image.new("1", im.size, 255) - diff = ImageChops.difference(bw, bg) - bbox = diff.getbbox() - if bbox: - im = im.crop(bbox) - return im -autocrop.valid_options = ('autocrop',) - - -def scale_and_crop(im, requested_size, opts): - x, y = [float(v) for v in im.size] - xr, yr = [float(v) for v in requested_size] - - if 'crop' in opts or 'max' in opts: - r = max(xr / x, yr / y) - else: - r = min(xr / x, yr / y) - - if r < 1.0 or (r > 1.0 and 'upscale' in opts): - im = im.resize((int(x * r), int(y * r)), resample=Image.ANTIALIAS) - - crop = opts.get('crop') or 'crop' in opts - if crop: - # Difference (for x and y) between new image size and requested size. - x, y = [float(v) for v in im.size] - dx, dy = (x - min(x, xr)), (y - min(y, yr)) - if dx or dy: - # Center cropping (default). - ex, ey = dx / 2, dy / 2 - box = [ex, ey, x - ex, y - ey] - # See if an edge cropping argument was provided. - edge_crop = (isinstance(crop, basestring) and - re.match(r'(?:(-?)(\d+))?,(?:(-?)(\d+))?$', crop)) - if edge_crop and filter(None, edge_crop.groups()): - x_right, x_crop, y_bottom, y_crop = edge_crop.groups() - if x_crop: - offset = min(x * int(x_crop) / 100, dx) - if x_right: - box[0] = dx - offset - box[2] = x - offset - else: - box[0] = offset - box[2] = x - (dx - offset) - if y_crop: - offset = min(y * int(y_crop) / 100, dy) - if y_bottom: - box[1] = dy - offset - box[3] = y - offset - else: - box[1] = offset - box[3] = y - (dy - offset) - # See if the image should be "smart cropped". - elif crop == 'smart': - left = top = 0 - right, bottom = x, y - while dx: - slice = min(dx, 10) - l_sl = im.crop((0, 0, slice, y)) - r_sl = im.crop((x - slice, 0, x, y)) - if utils.image_entropy(l_sl) >= utils.image_entropy(r_sl): - right -= slice - else: - left += slice - dx -= slice - while dy: - slice = min(dy, 10) - t_sl = im.crop((0, 0, x, slice)) - b_sl = im.crop((0, y - slice, x, y)) - if utils.image_entropy(t_sl) >= utils.image_entropy(b_sl): - bottom -= slice - else: - top += slice - dy -= slice - box = (left, top, right, bottom) - # Finally, crop the image! - im = im.crop([int(v) for v in box]) - return im -scale_and_crop.valid_options = ('crop', 'upscale', 'max') - - -def filters(im, requested_size, opts): - if 'detail' in opts: - im = im.filter(ImageFilter.DETAIL) - if 'sharpen' in opts: - im = im.filter(ImageFilter.SHARPEN) - return im -filters.valid_options = ('detail', 'sharpen') diff --git a/apps/sorl/thumbnail/templatetags/__init__.py b/apps/sorl/thumbnail/templatetags/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/apps/sorl/thumbnail/templatetags/thumbnail.py b/apps/sorl/thumbnail/templatetags/thumbnail.py deleted file mode 100644 index e7c2177e..00000000 --- a/apps/sorl/thumbnail/templatetags/thumbnail.py +++ /dev/null @@ -1,251 +0,0 @@ -import re -import math -from django.template import Library, Node, VariableDoesNotExist, \ - TemplateSyntaxError -from sorl.thumbnail.main import DjangoThumbnail, get_thumbnail_setting -from sorl.thumbnail.processors import dynamic_import, get_valid_options -from sorl.thumbnail.utils import split_args - -register = Library() - -size_pat = re.compile(r'(\d+)x(\d+)$') - -filesize_formats = ['k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'] -filesize_long_formats = { - 'k': 'kilo', 'M': 'mega', 'G': 'giga', 'T': 'tera', 'P': 'peta', - 'E': 'exa', 'Z': 'zetta', 'Y': 'yotta', -} - -try: - PROCESSORS = dynamic_import(get_thumbnail_setting('PROCESSORS')) - VALID_OPTIONS = get_valid_options(PROCESSORS) -except: - if get_thumbnail_setting('DEBUG'): - raise - else: - PROCESSORS = [] - VALID_OPTIONS = [] -TAG_SETTINGS = ['quality'] - - -class ThumbnailNode(Node): - def __init__(self, source_var, size_var, opts=None, - context_name=None, **kwargs): - self.source_var = source_var - self.size_var = size_var - self.opts = opts - self.context_name = context_name - self.kwargs = kwargs - - def render(self, context): - # Note that this isn't a global constant because we need to change the - # value for tests. - DEBUG = get_thumbnail_setting('DEBUG') - try: - # A file object will be allowed in DjangoThumbnail class - relative_source = self.source_var.resolve(context) - except VariableDoesNotExist: - if DEBUG: - raise VariableDoesNotExist("Variable '%s' does not exist." % - self.source_var) - else: - relative_source = None - try: - requested_size = self.size_var.resolve(context) - except VariableDoesNotExist: - if DEBUG: - raise TemplateSyntaxError("Size argument '%s' is not a" - " valid size nor a valid variable." % self.size_var) - else: - requested_size = None - # Size variable can be either a tuple/list of two integers or a valid - # string, only the string is checked. - else: - if isinstance(requested_size, basestring): - m = size_pat.match(requested_size) - if m: - requested_size = (int(m.group(1)), int(m.group(2))) - elif DEBUG: - raise TemplateSyntaxError("Variable '%s' was resolved but " - "'%s' is not a valid size." % - (self.size_var, requested_size)) - else: - requested_size = None - if relative_source is None or requested_size is None: - thumbnail = '' - else: - try: - kwargs = {} - for key, value in self.kwargs.items(): - kwargs[key] = value.resolve(context) - opts = dict([(k, v and v.resolve(context)) - for k, v in self.opts.items()]) - thumbnail = DjangoThumbnail(relative_source, requested_size, - opts=opts, processors=PROCESSORS, **kwargs) - except: - if DEBUG: - raise - else: - thumbnail = '' - # Return the thumbnail class, or put it on the context - if self.context_name is None: - return thumbnail - # We need to get here so we don't have old values in the context - # variable. - context[self.context_name] = thumbnail - return '' - - -def thumbnail(parser, token): - """ - Creates a thumbnail of for an ImageField. - - To just output the absolute url to the thumbnail:: - - {% thumbnail image 80x80 %} - - After the image path and dimensions, you can put any options:: - - {% thumbnail image 80x80 quality=95 crop %} - - To put the DjangoThumbnail class on the context instead of just rendering - the absolute url, finish the tag with ``as [context_var_name]``:: - - {% thumbnail image 80x80 as thumb %} - {{ thumb.width }} x {{ thumb.height }} - """ - args = token.split_contents() - tag = args[0] - # Check to see if we're setting to a context variable. - if len(args) > 4 and args[-2] == 'as': - context_name = args[-1] - args = args[:-2] - else: - context_name = None - - if len(args) < 3: - raise TemplateSyntaxError("Invalid syntax. Expected " - "'{%% %s source size [option1 option2 ...] %%}' or " - "'{%% %s source size [option1 option2 ...] as variable %%}'" % - (tag, tag)) - - # Get the source image path and requested size. - source_var = parser.compile_filter(args[1]) - # If the size argument was a correct static format, wrap it in quotes so - # that it is compiled correctly. - m = size_pat.match(args[2]) - if m: - args[2] = '"%s"' % args[2] - size_var = parser.compile_filter(args[2]) - - # Get the options. - args_list = split_args(args[3:]).items() - - # Check the options. - opts = {} - kwargs = {} # key,values here override settings and defaults - - for arg, value in args_list: - value = value and parser.compile_filter(value) - if arg in TAG_SETTINGS and value is not None: - kwargs[str(arg)] = value - continue - if arg in VALID_OPTIONS: - opts[arg] = value - else: - raise TemplateSyntaxError("'%s' tag received a bad argument: " - "'%s'" % (tag, arg)) - return ThumbnailNode(source_var, size_var, opts=opts, - context_name=context_name, **kwargs) - - -def filesize(bytes, format='auto1024'): - """ - Returns the number of bytes in either the nearest unit or a specific unit - (depending on the chosen format method). - - Acceptable formats are: - - auto1024, auto1000 - convert to the nearest unit, appending the abbreviated unit name to the - string (e.g. '2 KiB' or '2 kB'). - auto1024 is the default format. - auto1024long, auto1000long - convert to the nearest multiple of 1024 or 1000, appending the correctly - pluralized unit name to the string (e.g. '2 kibibytes' or '2 kilobytes'). - kB, MB, GB, TB, PB, EB, ZB or YB - convert to the exact unit (using multiples of 1000). - KiB, MiB, GiB, TiB, PiB, EiB, ZiB or YiB - convert to the exact unit (using multiples of 1024). - - The auto1024 and auto1000 formats return a string, appending the correct - unit to the value. All other formats return the floating point value. - - If an invalid format is specified, the bytes are returned unchanged. - """ - format_len = len(format) - # Check for valid format - if format_len in (2, 3): - if format_len == 3 and format[0] == 'K': - format = 'k%s' % format[1:] - if not format[-1] == 'B' or format[0] not in filesize_formats: - return bytes - if format_len == 3 and format[1] != 'i': - return bytes - elif format not in ('auto1024', 'auto1000', - 'auto1024long', 'auto1000long'): - return bytes - # Check for valid bytes - try: - bytes = long(bytes) - except (ValueError, TypeError): - return bytes - - # Auto multiple of 1000 or 1024 - if format.startswith('auto'): - if format[4:8] == '1000': - base = 1000 - else: - base = 1024 - logarithm = bytes and math.log(bytes, base) or 0 - index = min(int(logarithm) - 1, len(filesize_formats) - 1) - if index >= 0: - if base == 1000: - bytes = bytes and bytes / math.pow(1000, index + 1) - else: - bytes = bytes >> (10 * (index)) - bytes = bytes and bytes / 1024.0 - unit = filesize_formats[index] - else: - # Change the base to 1000 so the unit will just output 'B' not 'iB' - base = 1000 - unit = '' - if bytes >= 10 or ('%.1f' % bytes).endswith('.0'): - bytes = '%.0f' % bytes - else: - bytes = '%.1f' % bytes - if format.endswith('long'): - unit = filesize_long_formats.get(unit, '') - if base == 1024 and unit: - unit = '%sbi' % unit[:2] - unit = '%sbyte%s' % (unit, bytes != '1' and 's' or '') - else: - unit = '%s%s' % (base == 1024 and unit.upper() or unit, - base == 1024 and 'iB' or 'B') - - return '%s %s' % (bytes, unit) - - if bytes == 0: - return bytes - base = filesize_formats.index(format[0]) + 1 - # Exact multiple of 1000 - if format_len == 2: - return bytes / (1000.0 ** base) - # Exact multiple of 1024 - elif format_len == 3: - bytes = bytes >> (10 * (base - 1)) - return bytes / 1024.0 - - -register.tag(thumbnail) -register.filter(filesize) diff --git a/apps/sorl/thumbnail/tests/__init__.py b/apps/sorl/thumbnail/tests/__init__.py deleted file mode 100644 index 98f1cbd8..00000000 --- a/apps/sorl/thumbnail/tests/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ -# For these tests to run successfully, two conditions must be met: -# 1. MEDIA_URL and MEDIA_ROOT must be set in settings -# 2. The user running the tests must have read/write access to MEDIA_ROOT - -# Unit tests: -from sorl.thumbnail.tests.classes import ThumbnailTest, DjangoThumbnailTest -from sorl.thumbnail.tests.templatetags import ThumbnailTagTest -from sorl.thumbnail.tests.fields import FieldTest, \ - ImageWithThumbnailsFieldTest, ThumbnailFieldTest -# Doc tests: -from sorl.thumbnail.tests.utils import utils_tests -from sorl.thumbnail.tests.templatetags import filesize_tests -__test__ = { - 'utils_tests': utils_tests, - 'filesize_tests': filesize_tests, -} diff --git a/apps/sorl/thumbnail/tests/base.py b/apps/sorl/thumbnail/tests/base.py deleted file mode 100644 index 44a2fa22..00000000 --- a/apps/sorl/thumbnail/tests/base.py +++ /dev/null @@ -1,105 +0,0 @@ -import unittest -import os -from PIL import Image -from django.conf import settings -from sorl.thumbnail.base import Thumbnail - -try: - set -except NameError: - from sets import Set as set # For Python 2.3 - - -def get_default_settings(): - from sorl.thumbnail import defaults - def_settings = {} - for key in dir(defaults): - if key == key.upper() and key not in ['WVPS', 'CONVERT']: - def_settings[key] = getattr(defaults, key) - return def_settings - - -DEFAULT_THUMBNAIL_SETTINGS = get_default_settings() -RELATIVE_PIC_NAME = "sorl-thumbnail-test_source.jpg" -PIC_NAME = os.path.join(settings.MEDIA_ROOT, RELATIVE_PIC_NAME) -THUMB_NAME = os.path.join(settings.MEDIA_ROOT, "sorl-thumbnail-test_%02d.jpg") -PIC_SIZE = (800, 600) - - -class ChangeSettings: - def __init__(self): - self.default_settings = DEFAULT_THUMBNAIL_SETTINGS.copy() - - def change(self, override=None): - if override is not None: - self.default_settings.update(override) - for setting, default in self.default_settings.items(): - settings_s = 'THUMBNAIL_%s' % setting - self_s = 'original_%s' % setting - if hasattr(settings, settings_s) and not hasattr(self, self_s): - setattr(self, self_s, getattr(settings, settings_s)) - if hasattr(settings, settings_s) or \ - default != DEFAULT_THUMBNAIL_SETTINGS[setting]: - setattr(settings, settings_s, default) - - def revert(self): - for setting in self.default_settings: - settings_s = 'THUMBNAIL_%s' % setting - self_s = 'original_%s' % setting - if hasattr(self, self_s): - setattr(settings, settings_s, getattr(self, self_s)) - delattr(self, self_s) - - -class BaseTest(unittest.TestCase): - def setUp(self): - self.images_to_delete = set() - # Create the test image - Image.new('RGB', PIC_SIZE).save(PIC_NAME, 'JPEG') - self.images_to_delete.add(PIC_NAME) - # Change settings so we know they will be constant - self.change_settings = ChangeSettings() - self.change_settings.change() - - def verify_thumbnail(self, expected_size, thumbnail=None, - expected_filename=None, expected_mode=None): - assert thumbnail is not None or expected_filename is not None, \ - 'verify_thumbnail should be passed at least a thumbnail or an' \ - 'expected filename.' - - if thumbnail is not None: - # Verify that the templatetag method returned a Thumbnail instance - self.assertTrue(isinstance(thumbnail, Thumbnail)) - thumb_name = thumbnail.dest - else: - thumb_name = expected_filename - - if isinstance(thumb_name, basestring): - # Verify that the thumbnail file exists - self.assert_(os.path.isfile(thumb_name), - 'Thumbnail file not found') - - # Remember to delete the file - self.images_to_delete.add(thumb_name) - - # If we got an expected_filename, check that it is right - if expected_filename is not None and thumbnail is not None: - self.assertEqual(thumbnail.dest, expected_filename) - - image = Image.open(thumb_name) - - # Verify the thumbnail has the expected dimensions - self.assertEqual(image.size, expected_size) - - if expected_mode is not None: - self.assertEqual(image.mode, expected_mode) - - def tearDown(self): - # Remove all the files that have been created - for image in self.images_to_delete: - try: - os.remove(image) - except: - pass - # Change settings back to original - self.change_settings.revert() diff --git a/apps/sorl/thumbnail/tests/classes.py b/apps/sorl/thumbnail/tests/classes.py deleted file mode 100644 index d15dd193..00000000 --- a/apps/sorl/thumbnail/tests/classes.py +++ /dev/null @@ -1,175 +0,0 @@ -# -*- coding: utf-8 -*- -import os -import time -from StringIO import StringIO - -from PIL import Image -from django.conf import settings - -from sorl.thumbnail.base import Thumbnail -from sorl.thumbnail.main import DjangoThumbnail, get_thumbnail_setting -from sorl.thumbnail.processors import dynamic_import, get_valid_options -from sorl.thumbnail.tests.base import BaseTest, RELATIVE_PIC_NAME, PIC_NAME,\ - THUMB_NAME, PIC_SIZE - - -class ThumbnailTest(BaseTest): - def testThumbnails(self): - # Thumbnail - thumb = Thumbnail(source=PIC_NAME, dest=THUMB_NAME % 1, - requested_size=(240, 240)) - self.verify_thumbnail((240, 180), thumb) - - # Cropped thumbnail - thumb = Thumbnail(source=PIC_NAME, dest=THUMB_NAME % 2, - requested_size=(240, 240), opts=['crop']) - self.verify_thumbnail((240, 240), thumb) - - # Thumbnail with altered JPEG quality - thumb = Thumbnail(source=PIC_NAME, dest=THUMB_NAME % 3, - requested_size=(240, 240), quality=95) - self.verify_thumbnail((240, 180), thumb) - - def testRegeneration(self): - # Create thumbnail - thumb_name = THUMB_NAME % 4 - thumb_size = (240, 240) - Thumbnail(source=PIC_NAME, dest=thumb_name, requested_size=thumb_size) - self.images_to_delete.add(thumb_name) - thumb_mtime = os.path.getmtime(thumb_name) - time.sleep(1) - - # Create another instance, shouldn't generate a new thumb - Thumbnail(source=PIC_NAME, dest=thumb_name, requested_size=thumb_size) - self.assertEqual(os.path.getmtime(thumb_name), thumb_mtime) - - # Recreate the source image, then see if a new thumb is generated - Image.new('RGB', PIC_SIZE).save(PIC_NAME, 'JPEG') - Thumbnail(source=PIC_NAME, dest=thumb_name, requested_size=thumb_size) - self.assertNotEqual(os.path.getmtime(thumb_name), thumb_mtime) - - def testFilelikeDest(self): - # Thumbnail - filelike_dest = StringIO() - thumb = Thumbnail(source=PIC_NAME, dest=filelike_dest, - requested_size=(240, 240)) - self.verify_thumbnail((240, 180), thumb) - - def testRGBA(self): - # RGBA image - rgba_pic_name = os.path.join(settings.MEDIA_ROOT, - 'sorl-thumbnail-test_rgba_source.png') - Image.new('RGBA', PIC_SIZE).save(rgba_pic_name) - self.images_to_delete.add(rgba_pic_name) - # Create thumb and verify it's still RGBA - rgba_thumb_name = os.path.join(settings.MEDIA_ROOT, - 'sorl-thumbnail-test_rgba_dest.png') - thumb = Thumbnail(source=rgba_pic_name, dest=rgba_thumb_name, - requested_size=(240, 240)) - self.verify_thumbnail((240, 180), thumb, expected_mode='RGBA') - - -class DjangoThumbnailTest(BaseTest): - def setUp(self): - super(DjangoThumbnailTest, self).setUp() - # Add another source image in a sub-directory for testing subdir and - # basedir. - self.sub_dir = os.path.join(settings.MEDIA_ROOT, 'test_thumbnail') - try: - os.mkdir(self.sub_dir) - except OSError: - pass - self.pic_subdir = os.path.join(self.sub_dir, RELATIVE_PIC_NAME) - Image.new('RGB', PIC_SIZE).save(self.pic_subdir, 'JPEG') - self.images_to_delete.add(self.pic_subdir) - - def testFilenameGeneration(self): - basename = RELATIVE_PIC_NAME.replace('.', '_') - # Basic filename - thumb = DjangoThumbnail(relative_source=RELATIVE_PIC_NAME, - requested_size=(240, 120)) - expected = os.path.join(settings.MEDIA_ROOT, basename) - expected += '_240x120_q85.jpg' - self.verify_thumbnail((160, 120), thumb, expected_filename=expected) - - # Changed quality and cropped - thumb = DjangoThumbnail(relative_source=RELATIVE_PIC_NAME, - requested_size=(240, 120), opts=['crop'], - quality=95) - expected = os.path.join(settings.MEDIA_ROOT, basename) - expected += '_240x120_crop_q95.jpg' - self.verify_thumbnail((240, 120), thumb, expected_filename=expected) - - # All options on - processors = dynamic_import(get_thumbnail_setting('PROCESSORS')) - valid_options = get_valid_options(processors) - - thumb = DjangoThumbnail(relative_source=RELATIVE_PIC_NAME, - requested_size=(240, 120), opts=valid_options) - expected = (os.path.join(settings.MEDIA_ROOT, basename) + '_240x120_' - 'autocrop_bw_crop_detail_max_sharpen_upscale_q85.jpg') - self.verify_thumbnail((240, 120), thumb, expected_filename=expected) - - # Different basedir - basedir = 'sorl-thumbnail-test-basedir' - self.change_settings.change({'BASEDIR': basedir}) - thumb = DjangoThumbnail(relative_source=self.pic_subdir, - requested_size=(240, 120)) - expected = os.path.join(basedir, self.sub_dir, basename) - expected += '_240x120_q85.jpg' - self.verify_thumbnail((160, 120), thumb, expected_filename=expected) - # Different subdir - self.change_settings.change({'BASEDIR': '', 'SUBDIR': 'subdir'}) - thumb = DjangoThumbnail(relative_source=self.pic_subdir, - requested_size=(240, 120)) - expected = os.path.join(settings.MEDIA_ROOT, - os.path.basename(self.sub_dir), 'subdir', - basename) - expected += '_240x120_q85.jpg' - self.verify_thumbnail((160, 120), thumb, expected_filename=expected) - # Different prefix - self.change_settings.change({'SUBDIR': '', 'PREFIX': 'prefix-'}) - thumb = DjangoThumbnail(relative_source=self.pic_subdir, - requested_size=(240, 120)) - expected = os.path.join(self.sub_dir, 'prefix-' + basename) - expected += '_240x120_q85.jpg' - self.verify_thumbnail((160, 120), thumb, expected_filename=expected) - - def testAlternateExtension(self): - basename = RELATIVE_PIC_NAME.replace('.', '_') - # Control JPG - thumb = DjangoThumbnail(relative_source=RELATIVE_PIC_NAME, - requested_size=(240, 120)) - expected = os.path.join(settings.MEDIA_ROOT, basename) - expected += '_240x120_q85.jpg' - expected_jpg = expected - self.verify_thumbnail((160, 120), thumb, expected_filename=expected) - # Test PNG - thumb = DjangoThumbnail(relative_source=RELATIVE_PIC_NAME, - requested_size=(240, 120), extension='png') - expected = os.path.join(settings.MEDIA_ROOT, basename) - expected += '_240x120_q85.png' - self.verify_thumbnail((160, 120), thumb, expected_filename=expected) - # Compare the file size to make sure it's not just saving as a JPG with - # a different extension. - self.assertNotEqual(os.path.getsize(expected_jpg), - os.path.getsize(expected)) - - def testUnicodeName(self): - unicode_name = 'sorl-thumbnail-ążśź_source.jpg' - unicode_path = os.path.join(settings.MEDIA_ROOT, unicode_name) - Image.new('RGB', PIC_SIZE).save(unicode_path) - self.images_to_delete.add(unicode_path) - thumb = DjangoThumbnail(relative_source=unicode_name, - requested_size=(240, 120)) - base_name = unicode_name.replace('.', '_') - expected = os.path.join(settings.MEDIA_ROOT, - base_name + '_240x120_q85.jpg') - self.verify_thumbnail((160, 120), thumb, expected_filename=expected) - - def tearDown(self): - super(DjangoThumbnailTest, self).tearDown() - subdir = os.path.join(self.sub_dir, 'subdir') - if os.path.exists(subdir): - os.rmdir(subdir) - os.rmdir(self.sub_dir) diff --git a/apps/sorl/thumbnail/tests/fields.py b/apps/sorl/thumbnail/tests/fields.py deleted file mode 100644 index 425f5553..00000000 --- a/apps/sorl/thumbnail/tests/fields.py +++ /dev/null @@ -1,131 +0,0 @@ -import os.path - -from django.db import models -from django.conf import settings -from django.core.files.base import ContentFile - -from sorl.thumbnail.fields import ImageWithThumbnailsField, ThumbnailField -from sorl.thumbnail.tests.base import BaseTest, RELATIVE_PIC_NAME, PIC_NAME - -thumbnail = { - 'size': (50, 50), -} -extra_thumbnails = { - 'admin': { - 'size': (30, 30), - 'options': ('crop',), - } -} -extension_thumbnail = thumbnail.copy() -extension_thumbnail['extension'] = 'png' - - -# Temporary models for field_tests -class TestThumbnailFieldModel(models.Model): - avatar = ThumbnailField(upload_to='test', size=(300, 300)) - photo = ImageWithThumbnailsField(upload_to='test', thumbnail=thumbnail, - extra_thumbnails=extra_thumbnails) - - -class TestThumbnailFieldExtensionModel(models.Model): - photo = ImageWithThumbnailsField(upload_to='test', - thumbnail=extension_thumbnail, - extra_thumbnails=extra_thumbnails) - - -class TestThumbnailFieldGenerateModel(models.Model): - photo = ImageWithThumbnailsField(upload_to='test', thumbnail=thumbnail, - extra_thumbnails=extra_thumbnails, - generate_on_save=True) - - -class FieldTest(BaseTest): - """ - Test the base field functionality. These use an ImageWithThumbnailsField - but all the functionality tested is from BaseThumbnailField. - """ - def test_extra_thumbnails(self): - model = TestThumbnailFieldModel(photo=RELATIVE_PIC_NAME) - self.assertTrue('admin' in model.photo.extra_thumbnails) - thumb = model.photo.extra_thumbnails['admin'] - tag = model.photo.extra_thumbnails_tag['admin'] - expected_filename = os.path.join(settings.MEDIA_ROOT, - 'sorl-thumbnail-test_source_jpg_30x30_crop_q85.jpg') - self.verify_thumbnail((30, 30), thumb, expected_filename) - expected_tag = '' % \ - '/'.join((settings.MEDIA_URL.rstrip('/'), - 'sorl-thumbnail-test_source_jpg_30x30_crop_q85.jpg')) - self.assertEqual(tag, expected_tag) - - def test_extension(self): - model = TestThumbnailFieldExtensionModel(photo=RELATIVE_PIC_NAME) - thumb = model.photo.thumbnail - tag = model.photo.thumbnail_tag - expected_filename = os.path.join(settings.MEDIA_ROOT, - 'sorl-thumbnail-test_source_jpg_50x50_q85.png') - self.verify_thumbnail((50, 37), thumb, expected_filename) - expected_tag = '' % \ - '/'.join((settings.MEDIA_URL.rstrip('/'), - 'sorl-thumbnail-test_source_jpg_50x50_q85.png')) - self.assertEqual(tag, expected_tag) - - def test_delete_thumbnails(self): - model = TestThumbnailFieldModel(photo=RELATIVE_PIC_NAME) - thumb_file = model.photo.thumbnail.dest - open(thumb_file, 'wb').close() - self.assert_(os.path.exists(thumb_file)) - model.photo.delete(save=False) - self.assertFalse(os.path.exists(thumb_file)) - - def test_generate_on_save(self): - main_thumb = os.path.join(settings.MEDIA_ROOT, 'test', - 'sorl-thumbnail-test_source_jpg_50x50_q85.jpg') - admin_thumb = os.path.join(settings.MEDIA_ROOT, 'test', - 'sorl-thumbnail-test_source_jpg_30x30_crop_q85.jpg') - self.images_to_delete.add(main_thumb) - self.images_to_delete.add(admin_thumb) - # Default setting is to only generate when the thumbnail is used. - model = TestThumbnailFieldModel() - source = ContentFile(open(PIC_NAME).read()) - model.photo.save(RELATIVE_PIC_NAME, source, save=False) - self.images_to_delete.add(model.photo.path) - self.assertFalse(os.path.exists(main_thumb)) - self.assertFalse(os.path.exists(admin_thumb)) - os.remove(model.photo.path) - # But it's easy to set it up the other way... - model = TestThumbnailFieldGenerateModel() - source = ContentFile(open(PIC_NAME).read()) - model.photo.save(RELATIVE_PIC_NAME, source, save=False) - self.assert_(os.path.exists(main_thumb)) - self.assert_(os.path.exists(admin_thumb)) - - -class ImageWithThumbnailsFieldTest(BaseTest): - def test_thumbnail(self): - model = TestThumbnailFieldModel(photo=RELATIVE_PIC_NAME) - thumb = model.photo.thumbnail - tag = model.photo.thumbnail_tag - base_name = RELATIVE_PIC_NAME.replace('.', '_') - expected_filename = os.path.join(settings.MEDIA_ROOT, - '%s_50x50_q85.jpg' % base_name) - self.verify_thumbnail((50, 37), thumb, expected_filename) - expected_tag = ('' % - '/'.join([settings.MEDIA_URL.rstrip('/'), - '%s_50x50_q85.jpg' % base_name])) - self.assertEqual(tag, expected_tag) - - -class ThumbnailFieldTest(BaseTest): - def test_thumbnail(self): - model = TestThumbnailFieldModel() - source = ContentFile(open(PIC_NAME).read()) - dest_name = 'sorl-thumbnail-test_dest.jpg' - model.avatar.save(dest_name, source, save=False) - expected_filename = os.path.join(model.avatar.path) - self.verify_thumbnail((300, 225), expected_filename=expected_filename) - - tag = model.avatar.thumbnail_tag - expected_tag = ('' % - '/'.join([settings.MEDIA_URL.rstrip('/'), 'test', - dest_name])) - self.assertEqual(tag, expected_tag) diff --git a/apps/sorl/thumbnail/tests/templatetags.py b/apps/sorl/thumbnail/tests/templatetags.py deleted file mode 100644 index 5d1a1cb1..00000000 --- a/apps/sorl/thumbnail/tests/templatetags.py +++ /dev/null @@ -1,312 +0,0 @@ -import os -from django.conf import settings -from django.template import Template, Context, TemplateSyntaxError -from sorl.thumbnail.tests.classes import BaseTest, RELATIVE_PIC_NAME - - -class ThumbnailTagTest(BaseTest): - def render_template(self, source): - context = Context({ - 'source': RELATIVE_PIC_NAME, - 'invalid_source': 'not%s' % RELATIVE_PIC_NAME, - 'size': (90, 100), - 'invalid_size': (90, 'fish'), - 'strsize': '80x90', - 'invalid_strsize': ('1notasize2'), - 'invalid_q': 'notanumber'}) - source = '{% load thumbnail %}' + source - return Template(source).render(context) - - def testTagInvalid(self): - # No args, or wrong number of args - src = '{% thumbnail %}' - self.assertRaises(TemplateSyntaxError, self.render_template, src) - src = '{% thumbnail source %}' - self.assertRaises(TemplateSyntaxError, self.render_template, src) - src = '{% thumbnail source 80x80 as variable crop %}' - self.assertRaises(TemplateSyntaxError, self.render_template, src) - - # Invalid option - src = '{% thumbnail source 240x200 invalid %}' - self.assertRaises(TemplateSyntaxError, self.render_template, src) - - # Old comma separated options format can only have an = for quality - src = '{% thumbnail source 80x80 crop=1,quality=1 %}' - self.assertRaises(TemplateSyntaxError, self.render_template, src) - - # Invalid quality - src_invalid = '{% thumbnail source 240x200 quality=invalid_q %}' - src_missing = '{% thumbnail source 240x200 quality=missing_q %}' - # ...with THUMBNAIL_DEBUG = False - self.assertEqual(self.render_template(src_invalid), '') - self.assertEqual(self.render_template(src_missing), '') - # ...and with THUMBNAIL_DEBUG = True - self.change_settings.change({'DEBUG': True}) - self.assertRaises(TemplateSyntaxError, self.render_template, - src_invalid) - self.assertRaises(TemplateSyntaxError, self.render_template, - src_missing) - - # Invalid source - src = '{% thumbnail invalid_source 80x80 %}' - src_on_context = '{% thumbnail invalid_source 80x80 as thumb %}' - # ...with THUMBNAIL_DEBUG = False - self.change_settings.change({'DEBUG': False}) - self.assertEqual(self.render_template(src), '') - # ...and with THUMBNAIL_DEBUG = True - self.change_settings.change({'DEBUG': True}) - self.assertRaises(TemplateSyntaxError, self.render_template, src) - self.assertRaises(TemplateSyntaxError, self.render_template, - src_on_context) - - # Non-existant source - src = '{% thumbnail non_existant_source 80x80 %}' - src_on_context = '{% thumbnail non_existant_source 80x80 as thumb %}' - # ...with THUMBNAIL_DEBUG = False - self.change_settings.change({'DEBUG': False}) - self.assertEqual(self.render_template(src), '') - # ...and with THUMBNAIL_DEBUG = True - self.change_settings.change({'DEBUG': True}) - self.assertRaises(TemplateSyntaxError, self.render_template, src) - - # Invalid size as a tuple: - src = '{% thumbnail source invalid_size %}' - # ...with THUMBNAIL_DEBUG = False - self.change_settings.change({'DEBUG': False}) - self.assertEqual(self.render_template(src), '') - # ...and THUMBNAIL_DEBUG = True - self.change_settings.change({'DEBUG': True}) - self.assertRaises(TemplateSyntaxError, self.render_template, src) - # Invalid size as a string: - src = '{% thumbnail source invalid_strsize %}' - # ...with THUMBNAIL_DEBUG = False - self.change_settings.change({'DEBUG': False}) - self.assertEqual(self.render_template(src), '') - # ...and THUMBNAIL_DEBUG = True - self.change_settings.change({'DEBUG': True}) - self.assertRaises(TemplateSyntaxError, self.render_template, src) - - # Non-existant size - src = '{% thumbnail source non_existant_size %}' - # ...with THUMBNAIL_DEBUG = False - self.change_settings.change({'DEBUG': False}) - self.assertEqual(self.render_template(src), '') - # ...and THUMBNAIL_DEBUG = True - self.change_settings.change({'DEBUG': True}) - self.assertRaises(TemplateSyntaxError, self.render_template, src) - - def testTag(self): - expected_base = RELATIVE_PIC_NAME.replace('.', '_') - # Set DEBUG = True to make it easier to trace any failures - self.change_settings.change({'DEBUG': True}) - - # Basic - output = self.render_template('src="' - '{% thumbnail source 240x240 %}"') - expected = '%s_240x240_q85.jpg' % expected_base - expected_fn = os.path.join(settings.MEDIA_ROOT, expected) - self.verify_thumbnail((240, 180), expected_filename=expected_fn) - expected_url = ''.join((settings.MEDIA_URL, expected)) - self.assertEqual(output, 'src="%s"' % expected_url) - - # Size from context variable - # as a tuple: - output = self.render_template('src="' - '{% thumbnail source size %}"') - expected = '%s_90x100_q85.jpg' % expected_base - expected_fn = os.path.join(settings.MEDIA_ROOT, expected) - self.verify_thumbnail((90, 67), expected_filename=expected_fn) - expected_url = ''.join((settings.MEDIA_URL, expected)) - self.assertEqual(output, 'src="%s"' % expected_url) - # as a string: - output = self.render_template('src="' - '{% thumbnail source strsize %}"') - expected = '%s_80x90_q85.jpg' % expected_base - expected_fn = os.path.join(settings.MEDIA_ROOT, expected) - self.verify_thumbnail((80, 60), expected_filename=expected_fn) - expected_url = ''.join((settings.MEDIA_URL, expected)) - self.assertEqual(output, 'src="%s"' % expected_url) - - # On context - output = self.render_template('height:' - '{% thumbnail source 240x240 as thumb %}{{ thumb.height }}') - self.assertEqual(output, 'height:180') - - # With options and quality - output = self.render_template('src="' - '{% thumbnail source 240x240 sharpen crop quality=95 %}"') - # Note that the opts are sorted to ensure a consistent filename. - expected = '%s_240x240_crop_sharpen_q95.jpg' % expected_base - expected_fn = os.path.join(settings.MEDIA_ROOT, expected) - self.verify_thumbnail((240, 240), expected_filename=expected_fn) - expected_url = ''.join((settings.MEDIA_URL, expected)) - self.assertEqual(output, 'src="%s"' % expected_url) - - # With option and quality on context (also using its unicode method to - # display the url) - output = self.render_template( - '{% thumbnail source 240x240 sharpen crop quality=95 as thumb %}' - 'width:{{ thumb.width }}, url:{{ thumb }}') - self.assertEqual(output, 'width:240, url:%s' % expected_url) - - # Old comma separated format for options is still supported. - output = self.render_template( - '{% thumbnail source 240x240 sharpen,crop,quality=95 as thumb %}' - 'width:{{ thumb.width }}, url:{{ thumb }}') - self.assertEqual(output, 'width:240, url:%s' % expected_url) - -filesize_tests = r""" ->>> from sorl.thumbnail.templatetags.thumbnail import filesize - ->>> filesize('abc') -'abc' ->>> filesize(100, 'invalid') -100 - ->>> bytes = 20 ->>> filesize(bytes) -'20 B' ->>> filesize(bytes, 'auto1000') -'20 B' - ->>> bytes = 1001 ->>> filesize(bytes) -'1001 B' ->>> filesize(bytes, 'auto1000') -'1 kB' - ->>> bytes = 10100 ->>> filesize(bytes) -'9.9 KiB' - -# Note that the decimal place is only used if < 10 ->>> filesize(bytes, 'auto1000') -'10 kB' - ->>> bytes = 190000000 ->>> filesize(bytes) -'181 MiB' ->>> filesize(bytes, 'auto1000') -'190 MB' - -# 'auto*long' methods use pluralisation: ->>> filesize(1, 'auto1024long') -'1 byte' ->>> filesize(1, 'auto1000long') -'1 byte' ->>> filesize(2, 'auto1024long') -'2 bytes' ->>> filesize(0, 'auto1000long') -'0 bytes' - -# Test all 'auto*long' output: ->>> for i in range(1,10): -... print '%s, %s' % (filesize(1024**i, 'auto1024long'), -... filesize(1000**i, 'auto1000long')) -1 kibibyte, 1 kilobyte -1 mebibyte, 1 megabyte -1 gibibyte, 1 gigabyte -1 tebibyte, 1 terabyte -1 pebibyte, 1 petabyte -1 exbibyte, 1 exabyte -1 zebibyte, 1 zettabyte -1 yobibyte, 1 yottabyte -1024 yobibytes, 1000 yottabytes - -# Test all fixed outputs (eg 'kB' or 'MiB') ->>> from sorl.thumbnail.templatetags.thumbnail import filesize_formats,\ -... filesize_long_formats ->>> for f in filesize_formats: -... print '%s (%siB, %sB):' % (filesize_long_formats[f], f.upper(), f) -... for i in range(0, 10): -... print ' %s, %s' % (filesize(1024**i, '%siB' % f.upper()), -... filesize(1000**i, '%sB' % f)) -kilo (KiB, kB): - 0.0009765625, 0.001 - 1.0, 1.0 - 1024.0, 1000.0 - 1048576.0, 1000000.0 - 1073741824.0, 1000000000.0 - 1.09951162778e+12, 1e+12 - 1.12589990684e+15, 1e+15 - 1.15292150461e+18, 1e+18 - 1.18059162072e+21, 1e+21 - 1.20892581961e+24, 1e+24 -mega (MiB, MB): - 0.0, 1e-06 - 0.0009765625, 0.001 - 1.0, 1.0 - 1024.0, 1000.0 - 1048576.0, 1000000.0 - 1073741824.0, 1000000000.0 - 1.09951162778e+12, 1e+12 - 1.12589990684e+15, 1e+15 - 1.15292150461e+18, 1e+18 - 1.18059162072e+21, 1e+21 -giga (GiB, GB): - 0.0, 1e-09 - 0.0, 1e-06 - 0.0009765625, 0.001 - 1.0, 1.0 - 1024.0, 1000.0 - 1048576.0, 1000000.0 - 1073741824.0, 1000000000.0 - 1.09951162778e+12, 1e+12 - 1.12589990684e+15, 1e+15 - 1.15292150461e+18, 1e+18 -tera (TiB, TB): - 0.0, 1e-12 - 0.0, 1e-09 - 0.0, 1e-06 - 0.0009765625, 0.001 - 1.0, 1.0 - 1024.0, 1000.0 - 1048576.0, 1000000.0 - 1073741824.0, 1000000000.0 - 1.09951162778e+12, 1e+12 - 1.12589990684e+15, 1e+15 -peta (PiB, PB): - 0.0, 1e-15 - 0.0, 1e-12 - 0.0, 1e-09 - 0.0, 1e-06 - 0.0009765625, 0.001 - 1.0, 1.0 - 1024.0, 1000.0 - 1048576.0, 1000000.0 - 1073741824.0, 1000000000.0 - 1.09951162778e+12, 1e+12 -exa (EiB, EB): - 0.0, 1e-18 - 0.0, 1e-15 - 0.0, 1e-12 - 0.0, 1e-09 - 0.0, 1e-06 - 0.0009765625, 0.001 - 1.0, 1.0 - 1024.0, 1000.0 - 1048576.0, 1000000.0 - 1073741824.0, 1000000000.0 -zetta (ZiB, ZB): - 0.0, 1e-21 - 0.0, 1e-18 - 0.0, 1e-15 - 0.0, 1e-12 - 0.0, 1e-09 - 0.0, 1e-06 - 0.0009765625, 0.001 - 1.0, 1.0 - 1024.0, 1000.0 - 1048576.0, 1000000.0 -yotta (YiB, YB): - 0.0, 1e-24 - 0.0, 1e-21 - 0.0, 1e-18 - 0.0, 1e-15 - 0.0, 1e-12 - 0.0, 1e-09 - 0.0, 1e-06 - 0.0009765625, 0.001 - 1.0, 1.0 - 1024.0, 1000.0 -""" diff --git a/apps/sorl/thumbnail/tests/utils.py b/apps/sorl/thumbnail/tests/utils.py deleted file mode 100644 index 3a20cbbc..00000000 --- a/apps/sorl/thumbnail/tests/utils.py +++ /dev/null @@ -1,149 +0,0 @@ -from django.conf import settings -from sorl.thumbnail.utils import * - -try: - set -except NameError: - from sets import Set as set # For Python 2.3 - -MEDIA_ROOT_LENGTH = len(os.path.normpath(settings.MEDIA_ROOT)) - -utils_tests = r""" ->>> from sorl.thumbnail.tests.utils import * ->>> from sorl.thumbnail.tests.base import ChangeSettings ->>> from django.conf import settings - ->>> change_settings = ChangeSettings() ->>> change_settings.change() - ->>> media_root = settings.MEDIA_ROOT.rstrip('/') - -#============================================================================== -# Set up test images -#============================================================================== - ->>> make_image('test-thumbnail-utils/subdir/test_jpg_110x110_q85.jpg') ->>> make_image('test-thumbnail-utils/test_jpg_80x80_q85.jpg') ->>> make_image('test-thumbnail-utils/test_jpg_80x80_q95.jpg') ->>> make_image('test-thumbnail-utils/another_test_jpg_80x80_q85.jpg') ->>> make_image('test-thumbnail-utils/test_with_opts_jpg_80x80_crop_bw_q85.jpg') ->>> make_image('test-thumbnail-basedir/test-thumbnail-utils/test_jpg_100x100_' -... 'q85.jpg') ->>> make_image('test-thumbnail-utils/prefix-test_jpg_120x120_q85.jpg') - -#============================================================================== -# all_thumbnails() -#============================================================================== - -# Find all thumbs ->>> thumb_dir = os.path.join(settings.MEDIA_ROOT, 'test-thumbnail-utils') ->>> thumbs = all_thumbnails(thumb_dir) ->>> k = thumbs.keys() ->>> k.sort() ->>> [consistent_slash(path) for path in k] -['another_test.jpg', 'prefix-test.jpg', 'subdir/test.jpg', 'test.jpg', - 'test_with_opts.jpg'] - -# Find all thumbs, no recurse ->>> thumbs = all_thumbnails(thumb_dir, recursive=False) ->>> k = thumbs.keys() ->>> k.sort() ->>> k -['another_test.jpg', 'prefix-test.jpg', 'test.jpg', 'test_with_opts.jpg'] - -#============================================================================== -# thumbnails_for_file() -#============================================================================== - ->>> output = [] ->>> for thumb in thumbs['test.jpg']: -... thumb['rel_fn'] = strip_media_root(thumb['filename']) -... output.append('%(x)sx%(y)s %(quality)s %(rel_fn)s' % thumb) ->>> output.sort() ->>> output -['80x80 85 test-thumbnail-utils/test_jpg_80x80_q85.jpg', - '80x80 95 test-thumbnail-utils/test_jpg_80x80_q95.jpg'] - -# Thumbnails for file ->>> output = [] ->>> for thumb in thumbnails_for_file('test-thumbnail-utils/test.jpg'): -... output.append(strip_media_root(thumb['filename'])) ->>> output.sort() ->>> output -['test-thumbnail-utils/test_jpg_80x80_q85.jpg', - 'test-thumbnail-utils/test_jpg_80x80_q95.jpg'] - -# Thumbnails for file - shouldn't choke on non-existant file ->>> thumbnails_for_file('test-thumbnail-utils/non-existant.jpg') -[] - -# Thumbnails for file, with basedir setting ->>> change_settings.change({'BASEDIR': 'test-thumbnail-basedir'}) ->>> for thumb in thumbnails_for_file('test-thumbnail-utils/test.jpg'): -... print strip_media_root(thumb['filename']) -test-thumbnail-basedir/test-thumbnail-utils/test_jpg_100x100_q85.jpg - -# Thumbnails for file, with subdir setting ->>> change_settings.change({'SUBDIR': 'subdir', 'BASEDIR': ''}) ->>> for thumb in thumbnails_for_file('test-thumbnail-utils/test.jpg'): -... print strip_media_root(thumb['filename']) -test-thumbnail-utils/subdir/test_jpg_110x110_q85.jpg - -# Thumbnails for file, with prefix setting ->>> change_settings.change({'PREFIX': 'prefix-', 'SUBDIR': ''}) ->>> for thumb in thumbnails_for_file('test-thumbnail-utils/test.jpg'): -... print strip_media_root(thumb['filename']) -test-thumbnail-utils/prefix-test_jpg_120x120_q85.jpg - -#============================================================================== -# Clean up images / directories -#============================================================================== - ->>> clean_up() -""" - -images_to_delete = set() -dirs_to_delete = [] - - -def make_image(relative_image): - absolute_image = os.path.join(settings.MEDIA_ROOT, relative_image) - make_dirs(os.path.dirname(relative_image)) - open(absolute_image, 'w').close() - images_to_delete.add(absolute_image) - - -def make_dirs(relative_path): - if not relative_path: - return - absolute_path = os.path.join(settings.MEDIA_ROOT, relative_path) - if os.path.isdir(absolute_path): - return - if absolute_path not in dirs_to_delete: - dirs_to_delete.append(absolute_path) - make_dirs(os.path.dirname(relative_path)) - os.mkdir(absolute_path) - - -def clean_up(): - for image in images_to_delete: - os.remove(image) - for path in dirs_to_delete: - os.rmdir(path) - - -def strip_media_root(path): - path = os.path.normpath(path) - # chop off the MEDIA_ROOT and strip any leading os.sep - path = path[MEDIA_ROOT_LENGTH:].lstrip(os.sep) - return consistent_slash(path) - - -def consistent_slash(path): - """ - Ensure we're always testing against the '/' os separator (otherwise tests - fail against Windows). - """ - if os.sep != '/': - path = path.replace(os.sep, '/') - return path diff --git a/apps/sorl/thumbnail/utils.py b/apps/sorl/thumbnail/utils.py deleted file mode 100644 index 18b18b0b..00000000 --- a/apps/sorl/thumbnail/utils.py +++ /dev/null @@ -1,170 +0,0 @@ -import math -import os -import re - - -re_thumbnail_file = re.compile(r'(?P.+)_(?P\d+)x(?P\d+)' - r'(?:_(?P\w+))?_q(?P\d+)' - r'(?:.[^.]+)?$') -re_new_args = re.compile('(? 1 and split_arg[1] or None - args_dict[split_arg[0]] = value - return args_dict - - -def image_entropy(im): - """ - Calculate the entropy of an image. Used for "smart cropping". - """ - hist = im.histogram() - hist_size = float(sum(hist)) - hist = [h / hist_size for h in hist] - return -sum([p * math.log(p, 2) for p in hist if p != 0]) diff --git a/requirements.txt b/requirements.txt index 9c9509af..0014b59e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,15 +1,20 @@ ---find-links=http://stigma.nowoczesnapolska.org.pl/pypi/ - -Django>=1.1.1,<1.2 +## Python libraries lxml>=2.2 mercurial>=1.3.1 -librarian>=1.3.dev,<1.4 PyYAML>=3.0 -# MySQL-python>=1.2,<2.0 + +## Book conversion library +git+http://github.com/fnp/librarian.git@master#egg=librarian + +## Django +Django>=1.1.1,<1.2 +sorl-thumbnail>=3.2 +django-maintanancemode>=0.9 # migrations south>=0.6 -# debug stuff -django-nose>=0.0.3 -django-debug-toolbar>=0.8 +## Debugging utils, uncomment this if you want tests +# django-nose>=0.0.3 +# django-debug-toolbar>=0.8 +