diff --git a/.gitignore b/.gitignore deleted file mode 100644 index e2aa1a9..0000000 --- a/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -*.pyc -*.swp -ChangeLog -MANIFEST -build -dist -pyparted.spec -.tox diff --git a/AUTHORS b/AUTHORS deleted file mode 100644 index d038660..0000000 --- a/AUTHORS +++ /dev/null @@ -1,7 +0,0 @@ -David Cantrell -Chris Lumens -David Campbell - -Python 3 Porting: -Alex Skinner -Gabriel de Perthuis diff --git a/BUGS b/BUGS deleted file mode 100644 index fb30fc3..0000000 --- a/BUGS +++ /dev/null @@ -1,38 +0,0 @@ -List bugs in this file, numbered, with an example that can be run from the -Python interactive shell. - ---------------------------------------------------------------------------- - -1) parted.Disk.getLogicalPartitions() crashes - device = parted.getDevice("/dev/sda") - disk = parted.Disk(device) - disk.getLogicalPartitions() - -2) pydisk.c: - - py_ped_disk_type_get() returns NULL without setting an exception when - called with None argument - # XXX: NEED REPRODUCER - - py_ped_disk_type_check_feature() returns NULL without setting an - exception when called with 0 as argument - # XXX: NEED REPRODUCER - - py_ped_geometry_read() and py_ped_device_read() do not work properly - when the read data contains 0 bytes - # XXX: NEED REPRODUCER - -3) import parted - # create a parted.Disk - for part in disk.partitions: - print part - - "argument 2 must be _ped.Geometry, not _ped.Geometry" - -4) import parted - device = parted.Device(path="/dev/dm-0") - disk = parted.Disk(device=device) - disk.partitions[0].getDeviceNodeName() - - expected: "unrecognized disk label" - get: "/dev/dm-01" diff --git a/COPYING b/COPYING deleted file mode 100644 index a43ea21..0000000 --- a/COPYING +++ /dev/null @@ -1,339 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 675 Mass Ave, Cambridge, MA 02139, USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - Appendix: How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) 19yy - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) 19yy name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. diff --git a/HACKING b/HACKING deleted file mode 100644 index 1990587..0000000 --- a/HACKING +++ /dev/null @@ -1,211 +0,0 @@ -Contributing to pyparted - -This guide helps explain how to get your contributions accepted in to the -project. Coding style, patch generation, and how to submit patches are -all discussed here. - - -CODING STYLE FOR C - -Please follow the coding style you see in the C source files here. The project -is developed on Linux, which gcc is the compiler. That affords us a lot of -flexibility with regards to standards, but try to adhere to ISO C99 whenever -possible and avoid using gcc extensions. There is a possibility that this -project may need to be ported to a non-gcc compiler. - -Here are the major coding style highlights for this project: - -1) Indentation is four spaces. Please do not use tab and do not use more - or less than 4 spaces. A lot of the source files have vim control - settings at the bottom so if you are using vim, the indentation will - automatically be set up properly with the Tab key. However, if you are - unlucky and do not have vim, just make sure you use 4 spaces for indent. - Editor hints will be accepted for other editors, so long as the additions - to the source files are minimal (i.e., we're not looking for editor - configuration files). - - Examples: - - GOOD: - int main(int argc, char **argv) { - int i; - i = EXIT_SUCCESS; - - if (i == -1) { - return EXIT_FAILURE; - } - - return i; - } - -2) Spaces after keywords. Do not place an open paren next to 'if' or 'for'. - Examples: - - GOOD: - - if (i < j) { - for (i=0; i < 30; i++) { - - BAD: - - if(i < j) { - for(i=0; i < 30; i++) { - -3) Open brace stays on the same line for the function declaration or - statement it belongs to. Examples: - - GOOD: - - if (i < j ) { - - BAD: - - if (i < j) - { - -4) No brace-less blocks. If an 'if' test just requires one statement in - the block, do still wrap it in braces. This is to maintain consistency - with all blocks in the code. Examples: - - GOOD: - - if (i < j) { - printf("i is less than j!\n"); - } - - BAD: - - if (i < j) - printf("i is less than j!\n"); - -5) No K&R style function declarations. Examples: - - GOOD: - - int main(int argc, char **argv) { - - BAD: - - int main(argc, argv) - int argc; - char **argv; - { - -6) Let expressions breathe. There's no reason to remove all spaces from - a complex expression. Examples: - - GOOD: - - i = (a + b) << c >> d | e * f; - - BAD: - - i = (a+b)<>d|e*f; - -7) Function declarations have the return type on the same line as the - function. For long argument lists, wrap them to line up with the - parens. There is no space between the function name and the open - paren. Examples: - - GOOD: - - int main(int argc, char **argv) { - - void check_a_variable(int a, char b, int c, struct astruct, - int *d, char *e, void *buf) { - - BAD: - - int - main (int argc, char **argv) - { - -8) Name variables and functions using lowercase names and underscores rather - than CamelCase. Examples: - - GOOD: - - int c; - char *host_name = NULL; - void function_name(int argument); - - BAD: - - int counterForCountingThings; - char *hostName = NULL; - void functionName(int argument); - - -CODING STYLE FOR PYTHON - -First, read PEP-8: http://www.python.org/dev/peps/pep-0008/ - -Second, please follow the coding style you see in the Python source files here. -Here are the major coding style highlights for this project: - -1) 4-space indentation. Do not use tabs in Python code. - -2) Use CamelCase for class names. - -3) For method names, the standard CamelCase naming with the first - character being lowercase is preferred. - -4) Use properties instead of get/set methods. - -5) Use _ to prefix class variables accessed via properties. - -6) Hide anything with __ prefixes if it does not need to be fully public. - -7) List one module per import statement. Do not use a comma to list several - modules on one import line. - - -GENERATING PATCHES - -When you make changes to the code, you should generate a patch to send -upstream. Before editing, it's a good idea to copy the original source -file to a new name so you can edit the other copy. Here is a basic -workflow: - - $ cd pyparted-VERSION/src - $ cp -p _pedmodule.c _pedmodule.c.orig - $ vim _pedmodule.c # make your changes - -Generating a patch is done using GNU diffutils or a diff(1) command -capable of producing a unified diff: - - $ diff -u _pedmodule.c.orig _pedmodule.c > mypatch - -Submit the 'mypatch' file and explain your changes and why we should merge -your changes. - -If you are making a lot of changes to many files, it's probably easier to -use the git version control system. You can clone the upstream repository -and commit your changes locally and then generate a set of diffs against -the latest upstream code. - - $ git clone git://git.fedorahosted.org/pyparted.git/ - $ cd pyparted - $ # make your changes to files here - $ git add FILE # repeat this add/commit process for - $ git commit # each logical change to the code - $ git fetch - $ git rebase origin - $ git format-patch origin - -The output of git format-patch will be a set of files containing a patch -for each add/commit you made locally. The patches will be made against -the latest upstream. Submit your patch files upstream. - - -SUBMITTING PATCHES - -The best way to submit patches is to make a new ticket on the project web -site: - - http://fedorahosted.org/pyparted/ - -Attach your patch and explanation and it'll be reviewed. - -Alternatively, you can email the project maintainer(s) directly. The ChangeLog -and AUTHORS file contain email addresses of those who work on pyparted. diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 858c970..0000000 --- a/MANIFEST.in +++ /dev/null @@ -1,6 +0,0 @@ -include AUTHORS BUGS COPYING HACKING NEWS RELEASE TODO -include ChangeLog -include MANIFEST.in -include Makefile -recursive-include include *.h -recursive-include tests *.py diff --git a/Makefile b/Makefile deleted file mode 100644 index 81b5c8d..0000000 --- a/Makefile +++ /dev/null @@ -1,102 +0,0 @@ -# -# Makefile for pyparted -# Copyright (C) 2007-2011 Red Hat, Inc. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# -# Author(s): David Cantrell -# - -PYTHON ?= python - -DESTDIR ?= / - -PACKAGE = $(shell $(PYTHON) setup.py --name) -VERSION = $(shell $(PYTHON) setup.py --version) - -TAG = $(PACKAGE)-$(VERSION) - -PYLINTOPTS = src/parted/*py --msg-template='{msg_id}:{line:3d},{column}: {obj}: {msg}' --rcfile=/dev/null -r n --disable=C,R --disable=W0141,W0212,W0511,W0613,W0702,E1103 - -default: all - -all: - @$(PYTHON) setup.py build - -test: all - @env PYTHONPATH=$$(find $$(pwd) -name "*.so" | head -n 1 | xargs dirname):src/parted:src \ - $(PYTHON) -m unittest discover -v - -check: all - env PYTHONPATH=$$(find $$(pwd) -name "*.so" | head -n 1 | xargs dirname):src/parted:src \ - pylint $(PYLINTOPTS) src/parted/*.py - -ChangeLog: - git log > ChangeLog - -dist: ChangeLog - @$(PYTHON) setup.py sdist - -tag: dist - @if [ -z "$(GPGKEY)" ]; then \ - echo "GPGKEY environment variable missing, please set this to the key ID" ; \ - echo "you want to use to tag the repository." ; \ - exit 1 ; \ - fi - @git tag -u $(GPGKEY) -m "Tag as $(TAG)" -f $(TAG) - @echo "Tagged as $(TAG) (GPG signed)" - -release: tag - ( cd dist ; gzip -dc $(PACKAGE)-$(VERSION).tar.gz | tar -xvf - ) - ( cd dist/$(PACKAGE)-$(VERSION) && $(PYTHON) setup.py build ) || exit 1 - @echo - @echo "$(PACKAGE)-$(VERSION).tar.gz is now ready to upload." - @echo "Do not forget to push changes to the repository with:" - @echo " git push" - @echo " git push --tags" - @echo - @echo "Do not forget to add a new Version entry on the Trac site:" - @echo " https://fedorahosted.org/pyparted/admin/ticket/versions" - @echo - -rpmlog: - @prevtag="$$(git tag -l | grep -v "^start$$" | tail -n 2 | head -n 1)" ; \ - git log --pretty="format:- %s (%ae)" $${prevtag}.. | \ - sed -e 's/@.*)/)/' | \ - sed -e 's/%/%%/g' | \ - grep -v "New version" | \ - fold -s -w 77 | \ - while read line ; do \ - if [ ! "$$(echo $$line | cut -c-2)" = "- " ]; then \ - echo " $$line" ; \ - else \ - echo "$$line" ; \ - fi ; \ - done - -bumpver: - @OLDSUBVER=$$(echo $(VERSION) | rev | cut -d '.' -f 1 | rev) ; \ - NEWSUBVER=$$(($${OLDSUBVER} + 1)) ; \ - BASEVER="$$(echo $(VERSION) | sed -e "s|\.$${OLDSUBVER}$$||g")" ; \ - NEWVERSION="$${BASEVER}.$${NEWSUBVER}" ; \ - sed -i "s/pyparted_version = '$(VERSION)'/pyparted_version = '$${NEWVERSION}'/" setup.py ; \ - echo "New version is $${NEWVERSION}" - -install: all - @$(PYTHON) setup.py install --root $(DESTDIR) -c -O1 - -clean: - @$(PYTHON) setup.py clean - @[ -d .git ] && git clean -d -x -f diff --git a/NEWS b/NEWS deleted file mode 100644 index 49d19fa..0000000 --- a/NEWS +++ /dev/null @@ -1,16 +0,0 @@ -pyparted-2.1.0 --------------- - -pyparted supports new libparted API functions, but those functions are not -yet available in an official release on ftp.gnu.org. On Fedora systems, the -parted-1.9.0-23 package and later revisions contain the necessary API support. - - -pyparted-2.0.0 --------------- - -Complete rewrite of pyparted. There are now two Python modules exposing the -pyparted API: - - _ped Low level module interfacing with libparted. - parted Higher level module written in Python building on _ped. diff --git a/README b/README deleted file mode 100644 index c5fd11f..0000000 --- a/README +++ /dev/null @@ -1,60 +0,0 @@ -pyparted -Python bindings for libparted ------------------------------ - -OVERVIEW - -pyparted is a set of native Python bindings for libparted. libparted is the -library portion of the GNU parted project. With pyparted, you can write -applications that interact with disk partition tables and filesystems. - -The Python bindings are implemented in two layers. Since libparted itself -is written in C without any real implementation of objects, a simple 1:1 -mapping of externally accessible libparted functions was written. This -mapping is provided in the _ped Python module. You can use that module if -you want to, but it's really just meant for the larger parted module. - - _ped libparted Python bindings, direct 1:1: function mapping - parted Native Python code building on _ped, complete with classes, - exceptions, and advanced functionality. - -The _ped module is written and maintained by hand. I chose to do this -rather than rely on a tool like SWIG or Pyrex for several reasons. Mostly -because I was the GNU parted maintainer, but also because libparted is sort -of complex. It's a lowlevel system tool and I found it doesn't translate -well in the tools I tried. This is nothing against those tools, I just -don't think libparted is ideal to go through SWIG or Pyrex. By writing my -own bindings, I can also find bugs in libparted that I may have overlooked -before. See the WHY file for more explanation as to why I wrote the -bindings by hand. - - -HISTORY - -pyparted started life at Red Hat and continues there today. The main reason -for writing it was to let anaconda (the Red Hat installation program, now -used by RHEL and Fedora and many other distributions) interact with -libparted. Anaconda is written in Python, so native bindings made sense. - -pyparted went through many rewrites, but the end result was always the same. -And incomplete API via Python with just enough provided for anaconda to do -its job. - -The latest iteration of pyparted aims to be a complete API mapping and even -provide a nice set of classes so that people might want to integrate it in -to other installers or even write other applications (maybe a Python based -alternative to parted(8) or fdisk(8)). - - -QUESTIONS - -If you are reporting a pyparted failure in Fedora, it's most useful if -you file a bug at http://bugzilla.redhat.com/ against the appropriate -Fedora release you are using. - -Alternatively, you can file bugs directly on the project page: -http://fedorahosted.org/pyparted/ - -If you just have questions about pyparted, you can email us directly -using the contact information in the AUTHORS file. We will do our best -to help you. diff --git a/README.md b/README.md new file mode 100644 index 0000000..dc30179 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +pyparted_debian_dir +=================== + +debian dir to create debian package for pyparted diff --git a/RELEASE b/RELEASE deleted file mode 100644 index e145d2b..0000000 --- a/RELEASE +++ /dev/null @@ -1,22 +0,0 @@ -Instructions for making a new release: - -1) git checkout master -2) git clean -d -x -f # I hope you've commited or stashed everything - # you are working on -2) git fetch -3) git rebase origin -4) make bumpver -5) git commit -a -m "New version." -6) git clean -d -x -f -7) make release - -If packaging in RPM format, you might find the 'make rpmlog' target useful. -It gives you an RPM spec file formatted changelog block that contains the -git shortlog entries of all changes since the last tag. - -Resulting dist/pyparted-X.Y.tar.gz is the release. 'cp -p' this to the pkg -tree and make a new build. Also need to copy it to the project download site -and make a new version entry in the Trac site. - -9) git push -10) git push --tags diff --git a/TODO b/TODO deleted file mode 100644 index d2432d2..0000000 --- a/TODO +++ /dev/null @@ -1,80 +0,0 @@ -- Methods in the parted module that just return data and take in no - parameters...make those read-only properties and get rid of the - method. Since we have more or less established the API now, mark - the methods as Deprecated and leave them around for a release - before removing them. - -- add parted.Device.toSectors() method that takes in a size specification, - such as 10.5MB, as a string and converts that size to a sector count - based on the sector size of that Device - -- use disttools from Python to do as much work as possible - -- Walk through all of the src/py*.c files and make sure libparted exceptions - are captured and filtered back up through Python. Will need to define some - sane Python exception classes for libparted's exceptions. - -- Handle exceptions from libparted and pass to Python as necessary. The - PED_ASSERT things are where libparted aborts, so we may want to catch things - before it goes in to libparted so we can throw an exception rather than - letting the library abort(). The ped_exception_throw() instances are all - libparted's own exception-like system. - -- Handle exceptions throughout the _ped module code. Unique exceptions as - much as possible. - -- Figure out what, if anything, we can do with timers. They are optional in - libparted, but do we want to support them in pyparted? - -- Error handling in the get and set methods. - -- Free memory in error handling cases. - -- Exception handling: - - Audit error messages to make them more useful. - -- All test cases with '# TODO' in the runTest() method. Be sure to uncomment - them once you have written the test. - -- Make sure PyTypeObjects that have a tp_init are allocating memory that the - garbage collector knows about. I'm not sure if PyType_GenericAlloc or - PyType_GenericNew do this. - -- Coding policy that we need to make sure we're doing: - If object creation fails, we need to use PyObject_GC_Del() to destroy it - before throwing an exception at the user. For all other instances where - we need to delete or destroy the object, use Py_XDECREF(). Once the ref - count is zero, the GC will take over and run dealloc() for that object, - which will eventually run PyObject_GC_Del(). Basically, we should only - be using PyObject_GC_Del() in the convert functions or in __init__ - constructors where we are making a new object for the user. - - NOTE: If we need to destroy an object due to creation failure and the - object we are creating has other PyObject members, call Py_XDECREF on - those members rather than destroing them. We can't ensure that there - will be no other references to those members, so let the normal object - destructor handle PyObject members, but forcefully destroy the object - we are trying to create. - -- destroy() methods don't seem to be destroying the Python object. - -- Make sure this new code works in Python 3000 - -- Look through all PyTypeObject objects and see where we can expand - their functionality. Can we add str() support, for instance. - -- Move the constraint functions presently in _ped to be in the __init_() - method for _ped.Constraint, similar to what was done for _ped_Disk_init: - constraint_new_from_min_max - constraint_new_from_min - constraint_new_from_max - constraint_any - constraint_exact - -- parted module: - - Write docstrings for everything - -- autoconf - - More detailed API checks for libparted and Python - -... and much much more diff --git a/debian/changelog b/debian/changelog deleted file mode 100644 index df5dadd..0000000 --- a/debian/changelog +++ /dev/null @@ -1,252 +0,0 @@ -pyparted (3.10.3-1) experimental; urgency=medium - - * New upstream release - * Updated debian/copyright. - - -- Herbert Parentes Fortes Neto Sat, 28 Feb 2015 14:39:56 -0300 - -pyparted (3.10.2-1) experimental; urgency=medium - - * New upstream release - * New maintainer. Thanks to Luca Falavigna, the initial maintainer, for - your nice work over this package. (Closes: #755301) - * Acknowledge NMU. Thanks to Intrigeri and - Christian Kastner . (Closes: #769737) - * remove debian/docs. - * created debian/python-parted.docs and debian/python3-parted-docs files - with BUGS, HACKING, NEWS, README and TODO entries - * update debian/copyright. - Source field - on Files: * Copyright field. - update to 2007-2014 Red Hat Inc - on Files: debian/* Copyright field. - added Intrigeri - using GPL2 license as is in - /usr/share/debhelper/dh_make/licenses/gpl2 - * update debian/control: - Maintainer and Homepage fields. - Uploaders removed. - Vcs-Git and Vcs-Browser fields. - Build-Depends field. added dh-python. - python3-parted-dbg: fix Depends field. now ${python3:Depends}. - * update debian/rules file. - added DEB_LDFLAGS_MAINT_APPEND to stop 'blhc --all' messages. - remove empty directory usr/lib/python*/dist-packages/parted/. - * update debian/patches/no-last-flag-check.patch because the file - src/pydisk.c was changed. - * debian/patches/Fix-localeC-imports.patch removed. - the upstreamfixed the source code in version 3.10.1. - * update debian/watch file. - - -- Herbert Parentes Fortes Neto Sun, 30 Nov 2014 15:19:28 -0200 - -pyparted (3.10.0-1.1) unstable; urgency=medium - - * Non-maintainer upload. - * Backport patch Fix-localeC-imports.patch from upstream which fixes an - ImportError that rendered the python3-parted package unusable. - Thanks to Christian Kastner for the patch (Closes: #769737). - - -- intrigeri Sun, 16 Nov 2014 10:57:22 +0100 - -pyparted (3.10.0-1) unstable; urgency=medium - - * New upstream release. - * debian/compat: - - Bump to compatibility level 9. - * debian/control: - - Bump Standards-Version to 3.9.6. - * debian/copyright: - - Adjust copyright years. - - -- Luca Falavigna Tue, 30 Sep 2014 20:10:47 +0200 - -pyparted (3.10-1) unstable; urgency=medium - - [ Benjamin Drung ] - * New upstream release. - * Switch to pybuild. - * Add Python 3 support (Closes: #744211). - - [ Luca Falavigna ] - * debian/control: - - Use canoncal URIs for the VCS-* fields. - - Bump Standards-Version to 3.9.5. - * debian/copyright: - - Adjust copyright years. - - -- Luca Falavigna Sat, 19 Apr 2014 10:56:36 +0200 - -pyparted (3.6-6) unstable; urgency=low - - [ Tim Gardner ] - * m4/python.m4 really wants the full path in the PYTHON environment - variable in order to correctly determine all multiarch include paths - (closes: #697779). Thanks to Colin Watson for the suggestion. - - [ Colin Watson ] - * Improve debian/rules to stop immediately on errors. - - -- Colin Watson Thu, 10 Jan 2013 11:35:02 +0000 - -pyparted (3.6-5) unstable; urgency=low - - * debian/patches/no-last-flag-check.patch: - - Remove explicit *_LAST_FLAG checks, which impose additional interface - constraints not guaranteed by parted (closes: #697588). We'll still - get parted exceptions for invalid flags, although they'll no longer be - ValueError. - * debian/control: - - Add myself to Uploaders. - - -- Colin Watson Mon, 07 Jan 2013 11:53:42 +0000 - -pyparted (3.6-4) unstable; urgency=low - - * debian/patches/py26.patch: - - Enable support for python2.6 (Closes: #642545). - * debian/control: - - Set X-Python-Version back to >= 2.6. - * debian/copyright: - - Adopt DEP5 syntax. - - -- Luca Falavigna Sat, 24 Sep 2011 10:40:36 +0200 - -pyparted (3.6-3) unstable; urgency=low - - * debian/control: - - Build-depend on dh-autoreconf. - - Drop autoconf, automake and libtool build-dependencies. - - Drop Breaks field, no longer needed. - * debian/rules: - - Use autoreconf sequencer. - - Do not install .la file (Closes: #633254). - - -- Luca Falavigna Thu, 14 Jul 2011 23:32:12 +0200 - -pyparted (3.6-2) unstable; urgency=low - - * Upload to unstable. - * debian/control: - - Bump Standards-Version to 3.9.2, no changes required. - - -- Luca Falavigna Sat, 16 Apr 2011 15:35:58 +0200 - -pyparted (3.6-1) experimental; urgency=low - - * New upstream release. - * debian/control: - - New release is not compatible with python versions prior to 2.7, so - bump X-Python-Version field to >= 2.7. - - Bump minimum version of python related packages to >= 2.6.6-13~ to - make sure python 2.7 is a supported python version. - - -- Luca Falavigna Sun, 27 Mar 2011 12:07:47 +0200 - -pyparted (3.5-1) unstable; urgency=low - - * New upstream release. - * Switch to dh_python2. - * debian/control: - - Drop python-decorator (build-)dependency, no longer needed. - - Bump Standards-Version to 3.9.1, no changes required. - * debian/copyright: - - Update copyright years. - - -- Luca Falavigna Wed, 09 Feb 2011 00:00:17 +0100 - -pyparted (3.4-2) unstable; urgency=low - - * debian/patches/no_PED_PARTITION_DIAG.patch: - - Removed, PED_PARTITION_DIAG is available in parted 2.3. - * debian/control: - - python2.6 is default, simplify dependencies accordingly. - - Build-depend on libparted0-dev (>= 2.3). - - Bump Standards-Version to 3.9.0, no changes required. - - -- Luca Falavigna Tue, 29 Jun 2010 19:51:30 +0200 - -pyparted (3.4-1) unstable; urgency=low - - * New upstream release. - * Switch to format 3.0 (quilt). - * debian/patches/no_PED_PARTITION_DIAG.patch: - - Disable support for PARTITION_DIAG, not yet implemented upstream. - * debian/control: - - Add autoconf, automake and libtool to Build-Depends. - - Add autoconf2.13 and automake1.4 to Build-Conflicts. - * debian/rules: - - Run "autoreconf -fi -I m4" for every Python build instance to get - proper autoconf/libtool fixes. - - -- Luca Falavigna Sat, 01 May 2010 12:17:44 +0200 - -pyparted (3.1-2) unstable; urgency=low - - * debian/rules: - - Fix location of detached symbols in the -dbg package. - - -- Luca Falavigna Mon, 22 Mar 2010 11:39:54 +0100 - -pyparted (3.1-1) experimental; urgency=low - - * New upstream release. - * debian/control: - - Maintain package under Parted Maintainer Team umbrella. - - Build-depend on libparted0-dev (>= 2.2). - - Remove some build-dependencies, pulled by lipparded0-dev already. - - -- Luca Falavigna Tue, 09 Mar 2010 23:35:30 +0100 - -pyparted (3.0-1) experimental; urgency=low - - * New upstream release. - * debian/control: - - Build-depend on libparted-2.1-dev. - - Remove quilt from Build-Depends. - - Bump Standards-Version to 3.8.4, no changes required. - - Let python-parted-dbg depend on python-dbg (>= 2.6) | python2.6-dbg. - * debian/copyright: - - Adjust copyright years. - * debian/README.source: - - Remove it, no longer needed. - * debian/pyversions: - - Build extension for Python 2.6 only. - * Drop lower_parted_version.patch and no_Fedora.patch, they are no - longer useful because libparted 2.1 implemented those features. - * Drop python2.5_fallback.patch and no_HashNotImplemented.patch, - extension is built for Python 2.6 only, so there is no need to - provide compatibility for older releases. - - -- Luca Falavigna Mon, 08 Feb 2010 17:14:53 +0100 - -pyparted (2.2-1) unstable; urgency=low - - * New upstream release. - * debian/patches/lower_parted_version.patch: - - Refresh for new upstream release. - * Add python-decorator to Depends too. - - -- Luca Falavigna Tue, 13 Oct 2009 21:30:22 +0200 - -pyparted (2.1.1-1) unstable; urgency=low - - * New upstream release. - * debian/control: - - (Build-)Depend on python-decorator. - - Bump minimum libparted1.8-dev version to 1.8.8.git.2009.06.03. - - Update my e-mail address. - - Bump Standards-Version to 3.8.3, no changes required. - * debian/patches/lower_parted_version.patch: - - Lower required parted version, current Debian version already fulfil - pyparted requirements. - * debian/patches/no_Fedora.patch: - - Remove features available in Fedora's parted only. - - -- Luca Falavigna Fri, 02 Oct 2009 02:36:35 +0200 - -pyparted (2.0.12-1) unstable; urgency=low - - * Initial release (Closes: #512011). - - -- Luca Falavigna Mon, 18 May 2009 23:52:08 +0200 diff --git a/debian/compat b/debian/compat deleted file mode 100644 index ec63514..0000000 --- a/debian/compat +++ /dev/null @@ -1 +0,0 @@ -9 diff --git a/debian/control b/debian/control deleted file mode 100644 index 739cc7d..0000000 --- a/debian/control +++ /dev/null @@ -1,76 +0,0 @@ -Source: pyparted -Section: python -Priority: optional -Maintainer: Herbert Parentes Fortes Neto -Build-Depends: debhelper (>= 9), - dh-python, - python-all-dev (>= 2.6.6-13~), - python-all-dbg (>= 2.6.6-13~), - python3-all-dev, - python3-all-dbg, - pkg-config, - libparted0-dev (>= 2.3) -Standards-Version: 3.9.6 -X-Python-Version: >= 2.6 -X-Python3-Version: >= 3.0 -Homepage: https://github.com/dcantrell/pyparted -Vcs-Git: https://github.com/hpfn/pyparted_debian_dir -b debian -Vcs-Browser: https://github.com/hpfn/pyparted_debian_dir - -Package: python-parted -Architecture: any -Depends: ${python:Depends}, - ${shlibs:Depends}, - ${misc:Depends} -Provides: ${python:Provides} -Description: Python interface for libparted - pyparted is a set of Python modules that provide Python programmers an - interface to libparted (http://www.gnu.org/software/parted), the GNU parted - library for disk partitioning and file system manipulation. - . - This package contains Python extension itself. - -Package: python3-parted -Architecture: any -Depends: ${python3:Depends}, - ${shlibs:Depends}, - ${misc:Depends} -Provides: ${python3:Provides} -Description: Python 3 interface for libparted - pyparted is a set of Python modules that provide Python programmers an - interface to libparted (http://www.gnu.org/software/parted), the GNU parted - library for disk partitioning and file system manipulation. - . - This package contains Python 3 extension itself. - -Package: python-parted-dbg -Section: debug -Priority: extra -Architecture: any -Depends: ${python:Depends}, - python-dbg (>= 2.6.6-13~), - ${shlibs:Depends}, - ${misc:Depends}, - python-parted (= ${binary:Version}) -Description: Python interface for libparted - Debugging symbols - pyparted is a set of Python modules that provide Python programmers an - interface to libparted (http://www.gnu.org/software/parted), the GNU parted - library for disk partitioning and file system manipulation. - . - This package contains debugging symbols. - -Package: python3-parted-dbg -Section: debug -Priority: extra -Architecture: any -Depends: ${python3:Depends}, - python3-dbg (>= 3.0~), - ${shlibs:Depends}, - ${misc:Depends}, - python3-parted (= ${binary:Version}) -Description: Python 3 interface for libparted - Debugging symbols - pyparted is a set of Python modules that provide Python programmers an - interface to libparted (http://www.gnu.org/software/parted), the GNU parted - library for disk partitioning and file system manipulation. - . - This package contains debugging symbols for Python 3. diff --git a/debian/copyright b/debian/copyright deleted file mode 100644 index fa5e477..0000000 --- a/debian/copyright +++ /dev/null @@ -1,32 +0,0 @@ -Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ -Upstream-Name: pyparted -Upstream-Contact: David Cantrell -Source: https://github.com/dcantrell/pyparted - -Files: * -Copyright: 2007-2015 Red Hat, Inc. -License: GPL-2+ - -Files: debian/* -Copyright: 2009-2014 Luca Falavigna - 2014 Intrigeri - 2014-2015 Herbert Parentes Fortes Neto -License: GPL-2+ - -License: GPL-2+ - This package is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - . - This package is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - . - You should have received a copy of the GNU General Public License - along with this program. If not, see - . - On Debian systems, the complete text of the GNU General - Public License version 2 can be found in "/usr/share/common-licenses/GPL-2". - diff --git a/debian/patches/no-last-flag-check.patch b/debian/patches/no-last-flag-check.patch deleted file mode 100644 index 0d0c001..0000000 --- a/debian/patches/no-last-flag-check.patch +++ /dev/null @@ -1,27 +0,0 @@ -Description: Remove *_LAST_FLAG checks - The last flag in an enumeration is not really part of the ABI. Checking it - here means that changes to parted may unexpectedly break pyparted. -Author: Colin Watson -Reviewed-by: Herbert Parentes Fortes Neto -Bug-Debian: http://bugs.debian.org/697588 -Last-Update: 2014-11-30 ---- a/src/pydisk.c -+++ b/src/pydisk.c -@@ -1020,7 +1020,7 @@ - return NULL; - } - -- if ((flag < PED_DISK_FIRST_FLAG) || (flag > PED_DISK_LAST_FLAG)) { -+ if ((flag < PED_DISK_FIRST_FLAG)) { - PyErr_SetString(PyExc_ValueError, "Invalid flag provided."); - return NULL; - } -@@ -1404,7 +1404,7 @@ - return NULL; - } - -- if ((flag < PED_PARTITION_FIRST_FLAG) || (flag > PED_PARTITION_LAST_FLAG)) { -+ if ((flag < PED_PARTITION_FIRST_FLAG)) { - PyErr_SetString(PyExc_ValueError, "Invalid flag provided."); - return NULL; - } diff --git a/debian/patches/series b/debian/patches/series deleted file mode 100644 index 74ae2f7..0000000 --- a/debian/patches/series +++ /dev/null @@ -1 +0,0 @@ -no-last-flag-check.patch diff --git a/debian/python-parted.docs b/debian/python-parted.docs deleted file mode 100644 index 3f56ad5..0000000 --- a/debian/python-parted.docs +++ /dev/null @@ -1,5 +0,0 @@ -BUGS -HACKING -NEWS -README -TODO diff --git a/debian/python3-parted.docs b/debian/python3-parted.docs deleted file mode 100644 index 3f56ad5..0000000 --- a/debian/python3-parted.docs +++ /dev/null @@ -1,5 +0,0 @@ -BUGS -HACKING -NEWS -README -TODO diff --git a/debian/rules b/debian/rules deleted file mode 100755 index 6ec8237..0000000 --- a/debian/rules +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/make -f - -export PYBUILD_NAME=parted - -export DEB_LDFLAGS_MAINT_APPEND = -Wl,-z,now - -%: - dh $@ --buildsystem pybuild --with python2,python3 - -override_dh_auto_install: - dh_auto_install - rm -rf debian/python-parted-dbg/usr/lib/python2.7/dist-packages/parted/ - rm -rf debian/python3-parted-dbg/usr/lib/python3*/dist-packages/parted/ diff --git a/debian/source/format b/debian/source/format deleted file mode 100644 index 163aaf8..0000000 --- a/debian/source/format +++ /dev/null @@ -1 +0,0 @@ -3.0 (quilt) diff --git a/debian/watch b/debian/watch deleted file mode 100644 index 7532fc1..0000000 --- a/debian/watch +++ /dev/null @@ -1,2 +0,0 @@ -version=3 -https://github.com/dcantrell/pyparted/releases .*/archive/pyparted-(\d\S+)\.(?:zip|tar\.gz) diff --git a/include/_pedmodule.h b/include/_pedmodule.h deleted file mode 100644 index a15ae2c..0000000 --- a/include/_pedmodule.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * _pedmodule.h - * - * Copyright (C) 2007-2013 Red Hat, Inc. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions of - * the GNU General Public License v.2, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY expressed or implied, including the implied warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. Any Red Hat trademarks that are incorporated in the - * source code or documentation are not subject to the GNU General Public - * License and may only be used or replicated with the express permission of - * Red Hat, Inc. - * - * Author(s): David Cantrell - * Alex Skinner - */ - -#ifndef _PARTEDMODULE_H_INCLUDED -#define _PARTEDMODULE_H_INCLUDED - -#include - -extern PyObject *py_libparted_get_version(PyObject *, PyObject *); -extern PyObject *py_pyparted_version(PyObject *, PyObject *); -extern PyMODINIT_FUNC PyInit__ped(void); - -#endif /* _PARTEDMODULE_H_INCLUDED */ - -/* vim:tw=78:ts=4:et:sw=4 - */ diff --git a/include/convert.h b/include/convert.h deleted file mode 100644 index 140f794..0000000 --- a/include/convert.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * convert.h - * Functions for converting to/from Python _ped types and C libparted types - * - * Copyright (C) 2007-2013 Red Hat, Inc. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions of - * the GNU General Public License v.2, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY expressed or implied, including the implied warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. Any Red Hat trademarks that are incorporated in the - * source code or documentation are not subject to the GNU General Public - * License and may only be used or replicated with the express permission of - * Red Hat, Inc. - * - * Author(s): David Cantrell - * Chris Lumens - * Alex Skinner - */ - -#ifndef CONVERT_H_INCLUDED -#define CONVERT_H_INCLUDED - -#include - -#include "pyconstraint.h" -#include "pydevice.h" -#include "pydisk.h" -#include "pyfilesys.h" -#include "pygeom.h" -#include "pynatmath.h" -#include "pytimer.h" - -#if PY_MAJOR_VERSION < 3 -#define PyUnicode_AsUTF8 PyString_AsString -#define TP_FLAGS (Py_TPFLAGS_HAVE_CLASS | Py_TPFLAGS_CHECKTYPES | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_RICHCOMPARE) -#else -// XXX Restore tp_richcompare? -#define TP_FLAGS (Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE) -#endif - - -PedAlignment *_ped_Alignment2PedAlignment(PyObject *); -_ped_Alignment *PedAlignment2_ped_Alignment(PedAlignment *); - -PedConstraint *_ped_Constraint2PedConstraint(PyObject *); -_ped_Constraint *PedConstraint2_ped_Constraint(PedConstraint *); - -PedDevice *_ped_Device2PedDevice(PyObject *); -_ped_Device *PedDevice2_ped_Device(PedDevice *); - -PedDisk *_ped_Disk2PedDisk(PyObject *); -_ped_Disk *PedDisk2_ped_Disk(PedDisk *); - -PedDiskType *_ped_DiskType2PedDiskType(PyObject *); -_ped_DiskType *PedDiskType2_ped_DiskType(const PedDiskType *); - -PedFileSystem *_ped_FileSystem2PedFileSystem(PyObject *); -_ped_FileSystem *PedFileSystem2_ped_FileSystem(PedFileSystem *); - -PedFileSystemType *_ped_FileSystemType2PedFileSystemType(PyObject *); -_ped_FileSystemType *PedFileSystemType2_ped_FileSystemType(const PedFileSystemType *); - -PedGeometry *_ped_Geometry2PedGeometry(PyObject *); -_ped_Geometry *PedGeometry2_ped_Geometry(PedGeometry *); - -PedCHSGeometry *_ped_CHSGeometry2PedCHSGeometry(PyObject *); -_ped_CHSGeometry *PedCHSGeometry2_ped_CHSGeometry(PedCHSGeometry *); - -PedPartition *_ped_Partition2PedPartition(_ped_Partition *); -_ped_Partition *PedPartition2_ped_Partition(PedPartition *, _ped_Disk *); - -PedTimer *_ped_Timer2PedTimer(PyObject *); -_ped_Timer *PedTimer2_ped_Timer(PedTimer *); - -#endif /* CONVERT_H_INCLUDED */ - -/* vim:tw=78:ts=4:et:sw=4 - */ diff --git a/include/docstrings/pyconstraint.h b/include/docstrings/pyconstraint.h deleted file mode 100644 index 366b9dc..0000000 --- a/include/docstrings/pyconstraint.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * pyconstraint.h - * pyparted docstrings for pyconstraint.c - * - * Copyright (C) 2007, 2008 Red Hat, Inc. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions of - * the GNU General Public License v.2, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY expressed or implied, including the implied warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. Any Red Hat trademarks that are incorporated in the - * source code or documentation are not subject to the GNU General Public - * License and may only be used or replicated with the express permission of - * Red Hat, Inc. - * - * Red Hat Author(s): David Cantrell - * Chris Lumens - */ - -#ifndef DOCSTRINGS_PYCONSTRAINT_H_INCLUDED -#define DOCSTRINGS_PYCONSTRAINT_H_INCLUDED - -#include - -PyDoc_STRVAR(constraint_duplicate_doc, -"duplicate(Constraint) -> Constraint\n\n" -"Return a new Constraint that is a copy of the given Constraint."); - -PyDoc_STRVAR(constraint_intersect_doc, -"intersect(Constraint) -> Constraint\n\n" -"Return a Constraint that requires a region to satisfy both this\n" -"Constraint object and the one passed in to the method. Any\n" -"region satisfying both Constraints will also satisfy the returned\n" -"Constraint."); - -PyDoc_STRVAR(constraint_solve_max_doc, -"solve_max() -> Constraint\n\n" -"Find the largest region that satisfies this Constraint object and\n" -"return a new Constraint. There may be more than one solution.\n" -"There are no guarantees about which solution will be returned.\n"); - -PyDoc_STRVAR(constraint_solve_nearest_doc, -"solve_nearest(Geometry) -> Constraint\n\n" -"Return the nearest region to Geometry that will satisfy this\n" -"Constraint object. This function does not guarantee what nearest\n" -"means."); - -PyDoc_STRVAR(constraint_is_solution_doc, -"is_solution(Geometry) -> bool\n\n" -"Return True if Geometry satisfies this Constraint, False otherwise."); - -PyDoc_STRVAR(_ped_Constraint_doc, -"A _ped.Constraint object describes a set of restrictions on other pyparted\n" -"operations. Constraints can restrict the location and alignment of the start\n" -"and end of a partition, and its minimum and maximum size. Constraint\n" -"operations include various methods of creating constraints, intersecting,\n" -"and solving sets of constraints.\n\n" -"Most constraint operations can raise _ped.CreateException if creating\n" -"temporary objects fails, or ArithmeticError if an error occurrs during\n" -"calculations."); - -#endif /* DOCSTRINGS_PYCONSTRAINT_H_INCLUDED */ - -/* vim:tw=78:ts=4:et:sw=4 - */ diff --git a/include/docstrings/pydevice.h b/include/docstrings/pydevice.h deleted file mode 100644 index c1bbdc3..0000000 --- a/include/docstrings/pydevice.h +++ /dev/null @@ -1,216 +0,0 @@ -/* - * pydevice.h - * pyparted docstrings for pydevice.c - * - * Copyright (C) 2007, 2008, 2009 Red Hat, Inc. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions of - * the GNU General Public License v.2, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY expressed or implied, including the implied warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. Any Red Hat trademarks that are incorporated in the - * source code or documentation are not subject to the GNU General Public - * License and may only be used or replicated with the express permission of - * Red Hat, Inc. - * - * Red Hat Author(s): David Cantrell - */ - -#ifndef DOCSTRINGS_PYDEVICE_H_INCLUDED -#define DOCSTRINGS_PYDEVICE_H_INCLUDED - -#include - -PyDoc_STRVAR(disk_probe_doc, -"disk_probe(self) -> DiskType\n\n" -"Return the type of partition table detected, or raise _ped.IOException if\n" -"there is an error reading self."); - -PyDoc_STRVAR(device_is_busy_doc, -"is_busy(self) -> bool\n\n" -"Return True if this Device is currently in use, False otherwise."); - -PyDoc_STRVAR(device_open_doc, -"open(self) -> bool\n\n" -"Attempt to open this Device to allow use of read(), write(), and sync()\n" -"methods. The open() call is architecture-dependent. Apart from\n" -"requesting access to the device from the operating system, it does things\n" -"flushing caches.\n\n" -"This method may allocate internal resources depending on the architecture\n" -"All allocated resources are freed when you call the close() method.\n\n" -"Return True if the Device could be opened, False otherwise."); - -PyDoc_STRVAR(device_close_doc, -"close(self) -> bool\n\n" -"Close this Device. All allocated resources are freed. If a failure\n" -"occurs while closing the Device, this method returns False. The method\n" -"returns True on success."); - -PyDoc_STRVAR(device_destroy_doc, -"destroy(self) -> None\n\n" -"Destroys the Device, removes it from the device list, destroys all\n" -"allocated resources associated with it, and destroys the object."); - -PyDoc_STRVAR(device_cache_remove_doc, -"cache_remove(self) -> None\n\n" -"Remove the Device from the device list, but does not destroy it or any\n" -"allocated resources associated with it. USE WITH CAUTION."); - -PyDoc_STRVAR(device_begin_external_access_doc, -"begin_external_accessself() -> bool\n\n" -"Begins external access mode for this Device. External access mode allows\n" -"you to safely do I/O on the device. If a Device is open, then you should\n" -"not do any I/O on that Device, e.g. by calling an external program like\n" -"e2fsck, unless you put it in external access mode. You should not use\n" -"any commands that do I/O to a Device while it is in external access mode.\n\n" -"Also, you should not close a Device while it is in external access mode.\n\n" -"Return True if the Device was successfully put in external access mode,\n" -"False otherwise."); - -PyDoc_STRVAR(device_end_external_access_doc, -"end_external_access(self) -> bool\n\n" -"Ends external access mode for this Device. Returns True on success,\n" -"False on failure."); - -PyDoc_STRVAR(device_read_doc, -"read(self, start, count) -> bool\n\n" -"Read and return count sectors from this Device, starting at sector start.\n" -"Both start and count are long integers and buffer is a Python object large\n" -"enough to hold what you want to read."); - -PyDoc_STRVAR(device_write_doc, -"write(self, buffer, start, count) -> bool\n\n" -"Write count sectors from buffer to this Device, starting at sector start.\n" -"Both start and count are long integers and buffer is a Python object holding\n" -"what you want to write to this Device.\n\n" -"Return True if the write was successful, False otherwise."); - -PyDoc_STRVAR(device_sync_doc, -"sync(self) -> bool\n\n" -"Flushes all write-behind caches that might be holding up writes. It is\n" -"slow because it guarantees cache coherency among all relevant caches.\n" -"Return True on success, False otherwise."); - -PyDoc_STRVAR(device_sync_fast_doc, -"sync_fast(self) -> bool\n\n" -"Flushes all write-behind caches that might be holding writes. WARNING:\n" -"Does NOT ensure cache coherency with other caches. If you need cache\n" -"coherency, use sync() instead. Return True on success, False otherwise."); - -PyDoc_STRVAR(device_check_doc, -"check(self) -> long int\n\n" -"Architecture-dependent function that returns the number of sectors on\n" -"this Device that are ok."); - -PyDoc_STRVAR(disk_clobber_doc, -"clobber(self) -> boolean\n\n" -"Remove all identifying information from a partition table. If the partition\n" -"table cannot be cleared, a _ped.DiskException is raised."); - -PyDoc_STRVAR(device_get_constraint_doc, -"get_constraint(self) -> Constraint\n\n" -"Get a constraint that represents hardware requirements on geometry.\n" -"This method will return a constraint representing the limits imposed by\n" -"the size of the disk, it will *not* provide any alignment constraints.\n" -"\n" -"Alignment constraints may be desirable when using media that have a\n" -"physical sector size that is a multiple of the logical sector size, as\n" -"in this case proper partition alignment can benefit disk performance\n" -"signigicantly.\n"); - -PyDoc_STRVAR(device_get_minimal_aligned_constraint_doc, -"get_minimal_aligned_constraint(self) -> Constraint\n\n" -"Get a constraint that represents hardware requirements on geometry and\n" -"alignment. This method returns a constraint representing the limits\n" -"imposed by the size of the disk and the minimal alignment requirements\n" -"for proper performance of the disk.\n"); - -PyDoc_STRVAR(device_get_optimal_aligned_constraint_doc, -"get_optimal_aligned_constraint(self) -> Constraint\n\n" -"Get a constraint that represents hardware requirements on geometry and\n" -"alignment. This method returns a constraint representing the limits\n" -"imposed by the size of the disk and the alignment requirements for\n" -"optimal performance of the disk.\n"); - -PyDoc_STRVAR(device_get_minimum_alignment_doc, -"get_minimum_alignment(self) -> Alignment\n\n" -"Get an alignment that represents minimum hardware requirements on\n" -"alignment. When for example using media that has a physical sector size\n" -"that is a multiple of the logical sector size, it is desirable to have\n" -"disk accesses (and thus partitions) properly aligned. Having partitions\n" -"not aligned to the minimum hardware requirements may lead to a\n" -"performance penalty.\n\n" -"The returned alignment describes the alignment for the start sector of\n" -"the partition, the end sector should be aligned too, to get the end\n" -"sector alignment decrease the returned alignment's offset by 1.\n"); - -PyDoc_STRVAR(device_get_optimum_alignment_doc, -"get_optimum_alignment(self) -> Alignment\n\n" -"Get an alignment that represents the hardware requirements for optimal\n" -"performance.\n\n" -"The returned alignment describes the alignment for the start sector of\n" -"the partition, the end sector should be aligned too, to get the end\n" -"sector alignment decrease the returned alignment's offset by 1.\n"); - -PyDoc_STRVAR(unit_get_size_doc, -"unit_get_size(self, Unit) -> long\n\n" -"Returns the byte size of self in the specified Unit. The Unit\n" -"is any of the _ped.UNIT_* constants."); - -PyDoc_STRVAR(unit_format_custom_byte_doc, -"unit_format_custom_byte(Sector, Unit) -> string\n\n" -"Return a string that describes the location of the byte Sector on\n" -"self, as described by Unit. The Unit is any of the _ped.UNIT_*\n" -"constants."); - -PyDoc_STRVAR(unit_format_byte_doc, -"unit_format_byte(Sector) -> string\n\n" -"Return a string that describes the location of the byte Sector on\n" -"self, as described by the default Unit."); - -PyDoc_STRVAR(unit_format_custom_doc, -"unit_format_custom(Sector, Unit) -> string\n\n" -"Return a string that describes the location of Sector on self, as\n" -"described by Unit. The Unit is any of the _ped.UNIT_* constants."); - -PyDoc_STRVAR(unit_format_doc, -"unit_format(Device, Sector) -> string\n\n" -"Return a string that describes the location of Sector on self, as\n" -"described by the default Unit."); - -PyDoc_STRVAR(unit_parse_doc, -"unit_parse(string, Sector, Geometry) -> boolean\n\n" -"Given a string providing a valid description of a location on self,\n" -"create a Geometry and Sector describing it. Geometry will be two units\n" -"large, centered on Sector. If this makes the Geometry exist partially\n" -"outside self, the Geometry will be intersected with the whole device\n" -"geometry. This uses the default unit."); - -PyDoc_STRVAR(unit_parse_custom_doc, -"unit_parse(string, Unit, Sector, Geometry) -> boolean\n\n" -"Follows the same description as unit_parse_doc, but takes a Unit as\n" -"well. The Unit is any of the _ped.UNIT_* constants."); - -PyDoc_STRVAR(_ped_CHSGeometry_doc, -"A _ped.CHSGeometry object describes a disk using the older CHS style\n" -"of defining disk geometry. CHS stands for cylinders-heads-sectors.\n\n" -"The _ped.CHSGeometry objects are created automatically when devices are\n" -"probed by libparted. They are used for reference purposes to get the\n" -"number of cylinders, heads, or sectors on a disk. They cannot be used\n" -"to change the CHS values on a device."); - -PyDoc_STRVAR(_ped_Device_doc, -"A _ped.Device object describes a block device accessible via the\n" -"operating system. On Linux, an example block device is /dev/sda.\n\n" -"It is important to note that _ped.Device objects describe entire\n" -"block devices and not just partitions."); - -#endif /* DOCSTRINGS_PYDEVICE_H_INCLUDED */ - -/* vim:tw=78:ts=4:et:sw=4 - */ diff --git a/include/docstrings/pydisk.h b/include/docstrings/pydisk.h deleted file mode 100644 index f9f6f09..0000000 --- a/include/docstrings/pydisk.h +++ /dev/null @@ -1,299 +0,0 @@ -/* - * pydisk.h - * pyparted docstrings for pydisk.c - * - * Copyright (C) 2007, 2008, 2009 Red Hat, Inc. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions of - * the GNU General Public License v.2, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY expressed or implied, including the implied warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. Any Red Hat trademarks that are incorporated in the - * source code or documentation are not subject to the GNU General Public - * License and may only be used or replicated with the express permission of - * Red Hat, Inc. - * - * Red Hat Author(s): David Cantrell - * Chris Lumens - */ - -#ifndef DOCSTRINGS_PYDISK_H_INCLUDED -#define DOCSTRINGS_PYDISK_H_INCLUDED - -#include - -PyDoc_STRVAR(partition_destroy_doc, -"destroy(self) -> None\n\n" -"Destroys the Partition object."); - -PyDoc_STRVAR(partition_is_active_doc, -"is_active(self) -> boolean\n\n" -"Return whether self is active or not."); - -PyDoc_STRVAR(partition_set_flag_doc, -"set_flag(self, flag, state) -> boolean\n\n" -"Sets the state of the given flag on self . Flags have different types of\n" -"different types of disk labels, and are not guaranteed to exist on all disk\n" -"label types. If provided with an invalid flag for the disk's label,\n" -"_ped.PartitionException is raised."); - -PyDoc_STRVAR(partition_get_flag_doc, -"get_flag(self, flag) -> integer\n\n" -"Return the state of the given flag on self. There is no check for invalid\n" -"flag types, so these will always return 0. It is therefore recommended to\n" -"call self.is_flag_available() first to make sure."); - -PyDoc_STRVAR(partition_is_flag_available_doc, -"is_flag_available(self, flag) -> boolean\n\n" -"Return whether the given flag is valid for self."); - -PyDoc_STRVAR(partition_set_system_doc, -"set_system(self, FileSystemType) -> boolean\n\n" -"Set the system type on self to FileSystemType. On error,\n" -"_ped.PartitionException is raised."); - -PyDoc_STRVAR(partition_set_name_doc, -"set_name(self, string) -> boolean\n\n" -"On disk labels that support it, this method sets the partition's name.\n" -"Before attempting this operation, DiskType.check_feature() can be used to\n" -"determine if it is even supported. On error, _ped.PartitionException will\n" -"be raised."); - -PyDoc_STRVAR(partition_get_name_doc, -"get_name(self) -> string\n\n" -"On disk labels that support it, this method returns the partition's name. On\n" -"all other disk labels, _ped.PartitionException will be raised. Before calling\n" -"this method, DiskType.check_feature() can be called to check for support."); - -PyDoc_STRVAR(partition_is_busy_doc, -"is_busy(self) -> boolean\n\n" -"Return whether self is busy or not. The most likely reason for a partition\n" -"to be busy is because it's mounted. Additionally, extended partitions are\n" -"busy if any of their logical partitions are busy."); - -PyDoc_STRVAR(partition_get_path_doc, -"get_path(self) -> string\n\n" -"Return a path that could be used for addressing self at an operating system\n" -"level. For instance, on Linux this could return '/dev/sda' for a partition.\n" -"If an error occurs, _ped.PartitionException is raised."); - -PyDoc_STRVAR(partition_reset_num_doc, -"reset_num(self) -> boolean\n\n" -"Reset the partition's number to value allowing it to be set correctly when\n" -"the partition is added to _ped.PartedDisk. The returned value means\n" -"success/failure"); - -PyDoc_STRVAR(disk_duplicate_doc, -"duplicate(self) -> Disk\n\n" -"Return a new Disk that is a copy of self. This method raises\n" -"_ped.DiskException if there is an error making the copy."); - -PyDoc_STRVAR(disk_destroy_doc, -"destroy(self) -> None\n\n" -"Destroy the Disk object."); - -PyDoc_STRVAR(disk_commit_doc, -"commit(self) -> boolean\n\n" -"Write the in-memory changes to the disk's partition table and inform the\n" -"operating system of the changes. This method is equivalent to calling:\n" -"\tself.disk_commit_to_dev()\n" -"\tself.disk_commit_to_os()\n" -"On error, _ped.DiskException is raised."); - -PyDoc_STRVAR(disk_commit_to_dev_doc, -"commit_to_dev(self) -> boolean\n\n" -"Write the in-memory changes to the disk's partition table. On error,\n" -"_ped.DiskException is raised."); - -PyDoc_STRVAR(disk_commit_to_os_doc, -"commit_to_os(self) -> boolean\n\n" -"Inform the operating system that disk's partition table layout has changed.\n" -"What exactly this means depends on the operating system. On error, a\n" -"_ped.DiskException is raised."); - -PyDoc_STRVAR(disk_check_doc, -"check(self) -> boolean\n\n" -"Perform a basic sanity check on the partition table. This check does not\n" -"depend on the type of disk. If there is an error performing the check,\n" -"_ped.DiskException is raised."); - -PyDoc_STRVAR(disk_print_doc, -"print(self) -> None\n\n" -"Print a summary of the partitions on self."); - -PyDoc_STRVAR(disk_get_primary_partition_count_doc, -"get_primary_partition_count(self) -> integer\n\n" -"Return the number of primary partitions on self."); - -PyDoc_STRVAR(disk_get_last_partition_num_doc, -"get_last_partition_num(self) -> integer\n\n" -"Return the highest in-use partition number on self."); - -PyDoc_STRVAR(disk_get_max_primary_partition_count_doc, -"get_max_primary_partition_count(self) -> integer\n\n" -"Get the maximum number of primary partitions spported by the disk label."); - -PyDoc_STRVAR(disk_get_max_supported_partition_count_doc, -"get_max_supported_partition_count(self) -> integer\n\n" -"Get the highest supported partition number of this disk."); - -PyDoc_STRVAR(disk_get_partition_alignment_doc, -"get_partition_alignment(self) -> Alignment\n\n" -"Get the alignment needed for partition boundaries on this disk.\n" -"The returned alignment describes the alignment for the start sector\n" -"of the partition, for all disklabel types which require alignment,\n" -"except Sun disklabels, the end sector must be aligned too.\n" -"To get the end sector alignment decrease the PedAlignment offset by 1.\n"); - -PyDoc_STRVAR(disk_max_partition_length_doc, -"max_partition_length(self) -> long\n\n" -"This returns the maximum length for a partition the label on this disk\n" -"can represent. This does not necessarily mean that there is enough\n" -"freespace to create such a partition.\n" -"If this information is not available 0 is returned"); - -PyDoc_STRVAR(disk_max_partition_start_sector_doc, -"max_partition_start_sector(self) -> long\n\n" -"This returns the maximum partition start sector the label on this disk\n" -"can represent.\n" -"If this information is not available 0 is returned"); - -PyDoc_STRVAR(disk_set_flag_doc, -"set_flag(self, flag, state) -> boolean\n\n" -"Sets the state of the given flag on self .\n" -"If provided with an invalid flag for the disk's label,\n" -"a PartedException is raised."); - -PyDoc_STRVAR(disk_get_flag_doc, -"get_flag(self, flag) -> boolean\n\n" -"Return the state of the given flag on self. There is no check for invalid\n" -"flag types, so these will always return 0. It is therefore recommended to\n" -"call self.is_flag_available() first to make sure."); - -PyDoc_STRVAR(disk_is_flag_available_doc, -"is_flag_available(self, flag) -> boolean\n\n" -"Return whether the given flag is valid for self."); - -PyDoc_STRVAR(disk_add_partition_doc, -"add_partition(self, Partition, Constraint) -> boolean\n\n" -"Adds the new partition Partition to self. This operation may modify the\n" -"partition's geometry, subject to Constraint. Having a strict Constraint\n" -"will likely cause this operation to fail, raising a _ped.PartitionException\n" -"in the process."); - -PyDoc_STRVAR(disk_remove_partition_doc, -"remove_partition(self, Partition) -> boolean\n\n" -"Remove Partition from self. If Partition is an extended partition, it must\n" -"not contain any logical partitions. The Partition object itself is not\n" -"destroyed. The caller must use Partition.destroy() or self.delete_partition().\n" -"For all error cases, _ped.PartitionException will be raised."); - -PyDoc_STRVAR(disk_delete_partition_doc, -"delete_partition(self, Partition) -> boolean\n\n" -"Remove Partition from self and destroy the Partition object afterwards. This\n" -"is equivalent to calling:\n" -"\tself.remove_partition(Partition)\n" -"\tPartition.destroy()\n" -"For all error cases, _ped.PartitionException will be raised."); - -PyDoc_STRVAR(disk_delete_all_doc, -"disk_delete_all(self) -> boolean\n\n" -"Remove and destroy all partitions on self, raising _ped.PartitionException on\n" -"any error case."); - -PyDoc_STRVAR(disk_set_partition_geom_doc, -"set_partition_geom(self, Partition, Constraint, start_sector, end_sector) ->\n" -" boolean\n\n" -"Change the location of Partition by setting a new Geometry on it, subject to\n" -"the restrictions of Constraint. This operation can fail for many reasons,\n" -"all of which result in a _ped.PartitionException. One of the most likely\n" -"failure cases is that the new location overlaps with an existing partition.\n" -"On error, Partition will be unchanged. On success, the contents of the\n" -"partition will still not be changed - the file system itself will still\n" -"need to be resized."); - -PyDoc_STRVAR(disk_maximize_partition_doc, -"maximize_partition(self, Partition, Constraint) -> boolean\n\n" -"Grow the Partition to the largest possibly size, subject to the restrictions\n" -"of Constraint. Raise _ped.PartitionException on error."); - -PyDoc_STRVAR(disk_get_max_partition_geometry_doc, -"get_max_partition_geometry(self, Partition, Constraint) -> Geometry\n\n" -"Return the maximum Geometry that Partition can be grown to, subject to the\n" -"restrictions of Constraint. Raise _ped.PartitionException on error."); - -PyDoc_STRVAR(disk_minimize_extended_partition_doc, -"minimize_extended_partition(self) -> boolean\n\n" -"Reduce the size of an extended partition on self to the minimum while still\n" -"including all logical partitions. If there are no logical partitions, the\n" -"extended partition will be deleted. If the extended partition cannot be\n" -"shrunk, a _ped.PartitionException will be raised."); - -PyDoc_STRVAR(disk_next_partition_doc, -"next_partition(self, Partition) -> Partition\n\n" -"Return the next partition on self after Partition. If Partition is None,\n" -"return the first partition. If Partition is an extended partition, return\n" -"the first logical partition inside it. If Partition is the last partition,\n" -"raise IndexError. Repeatedly calling this method has the effect of\n" -"performing a depth-first traversal on self."); - -PyDoc_STRVAR(disk_get_partition_doc, -"get_partition(self, num) -> Partition\n\n" -"Return the Partition given by num, or raise _ped.PartitionException if no\n" -"partition with that index exists."); - -PyDoc_STRVAR(disk_get_partition_by_sector_doc, -"get_partition_by_sector(self, sector) -> Partition\n\n" -"Return the Partition containing sector, or raise _ped.PartitionException\n" -"otherwise. If sector exists within a logical partition, the logical\n" -"partition is returned."); - -PyDoc_STRVAR(disk_extended_partition_doc, -"extended_partition(self) -> Partition\n\n" -"If an extended partition exists on self, return it. Otherwise, raise\n" -"_ped.PartitionException"); - -PyDoc_STRVAR(disk_type_check_feature_doc, -"check_feature(self, DiskTypeFeature) -> boolean\n\n" -"Return whether or not self supports a particular partition table feature.\n" -"DiskTypeFeatures are given by the _ped.DISK_TYPE_* constants."); - -PyDoc_STRVAR(_ped_Partition_doc, -"A _ped.Partition object describes a single partition on a disk. Operations\n" -"on Partition objects are limited to getting and setting flags, names, and\n" -"paths. All other operations you may wish to do involving partitions are\n" -"done through a _ped.Disk or _ped.FileSystem object. These objects all exist\n" -"as attributes of a Partition, though.\n\n" -"Valid flags for Partitions are given by the _ped.PARTITION_* constants,\n" -"though not all flags are valid for every disk label type.\n\n" -"For most errors involving a Partition object, _ped.PartitionException will\n" -"be raised."); - -PyDoc_STRVAR(_ped_Disk_doc, -"A _ped.Disk object represents a disk label, or partition table, on a single\n" -"_ped.Device. Since parted supports a variety of platforms, it must also\n" -"support a variety of disk labels, not all of which may support the same set\n" -"of features. For instance, DOS disk labels support extended partitions while\n" -"other systems do not. The Disk object therefore includes a DiskType\n" -"reference to enumerate supported features. However, all other Disk operations\n" -"are supported on all disk label types.\n\n" -"Operations on Disk objects include creating, deleting, moving, and resizing\n" -"partitions in various ways. Creating filesystems within these partitions is\n" -"left up to the FileSystem objects.\n\n" -"For most errors involving a Disk object, _ped.PartitionException will be\n" -"raised. Some operations can also raise _ped.IOException or IndexError."); - -PyDoc_STRVAR(_ped_DiskType_doc, -"A _ped.DiskType object is a simple object that gives a partition table a\n" -"name and describes features it supports. A reference to one of these\n" -"objects is stored inside a _ped.Disk object."); - -#endif /* PYDISK_H_INCLUDED */ - -/* vim:tw=78:ts=4:et:sw=4 - */ diff --git a/include/docstrings/pyfilesys.h b/include/docstrings/pyfilesys.h deleted file mode 100644 index ef4a9ac..0000000 --- a/include/docstrings/pyfilesys.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * pyfilesys.h - * pyparted docstrings for pyfilesys.c - * - * Copyright (C) 2007-2011 Red Hat, Inc. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions of - * the GNU General Public License v.2, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY expressed or implied, including the implied warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. Any Red Hat trademarks that are incorporated in the - * source code or documentation are not subject to the GNU General Public - * License and may only be used or replicated with the express permission of - * Red Hat, Inc. - * - * Red Hat Author(s): David Cantrell - * Chris Lumens - */ - -#ifndef DOCSTRINGS_PYFILESYS_H_INCLUDED -#define DOCSTRINGS_PYFILESYS_H_INCLUDED - -#include - -PyDoc_STRVAR(_ped_FileSystemType_doc, -"A _ped.FileSystemType object gives a name to a single filesystem that parted\n" -"understands. parted maintains a list of these objects which can be\n" -"traversed with the self.get_next method or accessed directly via self.get()."); - -PyDoc_STRVAR(_ped_FileSystem_doc, -"A _ped.FileSystem object describes a filesystem that exists in a given\n" -"region on a device. The region is given by a _ped.Geometry object, and\n" -"the filesystem is further described by a _ped.FileSystemType object.\n\n" -"Filesystem operations are especially prone to failures, and pyparted raises\n" -"a variety of exceptions when error conditions are encountered. The most\n" -"common is _ped.FileSystemException, though _ped.IOException and\n" -"_ped.CreateException may also be raised."); - -#endif /* DOCSTRINGS_PYFILESYS_H_INCLUDED */ - -/* vim:tw=78:ts=4:et:sw=4 - */ diff --git a/include/docstrings/pygeom.h b/include/docstrings/pygeom.h deleted file mode 100644 index 677bef6..0000000 --- a/include/docstrings/pygeom.h +++ /dev/null @@ -1,132 +0,0 @@ -/* - * pygeom.h - * pyparted docstrings for pygeom.c - * - * Copyright (C) 2007, 2008 Red Hat, Inc. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions of - * the GNU General Public License v.2, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY expressed or implied, including the implied warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. Any Red Hat trademarks that are incorporated in the - * source code or documentation are not subject to the GNU General Public - * License and may only be used or replicated with the express permission of - * Red Hat, Inc. - * - * Red Hat Author(s): David Cantrell - * Chris Lumens - */ - -#ifndef DOCSTRINGS_PYGEOM_H_INCLUDED -#define DOCSTRINGS_PYGEOM_H_INCLUDED - -#include - -PyDoc_STRVAR(geometry_duplicate_doc, -"duplicate(self) -> _ped.Geometry\n\n" -"Create an identical copy of self. Raises _ped.CreateException if the\n" -"operation fails"); - -PyDoc_STRVAR(geometry_intersect_doc, -"intersect(self, Geometry) -> _ped.Geometry\n\n" -"Create a new Geometry describing the region common to both self and\n" -"Geometry. Raises ArithmeticError if the two regions do not intersect."); - -PyDoc_STRVAR(geometry_set_doc, -"set(self, start, length) -> boolean\n\n" -"Sets a new start Sector and length Sector in the Geometry object,\n" -"also implicitly setting the end Sector as well."); - -PyDoc_STRVAR(geometry_set_start_doc, -"set_start(self, start) -> boolean\n\n" -"Sets a new start Sector without modifying the end Sector. Length\n" -"will be modified to match the new starting position."); - -PyDoc_STRVAR(geometry_set_end_doc, -"set_end(self, end) -> boolean\n\n" -"Sets a new ending Sector without modifying the start Sector. Length\n" -"will be modified to match the new ending position."); - -PyDoc_STRVAR(geometry_test_overlap_doc, -"test_overlap(self, Geometry) -> boolean\n\n" -"Return whether self and Geometry are on the same physical device and\n" -"share at least part of the same region."); - -PyDoc_STRVAR(geometry_test_inside_doc, -"test_inside(self, Geometry) -> boolean\n\n" -"Return whether Geometry is entirely within self and on the same physical\n" -"device."); - -PyDoc_STRVAR(geometry_test_equal_doc, -"test_equal(self, Geometry) -> boolean\n\n" -"Return whether self and Geometry are on the same device and have the same\n" -"region."); - -PyDoc_STRVAR(geometry_test_sector_inside_doc, -"test_sector_inside(self, Sector) -> boolean\n\n" -"Return whether Sector is entirely within the region described by self."); - -PyDoc_STRVAR(geometry_read_doc, -"read(self, buffer, offset, count) -> boolean\n\n" -"Read data from the region described by self. This method reads count\n" -"Sectors starting at Sector offset (from the start of the region, not\n" -"from the start of the disk) into buffer. This method raises\n" -"_ped.IOException on error."); - -PyDoc_STRVAR(geometry_sync_doc, -"sync(self) -> boolean\n\n" -"Flushes all caches on the device described by self. This operation can be\n" -"slow because it must guarantee cache coherency among multiple caches. This\n" -"method raises _ped.IOException on error."); - -PyDoc_STRVAR(geometry_sync_fast_doc, -"sync_fast(self) -> boolean\n\n" -"Flushes all caches on the device described by self without guaranteeing\n" -"cache coherency. This makes it fast but more prone to error. This method\n" -"raises _ped.IOException on error."); - -PyDoc_STRVAR(geometry_write_doc, -"write(self, buffer, offset, count) -> boolean\n\n" -"Write data into the region described by self. This method writes count\n" -"Sectors of buffer into the region starting at Sector offset. The offset is\n" -"from the beginning of the region, not of the disk. This method raises\n" -"_ped.IOException on error."); - -PyDoc_STRVAR(geometry_check_doc, -"check(self, offset, granularity, count, timer=None) -> Sector\n\n" -"This method checks the region described by self for errors on the disk.\n" -"The region to check starts at offset Sectors from the beginning of the\n" -"region and is count Sectors long. granularity specifies how Sectors should\n" -"be grouped together.\n\n" -"This method returns the first bad sector, or 0 if there are no errors."); - -PyDoc_STRVAR(geometry_map_doc, -"map(self, Geometry, Sector) -> integer\n\n" -"Given a Geometry that overlaps with self and a Sector inside Geometry,\n" -"this method translates the address of Sector into an address inside self.\n" -"The new address is returned, or ArithmeticError is raised if Sector does\n" -"not exist within self."); - -PyDoc_STRVAR(_ped_Geometry_doc, -"A _ped.Geometry object describes a continuous region on a physical device.\n" -"This device is given by the dev attribute when the Geometry is created.\n" -"Most methods on this object involve creating new Geometry objects as needed\n" -"and can therefore raise _ped.CreateException when an error occurs creating\n" -"the new object. Most methods can also raise _ped.IOException when reading\n" -"or writing the underlying physical device fails.\n\n" -"libparted (and therefore pyparted) attempts to enforce the following\n" -"conditions on Geometry objects:\n\n" -"\t- start + length - 1 == end\n" -"\t- length > 0\n" -"\t- start >= 0\n" -"\t- end < dev.length"); - -#endif /* DOCSTRINGS_PYGEOM_H_INCLUDED */ - -/* vim:tw=78:ts=4:et:sw=4 - */ diff --git a/include/docstrings/pynatmath.h b/include/docstrings/pynatmath.h deleted file mode 100644 index b2f230b..0000000 --- a/include/docstrings/pynatmath.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * docstrings/pynatmath.h - * pyparted docstrings for for pynatmath.c - * - * Copyright (C) 2007, 2008 Red Hat, Inc. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions of - * the GNU General Public License v.2, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY expressed or implied, including the implied warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. Any Red Hat trademarks that are incorporated in the - * source code or documentation are not subject to the GNU General Public - * License and may only be used or replicated with the express permission of - * Red Hat, Inc. - * - * Red Hat Author(s): David Cantrell - * Chris Lumens - */ - -#ifndef DOCSTRINGS_PYNATMATH_H_INCLUDED -#define DOCSTRINGS_PYNATMATH_H_INCLUDED - -#include - -PyDoc_STRVAR(alignment_duplicate_doc, -"duplicate(self) -> _ped.Alignment\n\n" -"Create an identical copy of self. Raises _ped.CreateException if the\n" -"operation fails"); - -PyDoc_STRVAR(alignment_intersect_doc, -"intersect(self, Alignment) -> _ped.Alignment\n\n" -"Create a new Alignment that describes the intersection of self and\n" -"Alignment. A sector will satisfy the new Alignment iff it satisfies both\n" -"of the original alignments, where 'satisfy' is determined by is_aligned().\n" -"The proof of this is relatively complicated and is described thoroughly\n" -"in the libparted source. This method raises ArithmeticError if no\n" -"intersection can be found."); - -PyDoc_STRVAR(alignment_align_up_doc, -"align_up(self, Geometry, Sector) -> Sector\n\n" -"Returns the closest Sector to the input Sector that lies inside Geometry\n" -"and satisfies the alignment constraint. This method prefers, but does not\n" -"guarantee, that the result is beyond Sector. If no such Sector can be\n" -"found, an ArithmeticError is raised."); - -PyDoc_STRVAR(alignment_align_down_doc, -"align_down(self, Geometry, Sector) -> Sector\n\n" -"Returns the closest Sector to the input Sector that lies inside Geometry\n" -"and satisfies the alignment constraint. This method prefers, but does not\n" -"guarantee, that the result is below Sector. If no such Sector can be\n" -"found, an ArithmeticError is raised."); - -PyDoc_STRVAR(alignment_align_nearest_doc, -"align_nearest(self, Geometry, Sector) -> Sector\n\n" -"Returns the closest Sector to the input Sector that lies inside Geometry\n" -"and satisfies the aligmnent constraint. If no such Sector can be found,\n" -"an ArithmeticError is raised."); - -PyDoc_STRVAR(alignment_is_aligned_doc, -"is_aligned(self, Geometry, Sector) -> boolean\n\n" -"Returns whether or not Sector lies inside Geometry and satisfies the\n" -"alignment constraint. This method defines what 'satisfy' means for\n" -"intersection."); - -PyDoc_STRVAR(_ped_Alignment_doc, -"A _ped.Alignment object describes constraints on how sectors and Geometry\n" -"objects are aligned. It includes a variety of methods for aligning sectors\n" -"and calculating the intersection of two Alignment objects. Most methods on\n" -"this object can raise _ped.CreateException if creating temporary objects\n" -"fails and ArithmeticError if calculating alignments and intersections fails."); - -#endif /* DOCSTRINGS_PYNATMATH_H_INCLUDED */ - -/* vim:tw=78:ts=4:et:sw=4 - */ diff --git a/include/exceptions.h b/include/exceptions.h deleted file mode 100644 index 2a3e1f5..0000000 --- a/include/exceptions.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * exceptions.h - * - * Copyright (C) 2007-2013 Red Hat, Inc. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions of - * the GNU General Public License v.2, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY expressed or implied, including the implied warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. Any Red Hat trademarks that are incorporated in the - * source code or documentation are not subject to the GNU General Public - * License and may only be used or replicated with the express permission of - * Red Hat, Inc. - * - * Author(s): Chris Lumens - * Alex Skinner - */ - -#ifndef _EXCEPTIONS_H_INCLUDED -#define _EXCEPTIONS_H_INCLUDED - -#include - -/* custom exceptions for _ped */ -PyObject *AlignmentException; -PyObject *CreateException; -PyObject *ConstraintException; -PyObject *DeviceException; -PyObject *DiskException; -PyObject *DiskLabelException; -PyObject *FileSystemException; -PyObject *GeometryException; -PyObject *IOException; -PyObject *NotNeededException; -PyObject *PartedException; -PyObject *PartitionException; -PyObject *TimerException; -PyObject *UnknownDeviceException; -PyObject *UnknownTypeException; - -extern unsigned int partedExnRaised; -extern char *partedExnMessage; - -#endif /* _EXCEPTIONS_H_INCLUDED */ - -/* vim:tw=78:ts=4:et:sw=4 - */ diff --git a/include/pyconstraint.h b/include/pyconstraint.h deleted file mode 100644 index 37e3798..0000000 --- a/include/pyconstraint.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * pyconstraint.h - * pyparted type definitions for pyconstraint.c - * - * Copyright (C) 2007-2013 Red Hat, Inc. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions of - * the GNU General Public License v.2, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY expressed or implied, including the implied warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. Any Red Hat trademarks that are incorporated in the - * source code or documentation are not subject to the GNU General Public - * License and may only be used or replicated with the express permission of - * Red Hat, Inc. - * - * Author(s): David Cantrell - * Chris Lumens - * Alex Skinner - */ - -#ifndef PYCONSTRAINT_H_INCLUDED -#define PYCONSTRAINT_H_INCLUDED - -#include - -#include - -/* 1:1 function mappings for constraint.h in libparted */ -PyObject *py_ped_constraint_new_from_min_max(PyObject *, PyObject *); -PyObject *py_ped_constraint_new_from_min(PyObject *, PyObject *); -PyObject *py_ped_constraint_new_from_max(PyObject *, PyObject *); -PyObject *py_ped_constraint_duplicate(PyObject *, PyObject *); -PyObject *py_ped_constraint_intersect(PyObject *, PyObject *); -PyObject *py_ped_constraint_solve_max(PyObject *, PyObject *); -PyObject *py_ped_constraint_solve_nearest(PyObject *, PyObject *); -PyObject *py_ped_constraint_is_solution(PyObject *, PyObject *); -PyObject *py_ped_constraint_any(PyObject *, PyObject *); -PyObject *py_ped_constraint_exact(PyObject *, PyObject *); - -/* _ped.Constraint type is the Python equiv of PedConstraint in libparted */ -typedef struct { - PyObject_HEAD - - /* PedConstraint members */ - PyObject *start_align; /* _ped.Alignment */ - PyObject *end_align; /* _ped.Alignment */ - PyObject *start_range; /* _ped.Geometry */ - PyObject *end_range; /* _ped.Geometry */ - long long min_size; /* PedSector */ - long long max_size; /* PedSector */ -} _ped_Constraint; - -void _ped_Constraint_dealloc(_ped_Constraint *); -int _ped_Constraint_compare(_ped_Constraint *, PyObject *); -PyObject *_ped_Constraint_richcompare(_ped_Constraint *, PyObject *, int); -PyObject *_ped_Constraint_str(_ped_Constraint *); -int _ped_Constraint_traverse(_ped_Constraint *, visitproc, void *); -int _ped_Constraint_clear(_ped_Constraint *); -int _ped_Constraint_init(_ped_Constraint *, PyObject *, PyObject *); -PyObject *_ped_Constraint_get(_ped_Constraint *, void *); -int _ped_Constraint_set(_ped_Constraint *, PyObject *, void *); - -extern PyTypeObject _ped_Constraint_Type_obj; - -#endif /* PYCONSTRAINT_H_INCLUDED */ - -/* vim:tw=78:ts=4:et:sw=4 - */ diff --git a/include/pydevice.h b/include/pydevice.h deleted file mode 100644 index dd45285..0000000 --- a/include/pydevice.h +++ /dev/null @@ -1,119 +0,0 @@ -/* - * pydevice.h - * pyparted type definitions for pydevice.c - * - * Copyright (C) 2007-2013 Red Hat, Inc. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions of - * the GNU General Public License v.2, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY expressed or implied, including the implied warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. Any Red Hat trademarks that are incorporated in the - * source code or documentation are not subject to the GNU General Public - * License and may only be used or replicated with the express permission of - * Red Hat, Inc. - * - * Author(s): David Cantrell - * Alex Skinner - */ - -#ifndef PYDEVICE_H_INCLUDED -#define PYDEVICE_H_INCLUDED - -#include - -#include - -/* _ped.CHSGeometry type is the Python equiv of PedCHSGeometry in libparted */ -typedef struct { - PyObject_HEAD - - /* a PedCHSGeometry stores three ints */ - int cylinders; - int heads; - int sectors; -} _ped_CHSGeometry; - -void _ped_CHSGeometry_dealloc(_ped_CHSGeometry *); -int _ped_CHSGeometry_compare(_ped_CHSGeometry *, PyObject *); -PyObject *_ped_CHSGeometry_richcompare(_ped_CHSGeometry *, PyObject *, int); -PyObject *_ped_CHSGeometry_str(_ped_CHSGeometry *); -int _ped_CHSGeometry_traverse(_ped_CHSGeometry *, visitproc, void *); -int _ped_CHSGeometry_clear(_ped_CHSGeometry *); -PyObject *_ped_CHSGeometry_get(_ped_CHSGeometry *, void *); - -extern PyTypeObject _ped_CHSGeometry_Type_obj; - -/* _ped.Device type is the Python equivalent of PedDevice in libparted */ -typedef struct { - PyObject_HEAD - - /* a PedDevice is complex, we will store primitives when appropriate or - * just other Python objects we've created for the typedefs in libparted */ - char *model; - char *path; - long long type; - long long sector_size; - long long phys_sector_size; - long long length; /* PedSector */ - int open_count; - int read_only; - int external_mode; - int dirty; - int boot_dirty; - PyObject *hw_geom; /* a _ped.CHSGeometry */ - PyObject *bios_geom; /* a _ped.CHSGeometry */ - short host; - short did; -} _ped_Device; - -void _ped_Device_dealloc(_ped_Device *); -int _ped_Device_compare(_ped_Device *, PyObject *); -PyObject *_ped_Device_richcompare(_ped_Device *, PyObject *, int); -PyObject *_ped_Device_str(_ped_Device *); -int _ped_Device_traverse(_ped_Device *, visitproc, void *); -int _ped_Device_clear(_ped_Device *); -PyObject *_ped_Device_get(_ped_Device *, void *); - -extern PyTypeObject _ped_Device_Type_obj; - -/* 1:1 function mappings for device.h in libparted */ -PyObject *py_ped_disk_probe(PyObject *, PyObject *); -PyObject *py_ped_device_probe_all(PyObject *, PyObject *); -PyObject *py_ped_device_free_all(PyObject *, PyObject *); -PyObject *py_ped_device_get(PyObject *, PyObject *); -PyObject *py_ped_device_get_next(PyObject *, PyObject *); -PyObject *py_ped_device_is_busy(PyObject *, PyObject *); -PyObject *py_ped_device_open(PyObject *, PyObject *); -PyObject *py_ped_device_close(PyObject *, PyObject *); -PyObject *py_ped_device_destroy(PyObject *, PyObject *); -PyObject *py_ped_device_cache_remove(PyObject *, PyObject *); -PyObject *py_ped_device_begin_external_access(PyObject *, PyObject *); -PyObject *py_ped_device_end_external_access(PyObject *, PyObject *); -PyObject *py_ped_device_read(PyObject *, PyObject *); -PyObject *py_ped_device_write(PyObject *, PyObject *); -PyObject *py_ped_device_sync(PyObject *, PyObject *); -PyObject *py_ped_device_sync_fast(PyObject *, PyObject *); -PyObject *py_ped_device_check(PyObject *, PyObject *); -PyObject *py_ped_device_get_constraint(PyObject *, PyObject *); -PyObject *py_ped_device_get_minimal_aligned_constraint(PyObject *, PyObject *); -PyObject *py_ped_device_get_optimal_aligned_constraint(PyObject *, PyObject *); -PyObject *py_ped_device_get_minimum_alignment(PyObject *, PyObject *); -PyObject *py_ped_device_get_optimum_alignment(PyObject *, PyObject *); -PyObject *py_ped_unit_get_size(PyObject *, PyObject *); -PyObject *py_ped_unit_format_custom_byte(PyObject *, PyObject *); -PyObject *py_ped_unit_format_byte(PyObject *, PyObject *); -PyObject *py_ped_unit_format_custom(PyObject *, PyObject *); -PyObject *py_ped_unit_format(PyObject *, PyObject *); -PyObject *py_ped_unit_parse(PyObject *, PyObject *); -PyObject *py_ped_unit_parse_custom(PyObject *, PyObject *); - -#endif /* PYDEVICE_H_INCLUDED */ - -/* vim:tw=78:ts=4:et:sw=4 - */ diff --git a/include/pydisk.h b/include/pydisk.h deleted file mode 100644 index 5f69343..0000000 --- a/include/pydisk.h +++ /dev/null @@ -1,161 +0,0 @@ -/* - * pydisk.h - * pyparted type definitions for pydisk.c - * - * Copyright (C) 2007-2013 Red Hat, Inc. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions of - * the GNU General Public License v.2, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY expressed or implied, including the implied warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. Any Red Hat trademarks that are incorporated in the - * source code or documentation are not subject to the GNU General Public - * License and may only be used or replicated with the express permission of - * Red Hat, Inc. - * - * Author(s): David Cantrell - * Chris Lumens - * Alex Skinner - */ - -#ifndef PYDISK_H_INCLUDED -#define PYDISK_H_INCLUDED - -#include - -#include - -/* _ped.Partition type is the Python equivalent of PedPartition - * in libparted */ -typedef struct { - PyObject_HEAD - - /* PedPartition members */ - PyObject *disk; /* _ped.Disk */ - PyObject *geom; /* _ped.Geometry */ - int type; /* PedPartitionType */ - PyObject *fs_type; /* _ped.FileSystemType */ - - /* store the PedPartition from libparted */ - PedPartition *ped_partition; - - int _owned; /* Belongs to a Disk or not */ -} _ped_Partition; - -void _ped_Partition_dealloc(_ped_Partition *); -int _ped_Partition_compare(_ped_Partition *, PyObject *); -PyObject *_ped_Partition_richcompare(_ped_Partition *, PyObject *, int); -PyObject *_ped_Partition_str(_ped_Partition *); -int _ped_Partition_traverse(_ped_Partition *, visitproc, void *); -int _ped_Partition_clear(_ped_Partition *); -int _ped_Partition_init(_ped_Partition *, PyObject *, PyObject *); -PyObject *_ped_Partition_get(_ped_Partition *, void *); -int _ped_Partition_set(_ped_Partition *, PyObject *, void *); - -extern PyTypeObject _ped_Partition_Type_obj; - -/* _ped.Disk type is the Python equivalent of PedDisk in libparted */ -typedef struct { - PyObject_HEAD - - /* PedDisk members */ - PyObject *dev; /* _ped.Device */ - PyObject *type; /* _ped.DiskType */ - - /* store the PedDisk from libparted */ - PedDisk *ped_disk; -} _ped_Disk; - -void _ped_Disk_dealloc(_ped_Disk *); -int _ped_Disk_compare(_ped_Disk *, PyObject *); -PyObject *_ped_Disk_richcompare(_ped_Disk *, PyObject *, int); -PyObject *_ped_Disk_str(_ped_Disk *); -int _ped_Disk_traverse(_ped_Disk *, visitproc, void *); -int _ped_Disk_clear(_ped_Disk *); -int _ped_Disk_init(_ped_Disk *, PyObject *, PyObject *); - -extern PyTypeObject _ped_Disk_Type_obj; - -/* _ped.DiskType type is the Python equivalent of PedDiskType in libparted */ -typedef struct { - PyObject_HEAD - - /* PedDiskType members */ - char *name; - long long features; /* PedDiskTypeFeature */ -} _ped_DiskType; - -void _ped_DiskType_dealloc(_ped_DiskType *); -int _ped_DiskType_compare(_ped_DiskType *, PyObject *); -PyObject *_ped_DiskType_richcompare(_ped_DiskType *, PyObject *, int); -PyObject *_ped_DiskType_str(_ped_DiskType *); -int _ped_DiskType_traverse(_ped_DiskType *, visitproc, void *); -int _ped_DiskType_clear(_ped_DiskType *); -PyObject *_ped_DiskType_get(_ped_DiskType *, void *); - -extern PyTypeObject _ped_DiskType_Type_obj; - -/* 1:1 function mappings for disk.h in libparted */ -PyObject *py_ped_disk_type_get_next(PyObject *, PyObject *); -PyObject *py_ped_disk_type_get(PyObject *, PyObject *); -PyObject *py_ped_disk_type_check_feature(PyObject *, PyObject *); -PyObject *py_ped_disk_clobber(PyObject *, PyObject *); -PyObject *py_ped_disk_duplicate(PyObject *, PyObject *); -PyObject *py_ped_disk_destroy(PyObject *, PyObject *); -PyObject *py_ped_disk_commit(PyObject *, PyObject *); -PyObject *py_ped_disk_commit_to_dev(PyObject *, PyObject *); -PyObject *py_ped_disk_commit_to_os(PyObject *, PyObject *); -PyObject *py_ped_disk_check(PyObject *, PyObject *); -PyObject *py_ped_disk_print(PyObject *, PyObject *); -PyObject *py_ped_disk_get_primary_partition_count(PyObject *, PyObject *); -PyObject *py_ped_disk_get_last_partition_num(PyObject *, PyObject *); -PyObject *py_ped_disk_get_max_primary_partition_count(PyObject *, PyObject *); -PyObject *py_ped_disk_get_max_supported_partition_count(PyObject *, PyObject *); -PyObject *py_ped_disk_get_partition_alignment(PyObject *, PyObject *); -PyObject *py_ped_disk_max_partition_length(PyObject *, PyObject *); -PyObject *py_ped_disk_max_partition_start_sector(PyObject *, PyObject *); -PyObject *py_ped_disk_set_flag(PyObject *, PyObject *); -PyObject *py_ped_disk_get_flag(PyObject *, PyObject *); -PyObject *py_ped_disk_is_flag_available(PyObject *, PyObject *); -PyObject *py_ped_disk_flag_get_name(PyObject *, PyObject *); -PyObject *py_ped_disk_flag_get_by_name(PyObject *, PyObject *); -PyObject *py_ped_disk_flag_next(PyObject *, PyObject *); -PyObject *py_ped_partition_destroy(_ped_Partition *, PyObject *); -PyObject *py_ped_partition_is_active(_ped_Partition *, PyObject *); -PyObject *py_ped_partition_set_flag(_ped_Partition *, PyObject *); -PyObject *py_ped_partition_get_flag(_ped_Partition *, PyObject *); -PyObject *py_ped_partition_is_flag_available(_ped_Partition *, PyObject *); -PyObject *py_ped_partition_set_system(_ped_Partition *, PyObject *); -PyObject *py_ped_partition_set_name(_ped_Partition *, PyObject *); -PyObject *py_ped_partition_get_name(_ped_Partition *, PyObject *); -PyObject *py_ped_partition_is_busy(_ped_Partition *, PyObject *); -PyObject *py_ped_partition_get_path(_ped_Partition *, PyObject *); -PyObject *py_ped_partition_reset_num(_ped_Partition *, PyObject *); -PyObject *py_ped_partition_type_get_name(PyObject *, PyObject *); -PyObject *py_ped_partition_flag_get_name(PyObject *, PyObject *); -PyObject *py_ped_partition_flag_get_by_name(PyObject *, PyObject *); -PyObject *py_ped_partition_flag_next(PyObject *, PyObject *); -PyObject *py_ped_disk_add_partition(PyObject *, PyObject *); -PyObject *py_ped_disk_remove_partition(PyObject *, PyObject *); -PyObject *py_ped_disk_delete_partition(PyObject *, PyObject *); -PyObject *py_ped_disk_delete_all(PyObject *, PyObject *); -PyObject *py_ped_disk_set_partition_geom(PyObject *, PyObject *); -PyObject *py_ped_disk_maximize_partition(PyObject *, PyObject *); -PyObject *py_ped_disk_get_max_partition_geometry(PyObject *, PyObject *); -PyObject *py_ped_disk_minimize_extended_partition(PyObject *, PyObject *); -PyObject *py_ped_disk_next_partition(PyObject *, PyObject *); -PyObject *py_ped_disk_get_partition(PyObject *, PyObject *); -PyObject *py_ped_disk_get_partition_by_sector(PyObject *, PyObject *); -PyObject *py_ped_disk_extended_partition(PyObject *, PyObject *); -PyObject *py_ped_disk_new_fresh(PyObject *, PyObject *); -PyObject *py_ped_disk_new(PyObject *, PyObject *); - -#endif /* PYDISK_H_INCLUDED */ - -/* vim:tw=78:ts=4:et:sw=4 - */ diff --git a/include/pyfilesys.h b/include/pyfilesys.h deleted file mode 100644 index c61f0ac..0000000 --- a/include/pyfilesys.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * pyfilesys.h - * pyparted type definitions for pyfilesys.c - * - * Copyright (C) 2007-2013 Red Hat, Inc. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions of - * the GNU General Public License v.2, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY expressed or implied, including the implied warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. Any Red Hat trademarks that are incorporated in the - * source code or documentation are not subject to the GNU General Public - * License and may only be used or replicated with the express permission of - * Red Hat, Inc. - * - * Author(s): David Cantrell - * Chris Lumens - * Alex Skinner - */ - -#ifndef PYFILESYS_H_INCLUDED -#define PYFILESYS_H_INCLUDED - -#include - -#include - -/* These functions need to be added to libparted. Remove when that's done. */ -#define ped_file_system_destroy(fs) - -/* 1:1 function mappings for filesys.h in libparted */ -PyObject *py_ped_file_system_type_get(PyObject *, PyObject *); -PyObject *py_ped_file_system_type_get_next(PyObject *, PyObject *); -PyObject *py_ped_file_system_probe_specific(PyObject *, PyObject *); -PyObject *py_ped_file_system_probe(PyObject *, PyObject *); - -/* _ped.FileSystemType type is the Python equivalent of PedFileSystemType - * in libparted */ -typedef struct { - PyObject_HEAD - - /* PedFileSystemType members */ - char *name; -} _ped_FileSystemType; - -void _ped_FileSystemType_dealloc(_ped_FileSystemType *); -int _ped_FileSystemType_compare(_ped_FileSystemType *, PyObject *); -PyObject *_ped_FileSystemType_richcompare(_ped_FileSystemType *, PyObject *, - int); -PyObject *_ped_FileSystemType_str(_ped_FileSystemType *); -int _ped_FileSystemType_traverse(_ped_FileSystemType *, visitproc, void *); -int _ped_FileSystemType_clear(_ped_FileSystemType *); -PyObject *_ped_FileSystemType_get(_ped_FileSystemType *, void *); - -extern PyTypeObject _ped_FileSystemType_Type_obj; - -/* _ped.FileSystem type is the Python equiv of PedFileSystem in libparted */ -typedef struct { - PyObject_HEAD - - /* PedFileSystem members */ - PyObject *type; /* _ped.FileSystemType */ - PyObject *geom; /* _ped.Geometry */ - int checked; - - /* store the PedFileSystem from libparted */ - PedFileSystem *ped_filesystem; -} _ped_FileSystem; - -void _ped_FileSystem_dealloc(_ped_FileSystem *); -int _ped_FileSystem_compare(_ped_FileSystem *, PyObject *); -PyObject *_ped_FileSystem_richcompare(_ped_FileSystem *, PyObject *, int); -PyObject *_ped_FileSystem_str(_ped_FileSystem *); -int _ped_FileSystem_traverse(_ped_FileSystem *, visitproc, void *); -int _ped_FileSystem_clear(_ped_FileSystem *); -int _ped_FileSystem_init(_ped_FileSystem *, PyObject *, PyObject *); -PyObject *_ped_FileSystem_get(_ped_FileSystem *, void *); - -extern PyTypeObject _ped_FileSystem_Type_obj; - -#endif /* PYFILESYS_H_INCLUDED */ - -/* vim:tw=78:ts=4:et:sw=4 - */ diff --git a/include/pygeom.h b/include/pygeom.h deleted file mode 100644 index 7c80476..0000000 --- a/include/pygeom.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * pygeom.h - * pyparted type definitions for pygeom.c - * - * Copyright (C) 2007-2013 Red Hat, Inc. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions of - * the GNU General Public License v.2, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY expressed or implied, including the implied warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. Any Red Hat trademarks that are incorporated in the - * source code or documentation are not subject to the GNU General Public - * License and may only be used or replicated with the express permission of - * Red Hat, Inc. - * - * Author(s): David Cantrell - * Chris Lumens - * Alex Skinner - */ - -#ifndef PYGEOM_H_INCLUDED -#define PYGEOM_H_INCLUDED - -#include - -#include - -/* 1:1 function mappings for geom.h in libparted */ -PyObject *py_ped_geometry_duplicate(PyObject *, PyObject *); -PyObject *py_ped_geometry_intersect(PyObject *, PyObject *); -PyObject *py_ped_geometry_set(PyObject *, PyObject *); -PyObject *py_ped_geometry_set_start(PyObject *, PyObject *); -PyObject *py_ped_geometry_set_end(PyObject *, PyObject *); -PyObject *py_ped_geometry_test_overlap(PyObject *, PyObject *); -PyObject *py_ped_geometry_test_inside(PyObject *, PyObject *); -PyObject *py_ped_geometry_test_equal(PyObject *, PyObject *); -PyObject *py_ped_geometry_test_sector_inside(PyObject *, PyObject *); -PyObject *py_ped_geometry_read(PyObject *, PyObject *); -PyObject *py_ped_geometry_sync(PyObject *, PyObject *); -PyObject *py_ped_geometry_sync_fast(PyObject *, PyObject *); -PyObject *py_ped_geometry_write(PyObject *, PyObject *); -PyObject *py_ped_geometry_check(PyObject *, PyObject *); -PyObject *py_ped_geometry_map(PyObject *, PyObject *); - -/* _ped.Geometry type is the Python equivalent of PedGeometry in libparted */ -typedef struct { - PyObject_HEAD - - /* PedGeometry members */ - PyObject *dev; /* _ped.Device */ - - /* store the PedGeometry from libparted */ - PedGeometry *ped_geometry; -} _ped_Geometry; - -void _ped_Geometry_dealloc(_ped_Geometry *); -int _ped_Geometry_compare(_ped_Geometry *, PyObject *); -PyObject *_ped_Geometry_richcompare(_ped_Geometry *, PyObject *, int); -PyObject *_ped_Geometry_str(_ped_Geometry *); -int _ped_Geometry_traverse(_ped_Geometry *, visitproc, void *); -int _ped_Geometry_clear(_ped_Geometry *); -int _ped_Geometry_init(_ped_Geometry *, PyObject *, PyObject *); -PyObject *_ped_Geometry_get(_ped_Geometry *, void *); -int _ped_Geometry_set(_ped_Geometry *, PyObject *, void *); - -extern PyTypeObject _ped_Geometry_Type_obj; - -#endif /* PYGEOM_H_INCLUDED */ - -/* vim:tw=78:ts=4:et:sw=4 - */ diff --git a/include/pynatmath.h b/include/pynatmath.h deleted file mode 100644 index efe3a0d..0000000 --- a/include/pynatmath.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * pynatmath.h - * pyparted type definitions for pynatmath.c - * - * Copyright (C) 2007-2013 Red Hat, Inc. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions of - * the GNU General Public License v.2, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY expressed or implied, including the implied warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. Any Red Hat trademarks that are incorporated in the - * source code or documentation are not subject to the GNU General Public - * License and may only be used or replicated with the express permission of - * Red Hat, Inc. - * - * Author(s): David Cantrell - * Chris Lumens - * Alex Skinner - */ - -#ifndef PYNATMATH_H_INCLUDED -#define PYNATMATH_H_INCLUDED - -#include - -#include - -/* 1:1 function mappings for natmath.h in libparted */ -PyObject *py_ped_alignment_duplicate(PyObject *, PyObject *); -PyObject *py_ped_alignment_intersect(PyObject *, PyObject *); -PyObject *py_ped_alignment_align_up(PyObject *, PyObject *); -PyObject *py_ped_alignment_align_down(PyObject *, PyObject *); -PyObject *py_ped_alignment_align_nearest(PyObject *, PyObject *); -PyObject *py_ped_alignment_is_aligned(PyObject *, PyObject *); - -/* _ped.Alignment type is the Python equivalent of PedAlignment in libparted */ -typedef struct { - PyObject_HEAD - - /* PedAlignment members */ - long long offset; /* PedSector */ - long long grain_size; /* PedSector */ -} _ped_Alignment; - -void _ped_Alignment_dealloc(_ped_Alignment *); -int _ped_Alignment_compare(_ped_Alignment *, PyObject *); -PyObject *_ped_Alignment_richcompare(_ped_Alignment *, PyObject *, int); -PyObject *_ped_Alignment_str(_ped_Alignment *); -int _ped_Alignment_traverse(_ped_Alignment *, visitproc, void *); -int _ped_Alignment_clear(_ped_Alignment *); -int _ped_Alignment_init(_ped_Alignment *, PyObject *, PyObject *); -PyObject *_ped_Alignment_get(_ped_Alignment *, void *); -int _ped_Alignment_set(_ped_Alignment *, PyObject *, void *); - -extern PyTypeObject _ped_Alignment_Type_obj; - -#endif /* PYNATMATH_H_INCLUDED */ - -/* vim:tw=78:ts=4:et:sw=4 - */ diff --git a/include/pytimer.h b/include/pytimer.h deleted file mode 100644 index 882ea2c..0000000 --- a/include/pytimer.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * pytimer.h - * pyparted type definitions for pytimer.c - * - * Copyright (C) 2007-2013 Red Hat, Inc. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions of - * the GNU General Public License v.2, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY expressed or implied, including the implied warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. Any Red Hat trademarks that are incorporated in the - * source code or documentation are not subject to the GNU General Public - * License and may only be used or replicated with the express permission of - * Red Hat, Inc. - * - * Author(s): David Cantrell - * Alex Skinner - */ - -#ifndef PYTIMER_H_INCLUDED -#define PYTIMER_H_INCLUDED - -#include - -#include - -/* 1:1 function mappings for timer.h in libparted */ -PyObject *py_ped_timer_destroy(PyObject *, PyObject *); -PyObject *py_ped_timer_new_nested(PyObject *, PyObject *); -PyObject *py_ped_timer_destroy_nested(PyObject *, PyObject *); -PyObject *py_ped_timer_touch(PyObject *, PyObject *); -PyObject *py_ped_timer_reset(PyObject *, PyObject *); -PyObject *py_ped_timer_update(PyObject *, PyObject *); -PyObject *py_ped_timer_set_state_name(PyObject *, PyObject *); - -/* _ped.Timer type is the Python equivalent of PedTimer in libparted */ -typedef struct { - PyObject_HEAD - - /* PedTimer members */ - float frac; - time_t start; - time_t now; - time_t predicted_end; - char *state_name; - PedTimerHandler *handler; - void *context; -} _ped_Timer; - -void _ped_Timer_dealloc(_ped_Timer *); -int _ped_Timer_compare(_ped_Timer *, PyObject *); -PyObject *_ped_Timer_richcompare(_ped_Timer *, PyObject *, int); -PyObject *_ped_Timer_str(_ped_Timer *); -int _ped_Timer_traverse(_ped_Timer *, visitproc, void *); -int _ped_Timer_clear(_ped_Timer *); -int _ped_Timer_init(_ped_Timer *, PyObject *, PyObject *); -PyObject *_ped_Timer_get(_ped_Timer *, void *); -int _ped_Timer_set(_ped_Timer *, PyObject *, void *); - -extern PyTypeObject _ped_Timer_Type_obj; - -#endif /* PYTIMER_H_INCLUDED */ - -/* vim:tw=78:ts=4:et:sw=4 - */ diff --git a/include/pyunit.h b/include/pyunit.h deleted file mode 100644 index 3387e48..0000000 --- a/include/pyunit.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * pyunit.h - * pyparted type definitions for pyunit.c - * - * Copyright (C) 2007-2013 Red Hat, Inc. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions of - * the GNU General Public License v.2, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY expressed or implied, including the implied warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. Any Red Hat trademarks that are incorporated in the - * source code or documentation are not subject to the GNU General Public - * License and may only be used or replicated with the express permission of - * Red Hat, Inc. - * - * Author(s): David Cantrell - * Alex Skinner - */ - -#ifndef PYUNIT_H_INCLUDED -#define PYUNIT_H_INCLUDED - -#include - -#include - -/* a PedUnit is a long int in C, so we store it that way in Python */ - -/* 1:1 function mappings for unit.h in libparted */ -PyObject *py_ped_unit_set_default(PyObject *, PyObject *); -PyObject *py_ped_unit_get_default(PyObject *, PyObject *); -PyObject *py_ped_unit_get_name(PyObject *, PyObject *); -PyObject *py_ped_unit_get_by_name(PyObject *, PyObject *); - -#endif /* PYUNIT_H_INCLUDED */ - -/* vim:tw=78:ts=4:et:sw=4 - */ diff --git a/include/typeobjects/pyconstraint.h b/include/typeobjects/pyconstraint.h deleted file mode 100644 index 01b8082..0000000 --- a/include/typeobjects/pyconstraint.h +++ /dev/null @@ -1,115 +0,0 @@ -/* - * pyconstraint.h - * pyparted type objects for pyconstraint.c - * - * Copyright (C) 2007-2013 Red Hat, Inc. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions of - * the GNU General Public License v.2, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY expressed or implied, including the implied warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. Any Red Hat trademarks that are incorporated in the - * source code or documentation are not subject to the GNU General Public - * License and may only be used or replicated with the express permission of - * Red Hat, Inc. - * - * Author(s): David Cantrell - * Chris Lumens - * Alex Skinner - */ - -#ifndef TYPEOBJECTS_PYCONSTRAINT_H_INCLUDED -#define TYPEOBJECTS_PYCONSTRAINT_H_INCLUDED - -#include -#include - -/* _ped.Constraint type object */ -static PyMemberDef _ped_Constraint_members[] = { - {"start_align", T_OBJECT, offsetof(_ped_Constraint, start_align), 0, - "The _ped.Alignment describing the starting alignment constraints of the partition."}, - {"end_align", T_OBJECT, offsetof(_ped_Constraint, end_align), 0, - "The _ped.Alignment describing the ending alignment constraints of the partition."}, - {"start_range", T_OBJECT, offsetof(_ped_Constraint, start_range), 0, - "The _ped.Geometry describing the minimum size constraints of the partition."}, - {"end_range", T_OBJECT, offsetof(_ped_Constraint, end_range), 0, - "The _ped.Geometry describing the maximum size constraints of the partition."}, - {NULL} -}; - -static PyMethodDef _ped_Constraint_methods[] = { - {"duplicate", (PyCFunction) py_ped_constraint_duplicate, - METH_VARARGS, constraint_duplicate_doc}, - {"intersect", (PyCFunction) py_ped_constraint_intersect, - METH_VARARGS, constraint_intersect_doc}, - {"solve_max", (PyCFunction) py_ped_constraint_solve_max, - METH_VARARGS, constraint_solve_max_doc}, - {"solve_nearest", (PyCFunction) py_ped_constraint_solve_nearest, - METH_VARARGS, constraint_solve_nearest_doc}, - {"is_solution", (PyCFunction) py_ped_constraint_is_solution, - METH_VARARGS, constraint_is_solution_doc}, - {NULL} -}; - -static PyGetSetDef _ped_Constraint_getset[] = { - {"min_size", (getter) _ped_Constraint_get, - (setter) _ped_Constraint_set, - "The mimimum size in _ped.Sectors of the partition.", "min_size"}, - {"max_size", (getter) _ped_Constraint_get, - (setter) _ped_Constraint_set, - "The maximum size in _ped.Sectors of the partition.", "max_size"}, - {NULL} /* Sentinel */ -}; - -PyTypeObject _ped_Constraint_Type_obj = { - PyVarObject_HEAD_INIT(&PyType_Type,0) - .tp_name = "_ped.Constraint", - .tp_basicsize = sizeof(_ped_Constraint), - /* .tp_itemsize = XXX */ - .tp_dealloc = (destructor) _ped_Constraint_dealloc, - /* .tp_getattr = XXX */ - /* .tp_setattr = XXX */ - /* .tp_repr = XXX */ - /* .tp_as_number = XXX */ - /* .tp_as_sequence = XXX */ - /* .tp_as_mapping = XXX */ - .tp_hash = PyObject_HashNotImplemented, - .tp_call = NULL, - .tp_str = (reprfunc) _ped_Constraint_str, - .tp_getattro = PyObject_GenericGetAttr, - .tp_setattro = PyObject_GenericSetAttr, - /* .tp_as_buffer = XXX */ - .tp_flags = TP_FLAGS, - .tp_doc = _ped_Constraint_doc, - .tp_traverse = (traverseproc) _ped_Constraint_traverse, - .tp_clear = (inquiry) _ped_Constraint_clear, - .tp_richcompare = (richcmpfunc) _ped_Constraint_richcompare, - /* .tp_weaklistoffset = XXX */ - /* .tp_iter = XXX */ - /* .tp_iternext = XXX */ - .tp_methods = _ped_Constraint_methods, - .tp_members = _ped_Constraint_members, - .tp_getset = _ped_Constraint_getset, - .tp_base = NULL, - .tp_dict = NULL, - /* .tp_descr_get = XXX */ - /* .tp_descr_set = XXX */ - /* .tp_dictoffset = XXX */ - .tp_init = (initproc) _ped_Constraint_init, - .tp_alloc = PyType_GenericAlloc, - .tp_new = PyType_GenericNew, - /* .tp_free = XXX */ - /* .tp_is_gc = XXX */ - .tp_bases = NULL, - /* .tp_del = XXX */ -}; - -#endif /* TYPEOBJECTS_PYCONSTRAINT_H_INCLUDED */ - -/* vim:tw=78:ts=4:et:sw=4 - */ diff --git a/include/typeobjects/pydevice.h b/include/typeobjects/pydevice.h deleted file mode 100644 index 1b3ec09..0000000 --- a/include/typeobjects/pydevice.h +++ /dev/null @@ -1,261 +0,0 @@ -/* - * pydevice.h - * pyparted type objects for pydevice.c - * - * Copyright (C) 2007-2013 Red Hat, Inc. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions of - * the GNU General Public License v.2, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY expressed or implied, including the implied warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. Any Red Hat trademarks that are incorporated in the - * source code or documentation are not subject to the GNU General Public - * License and may only be used or replicated with the express permission of - * Red Hat, Inc. - * - * Author(s): David Cantrell - * Chris Lumens - * Alex Skinner - */ - -#ifndef TYPEOBJECTS_PYDEVICE_H_INCLUDED -#define TYPEOBJECTS_PYDEVICE_H_INCLUDED -#define PyGC_HEAD_SIZE 0 -#include -#include - -/* _ped.CHSGeometry type object */ -static PyMemberDef _ped_CHSGeometry_members[] = { - {NULL} -}; - -static PyMethodDef _ped_CHSGeometry_methods[] = { - {NULL} -}; - -static PyGetSetDef _ped_CHSGeometry_getset[] = { - {"cylinders", (getter) _ped_CHSGeometry_get, - NULL, - "The number of cylinders.", "cylinders"}, - {"heads", (getter) _ped_CHSGeometry_get, - NULL, - "The number of heads", "heads"}, - {"sectors", (getter) _ped_CHSGeometry_get, - NULL, - "The number of sectors", "sectors"}, - {NULL} /* Sentinel */ -}; - -PyTypeObject _ped_CHSGeometry_Type_obj = { - PyVarObject_HEAD_INIT(&PyType_Type,0) - .tp_name = "_ped.CHSGeometry", - .tp_basicsize = sizeof(_ped_CHSGeometry), - /* .tp_itemsize = XXX */ - .tp_dealloc = (destructor) _ped_CHSGeometry_dealloc, - /* .tp_getattr = XXX */ - /* .tp_setattr = XXX */ - /* .tp_repr = XXX */ - /* .tp_as_number = XXX */ - /* .tp_as_sequence = XXX */ - /* .tp_as_mapping = XXX */ - .tp_hash = PyObject_HashNotImplemented, - .tp_call = NULL, - .tp_str = (reprfunc) _ped_CHSGeometry_str, - .tp_getattro = PyObject_GenericGetAttr, - .tp_setattro = PyObject_GenericSetAttr, - /* .tp_as_buffer = XXX */ - .tp_flags = TP_FLAGS, - .tp_doc = _ped_CHSGeometry_doc, - .tp_traverse = (traverseproc) _ped_CHSGeometry_traverse, - .tp_clear = (inquiry) _ped_CHSGeometry_clear, - .tp_richcompare = (richcmpfunc) _ped_CHSGeometry_richcompare, - /* .tp_weaklistoffset = XXX */ - /* .tp_iter = XXX */ - /* .tp_iternext = XXX */ - .tp_methods = _ped_CHSGeometry_methods, - .tp_members = _ped_CHSGeometry_members, - .tp_getset = _ped_CHSGeometry_getset, - .tp_base = NULL, - .tp_dict = NULL, - /* .tp_descr_get = XXX */ - /* .tp_descr_set = XXX */ - /* .tp_dictoffset = XXX */ - .tp_init = NULL, - .tp_alloc = PyType_GenericAlloc, - .tp_new = NULL, - /* .tp_free = XXX */ - /* .tp_is_gc = XXX */ - .tp_bases = NULL, - /* .tp_del = XXX */ -}; - -/* _ped.Device type object */ -static PyMemberDef _ped_Device_members[] = { - {"hw_geom", T_OBJECT, offsetof(_ped_Device, hw_geom), READONLY, - "The CHSGeometry of the Device as reported by the hardware."}, - {"bios_geom", T_OBJECT, offsetof(_ped_Device, bios_geom), READONLY, - "The CHSGeometry of the Device as reported by the BIOS."}, - {NULL} -}; - -static PyMethodDef _ped_Device_methods[] = { - /* - * This is a unique function as it's in pydisk.c, but is really - * a method on _ped.Device, so it's part of this PyMethod Def - */ - {"disk_probe", (PyCFunction) py_ped_disk_probe, METH_VARARGS, - disk_probe_doc}, - - /* These functions are all in pydevice.c */ - {"is_busy", (PyCFunction) py_ped_device_is_busy, METH_VARARGS, - device_is_busy_doc}, - {"open", (PyCFunction) py_ped_device_open, METH_VARARGS, - device_open_doc}, - {"close", (PyCFunction) py_ped_device_close, METH_VARARGS, - device_close_doc}, - {"destroy", (PyCFunction) py_ped_device_destroy, METH_VARARGS, - device_destroy_doc}, - {"cache_remove", (PyCFunction) py_ped_device_cache_remove, - METH_VARARGS, device_cache_remove_doc}, - {"begin_external_access", (PyCFunction) py_ped_device_begin_external_access, - METH_VARARGS, device_begin_external_access_doc}, - {"end_external_access", (PyCFunction) py_ped_device_end_external_access, - METH_VARARGS, device_end_external_access_doc}, - {"read", (PyCFunction) py_ped_device_read, METH_VARARGS, - device_read_doc}, - {"write", (PyCFunction) py_ped_device_write, METH_VARARGS, - device_write_doc}, - {"sync", (PyCFunction) py_ped_device_sync, METH_VARARGS, - device_sync_doc}, - {"sync_fast", (PyCFunction) py_ped_device_sync_fast, METH_VARARGS, - device_sync_fast_doc}, - {"check", (PyCFunction) py_ped_device_check, METH_VARARGS, - device_check_doc}, - {"get_constraint", (PyCFunction) py_ped_device_get_constraint, - METH_VARARGS, device_get_constraint_doc}, - {"get_minimal_aligned_constraint", - (PyCFunction) py_ped_device_get_minimal_aligned_constraint, - METH_NOARGS, device_get_minimal_aligned_constraint_doc}, - {"get_optimal_aligned_constraint", - (PyCFunction) py_ped_device_get_optimal_aligned_constraint, - METH_NOARGS, device_get_optimal_aligned_constraint_doc}, - {"get_minimum_alignment", - (PyCFunction) py_ped_device_get_minimum_alignment, - METH_NOARGS, device_get_minimum_alignment_doc}, - {"get_optimum_alignment", - (PyCFunction) py_ped_device_get_optimum_alignment, - METH_NOARGS, device_get_optimum_alignment_doc}, - - /* - * These functions are in pydisk.c, but they work best as - * methods on a _ped.Device. - */ - {"clobber", (PyCFunction) py_ped_disk_clobber, METH_VARARGS, - disk_clobber_doc}, - - /* - * These functions are in pyunit.c, but they work best as methods - * on a _ped.Device - */ - {"unit_get_size", (PyCFunction) py_ped_unit_get_size, METH_VARARGS, - unit_get_size_doc}, - {"unit_format_custom_byte", (PyCFunction) py_ped_unit_format_custom_byte, - METH_VARARGS, unit_format_custom_byte_doc}, - {"unit_format_byte", (PyCFunction) py_ped_unit_format_byte, METH_VARARGS, - unit_format_byte_doc}, - {"unit_format_custom", (PyCFunction) py_ped_unit_format_custom, - METH_VARARGS, unit_format_custom_doc}, - {"unit_format", (PyCFunction) py_ped_unit_format, METH_VARARGS, - unit_format_doc}, - {"unit_parse", (PyCFunction) py_ped_unit_parse, METH_VARARGS, - unit_parse_doc}, - {"unit_parse_custom", (PyCFunction) py_ped_unit_parse_custom, - METH_VARARGS, unit_parse_custom_doc}, - - {NULL} -}; - -static PyGetSetDef _ped_Device_getset[] = { - {"model", (getter) _ped_Device_get, NULL, - "A brief description of the hardware, usually mfr and model.", - "model"}, - {"path", (getter) _ped_Device_get, NULL, - "The operating system level path to the device node.", "path"}, - {"type", (getter) _ped_Device_get, NULL, - "The type of device, deprecated in favor of PedDeviceType", "type"}, - {"sector_size", (getter) _ped_Device_get, NULL, - "Logical sector size.", "sector_size"}, - {"phys_sector_size", (getter) _ped_Device_get, NULL, - "Physical sector size.", "phys_sector_size"}, - {"length", (getter) _ped_Device_get, NULL, - "Device length, in sectors (LBA).", "length"}, - {"open_count", (getter) _ped_Device_get, NULL, - "How many times self.open() has been called.", "open_count"}, - {"read_only", (getter) _ped_Device_get, NULL, - "Is the device opened in read-only mode?", "read_only"}, - {"external_mode", (getter) _ped_Device_get, NULL, - "PedDevice external_mode", "external_mode"}, - {"dirty", (getter) _ped_Device_get, NULL, - "Have any unflushed changes been made to self?", "dirty"}, - {"boot_dirty", (getter) _ped_Device_get, NULL, - "Have any unflushed changes been made to the bootloader?", - "boot_dirty"}, - {"host", (getter) _ped_Device_get, NULL, - "Any SCSI host ID associated with self.", "host"}, - {"did", (getter) _ped_Device_get, NULL, - "Any SCSI device ID associated with self.", "did"}, - {NULL} /* Sentinel */ -}; - -PyTypeObject _ped_Device_Type_obj = { - PyVarObject_HEAD_INIT(&PyType_Type,0) - .tp_name = "_ped.Device", - .tp_basicsize = PyGC_HEAD_SIZE + sizeof(_ped_Device), - .tp_itemsize = 0, - .tp_dealloc = (destructor) _ped_Device_dealloc, - /* .tp_getattr = XXX */ - /* .tp_setattr = XXX */ - /* .tp_repr = XXX */ - /* .tp_as_number = XXX */ - /* .tp_as_sequence = XXX */ - /* .tp_as_mapping = XXX */ - .tp_hash = PyObject_HashNotImplemented, - .tp_call = NULL, - .tp_str = (reprfunc) _ped_Device_str, - .tp_getattro = PyObject_GenericGetAttr, - .tp_setattro = PyObject_GenericSetAttr, - /* .tp_as_buffer = XXX */ - .tp_flags = TP_FLAGS, - .tp_doc = _ped_Device_doc, - .tp_traverse = (traverseproc) _ped_Device_traverse, - .tp_clear = (inquiry) _ped_Device_clear, - .tp_richcompare = (richcmpfunc) _ped_Device_richcompare, - /* .tp_weaklistoffset = XXX */ - /* .tp_iter = XXX */ - /* .tp_iternext = XXX */ - .tp_methods = _ped_Device_methods, - .tp_members = _ped_Device_members, - .tp_getset = _ped_Device_getset, - .tp_base = NULL, - .tp_dict = NULL, - /* .tp_descr_get = XXX */ - /* .tp_descr_set = XXX */ - /* .tp_dictoffset = XXX */ - .tp_init = NULL, - .tp_alloc = PyType_GenericAlloc, - .tp_new = NULL, - /* .tp_free = XXX */ - /* .tp_is_gc = XXX */ - .tp_bases = NULL, - /* .tp_del = XXX */ -}; - -#endif /* TYPEOBJECTS_PYDEVICE_H_INCLUDED */ - -/* vim:tw=78:ts=4:et:sw=4 - */ diff --git a/include/typeobjects/pydisk.h b/include/typeobjects/pydisk.h deleted file mode 100644 index 6839b1f..0000000 --- a/include/typeobjects/pydisk.h +++ /dev/null @@ -1,326 +0,0 @@ -/* - * pydisk.h - * pyparted type objects for pydisk.c - * - * Copyright (C) 2007-2013 Red Hat, Inc. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions of - * the GNU General Public License v.2, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY expressed or implied, including the implied warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. Any Red Hat trademarks that are incorporated in the - * source code or documentation are not subject to the GNU General Public - * License and may only be used or replicated with the express permission of - * Red Hat, Inc. - * - * Author(s): David Cantrell - * Chris Lumens - * Alex Skinner - */ - -#ifndef TYPEOBJECTS_PYDISK_H_INCLUDED -#define TYPEOBJECTS_PYDISK_H_INCLUDED - -#include -#include - -/* _ped.Partition type object */ -static PyMemberDef _ped_Partition_members[] = { - {"disk", T_OBJECT, offsetof(_ped_Partition, disk), READONLY, - "The _ped.Disk this Partition exists on."}, - {"geom", T_OBJECT, offsetof(_ped_Partition, geom), READONLY, - "A _ped.Geometry object describing the region this Partition occupies."}, - {"fs_type", T_OBJECT, offsetof(_ped_Partition, fs_type), READONLY, - "A _ped.FileSystemType object describing the filesystem on this Partition."}, - {NULL} -}; - -static PyMethodDef _ped_Partition_methods[] = { - {"destroy", (PyCFunction) py_ped_partition_destroy, METH_VARARGS, - partition_destroy_doc}, - {"is_active", (PyCFunction) py_ped_partition_is_active, METH_VARARGS, - partition_is_active_doc}, - {"set_flag", (PyCFunction) py_ped_partition_set_flag, METH_VARARGS, - partition_set_flag_doc}, - {"get_flag", (PyCFunction) py_ped_partition_get_flag, METH_VARARGS, - partition_get_flag_doc}, - {"is_flag_available", (PyCFunction) py_ped_partition_is_flag_available, - METH_VARARGS, partition_is_flag_available_doc}, - {"set_system", (PyCFunction) py_ped_partition_set_system, - METH_VARARGS, partition_set_system_doc}, - {"set_name", (PyCFunction) py_ped_partition_set_name, METH_VARARGS, - partition_set_name_doc}, - {"get_name", (PyCFunction) py_ped_partition_get_name, METH_VARARGS, - partition_get_name_doc}, - {"is_busy", (PyCFunction) py_ped_partition_is_busy, METH_VARARGS, - partition_is_busy_doc}, - {"get_path", (PyCFunction) py_ped_partition_get_path, METH_VARARGS, - partition_get_path_doc}, - {"reset_num", (PyCFunction) py_ped_partition_reset_num, METH_VARARGS, - partition_reset_num_doc}, - {NULL} -}; - -static PyGetSetDef _ped_Partition_getset[] = { - {"num", (getter) _ped_Partition_get, NULL, - "The number of this Partition on self.disk.", "num"}, - {"type", (getter) _ped_Partition_get, (setter) _ped_Partition_set, - "PedPartition type", "type"}, - {NULL} /* Sentinel */ -}; - -PyTypeObject _ped_Partition_Type_obj = { - PyVarObject_HEAD_INIT(&PyType_Type,0) - .tp_name = "_ped.Partition", - .tp_basicsize = sizeof(_ped_Partition), - /* .tp_itemsize = XXX */ - .tp_dealloc = (destructor) _ped_Partition_dealloc, - /* .tp_getattr = XXX */ - /* .tp_setattr = XXX */ - /* .tp_compare = (cmpfunc) _ped_Partition_compare,*/ - /* .tp_repr = XXX */ - /* .tp_as_number = XXX */ - /* .tp_as_sequence = XXX */ - /* .tp_as_mapping = XXX */ - .tp_hash = PyObject_HashNotImplemented, - .tp_call = NULL, - .tp_str = (reprfunc) _ped_Partition_str, - .tp_getattro = PyObject_GenericGetAttr, - .tp_setattro = PyObject_GenericSetAttr, - /* .tp_as_buffer = XXX */ - .tp_flags = TP_FLAGS, - .tp_doc = _ped_Partition_doc, - .tp_traverse = (traverseproc) _ped_Partition_traverse, - .tp_clear = (inquiry) _ped_Partition_clear, - .tp_richcompare = (richcmpfunc) _ped_Partition_richcompare, - /* .tp_weaklistoffset = XXX */ - /* .tp_iter = XXX */ - /* .tp_iternext = XXX */ - .tp_methods = _ped_Partition_methods, - .tp_members = _ped_Partition_members, - .tp_getset = _ped_Partition_getset, - .tp_base = NULL, - .tp_dict = NULL, - /* .tp_descr_get = XXX */ - /* .tp_descr_set = XXX */ - /* .tp_dictoffset = XXX */ - .tp_init = (initproc) _ped_Partition_init, - .tp_alloc = PyType_GenericAlloc, - .tp_new = PyType_GenericNew, - /* .tp_free = XXX */ - /* .tp_is_gc = XXX */ - .tp_bases = NULL, - /* .tp_del = XXX */ -}; - -/* _ped.Disk type object */ -static PyMemberDef _ped_Disk_members[] = { - {"dev", T_OBJECT, offsetof(_ped_Disk, dev), READONLY, - "A _ped.Device object holding self's partition table."}, - {"type", T_OBJECT, offsetof(_ped_Disk, type), READONLY, - "The type of the disk label as a _ped.DiskType."}, - {NULL} -}; - -static PyMethodDef _ped_Disk_methods[] = { - {"duplicate", (PyCFunction) py_ped_disk_duplicate, METH_VARARGS, - disk_duplicate_doc}, - {"destroy", (PyCFunction) py_ped_disk_destroy, METH_VARARGS, - disk_destroy_doc}, - {"commit", (PyCFunction) py_ped_disk_commit, METH_VARARGS, - disk_commit_doc}, - {"commit_to_dev", (PyCFunction) py_ped_disk_commit_to_dev, - METH_VARARGS, disk_commit_to_dev_doc}, - {"commit_to_os", (PyCFunction) py_ped_disk_commit_to_os, - METH_VARARGS, disk_commit_to_os_doc}, - {"check", (PyCFunction) py_ped_disk_check, METH_VARARGS, - disk_check_doc}, - {"print", (PyCFunction) py_ped_disk_print, METH_VARARGS, - disk_print_doc}, - {"get_primary_partition_count", (PyCFunction) - py_ped_disk_get_primary_partition_count, - METH_VARARGS, - disk_get_primary_partition_count_doc}, - {"get_last_partition_num", (PyCFunction) - py_ped_disk_get_last_partition_num, - METH_VARARGS, - disk_get_last_partition_num_doc}, - {"get_max_primary_partition_count", (PyCFunction) - py_ped_disk_get_max_primary_partition_count, - METH_VARARGS, - disk_get_max_primary_partition_count_doc}, - {"get_max_supported_partition_count", (PyCFunction) - py_ped_disk_get_max_supported_partition_count, - METH_VARARGS, - disk_get_max_supported_partition_count_doc}, - {"get_partition_alignment", (PyCFunction) - py_ped_disk_get_partition_alignment, - METH_NOARGS, - disk_get_partition_alignment_doc}, - {"max_partition_length", (PyCFunction) - py_ped_disk_max_partition_length, - METH_NOARGS, - disk_max_partition_length_doc}, - {"max_partition_start_sector", (PyCFunction) - py_ped_disk_max_partition_start_sector, - METH_NOARGS, - disk_max_partition_start_sector_doc}, - {"set_flag", (PyCFunction) py_ped_disk_set_flag, METH_VARARGS, - disk_set_flag_doc}, - {"get_flag", (PyCFunction) py_ped_disk_get_flag, METH_VARARGS, - disk_get_flag_doc}, - {"is_flag_available", (PyCFunction) py_ped_disk_is_flag_available, - METH_VARARGS, disk_is_flag_available_doc}, - {"add_partition", (PyCFunction) py_ped_disk_add_partition, - METH_VARARGS, disk_add_partition_doc}, - {"remove_partition", (PyCFunction) py_ped_disk_remove_partition, - METH_VARARGS, disk_remove_partition_doc}, - {"delete_partition", (PyCFunction) py_ped_disk_delete_partition, - METH_VARARGS, disk_delete_partition_doc}, - {"delete_all", (PyCFunction) py_ped_disk_delete_all, METH_VARARGS, - disk_delete_all_doc}, - {"set_partition_geom", (PyCFunction) py_ped_disk_set_partition_geom, - METH_VARARGS, disk_set_partition_geom_doc}, - {"maximize_partition", (PyCFunction) py_ped_disk_maximize_partition, - METH_VARARGS, disk_maximize_partition_doc}, - {"get_max_partition_geometry", (PyCFunction) - py_ped_disk_get_max_partition_geometry, - METH_VARARGS, - disk_get_max_partition_geometry_doc}, - {"minimize_extended_partition", (PyCFunction) - py_ped_disk_minimize_extended_partition, - METH_VARARGS, - disk_minimize_extended_partition_doc}, - {"next_partition", (PyCFunction) py_ped_disk_next_partition, - METH_VARARGS, disk_next_partition_doc}, - {"get_partition", (PyCFunction) py_ped_disk_get_partition, - METH_VARARGS, disk_get_partition_doc}, - {"get_partition_by_sector", (PyCFunction) - py_ped_disk_get_partition_by_sector, - METH_VARARGS, disk_get_partition_by_sector_doc}, - {"extended_partition", (PyCFunction) py_ped_disk_extended_partition, - METH_VARARGS, disk_extended_partition_doc}, - {NULL} -}; - -static PyGetSetDef _ped_Disk_getset[] = { - {NULL} /* Sentinel */ -}; - -PyTypeObject _ped_Disk_Type_obj = { - PyVarObject_HEAD_INIT(&PyType_Type,0) - .tp_name = "_ped.Disk", - .tp_basicsize = sizeof(_ped_Disk), - /* .tp_itemsize = XXX */ - .tp_dealloc = (destructor) _ped_Disk_dealloc, - /* .tp_getattr = XXX */ - /* .tp_setattr = XXX */ - /* .tp_compare = (cmpfunc) _ped_Disk_compare,*/ - /* .tp_repr = XXX */ - /* .tp_as_number = XXX */ - /* .tp_as_sequence = XXX */ - /* .tp_as_mapping = XXX */ - .tp_hash = PyObject_HashNotImplemented, - .tp_call = NULL, - .tp_str = (reprfunc) _ped_Disk_str, - .tp_getattro = PyObject_GenericGetAttr, - .tp_setattro = PyObject_GenericSetAttr, - /* .tp_as_buffer = XXX */ - .tp_flags = TP_FLAGS, - .tp_doc = _ped_Disk_doc, - .tp_traverse = (traverseproc) _ped_Disk_traverse, - .tp_clear = (inquiry) _ped_Disk_clear, - .tp_richcompare = (richcmpfunc) _ped_Disk_richcompare, - /* .tp_weaklistoffset = XXX */ - /* .tp_iter = XXX */ - /* .tp_iternext = XXX */ - .tp_methods = _ped_Disk_methods, - .tp_members = _ped_Disk_members, - .tp_getset = _ped_Disk_getset, - .tp_base = NULL, - .tp_dict = NULL, - /* .tp_descr_get = XXX */ - /* .tp_descr_set = XXX */ - /* .tp_dictoffset = XXX */ - .tp_init = (initproc) _ped_Disk_init, - .tp_alloc = PyType_GenericAlloc, - .tp_new = PyType_GenericNew, - /* .tp_free = XXX */ - /* .tp_is_gc = XXX */ - .tp_bases = NULL, - /* .tp_del = XXX */ -}; - -/* _ped.DiskType type object */ -static PyMemberDef _ped_DiskType_members[] = { - {NULL} -}; - -static PyMethodDef _ped_DiskType_methods[] = { - {"check_feature", (PyCFunction) py_ped_disk_type_check_feature, - METH_VARARGS, disk_type_check_feature_doc}, - {NULL} -}; - -static PyGetSetDef _ped_DiskType_getset[] = { - {"name", (getter) _ped_DiskType_get, NULL, - "The name of the partition table type.", "name"}, - {"features", (getter) _ped_DiskType_get, NULL, - "A bitmask of features supported by this DiskType.", - "features"}, - {NULL} /* Sentinel */ -}; - -PyTypeObject _ped_DiskType_Type_obj = { - PyVarObject_HEAD_INIT(&PyType_Type,0) - .tp_name = "_ped.DiskType", - .tp_basicsize = sizeof(_ped_DiskType), - /* .tp_itemsize = XXX */ - .tp_dealloc = (destructor) _ped_DiskType_dealloc, - /* .tp_getattr = XXX */ - /* .tp_setattr = XXX */ - /* .tp_compare = (cmpfunc) _ped_DiskType_compare,*/ - /* .tp_repr = XXX */ - /* .tp_as_number = XXX */ - /* .tp_as_sequence = XXX */ - /* .tp_as_mapping = XXX */ - .tp_hash = PyObject_HashNotImplemented, - .tp_call = NULL, - .tp_str = (reprfunc) _ped_DiskType_str, - .tp_getattro = PyObject_GenericGetAttr, - .tp_setattro = PyObject_GenericSetAttr, - /* .tp_as_buffer = XXX */ - .tp_flags = TP_FLAGS, - .tp_doc = _ped_DiskType_doc, - .tp_traverse = (traverseproc) _ped_DiskType_traverse, - .tp_clear = (inquiry) _ped_DiskType_clear, - .tp_richcompare = (richcmpfunc) _ped_DiskType_richcompare, - /* .tp_weaklistoffset = XXX */ - /* .tp_iter = XXX */ - /* .tp_iternext = XXX */ - .tp_methods = _ped_DiskType_methods, - .tp_members = _ped_DiskType_members, - .tp_getset = _ped_DiskType_getset, - .tp_base = NULL, - .tp_dict = NULL, - /* .tp_descr_get = XXX */ - /* .tp_descr_set = XXX */ - /* .tp_dictoffset = XXX */ - .tp_init = NULL, - .tp_alloc = PyType_GenericAlloc, - .tp_new = NULL, - /* .tp_free = XXX */ - /* .tp_is_gc = XXX */ - .tp_bases = NULL, - /* .tp_del = XXX */ -}; - -#endif /* TYPEOBJECTS_PYDISK_H_INCLUDED */ - -/* vim:tw=78:ts=4:et:sw=4 - */ diff --git a/include/typeobjects/pyfilesys.h b/include/typeobjects/pyfilesys.h deleted file mode 100644 index 2513843..0000000 --- a/include/typeobjects/pyfilesys.h +++ /dev/null @@ -1,145 +0,0 @@ -/* - * pyfilesys.h - * pyparted type objects for pyfilesys.c - * - * Copyright (C) 2007-2013 Red Hat, Inc. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions of - * the GNU General Public License v.2, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY expressed or implied, including the implied warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. Any Red Hat trademarks that are incorporated in the - * source code or documentation are not subject to the GNU General Public - * License and may only be used or replicated with the express permission of - * Red Hat, Inc. - * - * Author(s): David Cantrell - * Chris Lumens - * Alex Skinner - */ - -#ifndef TYPEOBJECTS_PYFILESYS_H_INCLUDED -#define TYPEOBJECTS_PYFILESYS_H_INCLUDED - -#include -#include - -/* _ped.FileSystemType type object */ -static PyMemberDef _ped_FileSystemType_members[] = { - {NULL} -}; - -static PyMethodDef _ped_FileSystemType_methods[] = { - {NULL} -}; - -static PyGetSetDef _ped_FileSystemType_getset[] = { - {"name", (getter) _ped_FileSystemType_get, NULL, - "The name of the FileSystemType.", "name"}, - {NULL} /* Sentinel */ -}; - -PyTypeObject _ped_FileSystemType_Type_obj = { - PyVarObject_HEAD_INIT(&PyType_Type,0) - .tp_name = "_ped.FileSystemType", - .tp_basicsize = sizeof(_ped_FileSystemType), - /* .tp_itemsize = XXX */ - .tp_dealloc = (destructor) _ped_FileSystemType_dealloc, - /* .tp_getattr = XXX */ - /* .tp_setattr = XXX */ - /* .tp_repr = XXX */ - /* .tp_as_number = XXX */ - /* .tp_as_sequence = XXX */ - /* .tp_as_mapping = XXX */ - .tp_hash = PyObject_HashNotImplemented, - .tp_call = NULL, - .tp_str = (reprfunc) _ped_FileSystemType_str, - .tp_getattro = PyObject_GenericGetAttr, - .tp_setattro = PyObject_GenericSetAttr, - /* .tp_as_buffer = XXX */ - .tp_flags = TP_FLAGS, - .tp_doc = _ped_FileSystemType_doc, - .tp_traverse = (traverseproc) _ped_FileSystemType_traverse, - .tp_clear = (inquiry) _ped_FileSystemType_clear, - .tp_richcompare = (richcmpfunc) _ped_FileSystemType_richcompare, - /* .tp_weaklistoffset = XXX */ - /* .tp_iter = XXX */ - /* .tp_iternext = XXX */ - .tp_methods = _ped_FileSystemType_methods, - .tp_members = _ped_FileSystemType_members, - .tp_getset = _ped_FileSystemType_getset, - .tp_base = NULL, - .tp_dict = NULL, - /* .tp_descr_get = XXX */ - /* .tp_descr_set = XXX */ - /* .tp_dictoffset = XXX */ - .tp_init = NULL, - .tp_alloc = PyType_GenericAlloc, - .tp_new = NULL, - /* .tp_free = XXX */ - /* .tp_is_gc = XXX */ - .tp_bases = NULL, - /* .tp_del = XXX */ -}; - -/* _ped.FileSystem type object */ -static PyMemberDef _ped_FileSystem_members[] = { - {"type", T_OBJECT, offsetof(_ped_FileSystem, type), READONLY, - "A _ped.FileSystemType object describing the filesystem on self.geom."}, - {"geom", T_OBJECT, offsetof(_ped_FileSystem, geom), READONLY, - "The on-disk region where this FileSystem object exists."}, - {NULL} -}; - -PyTypeObject _ped_FileSystem_Type_obj = { - PyVarObject_HEAD_INIT(&PyType_Type,0) - .tp_name = "_ped.FileSystem", - .tp_basicsize = sizeof(_ped_FileSystem), - /* .tp_itemsize = XXX */ - .tp_dealloc = (destructor) _ped_FileSystem_dealloc, - /* .tp_getattr = XXX */ - /* .tp_setattr = XXX */ - /* .tp_repr = XXX */ - /* .tp_as_number = XXX */ - /* .tp_as_sequence = XXX */ - /* .tp_as_mapping = XXX */ - .tp_hash = PyObject_HashNotImplemented, - .tp_call = NULL, - .tp_str = (reprfunc) _ped_FileSystem_str, - .tp_getattro = PyObject_GenericGetAttr, - .tp_setattro = PyObject_GenericSetAttr, - /* .tp_as_buffer = XXX */ - .tp_flags = TP_FLAGS, - .tp_doc = _ped_FileSystem_doc, - .tp_traverse = (traverseproc) _ped_FileSystem_traverse, - .tp_clear = (inquiry) _ped_FileSystem_clear, - .tp_richcompare = (richcmpfunc) _ped_FileSystem_richcompare, - /* .tp_weaklistoffset = XXX */ - /* .tp_iter = XXX */ - /* .tp_iternext = XXX */ - /* .tp_methods = XXX */ - .tp_members = _ped_FileSystem_members, - /* .tp_getset = XXX */ - .tp_base = NULL, - .tp_dict = NULL, - /* .tp_descr_get = XXX */ - /* .tp_descr_set = XXX */ - /* .tp_dictoffset = XXX */ - .tp_init = (initproc) _ped_FileSystem_init, - .tp_alloc = PyType_GenericAlloc, - .tp_new = PyType_GenericNew, - /* .tp_free = XXX */ - /* .tp_is_gc = XXX */ - .tp_bases = NULL, - /* .tp_del = XXX */ -}; - -#endif /* TYPEOBJECTS_PYFILESYS_H_INCLUDED */ - -/* vim:tw=78:ts=4:et:sw=4 - */ diff --git a/include/typeobjects/pygeom.h b/include/typeobjects/pygeom.h deleted file mode 100644 index 07950de..0000000 --- a/include/typeobjects/pygeom.h +++ /dev/null @@ -1,133 +0,0 @@ -/* - * pygeom.h - * pyparted type objects for pygeom.c - * - * Copyright (C) 2007-2013 Red Hat, Inc. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions of - * the GNU General Public License v.2, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY expressed or implied, including the implied warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. Any Red Hat trademarks that are incorporated in the - * source code or documentation are not subject to the GNU General Public - * License and may only be used or replicated with the express permission of - * Red Hat, Inc. - * - * Author(s): David Cantrell - * Chris Lumens - * Alex Skinner - */ - -#ifndef TYPEOBJECTS_PYGEOM_H_INCLUDED -#define TYPEOBJECTS_PYGEOM_H_INCLUDED - -#include -#include - -/* _ped.Geometry type object */ -static PyMemberDef _ped_Geometry_members[] = { - {"dev", T_OBJECT, offsetof(_ped_Geometry, dev), READONLY, - "The _ped.Device described by this _ped.Geometry object."}, - {NULL} -}; - -static PyMethodDef _ped_Geometry_methods[] = { - {"duplicate", (PyCFunction) py_ped_geometry_duplicate, METH_VARARGS, - geometry_duplicate_doc}, - {"intersect", (PyCFunction) py_ped_geometry_intersect, METH_VARARGS, - geometry_intersect_doc}, - {"set", (PyCFunction) py_ped_geometry_set, METH_VARARGS, - geometry_set_doc}, - {"set_start", (PyCFunction) py_ped_geometry_set_start, METH_VARARGS, - geometry_set_start_doc}, - {"set_end", (PyCFunction) py_ped_geometry_set_end, METH_VARARGS, - geometry_set_end_doc}, - {"test_overlap", (PyCFunction) py_ped_geometry_test_overlap, - METH_VARARGS, geometry_test_overlap_doc}, - {"test_inside", (PyCFunction) py_ped_geometry_test_inside, - METH_VARARGS, geometry_test_inside_doc}, - {"test_equal", (PyCFunction) py_ped_geometry_test_equal, - METH_VARARGS, geometry_test_equal_doc}, - {"test_sector_inside", (PyCFunction) py_ped_geometry_test_sector_inside, - METH_VARARGS, geometry_test_sector_inside_doc}, - {"read", (PyCFunction) py_ped_geometry_read, METH_VARARGS, - geometry_read_doc}, - {"sync", (PyCFunction) py_ped_geometry_sync, METH_VARARGS, - geometry_sync_doc}, - {"sync_fast", (PyCFunction) py_ped_geometry_sync_fast, METH_VARARGS, - geometry_sync_fast_doc}, - {"write", (PyCFunction) py_ped_geometry_write, METH_VARARGS, - geometry_write_doc}, - {"check", (PyCFunction) py_ped_geometry_check, METH_VARARGS, - geometry_check_doc}, - {"map", (PyCFunction) py_ped_geometry_map, METH_VARARGS, - geometry_map_doc}, - {NULL} -}; - -static PyGetSetDef _ped_Geometry_getset[] = { - {"start", (getter) _ped_Geometry_get, - (setter) _ped_Geometry_set, - "The starting Sector of the region.", "start"}, - {"length", (getter) _ped_Geometry_get, - (setter) _ped_Geometry_set, - "The length of the region described by this Geometry object.", - "length"}, - {"end", (getter) _ped_Geometry_get, - (setter) _ped_Geometry_set, - "The ending Sector of the region.", "end"}, - {NULL} /* Sentinel */ -}; - -PyTypeObject _ped_Geometry_Type_obj = { - PyVarObject_HEAD_INIT(&PyType_Type,0) - .tp_name = "_ped.Geometry", - .tp_basicsize = sizeof(_ped_Geometry), - /* .tp_itemsize = XXX */ - .tp_dealloc = (destructor) _ped_Geometry_dealloc, - /* .tp_getattr = XXX */ - /* .tp_setattr = XXX */ - /* .tp_repr = XXX */ - /* .tp_as_number = XXX */ - /* .tp_as_sequence = XXX */ - /* .tp_as_mapping = XXX */ - .tp_hash = PyObject_HashNotImplemented, - .tp_call = NULL, - .tp_str = (reprfunc) _ped_Geometry_str, - .tp_getattro = PyObject_GenericGetAttr, - .tp_setattro = PyObject_GenericSetAttr, - /* .tp_as_buffer = XXX */ - .tp_flags = TP_FLAGS, - .tp_doc = _ped_Geometry_doc, - .tp_traverse = (traverseproc) _ped_Geometry_traverse, - .tp_clear = (inquiry) _ped_Geometry_clear, - .tp_richcompare = (richcmpfunc) _ped_Geometry_richcompare, - /* .tp_weaklistoffset = XXX */ - /* .tp_iter = XXX */ - /* .tp_iternext = XXX */ - .tp_methods = _ped_Geometry_methods, - .tp_members = _ped_Geometry_members, - .tp_getset = _ped_Geometry_getset, - .tp_base = NULL, - .tp_dict = NULL, - /* .tp_descr_get = XXX */ - /* .tp_descr_set = XXX */ - /* .tp_dictoffset = XXX */ - .tp_init = (initproc) _ped_Geometry_init, - .tp_alloc = PyType_GenericAlloc, - .tp_new = PyType_GenericNew, - /* .tp_free = XXX */ - /* .tp_is_gc = XXX */ - .tp_bases = NULL, - /* .tp_del = XXX */ -}; - -#endif /* TYPEOBJECTS_PYGEOM_H_INCLUDED */ - -/* vim:tw=78:ts=4:et:sw=4 - */ diff --git a/include/typeobjects/pynatmath.h b/include/typeobjects/pynatmath.h deleted file mode 100644 index b4ac0cc..0000000 --- a/include/typeobjects/pynatmath.h +++ /dev/null @@ -1,109 +0,0 @@ -/* - * pynatmath.h - * pyparted type objects for pynatmath.c - * - * Copyright (C) 2007-2013 Red Hat, Inc. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions of - * the GNU General Public License v.2, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY expressed or implied, including the implied warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. Any Red Hat trademarks that are incorporated in the - * source code or documentation are not subject to the GNU General Public - * License and may only be used or replicated with the express permission of - * Red Hat, Inc. - * - * Author(s): David Cantrell - * Chris Lumens - * Alex Skinner - */ - -#ifndef TYPEOBJECTS_PYNATMATH_H_INCLUDED -#define TYPEOBJECTS_PYNATMATH_H_INCLUDED - -#include -#include - -/* _ped.Alignment type object */ -static PyMemberDef _ped_Alignment_members[] = { - {NULL} -}; - -static PyMethodDef _ped_Alignment_methods[] = { - {"duplicate", (PyCFunction) py_ped_alignment_duplicate, METH_VARARGS, - alignment_duplicate_doc}, - {"intersect", (PyCFunction) py_ped_alignment_intersect, METH_VARARGS, - alignment_intersect_doc}, - {"align_up", (PyCFunction) py_ped_alignment_align_up, METH_VARARGS, - alignment_align_up_doc}, - {"align_down", (PyCFunction) py_ped_alignment_align_down, - METH_VARARGS, alignment_align_down_doc}, - {"align_nearest", (PyCFunction) py_ped_alignment_align_nearest, - METH_VARARGS, alignment_align_nearest_doc}, - {"is_aligned", (PyCFunction) py_ped_alignment_is_aligned, - METH_VARARGS, alignment_is_aligned_doc}, - {NULL} -}; - -static PyGetSetDef _ped_Alignment_getset[] = { - {"offset", (getter) _ped_Alignment_get, - (setter) _ped_Alignment_set, - "Offset in sectors from the start of a _ped.Geometry.", "offset"}, - {"grain_size", (getter) _ped_Alignment_get, - (setter) _ped_Alignment_set, - "Alignment grain_size", "grain_size"}, - {NULL} /* Sentinel */ -}; - -PyTypeObject _ped_Alignment_Type_obj = { - PyVarObject_HEAD_INIT(&PyType_Type,0) - .tp_name = "_ped.Alignment", - .tp_basicsize = sizeof(_ped_Alignment), - /* .tp_itemsize = XXX */ - .tp_dealloc = (destructor) _ped_Alignment_dealloc, - /* .tp_getattr = XXX */ - /* .tp_setattr = XXX */ - /* .tp_repr = XXX */ - /* .tp_as_number = XXX */ - /* .tp_as_sequence = XXX */ - /* .tp_as_mapping = XXX */ - .tp_hash = PyObject_HashNotImplemented, - .tp_call = NULL, - .tp_str = (reprfunc) _ped_Alignment_str, - .tp_getattro = PyObject_GenericGetAttr, - .tp_setattro = PyObject_GenericSetAttr, - /* .tp_as_buffer = XXX */ - .tp_flags = TP_FLAGS, - .tp_doc = _ped_Alignment_doc, - .tp_traverse = (traverseproc) _ped_Alignment_traverse, - .tp_clear = (inquiry) _ped_Alignment_clear, - .tp_richcompare = (richcmpfunc) _ped_Alignment_richcompare, - /* .tp_weaklistoffset = XXX */ - /* .tp_iter = XXX */ - /* .tp_iternext = XXX */ - .tp_methods = _ped_Alignment_methods, - .tp_members = _ped_Alignment_members, - .tp_getset = _ped_Alignment_getset, - .tp_base = NULL, - .tp_dict = NULL, - /* .tp_descr_get = XXX */ - /* .tp_descr_set = XXX */ - /* .tp_dictoffset = XXX */ - .tp_init = (initproc) _ped_Alignment_init, - .tp_alloc = PyType_GenericAlloc, - .tp_new = PyType_GenericNew, - /* .tp_free = XXX */ - /* .tp_is_gc = XXX */ - .tp_bases = NULL, - /* .tp_del = XXX */ -}; - -#endif /* TYPEOBJECTS_PYNATMATH_H_INCLUDED */ - -/* vim:tw=78:ts=4:et:sw=4 - */ diff --git a/include/typeobjects/pytimer.h b/include/typeobjects/pytimer.h deleted file mode 100644 index c92b525..0000000 --- a/include/typeobjects/pytimer.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - * pytimer.h - * pyparted type objects for pytimer.c - * - * Copyright (C) 2007-2013 Red Hat, Inc. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions of - * the GNU General Public License v.2, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY expressed or implied, including the implied warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. Any Red Hat trademarks that are incorporated in the - * source code or documentation are not subject to the GNU General Public - * License and may only be used or replicated with the express permission of - * Red Hat, Inc. - * - * Author(s): David Cantrell - * Chris Lumens - * Alex Skinner - */ - -#ifndef TYPEOBJECTS_PYTIMER_H_INCLUDED -#define TYPEOBJECTS_PYTIMER_H_INCLUDED - -#include -#include - -/* _ped.Timer type object */ -static PyMemberDef _ped_Timer_members[] = { - {NULL} -}; - -static PyMethodDef _ped_Timer_methods[] = { - {"destroy", (PyCFunction) py_ped_timer_destroy, METH_VARARGS, NULL}, - {"new_nested", (PyCFunction) py_ped_timer_new_nested, METH_VARARGS, NULL}, - {"destroy_nested", (PyCFunction) py_ped_timer_destroy_nested, - METH_VARARGS, NULL}, - {"touch", (PyCFunction) py_ped_timer_touch, METH_VARARGS, NULL}, - {"reset", (PyCFunction) py_ped_timer_reset, METH_VARARGS, NULL}, - {"update", (PyCFunction) py_ped_timer_update, METH_VARARGS, NULL}, - {"set_state_name", (PyCFunction) py_ped_timer_set_state_name, - METH_VARARGS, NULL}, - {NULL} -}; - -static PyGetSetDef _ped_Timer_getset[] = { - {"frac", (getter) _ped_Timer_get, (setter) _ped_Timer_set, - "PedTimer frac", "frac"}, - {"start", (getter) _ped_Timer_get, (setter) _ped_Timer_set, - "PedTimer.start", "start"}, - {"now", (getter) _ped_Timer_get, (setter) _ped_Timer_set, - "PedTimer.now", "now"}, - {"predicted_end", (getter) _ped_Timer_get, (setter) _ped_Timer_set, - "PedTimer.predicted_end", "predicted_end"}, - {"state_name", (getter) _ped_Timer_get, (setter) _ped_Timer_set, - "PedTimer.state_name", "state_name"}, - {NULL} /* Sentinel */ -}; - -PyTypeObject _ped_Timer_Type_obj = { - PyVarObject_HEAD_INIT(&PyType_Type,0) - .tp_name = "_ped.Timer", - .tp_basicsize = sizeof(_ped_Timer), - /* .tp_itemsize = XXX */ - .tp_dealloc = (destructor) _ped_Timer_dealloc, - /* .tp_getattr = XXX */ - /* .tp_setattr = XXX */ - /* .tp_repr = XXX */ - /* .tp_as_number = XXX */ - /* .tp_as_sequence = XXX */ - /* .tp_as_mapping = XXX */ - .tp_hash = PyObject_HashNotImplemented, - .tp_call = NULL, - .tp_str = (reprfunc) _ped_Timer_str, - .tp_getattro = PyObject_GenericGetAttr, - .tp_setattro = PyObject_GenericSetAttr, - /* .tp_as_buffer = XXX */ - .tp_flags = TP_FLAGS, - .tp_doc = "PedTimer objects", - .tp_traverse = (traverseproc) _ped_Timer_traverse, - .tp_clear = (inquiry) _ped_Timer_clear, - .tp_richcompare = (richcmpfunc) _ped_Timer_richcompare, - /* .tp_weaklistoffset = XXX */ - /* .tp_iter = XXX */ - /* .tp_iternext = XXX */ - .tp_methods = _ped_Timer_methods, - .tp_members = _ped_Timer_members, - .tp_getset = _ped_Timer_getset, - .tp_base = NULL, - .tp_dict = NULL, - /* .tp_descr_get = XXX */ - /* .tp_descr_set = XXX */ - /* .tp_dictoffset = XXX */ - .tp_init = (initproc) _ped_Timer_init, - .tp_alloc = PyType_GenericAlloc, - .tp_new = PyType_GenericNew, - /* .tp_free = XXX */ - /* .tp_is_gc = XXX */ - .tp_bases = NULL, - /* .tp_del = XXX */ -}; - -#endif /* TYPEOBJECTS_PYTIMER_H_INCLUDED */ - -/* vim:tw=78:ts=4:et:sw=4 - */ diff --git a/setup.py b/setup.py deleted file mode 100644 index 4a3c391..0000000 --- a/setup.py +++ /dev/null @@ -1,78 +0,0 @@ -# setup.py script for pyparted -# Copyright (C) 2011-2013 Red Hat, Inc. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# -# Author(s): David Cantrell -# Alex Skinner - -import subprocess -import glob -import os -import platform -import sys -from distutils.ccompiler import new_compiler -from distutils.errors import CompileError -from distutils.errors import LinkError -from distutils.core import setup -from distutils.core import Extension - -pyparted_version = '3.10.3' -python_version = sys.version_info - -need_libparted_version = '2.3' -need_python_version = (2, 7) - -if python_version < need_python_version: - raise RuntimeError("pyparted requires Python version %d.%d or higher" - % need_python_version) -# Recipe from: -# http://code.activestate.com/recipes/502261-python-distutils-pkg-config/ -def pkgconfig(*packages, **kwargs): - flag_map = {'-I': 'include_dirs', '-L': 'library_dirs', '-l': 'libraries'} - for token in subprocess.check_output(["pkg-config", "--libs", "--cflags"] + list(packages)).decode('utf-8').split(): - - kwargs.setdefault(flag_map.get(token[:2]), []).append(token[2:]) - return kwargs - -def check_mod_version(module, version): - modversion = subprocess.check_output(["pkg-config", "--modversion", module]) - if not float(modversion) >= float(version): - sys.stderr.write("*** Minimum required %s version: %s, found: %s\n" % (module, version, modversion,)) - sys.exit(1) - return - -check_mod_version('libparted', need_libparted_version) - -# This list is in the format necessary for the define_macros parameter -# for an Extension() module definition. See: -# http://docs.python.org/distutils/setupscript.html#preprocessor-options -features = [('PYPARTED_VERSION', "\"%s\"" % pyparted_version)] - -setup(name='pyparted', - version=pyparted_version, - author='pyparted Development Team', - author_email='pyparted-devel@redhat.com', - url='https://fedorahosted.org/pyparted/', - description='Python bindings for GNU parted', - license='GPLv2+', - packages=['parted'], - package_dir={'parted': 'src/parted'}, - ext_modules=[Extension('_ped', - glob.glob(os.path.join('src', '*.c')), - define_macros=features, - **pkgconfig('libparted', - include_dirs=['include'])) - ]) diff --git a/src/_pedmodule.c b/src/_pedmodule.c deleted file mode 100644 index 1186d65..0000000 --- a/src/_pedmodule.c +++ /dev/null @@ -1,772 +0,0 @@ -/* - * _pedmodule.c - * libparted Python bindings. This module is low-level in that it directly - * maps to the libparted API. It is intended to be used by a higher level - * Python module that implements the libparted functionality via Python - * classes and other high level language features. - * - * Copyright (C) 2007-2015 Red Hat, Inc. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions of - * the GNU General Public License v.2, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY expressed or implied, including the implied warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. Any Red Hat trademarks that are incorporated in the - * source code or documentation are not subject to the GNU General Public - * License and may only be used or replicated with the express permission of - * Red Hat, Inc. - * - * Author(s): David Cantrell - * Chris Lumens - * Alex Skinner - */ - -#include -#include -#include -#include - -#include "_pedmodule.h" -#include "exceptions.h" -#include "pyconstraint.h" -#include "pydevice.h" -#include "pydisk.h" -#include "pyfilesys.h" -#include "pygeom.h" -#include "pynatmath.h" -#include "pytimer.h" -#include "pyunit.h" - -#if PED_DISK_LAST_FLAG < 2 -#define PED_DISK_GPT_PMBR_BOOT 2 -#endif - -#if PED_PARTITION_LAST_FLAG < 15 -#define PED_PARTITION_LEGACY_BOOT 15 -#endif - -char *partedExnMessage = NULL; -unsigned int partedExnRaised = 0; - -PyObject *exn_handler = NULL; - -/* Docs strings are broken out of the module structure here to be at least a - * little bit readable. - */ -PyDoc_STRVAR(libparted_version_doc, -"libparted_version() -> string\n\n" -"Return the version of libparted that pyparted was built against."); - -PyDoc_STRVAR(pyparted_version_doc, -"pyparted_version() -> (major, minor, update)\n\n" -"Return the version of the pyparted module."); - -PyDoc_STRVAR(constraint_new_from_min_max_doc, -"constraint_new_from_min_max(min, max) -> Constraint\n\n" -"min and max are Geometry objects. Return a Constraint that requires the region\n" -"to be entirely contained inside max and to entirely contain min."); - -PyDoc_STRVAR(constraint_new_from_min_doc, -"constraint_new_from_min(Geometry) -> Constraint\n\n" -"Return a Constraint that requires a region to entirely contain Geometry."); - -PyDoc_STRVAR(constraint_new_from_max, -"constraint_new_from_max(Geometry) -> Constraint\n\n" -"Return a Constraint that requires a region to be entirely contained inside\n" -"Geometry."); - -PyDoc_STRVAR(constraint_any_doc, -"constraint_any(Device) -> Constraint\n\n" -"Return a Constraint that any region on Device will satisfy."); - -PyDoc_STRVAR(constraint_exact_doc, -"constraint_exact(Geometry) -> Constraint\n\n" -"Return a Constraint that only the given Geometry will satisfy."); - -PyDoc_STRVAR(device_get_doc, -"device_get(string) -> Device\n\n" -"Return the Device corresponding to the given path. Typically, path will\n" -"be a device name like /dev/sda."); - -PyDoc_STRVAR(device_get_next_doc, -"device_get_next(Device) -> Device\n\n" -"Return the next Device in the list detected by _ped.device_probe_all()."); - -PyDoc_STRVAR(device_probe_all_doc, -"device_probe_all()\n\n" -"Attempt to detect all devices."); - -PyDoc_STRVAR(device_free_all_doc, -"device_free_all()\n\n" -"Close and free all devices."); - -PyDoc_STRVAR(file_system_probe_doc, -"file_system_probe(Geometry) -> FileSystem\n\n" -"Attempt to detect a FileSystem in the region described by Geometry.\n" -"This function tries to be clever at dealing with ambiguous\n" -"situations, such as when one file system was not completely erased\n" -"before a new file system was created on top of it."); - -PyDoc_STRVAR(file_system_probe_specific_doc, -"file_system_probe_specific(FileSystemType, Geometry) -> FileSystem\n\n" -"Look at Geometry for FileSystemType, return FileSystem for that type\n" -"if found in the specified region."); - -PyDoc_STRVAR(file_system_type_get_doc, -"file_system_type_get(self, string) -> _ped.FileSystemType\n\n" -"Get a FileSystemType by its name, or raise _ped.UnknownTypeException if no\n" -"type by that name exists."); - -PyDoc_STRVAR(file_system_type_get_next_doc, -"file_system_type_get_next(self) -> _ped.FileSystemType\n\n" -"Get the next FileSystemType in parted's list after self, or raise IndexError\n" -"if there are no more types."); - -PyDoc_STRVAR(disk_type_get_next_doc, -"disk_type_get_next(self) -> DiskType\n\n" -"Return the next DiskType after self. If self is the last DiskType, raise\n" -"IndexError."); - -PyDoc_STRVAR(disk_type_get_doc, -"disk_type_get(string) -> DiskType\n\n" -"Return a DiskType object with the given name. If no DiskType exists with\n" -"that name, raise _ped.UnknownTypeException."); - -PyDoc_STRVAR(partition_type_get_name_doc, -"partition_type_get_name(integer) -> string\n\n" -"Return a name for a partition type constant. This mainly exists just to\n" -"present something in user interfaces. It doesn't really provide the best\n" -"names for partition types."); - -PyDoc_STRVAR(partition_flag_get_name_doc, -"partition_flag_get_name(integer) -> string\n\n" -"Return a name for a partition flag constant. If an invalid flag is provided,\n" -"_ped.PartedExeption will be raised."); - -PyDoc_STRVAR(partition_flag_get_by_name_doc, -"partition_flag_get_by_name(string) -> integer\n\n" -"Return a partition flag given its name, or 0 if no flag matches the name."); - -PyDoc_STRVAR(partition_flag_next_doc, -"partition_flag_next(integer) -> integer\n\n" -"Given a partition flag, return the next flag. If there is no next flag, 0\n" -"is returned."); - -PyDoc_STRVAR(disk_new_fresh_doc, -"disk_new_fresh(Device, DiskType) -> Disk\n\n" -"Given the Device and DiskType, create a new Disk object with using the\n" -"DiskType specified. The new disk label is only in-memory, the caller\n" -"will have to use the commit_to_dev() method to write the new label to\n" -"the disk."); - -PyDoc_STRVAR(disk_new_doc, -"disk_new(Device) -> Disk\n\n" -"Given the Device, create a new Disk object. And probe, read the details of\n" -"the disk."); - -PyDoc_STRVAR(disk_flag_get_name_doc, -"disk_flag_get_name(integer) -> string\n\n" -"Return a name for a disk flag constant. If an invalid flag is provided,\n" -"a ValueError will be raised."); - -PyDoc_STRVAR(disk_flag_get_by_name_doc, -"disk_flag_get_by_name(string) -> integer\n\n" -"Return a disk flag given its name, or 0 if no flag matches the name."); - -PyDoc_STRVAR(disk_flag_next_doc, -"disk_flag_next(integer) -> integer\n\n" -"Given a disk flag, return the next flag. If there is no next flag, 0\n" -"is returned."); - -PyDoc_STRVAR(unit_set_default_doc, -"unit_set_default(Unit)\n\n" -"Sets the default Unit to be used by further unit_* calls. This\n" -"primarily affects the formatting of error messages."); - -PyDoc_STRVAR(unit_get_default_doc, -"unit_get_default() -> Unit\n\n" -"Returns the default Unit."); - -PyDoc_STRVAR(unit_get_name_doc, -"unit_get_name(Unit) -> string\n\n" -"Returns a textual representation of a given Unit."); - -PyDoc_STRVAR(unit_get_by_name_doc, -"unit_get_by_name(string) -> Unit\n\n" -"Returns a Unit given its textual representation. Returns one of the\n" -"UNIT_* constants."); - -PyDoc_STRVAR(register_exn_handler_doc, -"register_exn_handler(function)\n\n" -"When parted raises an exception, the function registered here will be called\n" -"to help determine what action to take. This does not bypass the exception\n" -"handler pyparted uses. Instead, it can be used to pop up a dialog to ask the\n" -"user which course of action to take, or to provide a different default answer,\n" -"or other actions.\n\n" -"The given function must accept as arguments: (1) an integer corresponding to\n" -"one of the EXCEPTION_TYPE_* constants; (2) an integer corresponding to one of the\n" -"EXCEPTION_OPT_* constants; and (3) a string that is the problem encountered by\n" -"parted. This string will already be translated. The given function must return\n" -"one of the EXCEPTION_RESOLVE_* constants instructing parted how to proceed."); - -PyDoc_STRVAR(clear_exn_handler_doc, -"clear_exn_handler()\n\n" -"Clear any previously added exception handling function. This means the\n" -"default behavior for all parted exceptions will be used, so only safe\n" -"answers to any questions parted asks will be automatically provided."); - -PyDoc_STRVAR(_ped_doc, -"This module implements an interface to libparted.\n\n" -"pyparted provides two API layers: a lower level that exposes the complete\n" -"libparted API, and a higher level built on top of that which provides a\n" -"more Python-like view. The _ped module is the base of the lower level\n" -"API. It provides:\n\n" -"\t- Access to all the basic objects and submodules of pyparted\n" -"\t- Basic unit handling and mathematical functions\n" -"\t- A few basic device probing functions\n" -"\t- The DEVICE_*, PARTITION_*, and UNIT_* constants from libparted\n" -"\t- A variety of exceptions for handling error conditions\n\n" -"For complete documentation, refer to the docs strings for each _ped\n" -"method, exception class, and subclass."); - -PyObject *py_ped_register_exn_handler(PyObject *s, PyObject *args) { - PyObject *fn = NULL; - - if (!PyArg_ParseTuple(args, "O", &fn)) { - return NULL; - } - - Py_DECREF(exn_handler); - exn_handler = fn; - - Py_RETURN_TRUE; -} - -PyObject *py_ped_clear_exn_handler(PyObject *s, PyObject *args) { - exn_handler = Py_None; - Py_INCREF(exn_handler); - Py_RETURN_TRUE; -} - -/* all of the methods for the _ped module */ -static struct PyMethodDef PyPedModuleMethods[] = { - {"libparted_version", (PyCFunction) py_libparted_get_version, METH_VARARGS, - libparted_version_doc}, - {"pyparted_version", (PyCFunction) py_pyparted_version, METH_VARARGS, - pyparted_version_doc}, - - {"register_exn_handler", (PyCFunction) py_ped_register_exn_handler, METH_VARARGS, - register_exn_handler_doc}, - {"clear_exn_handler", (PyCFunction) py_ped_clear_exn_handler, METH_VARARGS, - clear_exn_handler_doc}, - - /* pyconstraint.c */ - {"constraint_new_from_min_max", (PyCFunction) py_ped_constraint_new_from_min_max, - METH_VARARGS, constraint_new_from_min_max_doc}, - {"constraint_new_from_min", (PyCFunction) py_ped_constraint_new_from_min, - METH_VARARGS, constraint_new_from_min_doc}, - {"constraint_new_from_max", (PyCFunction) py_ped_constraint_new_from_max, - METH_VARARGS, constraint_new_from_max}, - {"constraint_any", (PyCFunction) py_ped_constraint_any, METH_VARARGS, - constraint_any_doc}, - {"constraint_exact", (PyCFunction) py_ped_constraint_exact, METH_VARARGS, - constraint_exact_doc}, - - /* pydevice.c */ - {"device_get", (PyCFunction) py_ped_device_get, METH_VARARGS, - device_get_doc}, - {"device_get_next", (PyCFunction) py_ped_device_get_next, METH_VARARGS, - device_get_next_doc}, - {"device_probe_all", (PyCFunction) py_ped_device_probe_all, METH_VARARGS, - device_probe_all_doc}, - {"device_free_all", (PyCFunction) py_ped_device_free_all, METH_VARARGS, - device_free_all_doc}, - - /* pydisk.c */ - {"disk_type_get_next", (PyCFunction) py_ped_disk_type_get_next, METH_VARARGS, - disk_type_get_next_doc}, - {"disk_type_get", (PyCFunction) py_ped_disk_type_get, METH_VARARGS, - disk_type_get_doc}, - {"partition_type_get_name", (PyCFunction) py_ped_partition_type_get_name, - METH_VARARGS, partition_type_get_name_doc}, - {"partition_flag_get_name", (PyCFunction) py_ped_partition_flag_get_name, - METH_VARARGS, partition_flag_get_name_doc}, - {"partition_flag_get_by_name", (PyCFunction) py_ped_partition_flag_get_by_name, - METH_VARARGS, partition_flag_get_by_name_doc}, - {"partition_flag_next", (PyCFunction) py_ped_partition_flag_next, - METH_VARARGS, partition_flag_next_doc}, - {"disk_new_fresh", (PyCFunction) py_ped_disk_new_fresh, - METH_VARARGS, disk_new_fresh_doc}, - {"disk_new", (PyCFunction) py_ped_disk_new, - METH_VARARGS, disk_new_doc}, - {"disk_flag_get_name", (PyCFunction) py_ped_disk_flag_get_name, - METH_VARARGS, disk_flag_get_name_doc}, - {"disk_flag_get_by_name", (PyCFunction) py_ped_disk_flag_get_by_name, - METH_VARARGS, disk_flag_get_by_name_doc}, - {"disk_flag_next", (PyCFunction) py_ped_disk_flag_next, - METH_VARARGS, disk_flag_next_doc}, - - /* pyfilesys.c */ - {"file_system_probe", (PyCFunction) py_ped_file_system_probe, METH_VARARGS, - file_system_probe_doc}, - {"file_system_probe_specific", (PyCFunction) py_ped_file_system_probe_specific, - METH_VARARGS, file_system_probe_specific_doc}, - {"file_system_type_get", (PyCFunction) py_ped_file_system_type_get, METH_VARARGS, - file_system_type_get_doc}, - {"file_system_type_get_next", (PyCFunction) py_ped_file_system_type_get_next, - METH_VARARGS, file_system_type_get_next_doc}, - - /* pyunit.c */ - {"unit_set_default", (PyCFunction) py_ped_unit_set_default, METH_VARARGS, - unit_set_default_doc}, - {"unit_get_default", (PyCFunction) py_ped_unit_get_default, METH_VARARGS, - unit_get_default_doc}, - {"unit_get_name", (PyCFunction) py_ped_unit_get_name, METH_VARARGS, - unit_get_name_doc}, - {"unit_get_by_name", (PyCFunction) py_ped_unit_get_by_name, METH_VARARGS, - unit_get_by_name_doc}, - - { NULL, NULL, 0, NULL } -}; - -#if PY_MAJOR_VERSION >= 3 -#define MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void) -#define MOD_ERROR_VAL NULL -#define MOD_SUCCESS_VAL(val) val - -struct PyModuleDef module_def = { - PyModuleDef_HEAD_INIT, - "_ped", - _ped_doc, - -1, - PyPedModuleMethods, - NULL, NULL, NULL, NULL - }; -#else -#define MOD_INIT(name) PyMODINIT_FUNC init##name(void) -#define MOD_ERROR_VAL -#define MOD_SUCCESS_VAL(val) -#endif - -PyObject *py_libparted_get_version(PyObject *s, PyObject *args) { - char *ret = (char *) ped_get_version(); - - if (ret != NULL) - return PyUnicode_FromString(ret); - else - return PyUnicode_FromString(""); -} - -PyObject *py_pyparted_version(PyObject *s, PyObject *args) { - int t = 0; - int major = -1, minor = -1, update = -1; - char suffix[11]; - char *v = PYPARTED_VERSION; - - /* Read pyparted version string. Support the following formats: - * X - * X.Y - * X.Y.Z - * X.Y.Z-string - */ - if (index(v, '-')) { - memset(&suffix, '\0', sizeof(suffix)); - t = sscanf(v, "%d.%d.%d-%10s", &major, &minor, &update, - (char *) &suffix); - } else { - t = sscanf(v, "%d.%d.%d", &major, &minor, &update); - } - - if (t == 0 || t == EOF) { - return NULL; - } - - if (t == 1) { - return Py_BuildValue("(i)", major); - } else if (t == 2) { - if (minor == -1) { - return Py_BuildValue("(is)", major, suffix); - } else { - return Py_BuildValue("(ii)", major, minor); - } - } else if (t == 3) { - if (update == -1) { - return Py_BuildValue("(iis)", major, minor, suffix); - } else { - return Py_BuildValue("(iii)", major, minor, update); - } - } else { - return Py_BuildValue("(iiis)", major, minor, update, suffix); - } -} - -/* This function catches libparted exceptions and converts them into Python - * exceptions that the various methods can catch and do something with. The - * main motivation for this function is that methods in our parted module need - * to be able to raise specific, helpful exceptions instead of something - * generic. - * - * It is also possible for callers to specify a function to help in deciding - * what to do with parted exceptions. See the docs for the - * py_ped_register_exn_handler function. - */ -static PedExceptionOption partedExnHandler(PedException *e) { - switch (e->type) { - /* Raise yes/no exceptions so the caller can deal with them, - * otherwise ignore */ - case PED_EXCEPTION_INFORMATION: - case PED_EXCEPTION_WARNING: - if (e->options == PED_EXCEPTION_YES_NO) { - partedExnRaised = 1; - partedExnMessage = strdup(e->message); - - if (partedExnMessage == NULL) - PyErr_NoMemory(); - else if (exn_handler && PyCallable_Check(exn_handler)) { - PyObject *args, *retval; - - args = PyTuple_New(3); - PyTuple_SetItem(args, 0, PyLong_FromLong(e->type)); - PyTuple_SetItem(args, 1, PyLong_FromLong(e->options)); - PyTuple_SetItem(args, 2, PyUnicode_FromString(e->message)); - - retval = PyObject_CallObject(exn_handler, args); - Py_DECREF(args); - if (retval != NULL && (PyLong_AsLong(retval) == PED_EXCEPTION_UNHANDLED || (PyLong_AsLong(retval) & e->options) > 0)) - return PyLong_AsLong(retval); - else - /* Call failed, use the default value. */ - return PED_EXCEPTION_NO; - } - else { - /* If no exception handling function was registered to - * tell us what to do, return "no" for any yes/no - * questions to prevent any potential disk destruction. - */ - return PED_EXCEPTION_NO; - } - } else { - partedExnRaised = 0; - return PED_EXCEPTION_IGNORE; - } - - /* Set global flags so parted module methods can raise specific - * exceptions with the message. - */ - case PED_EXCEPTION_ERROR: - case PED_EXCEPTION_FATAL: - partedExnRaised = 1; - partedExnMessage = strdup(e->message); - - if (partedExnMessage == NULL) - PyErr_NoMemory(); - else if (exn_handler && PyCallable_Check(exn_handler)) { - PyObject *args, *retval; - - args = PyTuple_New(3); - PyTuple_SetItem(args, 0, PyLong_FromLong(e->type)); - PyTuple_SetItem(args, 1, PyLong_FromLong(e->options)); - PyTuple_SetItem(args, 2, PyUnicode_FromString(e->message)); - - retval = PyObject_CallObject(exn_handler, args); - Py_DECREF(args); - if (retval != NULL && (PyLong_AsLong(retval) == PED_EXCEPTION_UNHANDLED || (PyLong_AsLong(retval) & e->options) > 0)) - return PyLong_AsLong(retval); - else - /* Call failed, use the default value. */ - return PED_EXCEPTION_CANCEL; - } - else { - /* If no exception handling function was registered to tell us - * what to do, return "cancel" for any questions to prevent - * any potential disk destruction. - */ - return PED_EXCEPTION_CANCEL; - } - - /* Raise exceptions for internal parted bugs immediately. */ - case PED_EXCEPTION_BUG: - partedExnRaised = 1; - PyErr_SetString (PartedException, e->message); - return PED_EXCEPTION_CANCEL; - - /* Raise NotImplemented exceptions immediately too. */ - case PED_EXCEPTION_NO_FEATURE: - partedExnRaised = 1; - PyErr_SetString (PyExc_NotImplementedError, e->message); - return PED_EXCEPTION_CANCEL; - } - - return PED_EXCEPTION_IGNORE; -} - -MOD_INIT(_ped) { - PyObject *m = NULL; - - /* init the main Python module and add methods */ -#if PY_MAJOR_VERSION >= 3 - m = PyModule_Create(&module_def); -#else - m = Py_InitModule3("_ped", PyPedModuleMethods, _ped_doc); -#endif - - /* PedUnit possible values */ - PyModule_AddIntConstant(m, "UNIT_SECTOR", PED_UNIT_SECTOR); - PyModule_AddIntConstant(m, "UNIT_BYTE", PED_UNIT_BYTE); - PyModule_AddIntConstant(m, "UNIT_KILOBYTE", PED_UNIT_KILOBYTE); - PyModule_AddIntConstant(m, "UNIT_MEGABYTE", PED_UNIT_MEGABYTE); - PyModule_AddIntConstant(m, "UNIT_GIGABYTE", PED_UNIT_GIGABYTE); - PyModule_AddIntConstant(m, "UNIT_TERABYTE", PED_UNIT_TERABYTE); - PyModule_AddIntConstant(m, "UNIT_COMPACT", PED_UNIT_COMPACT); - PyModule_AddIntConstant(m, "UNIT_CYLINDER", PED_UNIT_CYLINDER); - PyModule_AddIntConstant(m, "UNIT_CHS", PED_UNIT_CHS); - PyModule_AddIntConstant(m, "UNIT_PERCENT", PED_UNIT_PERCENT); - PyModule_AddIntConstant(m, "UNIT_KIBIBYTE", PED_UNIT_KIBIBYTE); - PyModule_AddIntConstant(m, "UNIT_MEBIBYTE", PED_UNIT_MEBIBYTE); - PyModule_AddIntConstant(m, "UNIT_GIBIBYTE", PED_UNIT_GIBIBYTE); - PyModule_AddIntConstant(m, "UNIT_TEBIBYTE", PED_UNIT_TEBIBYTE); - - /* add PedCHSGeometry type as _ped.CHSGeometry */ - if (PyType_Ready(&_ped_CHSGeometry_Type_obj) < 0) - return MOD_ERROR_VAL; - - Py_INCREF(&_ped_CHSGeometry_Type_obj); - PyModule_AddObject(m, "CHSGeometry", - (PyObject *)&_ped_CHSGeometry_Type_obj); - - /* add PedDevice type as _ped.Device */ - if (PyType_Ready(&_ped_Device_Type_obj) < 0) - return MOD_ERROR_VAL; - - Py_INCREF(&_ped_Device_Type_obj); - PyModule_AddObject(m, "Device", (PyObject *)&_ped_Device_Type_obj); - - PyModule_AddIntConstant(m, "DEVICE_UNKNOWN", PED_DEVICE_UNKNOWN); - PyModule_AddIntConstant(m, "DEVICE_SCSI", PED_DEVICE_SCSI); - PyModule_AddIntConstant(m, "DEVICE_IDE", PED_DEVICE_IDE); - PyModule_AddIntConstant(m, "DEVICE_DAC960", PED_DEVICE_DAC960); - PyModule_AddIntConstant(m, "DEVICE_CPQARRAY", PED_DEVICE_CPQARRAY); - PyModule_AddIntConstant(m, "DEVICE_FILE", PED_DEVICE_FILE); - PyModule_AddIntConstant(m, "DEVICE_ATARAID", PED_DEVICE_ATARAID); - PyModule_AddIntConstant(m, "DEVICE_I2O", PED_DEVICE_I2O); - PyModule_AddIntConstant(m, "DEVICE_UBD", PED_DEVICE_UBD); - PyModule_AddIntConstant(m, "DEVICE_DASD", PED_DEVICE_DASD); - PyModule_AddIntConstant(m, "DEVICE_VIODASD", PED_DEVICE_VIODASD); - PyModule_AddIntConstant(m, "DEVICE_SX8", PED_DEVICE_SX8); - PyModule_AddIntConstant(m, "DEVICE_DM", PED_DEVICE_DM); - PyModule_AddIntConstant(m, "DEVICE_XVD", PED_DEVICE_XVD); - PyModule_AddIntConstant(m, "DEVICE_SDMMC", PED_DEVICE_SDMMC); - PyModule_AddIntConstant(m, "DEVICE_VIRTBLK", PED_DEVICE_VIRTBLK); - - /* add PedTimer type as _ped.Timer */ - if (PyType_Ready(&_ped_Timer_Type_obj) < 0) - return MOD_ERROR_VAL; - - Py_INCREF(&_ped_Timer_Type_obj); - PyModule_AddObject(m, "Timer", (PyObject *)&_ped_Timer_Type_obj); - - /* add PedGeometry type as _ped.Geometry */ - if (PyType_Ready(&_ped_Geometry_Type_obj) < 0) - return MOD_ERROR_VAL; - - Py_INCREF(&_ped_Geometry_Type_obj); - PyModule_AddObject(m, "Geometry", (PyObject *)&_ped_Geometry_Type_obj); - - /* add PedAlignment type as _ped.Alignment */ - if (PyType_Ready(&_ped_Alignment_Type_obj) < 0) - return MOD_ERROR_VAL; - - Py_INCREF(&_ped_Alignment_Type_obj); - PyModule_AddObject(m, "Alignment", (PyObject *)&_ped_Alignment_Type_obj); - - /* add PedConstraint type as _ped.Constraint */ - if (PyType_Ready(&_ped_Constraint_Type_obj) < 0) - return MOD_ERROR_VAL; - - Py_INCREF(&_ped_Constraint_Type_obj); - PyModule_AddObject(m, "Constraint", (PyObject *)&_ped_Constraint_Type_obj); - - /* add PedPartition type as _ped.Partition */ - if (PyType_Ready(&_ped_Partition_Type_obj) < 0) - return MOD_ERROR_VAL; - - Py_INCREF(&_ped_Partition_Type_obj); - PyModule_AddObject(m, "Partition", (PyObject *)&_ped_Partition_Type_obj); - - /* add PedDisk as _ped.Disk */ - if (PyType_Ready(&_ped_Disk_Type_obj) < 0) - return MOD_ERROR_VAL; - - Py_INCREF(&_ped_Disk_Type_obj); - PyModule_AddObject(m, "Disk", (PyObject *)&_ped_Disk_Type_obj); - - /* add PedDiskType as _ped.DiskType */ - if (PyType_Ready(&_ped_DiskType_Type_obj) < 0) - return MOD_ERROR_VAL; - - Py_INCREF(&_ped_DiskType_Type_obj); - PyModule_AddObject(m, "DiskType", (PyObject *)&_ped_DiskType_Type_obj); - - /* possible PedDiskTypeFeature values */ - PyModule_AddIntConstant(m, "PARTITION_NORMAL", PED_PARTITION_NORMAL); - PyModule_AddIntConstant(m, "PARTITION_LOGICAL", PED_PARTITION_LOGICAL); - PyModule_AddIntConstant(m, "PARTITION_EXTENDED", PED_PARTITION_EXTENDED); - PyModule_AddIntConstant(m, "PARTITION_FREESPACE", PED_PARTITION_FREESPACE); - PyModule_AddIntConstant(m, "PARTITION_METADATA", PED_PARTITION_METADATA); - PyModule_AddIntConstant(m, "PARTITION_PROTECTED", PED_PARTITION_PROTECTED); - - PyModule_AddIntConstant(m, "PARTITION_BOOT", PED_PARTITION_BOOT); - PyModule_AddIntConstant(m, "PARTITION_ROOT", PED_PARTITION_ROOT); - PyModule_AddIntConstant(m, "PARTITION_SWAP", PED_PARTITION_SWAP); - PyModule_AddIntConstant(m, "PARTITION_HIDDEN", PED_PARTITION_HIDDEN); - PyModule_AddIntConstant(m, "PARTITION_RAID", PED_PARTITION_RAID); - PyModule_AddIntConstant(m, "PARTITION_LVM", PED_PARTITION_LVM); - PyModule_AddIntConstant(m, "PARTITION_LBA", PED_PARTITION_LBA); - PyModule_AddIntConstant(m, "PARTITION_HPSERVICE", PED_PARTITION_HPSERVICE); - PyModule_AddIntConstant(m, "PARTITION_PALO", PED_PARTITION_PALO); - PyModule_AddIntConstant(m, "PARTITION_PREP", PED_PARTITION_PREP); - PyModule_AddIntConstant(m, "PARTITION_MSFT_RESERVED", PED_PARTITION_MSFT_RESERVED); - PyModule_AddIntConstant(m, "PARTITION_APPLE_TV_RECOVERY", PED_PARTITION_APPLE_TV_RECOVERY); - PyModule_AddIntConstant(m, "PARTITION_BIOS_GRUB", PED_PARTITION_BIOS_GRUB); - PyModule_AddIntConstant(m, "PARTITION_DIAG", PED_PARTITION_DIAG); - PyModule_AddIntConstant(m, "PARTITION_LEGACY_BOOT", PED_PARTITION_LEGACY_BOOT); -#ifdef PED_PARTITION_MSFT_DATA - PyModule_AddIntConstant(m, "PARTITION_MSFT_DATA", PED_PARTITION_MSFT_DATA); -#endif -#ifdef PED_PARTITION_IRST - PyModule_AddIntConstant(m, "PARTITION_IRST", PED_PARTITION_IRST); -#endif -#ifdef PED_PARTITION_ESP - PyModule_AddIntConstant(m, "PARTITION_ESP", PED_PARTITION_ESP); -#endif - - PyModule_AddIntConstant(m, "DISK_CYLINDER_ALIGNMENT", PED_DISK_CYLINDER_ALIGNMENT); - PyModule_AddIntConstant(m, "DISK_GPT_PMBR_BOOT", PED_DISK_GPT_PMBR_BOOT); - - PyModule_AddIntConstant(m, "DISK_TYPE_EXTENDED", PED_DISK_TYPE_EXTENDED); - PyModule_AddIntConstant(m, "DISK_TYPE_PARTITION_NAME", PED_DISK_TYPE_PARTITION_NAME); - - /* add PedFileSystemType as _ped.FileSystemType */ - if (PyType_Ready(&_ped_FileSystemType_Type_obj) < 0) - return MOD_ERROR_VAL; - - Py_INCREF(&_ped_FileSystemType_Type_obj); - PyModule_AddObject(m, "FileSystemType", - (PyObject *)&_ped_FileSystemType_Type_obj); - - /* add PedFileSystem as _ped.FileSystem */ - if (PyType_Ready(&_ped_FileSystem_Type_obj) < 0) - return MOD_ERROR_VAL; - - Py_INCREF(&_ped_FileSystem_Type_obj); - PyModule_AddObject(m, "FileSystem", (PyObject *)&_ped_FileSystem_Type_obj); - - /* add our custom exceptions */ - AlignmentException = PyErr_NewException("_ped.AlignmentException", NULL, - NULL); - Py_INCREF(AlignmentException); - PyModule_AddObject(m, "AlignmentException", AlignmentException); - - ConstraintException = PyErr_NewException("_ped.ConstraintException", NULL, - NULL); - Py_INCREF(ConstraintException); - PyModule_AddObject(m, "ConstraintException", ConstraintException); - - CreateException = PyErr_NewException("_ped.CreateException", NULL, NULL); - Py_INCREF(CreateException); - PyModule_AddObject(m, "CreateException", CreateException); - - DeviceException = PyErr_NewException("_ped.DeviceException", NULL, NULL); - Py_INCREF(DeviceException); - PyModule_AddObject(m, "DeviceException", DeviceException); - - DiskException = PyErr_NewException("_ped.DiskException", NULL, NULL); - Py_INCREF(DiskException); - PyModule_AddObject(m, "DiskException", DiskException); - - DiskLabelException = PyErr_NewException("_ped.DiskLabelException", NULL, NULL); - Py_INCREF(DiskLabelException); - PyModule_AddObject(m, "DiskLabelException", DiskLabelException); - - FileSystemException = PyErr_NewException("_ped.FileSystemException", NULL, - NULL); - Py_INCREF(FileSystemException); - PyModule_AddObject(m, "FileSystemException", FileSystemException); - - GeometryException = PyErr_NewException("_ped.GeometryException", NULL, NULL); - Py_INCREF(GeometryException); - PyModule_AddObject(m, "GeometryException", GeometryException); - - IOException = PyErr_NewException("_ped.IOException", NULL, NULL); - Py_INCREF(IOException); - PyModule_AddObject(m, "IOException", IOException); - - NotNeededException = PyErr_NewException("_ped.NotNeededException", - NULL, NULL); - Py_INCREF(NotNeededException); - PyModule_AddObject(m, "NotNeededException", NotNeededException); - - PartedException = PyErr_NewException("_ped.PartedException", NULL, NULL); - Py_INCREF(PartedException); - PyModule_AddObject(m, "PartedException", PartedException); - - PartitionException = PyErr_NewException("_ped.PartitionException", NULL, - NULL); - Py_INCREF(PartitionException); - PyModule_AddObject(m, "PartitionException", PartitionException); - - TimerException = PyErr_NewException("_ped.TimerException", NULL, NULL); - Py_INCREF(TimerException); - PyModule_AddObject(m, "TimerException", TimerException); - - UnknownDeviceException = PyErr_NewException("_ped.UnknownDeviceException", - NULL, NULL); - Py_INCREF(UnknownDeviceException); - PyModule_AddObject(m, "UnknownDeviceException", UnknownDeviceException); - - UnknownTypeException = PyErr_NewException("_ped.UnknownTypeException", NULL, - NULL); - Py_INCREF(UnknownTypeException); - PyModule_AddObject(m, "UnknownTypeException", UnknownTypeException); - - /* Exception type constants. */ - PyModule_AddIntConstant(m, "EXCEPTION_TYPE_INFORMATION", PED_EXCEPTION_INFORMATION); - PyModule_AddIntConstant(m, "EXCEPTION_TYPE_WARNING", PED_EXCEPTION_WARNING); - PyModule_AddIntConstant(m, "EXCEPTION_TYPE_ERROR", PED_EXCEPTION_ERROR); - PyModule_AddIntConstant(m, "EXCEPTION_TYPE_FATAL", PED_EXCEPTION_FATAL); - PyModule_AddIntConstant(m, "EXCEPTION_TYPE_BUG", PED_EXCEPTION_BUG); - PyModule_AddIntConstant(m, "EXCEPTION_TYPE_NO_FEATURE", PED_EXCEPTION_NO_FEATURE); - - /* Exception resolution constants. */ - PyModule_AddIntConstant(m, "EXCEPTION_RESOLVE_UNHANDLED", PED_EXCEPTION_UNHANDLED); - PyModule_AddIntConstant(m, "EXCEPTION_RESOLVE_FIX", PED_EXCEPTION_FIX); - PyModule_AddIntConstant(m, "EXCEPTION_RESOLVE_YES", PED_EXCEPTION_YES); - PyModule_AddIntConstant(m, "EXCEPTION_RESOLVE_NO", PED_EXCEPTION_NO); - PyModule_AddIntConstant(m, "EXCEPTION_RESOLVE_OK", PED_EXCEPTION_OK); - PyModule_AddIntConstant(m, "EXCEPTION_RESOLVE_RETRY", PED_EXCEPTION_RETRY); - PyModule_AddIntConstant(m, "EXCEPTION_RESOLVE_IGNORE", PED_EXCEPTION_IGNORE); - PyModule_AddIntConstant(m, "EXCEPTION_RESOLVE_CANCEL", PED_EXCEPTION_CANCEL); - - /* Exception option constants. */ - PyModule_AddIntConstant(m, "EXCEPTION_OPT_OK_CANCEL", PED_EXCEPTION_OK_CANCEL); - PyModule_AddIntConstant(m, "EXCEPTION_OPT_YES_NO", PED_EXCEPTION_YES_NO); - PyModule_AddIntConstant(m, "EXCEPTION_OPT_YES_NO_CANCEL", PED_EXCEPTION_YES_NO_CANCEL); - PyModule_AddIntConstant(m, "EXCEPTION_OPT_IGNORE_CANCEL", PED_EXCEPTION_IGNORE_CANCEL); - PyModule_AddIntConstant(m, "EXCEPTION_OPT_RETRY_CANCEL", PED_EXCEPTION_RETRY_CANCEL); - PyModule_AddIntConstant(m, "EXCEPTION_OPT_RETRY_IGNORE_CANCEL", PED_EXCEPTION_RETRY_IGNORE_CANCEL); - - exn_handler = Py_None; - Py_INCREF(exn_handler); - - /* Set up our libparted exception handler. */ - ped_exception_set_handler(partedExnHandler); - return MOD_SUCCESS_VAL(m); -} - -/* vim:tw=78:ts=4:et:sw=4 - */ diff --git a/src/convert.c b/src/convert.c deleted file mode 100644 index a555dd4..0000000 --- a/src/convert.c +++ /dev/null @@ -1,687 +0,0 @@ -/* - * convert.c - * Convert _ped Python types to libparted typedefs. Only typedef structs - * need to be converted. When a typedef in libparted is a primitive type, - * we can just use it directly. - * - * Copyright (C) 2007-2013 Red Hat, Inc. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions of - * the GNU General Public License v.2, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY expressed or implied, including the implied warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. Any Red Hat trademarks that are incorporated in the - * source code or documentation are not subject to the GNU General Public - * License and may only be used or replicated with the express permission of - * Red Hat, Inc. - * - * Author(s): David Cantrell - * Chris Lumens - * Alex Skinner - */ - -#include - -#include "convert.h" -#include "exceptions.h" -#include "pyconstraint.h" -#include "pydevice.h" -#include "pygeom.h" -#include "pynatmath.h" -#include "pytimer.h" -#include "pyunit.h" - -/* - * These functions convert between pyparted Python types and libparted types. - * Some are structures, some are simply C primitives. Important notes: - * - * 1) When using a _ped_X2Y() function, you are converting a pyparted Python - * type to a libparted type. If the function returns a pointer, you need - * to free it when you are done using it. - * 2) When using a PedX2_ped_Y() function, you are converting a libparted - * type to a pyparted Python type. You will get a pointer to a PyObject - * back, but don't free this variable. Python will handle clean up of - * these variables through reference counts. - * 3) Some functions return C primitives, so no memory management needs to - * be done. - * - * Error handling notes: - * - * 1) When converting from a PyObject, first check for NULL and raise a - * PyExc_Type error. - * 2) When converting from a Ped*, first check for NULL and raise a - * PyExc_Type error. - * 3) Check the return value of all calls to other convert.c functions and - * return NULL on error, but do not raise an exception. - * 4) Check the return value of PyObject_new, malloc, strdup, and any other - * functions that allocate memory and call PyErr_NoMemory on error. - * 5) When calling a libparted function, check for error conditions and - * raise the appropriate exceptions. Create new exceptions if needed. - * 6) At the end of a conversion function, make sure the return value is - * not NULL. Raise the appropriate exception if it is. - */ - -/* _ped_Alignment -> PedAlignment functions */ -PedAlignment *_ped_Alignment2PedAlignment(PyObject *s) { - PedAlignment *ret = NULL; - _ped_Alignment *alignment = (_ped_Alignment *) s; - - if (alignment == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty _ped.Alignment()"); - return NULL; - } - - ret = ped_alignment_new(alignment->offset, alignment->grain_size); - if (ret == NULL) - return (PedAlignment *) PyErr_NoMemory(); - - return ret; -} - -_ped_Alignment *PedAlignment2_ped_Alignment(PedAlignment *alignment) { - _ped_Alignment *ret = NULL; - PyObject *args = NULL; - - if (alignment == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty PedAlignment()"); - return NULL; - } - - ret = (_ped_Alignment *) _ped_Alignment_Type_obj.tp_new(&_ped_Alignment_Type_obj, NULL, NULL); - if (!ret) - return (_ped_Alignment *) PyErr_NoMemory(); - - args = Py_BuildValue("LL", alignment->offset, alignment->grain_size); - if (args == NULL) { - goto error; - } - - if (_ped_Alignment_Type_obj.tp_init((PyObject *) ret, args, NULL)) { - goto error; - } - - Py_DECREF(args); - - return ret; - -error: - Py_XDECREF(args); - Py_DECREF(ret); - return NULL; -} - -/* _ped_Constraint -> PedConstraint functions */ -PedConstraint *_ped_Constraint2PedConstraint(PyObject *s) { - PedConstraint *ret = NULL; - PedAlignment *start_align = NULL, *end_align = NULL; - PedGeometry *start_range = NULL, *end_range = NULL; - _ped_Constraint *constraint = (_ped_Constraint *) s; - - if (constraint == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty _ped.Constraint()"); - return NULL; - } - - start_align = _ped_Alignment2PedAlignment(constraint->start_align); - if (start_align == NULL) { - return NULL; - } - - end_align = _ped_Alignment2PedAlignment(constraint->end_align); - if (end_align == NULL) { - ped_alignment_destroy(start_align); - return NULL; - } - - start_range = _ped_Geometry2PedGeometry(constraint->start_range); - if (start_range == NULL) { - ped_alignment_destroy(start_align); - ped_alignment_destroy(end_align); - return NULL; - } - - end_range = _ped_Geometry2PedGeometry(constraint->end_range); - if (end_range == NULL) { - ped_alignment_destroy(start_align); - ped_alignment_destroy(end_align); - return NULL; - } - - ret = ped_constraint_new(start_align, end_align, start_range, end_range, - constraint->min_size, constraint->max_size); - if (ret == NULL) { - /* Fall through to clean up memory, but set the error condition now. */ - PyErr_NoMemory(); - } - - ped_alignment_destroy(start_align); - ped_alignment_destroy(end_align); - - return ret; -} - -_ped_Constraint *PedConstraint2_ped_Constraint(PedConstraint *constraint) { - _ped_Constraint *ret = NULL; - _ped_Alignment *start_align = NULL; - _ped_Alignment *end_align = NULL; - _ped_Geometry *start_range = NULL; - _ped_Geometry *end_range = NULL; - PyObject *args = NULL; - - if (constraint == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty PedConstraint()"); - return NULL; - } - - ret = (_ped_Constraint *) _ped_Constraint_Type_obj.tp_new(&_ped_Constraint_Type_obj, NULL, NULL); - if (!ret) - return (_ped_Constraint *) PyErr_NoMemory(); - - if ((start_align = PedAlignment2_ped_Alignment(constraint->start_align)) == NULL) - goto error; - - if ((end_align = PedAlignment2_ped_Alignment(constraint->end_align)) == NULL) - goto error; - - if ((start_range = PedGeometry2_ped_Geometry(constraint->start_range)) == NULL) - goto error; - - if ((end_range = PedGeometry2_ped_Geometry(constraint->end_range)) == NULL) - goto error; - - args = Py_BuildValue("OOOOLL", start_align, end_align, start_range, end_range, constraint->min_size, constraint->max_size); - if (args == NULL) { - goto error; - } - - if (_ped_Constraint_Type_obj.tp_init((PyObject *) ret, args, NULL)) { - goto error; - } - - Py_DECREF(args); - Py_DECREF(start_align); - Py_DECREF(end_align); - Py_DECREF(start_range); - Py_DECREF(end_range); - - return ret; - -error: - Py_XDECREF(args); - Py_XDECREF(start_align); - Py_XDECREF(end_align); - Py_XDECREF(start_range); - Py_XDECREF(end_range); - Py_DECREF(ret); - return NULL; -} - -/* _ped_Device -> PedDevice functions */ -PedDevice *_ped_Device2PedDevice(PyObject *s) { - _ped_Device *dev = (_ped_Device *) s; - PedDevice *ret; - - if (dev == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty _ped.Device()"); - return NULL; - } - - ret = ped_device_get(dev->path); - if (ret == NULL) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(DeviceException, partedExnMessage); - } - else - PyErr_Format(DeviceException, "Could not find device for path %s", dev->path); - } - return ret; -} - -/* PedDevice -> _ped_Device functions */ -_ped_Device *PedDevice2_ped_Device(PedDevice *device) { - _ped_Device *ret = NULL; - - if (device == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty PedDevice"); - return NULL; - } - - ret = (_ped_Device *) _ped_Device_Type_obj.tp_alloc(&_ped_Device_Type_obj, 1); - if (!ret) - return (_ped_Device *) PyErr_NoMemory(); - - ret->model = strdup(device->model); - if (ret->model == NULL) { - PyErr_NoMemory(); - goto error; - } - - ret->path = strdup(device->path); - if (ret->path == NULL) { - PyErr_NoMemory(); - goto error; - } - - ret->type = device->type; - ret->sector_size = device->sector_size; - ret->phys_sector_size = device->phys_sector_size; - ret->open_count = device->open_count; - ret->read_only = device->read_only; - ret->external_mode = device->external_mode; - ret->dirty = device->dirty; - ret->boot_dirty = device->boot_dirty; - ret->host = device->host; - ret->did = device->did; - ret->length = device->length; - - ret->hw_geom = (PyObject *) PedCHSGeometry2_ped_CHSGeometry(&device->hw_geom); - if (ret->hw_geom == NULL) - goto error; - - ret->bios_geom = (PyObject *) PedCHSGeometry2_ped_CHSGeometry(&device->bios_geom); - if (ret->bios_geom == NULL) - goto error; - - return ret; - -error: - Py_DECREF(ret); - return NULL; -} - -PedDisk *_ped_Disk2PedDisk(PyObject *s) { - _ped_Disk *disk = (_ped_Disk *) s; - - if (disk == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty _ped.Disk()"); - return NULL; - } - - return disk->ped_disk; -} - -_ped_Disk *PedDisk2_ped_Disk(PedDisk *disk) { - _ped_Disk *ret = NULL; - - if (disk == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty PedDisk()"); - return NULL; - } - - ret = (_ped_Disk *) _ped_Disk_Type_obj.tp_new(&_ped_Disk_Type_obj, NULL, NULL); - if (!ret) { - ped_disk_destroy(disk); - return (_ped_Disk *) PyErr_NoMemory(); - } - ret->ped_disk = disk; - - ret->dev = (PyObject *) PedDevice2_ped_Device(disk->dev); - if (!ret->dev) - goto error; - - ret->type = (PyObject *) PedDiskType2_ped_DiskType(disk->type); - if (!ret->type) - goto error; - - return ret; - -error: - Py_DECREF(ret); - return NULL; -} - -PedDiskType *_ped_DiskType2PedDiskType(PyObject *s) { - PedDiskType *ret = NULL; - _ped_DiskType *type = (_ped_DiskType *) s; - - if (type == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty _ped.DiskType()"); - return NULL; - } - - ret = ped_disk_type_get(type->name); - if (ret == NULL) { - PyErr_SetString(UnknownTypeException, type->name); - return NULL; - } - - return ret; -} - -_ped_DiskType *PedDiskType2_ped_DiskType(const PedDiskType *type) { - _ped_DiskType *ret = NULL; - - if (type == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty PedDiskType()"); - return NULL; - } - - ret = (_ped_DiskType *) _ped_DiskType_Type_obj.tp_alloc(&_ped_DiskType_Type_obj, 1); - if (!ret) - return (_ped_DiskType *) PyErr_NoMemory(); - - ret->name = strdup(type->name); - if (ret->name == NULL) { - Py_DECREF(ret); - return (_ped_DiskType *) PyErr_NoMemory(); - } - - ret->features = type->features; - - return ret; -} - -/* _ped_FileSystem -> PedFileSystem functions */ -PedFileSystem *_ped_FileSystem2PedFileSystem(PyObject *s) { - _ped_FileSystem *fs = (_ped_FileSystem *) s; - - if (fs == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty _ped.FileSystem"); - return NULL; - } - - if (fs->ped_filesystem == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty _ped.FileSystem.ped_filesystem"); - return NULL; - } else { - return fs->ped_filesystem; - } -} - -_ped_FileSystem *PedFileSystem2_ped_FileSystem(PedFileSystem *fs) { - _ped_FileSystem *ret = NULL; - _ped_FileSystemType *type = NULL; - _ped_Geometry *geom = NULL; - PyObject *args = NULL; - - if (fs == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty PedFileSystem()"); - return NULL; - } - - ret = (_ped_FileSystem *) _ped_FileSystem_Type_obj.tp_new(&_ped_FileSystem_Type_obj, NULL, NULL); - if (!ret) - return (_ped_FileSystem *) PyErr_NoMemory(); - - if ((type = PedFileSystemType2_ped_FileSystemType(fs->type)) == NULL) - goto error; - - if ((geom = PedGeometry2_ped_Geometry(fs->geom)) == NULL) - goto error; - - args = Py_BuildValue("OOi", type, geom, fs->checked); - if (args == NULL) { - goto error; - } - - if (_ped_FileSystem_Type_obj.tp_init((PyObject *) ret, args, NULL)) { - goto error; - } - - Py_DECREF(args); - Py_DECREF(type); - Py_DECREF(geom); - - return ret; - -error: - Py_XDECREF(args); - Py_XDECREF(type); - Py_XDECREF(geom); - Py_DECREF(ret); - return NULL; -} - -/* _ped_FileSystemType -> PedFileSystemType functions */ -PedFileSystemType *_ped_FileSystemType2PedFileSystemType(PyObject *s) { - PedFileSystemType *ret = NULL; - _ped_FileSystemType *type = (_ped_FileSystemType *) s; - - if (type == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty _ped.FileSystemType"); - return NULL; - } - - if ((ret = ped_file_system_type_get(type->name)) == NULL) { - PyErr_SetString(UnknownTypeException, type->name); - return NULL; - } - - return ret; -} - -_ped_FileSystemType *PedFileSystemType2_ped_FileSystemType(const PedFileSystemType *fstype) { - _ped_FileSystemType *ret = NULL; - - if (fstype == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty PedFileSystemType()"); - return NULL; - } - - ret = (_ped_FileSystemType *) _ped_FileSystemType_Type_obj.tp_alloc(&_ped_FileSystemType_Type_obj, 1); - if (!ret) - return (_ped_FileSystemType *) PyErr_NoMemory(); - - ret->name = strdup(fstype->name); - if (ret->name == NULL) { - Py_DECREF(ret); - return (_ped_FileSystemType *) PyErr_NoMemory(); - } - - return ret; -} - -/* _ped_Geometry -> PedGeometry functions */ -PedGeometry *_ped_Geometry2PedGeometry(PyObject *s) { - _ped_Geometry *geometry = (_ped_Geometry *) s; - - if (geometry == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty _ped.Geometry()"); - return NULL; - } - - return geometry->ped_geometry; -} - -_ped_Geometry *PedGeometry2_ped_Geometry(PedGeometry *geometry) { - _ped_Geometry *ret = NULL; - _ped_Device *dev = NULL; - PyObject *args = NULL; - - if (geometry == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty PedGeometry()"); - return NULL; - } - - ret = (_ped_Geometry *) _ped_Geometry_Type_obj.tp_new(&_ped_Geometry_Type_obj, NULL, NULL); - if (!ret) - return (_ped_Geometry *) PyErr_NoMemory(); - - if ((dev = PedDevice2_ped_Device(geometry->dev)) == NULL) - goto error; - - args = Py_BuildValue("OLLL", dev, geometry->start, geometry->length, geometry->end); - if (args == NULL) { - goto error; - } - - if (_ped_Geometry_Type_obj.tp_init((PyObject *) ret, args, NULL)) { - goto error; - } - - Py_DECREF(args); - Py_DECREF(dev); - - return ret; - -error: - Py_XDECREF(args); - Py_XDECREF(dev); - Py_DECREF(ret); - return NULL; -} - -/* _ped_CHSGeometry -> PedCHSGeometry functions */ -PedCHSGeometry *_ped_CHSGeometry2PedCHSGeometry(PyObject *s) { - PedCHSGeometry *ret = NULL; - _ped_CHSGeometry *srcgeom = (_ped_CHSGeometry *) s; - - if (srcgeom == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty _ped.CHSGeometry()"); - return NULL; - } - - if ((ret = malloc(sizeof(PedCHSGeometry))) == NULL) - return (PedCHSGeometry *) PyErr_NoMemory(); - - ret->cylinders = srcgeom->cylinders; - ret->heads = srcgeom->heads; - ret->sectors = srcgeom->sectors; - - return ret; -} - -/* PedCHSGeometry -> _ped_CHSGeometry functions */ -_ped_CHSGeometry *PedCHSGeometry2_ped_CHSGeometry(PedCHSGeometry *geom) { - _ped_CHSGeometry *ret = NULL; - - if (geom == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty PedCHSGeometry()"); - return NULL; - } - - ret = (_ped_CHSGeometry *) _ped_CHSGeometry_Type_obj.tp_alloc(&_ped_CHSGeometry_Type_obj, 1); - if (!ret) - return (_ped_CHSGeometry *) PyErr_NoMemory(); - - ret->cylinders = geom->cylinders; - ret->heads = geom->heads; - ret->sectors = geom->sectors; - - return ret; -} - -PedPartition *_ped_Partition2PedPartition(_ped_Partition *s) { - if (s == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty _ped.Partition()"); - return NULL; - } - - return s->ped_partition; -} - -_ped_Partition *PedPartition2_ped_Partition(PedPartition *part, - _ped_Disk *pydisk) { - _ped_Partition *ret = NULL; - - if (part == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty PedPartition()"); - return NULL; - } - - if (pydisk == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty _ped_Disk()"); - return NULL; - } - - ret = (_ped_Partition *) _ped_Partition_Type_obj.tp_new(&_ped_Partition_Type_obj, NULL, NULL); - if (!ret) - return (_ped_Partition *) PyErr_NoMemory(); - - ret->disk = (PyObject *)pydisk; - Py_INCREF(ret->disk); - - ret->geom = (PyObject *)PedGeometry2_ped_Geometry(&part->geom); - if (!ret->geom) - goto error; - - if (part->fs_type == NULL) { - ret->fs_type = Py_None; - Py_INCREF(ret->fs_type); - } else { - ret->fs_type = (PyObject *)PedFileSystemType2_ped_FileSystemType(part->fs_type); - if (!ret->fs_type) - goto error; - } - - ret->type = part->type; - ret->ped_partition = part; - - return ret; - -error: - Py_DECREF(ret); - return NULL; -} - -/* _ped_Timer -> PedTimer functions */ -PedTimer *_ped_Timer2PedTimer(PyObject *s) { - PedTimer *ret = NULL; - _ped_Timer *timer = (_ped_Timer *) s; - - if (timer == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty _ped.Timer()"); - return NULL; - } - - if ((ret = malloc(sizeof(PedTimer))) == NULL) - return (PedTimer *) PyErr_NoMemory(); - - ret->frac = timer->frac; - ret->start = timer->start; - ret->now = timer->now; - ret->predicted_end = timer->predicted_end; - ret->handler = timer->handler; - ret->context = timer->context; - - ret->state_name = strdup(timer->state_name); - if (ret->state_name == NULL) { - free(ret); - return (PedTimer *) PyErr_NoMemory(); - } - - return ret; -} - -/* PedTimer -> _ped_Timer functions */ -_ped_Timer *PedTimer2_ped_Timer(PedTimer *timer) { - _ped_Timer *ret = NULL; - - if (timer == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty PedTimer()"); - return NULL; - } - - ret = (_ped_Timer *) _ped_Timer_Type_obj.tp_new(&_ped_Timer_Type_obj, NULL, NULL); - if (!ret) - return (_ped_Timer *) PyErr_NoMemory(); - - ret->frac = timer->frac; - ret->start = timer->start; - ret->now = timer->now; - ret->predicted_end = timer->predicted_end; - - ret->state_name = strdup(timer->state_name); - if (ret->state_name == NULL) { - Py_DECREF(ret); - return (_ped_Timer *) PyErr_NoMemory(); - } - - /* XXX: don't know what to do with these */ - ret->handler = timer->handler; - ret->context = timer->context; - - return ret; -} - -/* vim:tw=78:ts=4:et:sw=4 - */ diff --git a/src/fdisk/fdisk.py b/src/fdisk/fdisk.py deleted file mode 100644 index 635a6c8..0000000 --- a/src/fdisk/fdisk.py +++ /dev/null @@ -1,174 +0,0 @@ -# -# fdisk.py -# Partitioning utility with an fdisk-style interface, but written in -# Python and using the pyparted Python module. -# -# Copyright (C) 2009 Red Hat, Inc. -# -# This copyrighted material is made available to anyone wishing to use, -# modify, copy, or redistribute it subject to the terms and conditions of -# the GNU General Public License v.2, or (at your option) any later version. -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY expressed or implied, including the implied warranties of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. You should have received a copy of the -# GNU General Public License along with this program; if not, write to the -# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the -# source code or documentation are not subject to the GNU General Public -# License and may only be used or replicated with the express permission of -# Red Hat, Inc. -# -# Red Hat Author(s): David Cantrell -# - -import getopt -import os -import parted -import sys - -def usage(cmd): - sys.stdout.write("Usage: %s [-b SSZ] [-u] DISK Change partition table\n" % (cmd,)) - sys.stdout.write(" %s [-l] [-b SSZ] [-u] DISK List partition table(s)\n" % (cmd,)) - sys.stdout.write(" %s -s PARTITION Give partition size(s) in blocks\n\n" % (cmd,)) - sys.stdout.write("Here DISK is something like /dev/hdb or /dev/sda\n") - sys.stdout.write("and PARTITION is something like /dev/hda7\n\n") - sys.stdout.write("Options:\n") - sys.stdout.write(" -b=SSZ, --sectorsize=SSZ Sector size (in bytes) to use\n") - sys.stdout.write(" -l, --list List partition table(s)\n") - sys.stdout.write(" -u, --showsectors Give Start and End in sector units\n") - sys.stdout.write(" -s, --showblocks Give Start and End in block units\n") - sys.stdout.write(" -V, --version Show fdisk version\n") - sys.stdout.write(" -?, --help Display fdisk usage screen\n") - -def listPartitionTable(path, sectorsize, showsectors, showblocks): - device = parted.getDevice(path) - (cylinders, heads, sectors) = device.biosGeometry - sizeInBytes = device.length * device.sectorSize - disk = parted.Disk(device) - - partlist = [] - for partition in disk.partitions: - if partition.type == parted.PARTITION_PROTECTED or \ - partition.type == parted.PARTITION_METADATA or \ - partition.type == parted.PARTITION_FREESPACE: - continue - - partlist.append((partition, - partition.path, - partition.getFlag(parted.PARTITION_BOOT), - partition.geometry.start, - partition.geometry.end, - partition.geometry.length, - partition.type, - partition.fileSystem)) - - colLength = 0 - for slice in partlist: - (partition, path, bootable, start, end, length, type, fs) = slice - if len(path) > colLength: - colLength = len(path) - - sys.stdout.write("Disk %s: %%d %%s, %d bytes\n" % (disk.device.path, sizeInBytes)) - sys.stdout.write("%d heads, %d sectors/track, %d cylinders\n" % (heads, sectors, cylinders,)) - sys.stdout.write("Units = FIXME\n") - sys.stdout.write("Disk identifier: FIXME\n\n") - - sys.stdout.write("%-11s %-4s %-11s %-11s %-12s %-4s %s\n" % ("Device", "Boot", "Start", "End", "Blocks", "Id", "System",)) - - for slice in partlist: - (partition, path, bootable, start, end, length, type, fs) = slice - - if bootable: - bootflag = '*' - else: - bootflag = '' - - sys.stdout.write("%-11s %-4s %-11d %-11d %-12d %-4s" % (path, bootflag, start, end, length, type,)) - - if fs is None: - # no filesystem, check flags - if partition.getFlag(parted.PARTITION_SWAP): - sys.stdout.write(" Linux swap\n") - elif partition.getFlag(parted.PARTITION_RAID): - sys.stdout.write(" RAID\n") - elif partition.getFlag(parted.PARTITION_LVM): - sys.stdout.write(" Linux LVM\n") - elif partition.getFlag(parted.PARTITION_HPSERVICE): - sys.stdout.write(" HP Service\n") - elif partition.getFlag(parted.PARTITION_PALO): - sys.stdout.write(" PALO\n") - elif partition.getFlag(parted.PARTITION_PREP): - sys.stdout.write(" PReP\n") - elif partition.getFlag(parted.MSFT_RESERVED): - sys.stdout.write(" MSFT Reserved\n") - else: - sys.stdout.write(" unknown\n") - else: - sys.stdout.write(" %s\n" % (fs.type,)) - -#Disk /dev/sda: 250.0 GB, 250059350016 bytes -#255 heads, 63 sectors/track, 30401 cylinders -#Units = cylinders of 16065 * 512 = 8225280 bytes -#Disk identifier: 0x00000000 -# -# Device Boot Start End Blocks Id System -#/dev/sda1 1 26 204819+ ee GPT -#/dev/sda2 26 4203 33554432 af Unknown -#/dev/sda3 * 4203 4229 204800 83 Linux -#/dev/sda4 4229 30402 210234515+ 8e Linux LVM - - - -def main(argv): - cmd = os.path.basename(sys.argv[0]) - opts, args = [], [] - help, list, showsectors, showblocks = False, False, False, False - sectorsize, cylinders, heads, sectors = None, None, None, None - - if len(sys.argv) == 1: - help = True - - try: - opts, args = getopt.getopt(sys.argv[1:], "lb:C:H:S:usV?", - ["list", "sectorsize=", "cylinders=", - "heads=", "sectors=", "showsectors", - "showblocks", "version", "help"]) - except getopt.GetoptError: - help = True - - for o, a in opts: - if o in ('-l', '--list'): - list = True - elif o in ('-b', '--sectorsize'): - sectorsize = a - elif o in ('-C', '--cylinders'): - cylinders = a - elif o in ('-H', '--heads'): - heads = a - elif o in ('-S', '--sectors'): - sectors = a - elif o in ('-u', '--showsectors'): - showsectors = True - elif o in ('-s', '--showblocks'): - showblocks = True - elif o in ('-V', '--version'): - displayVersion(cmd) - sys.exit(0) - elif o in ('-?', '--help'): - usage(cmd) - sys.exit(0) - else: - sys.stderr.write("Invalid option: %s\n\n" % (o,)) - help = True - - if help: - usage(cmd) - sys.exit(1) - - for arg in args: - if list: - listPartitionTable(arg, sectorsize, showsectors, showblocks) - -if __name__ == "__main__": - main(sys.argv) diff --git a/src/fdisk/localtest b/src/fdisk/localtest deleted file mode 100755 index 54b459a..0000000 --- a/src/fdisk/localtest +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -export PYTHONPATH=$(pwd)/..:$(pwd)/../.libs -python fdisk.py $* diff --git a/src/parted/__init__.py b/src/parted/__init__.py deleted file mode 100644 index 23f4f8f..0000000 --- a/src/parted/__init__.py +++ /dev/null @@ -1,492 +0,0 @@ -# -# __init__.py -# Python bindings for libparted (built on top of the _ped Python module). -# -# Copyright (C) 2007-2015 Red Hat, Inc. -# -# This copyrighted material is made available to anyone wishing to use, -# modify, copy, or redistribute it subject to the terms and conditions of -# the GNU General Public License v.2, or (at your option) any later version. -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY expressed or implied, including the implied warranties of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. You should have received a copy of the -# GNU General Public License along with this program; if not, write to the -# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the -# source code or documentation are not subject to the GNU General Public -# License and may only be used or replicated with the express permission of -# Red Hat, Inc. -# -# Author(s): David Cantrell -# Chris Lumens -# Alex Skinner -# - -from __future__ import division - -import platform -import re -import sys -import warnings -import _ped - -__all__ = ['Alignment', 'Constraint', 'Device', 'Disk', - 'FileSystem', 'Geometry', 'Partition'] - -from _ped import AlignmentException -from _ped import CreateException -from _ped import ConstraintException -from _ped import DeviceException -from _ped import DiskException -from _ped import DiskLabelException -from _ped import FileSystemException -from _ped import GeometryException -from _ped import IOException -from _ped import NotNeededException -from _ped import PartedException -from _ped import PartitionException -from _ped import TimerException -from _ped import UnknownDeviceException -from _ped import UnknownTypeException - -from _ped import register_exn_handler -from _ped import clear_exn_handler - -from parted.alignment import Alignment -from parted.constraint import Constraint -from parted.device import Device -from parted.disk import Disk -from parted.disk import diskType -from parted.disk import diskFlag -from parted.filesystem import FileSystem -from parted.filesystem import fileSystemType -from parted.geometry import Geometry -from parted.partition import Partition -from parted.partition import partitionFlag - -# the enumerated types in _ped need to be available from here too -from _ped import UNIT_SECTOR -from _ped import UNIT_BYTE -from _ped import UNIT_KILOBYTE -from _ped import UNIT_MEGABYTE -from _ped import UNIT_GIGABYTE -from _ped import UNIT_TERABYTE -from _ped import UNIT_COMPACT -from _ped import UNIT_CYLINDER -from _ped import UNIT_CHS -from _ped import UNIT_PERCENT -from _ped import UNIT_KIBIBYTE -from _ped import UNIT_MEBIBYTE -from _ped import UNIT_GIBIBYTE -from _ped import UNIT_TEBIBYTE - -from _ped import DEVICE_UNKNOWN -from _ped import DEVICE_SCSI -from _ped import DEVICE_IDE -from _ped import DEVICE_DAC960 -from _ped import DEVICE_CPQARRAY -from _ped import DEVICE_FILE -from _ped import DEVICE_ATARAID -from _ped import DEVICE_I2O -from _ped import DEVICE_UBD -from _ped import DEVICE_DASD -from _ped import DEVICE_VIODASD -from _ped import DEVICE_SX8 -from _ped import DEVICE_DM -from _ped import DEVICE_XVD -from _ped import DEVICE_SDMMC -from _ped import DEVICE_VIRTBLK - -from _ped import PARTITION_NORMAL -from _ped import PARTITION_LOGICAL -from _ped import PARTITION_EXTENDED -from _ped import PARTITION_FREESPACE -from _ped import PARTITION_METADATA -from _ped import PARTITION_PROTECTED - -from _ped import PARTITION_BOOT -from _ped import PARTITION_ROOT -from _ped import PARTITION_SWAP -from _ped import PARTITION_HIDDEN -from _ped import PARTITION_RAID -from _ped import PARTITION_LVM -from _ped import PARTITION_LBA -from _ped import PARTITION_HPSERVICE -from _ped import PARTITION_PALO -from _ped import PARTITION_PREP -from _ped import PARTITION_MSFT_RESERVED -from _ped import PARTITION_APPLE_TV_RECOVERY -from _ped import PARTITION_BIOS_GRUB -from _ped import PARTITION_DIAG -from _ped import PARTITION_LEGACY_BOOT -if hasattr(_ped, 'PARTITION_MSFT_DATA'): - # pylint: disable=E0611 - from _ped import PARTITION_MSFT_DATA -if hasattr(_ped, 'PARTITION_IRST'): - # pylint: disable=E0611 - from _ped import PARTITION_IRST -if hasattr(_ped, 'PARTITION_ESP'): - # pylint: disable=E0611 - from _ped import PARTITION_ESP - -from _ped import DISK_CYLINDER_ALIGNMENT -from _ped import DISK_GPT_PMBR_BOOT - -from _ped import DISK_TYPE_EXTENDED -from _ped import DISK_TYPE_PARTITION_NAME - -from _ped import EXCEPTION_TYPE_INFORMATION -from _ped import EXCEPTION_TYPE_WARNING -from _ped import EXCEPTION_TYPE_ERROR -from _ped import EXCEPTION_TYPE_FATAL -from _ped import EXCEPTION_TYPE_BUG -from _ped import EXCEPTION_TYPE_NO_FEATURE - -from _ped import EXCEPTION_RESOLVE_UNHANDLED -from _ped import EXCEPTION_RESOLVE_FIX -from _ped import EXCEPTION_RESOLVE_YES -from _ped import EXCEPTION_RESOLVE_NO -from _ped import EXCEPTION_RESOLVE_OK -from _ped import EXCEPTION_RESOLVE_RETRY -from _ped import EXCEPTION_RESOLVE_IGNORE -from _ped import EXCEPTION_RESOLVE_CANCEL - -from _ped import EXCEPTION_OPT_OK_CANCEL -from _ped import EXCEPTION_OPT_YES_NO -from _ped import EXCEPTION_OPT_YES_NO_CANCEL -from _ped import EXCEPTION_OPT_IGNORE_CANCEL -from _ped import EXCEPTION_OPT_RETRY_CANCEL -from _ped import EXCEPTION_OPT_RETRY_IGNORE_CANCEL - -from parted.decorators import localeC - -if sys.version_info >= (3,): - string_types = str -else: - string_types = basestring - -partitionTypesDict = { - 0x00: "Empty", - 0x01: "DOS 12-bit FAT", - 0x02: "XENIX root", - 0x03: "XENIX usr", - 0x04: "DOS 16-bit <32M", - 0x05: "Extended", - 0x06: "DOS 16-bit >=32M", - 0x07: "NTFS/HPFS", - 0x08: "AIX", - 0x09: "AIX bootable", - 0x0a: "OS/2 Boot Manager", - 0x0b: "Win95 FAT32", - 0x0c: "Win95 FAT32", - 0x0e: "Win95 FAT16", - 0x0f: "Win95 Ext'd", - 0x10: "OPUS", - 0x11: "Hidden FAT12", - 0x12: "Compaq Setup", - 0x14: "Hidden FAT16 <32M", - 0x16: "Hidden FAT16", - 0x17: "Hidden HPFS/NTFS", - 0x18: "AST SmartSleep", - 0x1b: "Hidden Win95 FAT32", - 0x1c: "Hidden Win95 FAT32 (LBA)", - 0x1e: "Hidden Win95 FAT16 (LBA)", - 0x24: "NEC_DOS", - 0x39: "Plan 9", - 0x40: "Venix 80286", - 0x41: "PPC_PReP Boot", - 0x42: "SFS", - 0x4d: "QNX4.x", - 0x4e: "QNX4.x 2nd part", - 0x4f: "QNX4.x 2nd part", - 0x51: "Novell?", - 0x52: "Microport", - 0x63: "GNU HURD", - 0x64: "Novell Netware 286", - 0x65: "Novell Netware 386", - 0x75: "PC/IX", - 0x80: "Old MINIX", - 0x81: "Linux/MINIX", - 0x82: "Linux swap", - 0x83: "Linux native", - 0x84: "OS/2 hidden C:", - 0x85: "Linux Extended", - 0x86: "NTFS volume set", - 0x87: "NTFS volume set", - 0x8e: "Linux LVM", - 0x93: "Amoeba", - 0x94: "Amoeba BBT", - 0x9f: "BSD/OS", - 0xa0: "IBM Thinkpad hibernation", - 0xa5: "BSD/386", - 0xa6: "OpenBSD", - 0xb7: "BSDI fs", - 0xb8: "BSDI swap", - 0xbf: "Solaris", - 0xc7: "Syrinx", - 0xdb: "CP/M", - 0xde: "Dell Utility", - 0xe1: "DOS access", - 0xe3: "DOS R/O", - 0xeb: "BEOS", - 0xee: "EFI GPT", - 0xef: "EFI (FAT-12/16/32)", - 0xf2: "DOS secondary", - 0xfd: "Linux RAID", - 0xff: "BBT" -} - -# Exponents for 1024 used when converting sizes to byte-sized -# units for display. The keys are: -# b bytes 1024^0 = 1 -# kb kilobytes 1024^1 = 1024 -# mb megabytes 1024^2 = 1048576 -# gb gigabytes 1024^3 = 1073741824 -# tb terabytes 1024^4 = 1099511627776 -# pb petabytes 1024^5 = 1125899906842624 -# eb exabytes 1024^6 = 1152921504606846976 -# zb zettabytes 1024^7 = 1180591620717411303424 -# yb yottabytes 1024^8 = 1208925819614629174706176 -# The resulting value for 1024 raised to the power is used as -# the divisor for conversion functions. -_exponent = {'b': 0, 'kb': 1, 'mb': 2, 'gb': 3, 'tb': 4, - 'pb': 5, 'eb': 6, 'zb': 7, 'yb': 8} - -# Refercences: -# -# 1. NIST Special Publication 330, 2008 Edition, Barry N. Taylor and Ambler -# Thompson, Editors -# The International System of Units (SI) -# Available from: http://physics.nist.gov/cuu/pdf/sp811.pdf -# -# 2. International standard IEC 60027-2, third edition, -# Letter symbols to be used in electrical technology -- -# Part 2: Telecommunications and electronics. -# -# See the links below for quick online summaries: -# -# SI units: http://physics.nist.gov/cuu/Units/prefixes.html -# IEC units: http://physics.nist.gov/cuu/Units/binary.html -__exponents = { - "B": 1, # byte - "kB": 1000**1, # kilobyte - "MB": 1000**2, # megabyte - "GB": 1000**3, # gigabyte - "TB": 1000**4, # terabyte - "PB": 1000**5, # petabyte - "EB": 1000**6, # exabyte - "ZB": 1000**7, # zettabyte - "YB": 1000**8, # yottabyte - - "KiB": 1024**1, # kibibyte - "MiB": 1024**2, # mebibyte - "GiB": 1024**3, # gibibyte - "TiB": 1024**4, # tebibyte - "PiB": 1024**5, # pebibyte - "EiB": 1024**6, # exbibyte - "ZiB": 1024**7, # zebibyte - "YiB": 1024**8 # yobibyte -} - -def formatBytes(bytes_, unit): - """Convert bytes_ using an SI or IEC prefix. Note that unit is a - case sensitive string that must exactly match one of the IEC or SI - prefixes followed by 'B' (e.g. 'GB').""" - - if unit not in __exponents.keys(): - raise SyntaxError("{:} is not a valid SI or IEC byte unit".format(unit)) - else: - return (bytes_ / __exponents[unit]) - -def sizeToSectors(bytes_, unit, sector_size): - """Convert bytes_ of unit to a number of sectors. Note that unit is a - case sensitive string that must exactly match one of the IEC or SI - prefixes followed by 'B' (e.g. 'GB').""" - - if unit not in __exponents.keys(): - raise SyntaxError("{:} is not a valid SI or IEC byte unit".format(unit)) - else: - return bytes_ * __exponents[unit] // sector_size - -# Valid disk labels per architecture type. The list of label -# names map to keys in the parted.diskType hash table. -archLabels = {'i386': ['msdos', 'gpt'], - 's390': ['dasd', 'msdos'], - 'alpha': ['bsd', 'msdos'], - 'sparc': ['sun'], - 'ia64': ['msdos', 'gpt'], - 'ppc': ['msdos', 'mac', 'amiga', 'gpt'], - 'ppc64': ['msdos', 'mac', 'amiga', 'gpt'], - 'ppc64le': ['msdos', 'gpt'], - 'x86_64': ['msdos', 'gpt'], - 'aarch64': ['msdos', 'gpt'], - 'armv7l': ['msdos', 'gpt']} - -# Adapted from: -# http://stackoverflow.com/questions/922550/how-to-mark-a-global-as-deprecated-in-python -# -# Remember that DeprecationWarnings are ignored by default as they are not really -# useful to users. Developers can turn on DeprecationWarning notices by passing -# the -Wd option to python or by setting PYTHONWARNINGS=d in the environment. -def Deprecated(mod, deprecated=None): - """ Return a wrapped object that warns about deprecated accesses. """ - - if not deprecated: - deprecated = {} - - class Wrapper(object): - warnmsg = "%s is deprecated and will be removed in a future release." - - def __getattr__(self, attr): - if attr in deprecated.keys(): - msg = self.warnmsg + " " + deprecated[attr] - warnings.warn(msg % attr, DeprecationWarning) - - return getattr(mod, attr) - - def __setattr__(self, attr, value): - if attr in deprecated.keys(): - msg = self.warnmsg + " " + deprecated[attr] - warnings.warn(msg % attr, DeprecationWarning) - setattr(mod, attr, value) - - return Wrapper() - -# Valid disk labels and their applicable architectures. The label names map -# to keys in the parted.diskType hash table. -__archLabels = (('amiga', 'ppc(64)?$'), - ('bsd', 'alpha$'), - ('dasd', 's390x?$'), - ('gpt', 'i[3-6]86$|x86_64$|ia64$|ppc(64|64le)?$|aarch64$|armv7l$'), - ('mac', 'ppc(64)?$'), - ('msdos', 'i[3-6]86$|x86_64$|s390x?$|alpha$|ia64$|ppc(64|64le)?$|aarch64$|armv7l$'), - ('sun', 'sparc(64)?$')) - -def getLabels(arch=None): - """Return a set containing the disk labels compatible with the - architecture of the computer calling this function. If an architecture - is passed, return the labels compatible with that architecture.""" - labels = set() - if arch is None: - arch = platform.machine() - - for label, regex in __archLabels: - if re.match(regex, arch): - labels.add(label) - - return labels - -class ReadOnlyProperty(Exception): - """Exception raised when a write operation occurs on a read-only property.""" - - # pylint: disable=W0231 - def __init__(self, prop=''): - self.message = "%s is a read-only property" % (prop,) - -class WriteOnlyProperty(Exception): - """Exception raised when a read operation occurs on a write-only property.""" - - # pylint: disable=W0231 - def __init__(self, prop=''): - self.message = "%s is a write-only property" % (prop,) - -@localeC -def getDevice(path): - """Given the operating system level path to a device node, return - a Device object for that disk. Raises DeviceException if an invalid - path is given.""" - return Device(path=path) - -@localeC -def getAllDevices(): - """Return a list of Device objects for all devices in the system.""" - from _ped import device_probe_all - from _ped import device_get_next - - lst = [] - device = None - - device_probe_all() - - while True: - try: - if not device: - device = device_get_next() - else: - device = device_get_next(device) - - lst.append(Device(PedDevice=device)) - except IndexError: - return lst - -@localeC -def freeAllDevices(): - """Free all Device objects. There is no reason to call this function.""" - from _ped import device_free_all - return device_free_all() - -@localeC -def probeForSpecificFileSystem(fstype, geometry): - """Call the _ped.file_system_probe_specific() function given the - filesystem type and geometry. fstype must be a string - representing a valid _ped.FileSystemType, geometry is a - parted.Geometry.""" - from _ped import file_system_probe_specific - geom = file_system_probe_specific(fileSystemType[fstype], geometry.getPedGeometry()) - return geometry.Geometry(PedGeometry=geom) - -@localeC -def probeFileSystem(geometry): - """Return the name of the filesystem detected on the given - Geometry. Returns None is no filesystem found.""" - from _ped import file_system_probe - fstype = file_system_probe(geometry.getPedGeometry()) - return fstype.name - -@localeC -def freshDisk(device, ty): - """Return a Disk object for this Device and using this DiskType. - The type should be a member of the parted.diskType hash, - either a key or a value. - - The new label is not written to disk until commitToDevice() - is called on the Disk.""" - from _ped import disk_new_fresh, DiskType - - if isinstance(ty, string_types): - ty = diskType[ty] - elif not isinstance(ty, DiskType): - raise TypeError("type must be a key or value in parted.diskType", ty) - - peddisk = disk_new_fresh(device.getPedDevice(), ty) - return Disk(PedDisk=peddisk) - -@localeC -def newDisk(device): - """Return a Disk object for this Device. Read the partition table off - a device (if one is found).""" - from _ped import disk_new - - peddisk = disk_new(device.getPedDevice()) - return Disk(PedDisk=peddisk) - -@localeC -def version(): - """Return a dict containing the pyparted and libparted versions.""" - from _ped import libparted_version - from _ped import pyparted_version - - ver = {} - ver['libparted'] = libparted_version() - ver['pyparted'] = pyparted_version() - return ver - -# Mark deprecated items -_deprecated = {"partitionTypesDict": "DOS disk label types are not provided " - "by libparted, so the codes are not " - "useful.", - "_exponent": "Use __exponents instead.", - "archLabels": "Use getLabels() instead.", - } -sys.modules[__name__] = Deprecated(sys.modules[__name__], _deprecated) diff --git a/src/parted/alignment.py b/src/parted/alignment.py deleted file mode 100644 index ad059dc..0000000 --- a/src/parted/alignment.py +++ /dev/null @@ -1,120 +0,0 @@ -# -# geometry.py -# Python bindings for libparted (built on top of the _ped Python module). -# -# Copyright (C) 2009 Red Hat, Inc. -# -# This copyrighted material is made available to anyone wishing to use, -# modify, copy, or redistribute it subject to the terms and conditions of -# the GNU General Public License v.2, or (at your option) any later version. -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY expressed or implied, including the implied warranties of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. You should have received a copy of the -# GNU General Public License along with this program; if not, write to the -# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the -# source code or documentation are not subject to the GNU General Public -# License and may only be used or replicated with the express permission of -# Red Hat, Inc. -# -# Author(s): Chris Lumens -# David Cantrell -# Alex Skinner -# - -import parted -import _ped - -from parted.decorators import localeC - -class Alignment(object): - """Alignment() - - An Alignment object describes constraints on how sectors and Geometry - objects are aligned. Being aligned means that the sector be located at - a specific sector multiple on a device, or that a geometry must start - and end at sectors at those specific multiples. Most methods on this - object raise ArithmeticError if calculating alignments fails.""" - @localeC - def __init__(self, *args, **kwargs): - """Create a new Alignment object from the sectors offset and - grainSize.""" - if "PedAlignment" in kwargs: - self.__alignment = kwargs.get("PedAlignment") - elif "offset" in kwargs and "grainSize" in kwargs: - self.__alignment = _ped.Alignment(kwargs.get("offset"), - kwargs.get("grainSize")) - else: - raise parted.AlignmentException("no offset+grainSize or PedAlignment specified") - - offset = property(lambda s: s.__alignment.offset, lambda s, v: setattr(s.__alignment, "offset", v)) - grainSize = property(lambda s: s.__alignment.grain_size, lambda s, v: setattr(s.__alignment, "grain_size", v)) - - def __eq__(self, other): - return not self.__ne__(other) - - def __ne__(self, other): - if hash(self) == hash(other): - return False - - if type(self) != type(other): - return True - - return self.offset != other.offset or self.grainSize != other.grainSize - - def __str__(self): - s = ("parted.Alignment instance --\n" - " offset: %(offset)s grainSize: %(grainSize)s\n" - " PedAlignment: %(ped)r" % - {"offset": self.offset, "grainSize": self.grainSize, - "ped": self.__alignment}) - return s - - @localeC - def intersect(self, b): - """Create and return a new Alignment that describes the intersection of - self and alignment b. A sector will satisfy the new alignment iff - it satisfies both of the original alignments. Whether a sector - satisfies a given alignment is determined by is_aligned().""" - return parted.Alignment(PedAlignment=self.__alignment.intersect(b.getPedAlignment())) - - @localeC - def alignUp(self, geom, sector): - """Return the closest sector to the provided sector that lies inside - geom and satisfies the alignment constraint self. This method - prefers, but does not guarantee, that the result is beyond sector. - If no such sector can be found, an ArithmeticError is raised.""" - return self.__alignment.align_up(geom.getPedGeometry(), sector) - - @localeC - def alignDown(self, geom, sector): - """Return the closest sector to the provided sector that lies inside - geom and satisfies the alignment constraint self. This method - prefers, but does not guarantee, that the result is below sector. - If no such sector can be found, an ArithmeticError is raised.""" - return self.__alignment.align_down(geom.getPedGeometry(), sector) - - @localeC - def alignNearest(self, geom, sector): - """Return the closest sector to the input sector that lies inside - geom and satisfies the alignment constraint self. If no such sector - can be found, an ArithmeticError is raised.""" - return self.__alignment.align_nearest(geom.getPedGeometry(), sector) - - @localeC - def isAligned(self, geom, sector): - """Determine whether sector lies inside geom and satisfies the - alignment constraint self.""" - if not geom: - raise TypeError("missing parted.Geometry parameter") - - if sector is None: - raise TypeError("missing sector parameter") - - return self.__alignment.is_aligned(geom.getPedGeometry(), sector) - - def getPedAlignment(self): - """Return the _ped.Alignment object contained in this Alignment. - For internal module use only.""" - return self.__alignment diff --git a/src/parted/cachedlist.py b/src/parted/cachedlist.py deleted file mode 100644 index 6c522dc..0000000 --- a/src/parted/cachedlist.py +++ /dev/null @@ -1,90 +0,0 @@ -# -# Python bindings for libparted (built on top of the _ped Python module). -# -# Copyright (C) 2009 Red Hat, Inc. -# -# This copyrighted material is made available to anyone wishing to use, -# modify, copy, or redistribute it subject to the terms and conditions of -# the GNU General Public License v.2, or (at your option) any later version. -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY expressed or implied, including the implied warranties of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. You should have received a copy of the -# GNU General Public License along with this program; if not, write to the -# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the -# source code or documentation are not subject to the GNU General Public -# License and may only be used or replicated with the express permission of -# Red Hat, Inc. -# -# Red Hat Author(s): Chris Lumens -# - -from collections import Sequence - -class CachedList(Sequence): - """CachedList() - - Provides an immutable list that is constructed from a function that - could take a while to run. This is basically the same concept as - memoization, except that the function does not take any parameters - and therefore there is nothing to use as a memo. - - The constructor function is provided to __init__, must not take any - parameters, and must return a list. The invalidate() method indicates - that the list is no longer valid and should be reconstucted by - calling the function again. It is up to client code to call invalidate. - The rest of the procedure is handled by this class. - - In all ways, this should appear to be just like a list.""" - def __init__(self, lstFn): - """Construct a new CachedList. The lstFn is a function that takes - no parameters and returns a list. It will be called lazily - the - list is not constructed until the first access, which could be - quite a while after this method is called.""" - self._invalid = True - self._lst = [] - self._lstFn = lstFn - - def __rebuildList(self): - if self._invalid: - self._lst = self._lstFn() - self._invalid = False - - def __contains__(self, value): - self.__rebuildList() - return self._lst.__contains__(value) - - def __getitem__(self, index): - self.__rebuildList() - return self._lst.__getitem__(index) - - def __iter__(self): - self.__rebuildList() - return self._lst.__iter__() - - def __len__(self): - self.__rebuildList() - return len(self._lst) - - def __repr__(self): - self.__rebuildList() - return repr(self._lst) - - def __str__(self): - self.__rebuildList() - return str(self._lst) - - def count(self, value): - self.__rebuildList() - return self._lst.count(value) - - def index(self, value): - self.__rebuildList() - return self._lst.index(value) - - def invalidate(self): - """Indicate that the list is no longer valid, due to some external - changes. The next access to the list will result in the provided - list construction function being called to build a new list.""" - self._invalid = True diff --git a/src/parted/constraint.py b/src/parted/constraint.py deleted file mode 100644 index cdf4b5a..0000000 --- a/src/parted/constraint.py +++ /dev/null @@ -1,172 +0,0 @@ -# -# constraint.py -# Python bindings for libparted (built on top of the _ped Python module). -# -# Copyright (C) 2009 Red Hat, Inc. -# -# This copyrighted material is made available to anyone wishing to use, -# modify, copy, or redistribute it subject to the terms and conditions of -# the GNU General Public License v.2, or (at your option) any later version. -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY expressed or implied, including the implied warranties of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. You should have received a copy of the -# GNU General Public License along with this program; if not, write to the -# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the -# source code or documentation are not subject to the GNU General Public -# License and may only be used or replicated with the express permission of -# Red Hat, Inc. -# -# Author(s): Chris Lumens -# David Cantrell -# Alex Skinner -# - -import parted -import _ped - -from parted.decorators import localeC - -class Constraint(object): - """Constraint() - - A Constraint object describes a set of restrictions on other pyparted - operations. Constraints can restrict the location and alignment of the - start and end of a partition, and its minimum and maximum size. Most - constraint operations can raise CreateException if creating temporary - objects fails, or ArithmeticError if an error occurs during - calculations.""" - @localeC - def __init__(self, *args, **kwargs): - """Create a new Constraint object. There are many different ways to - create a Constraint, all depending on the parameters passed to - __init__. If minGeom and maxGeom are supplied, the constraint will - be created to satisfy both. If only one of minGeom or maxGeom are - supplied, the constraint is only guaranteed to solve the given - paramter. If exactGeom is given, the constraint will only be - satisfied by the given geometry. If device is given, any region - on that device will satisfy the constraint. - - If none of the previously mentioned parameters are supplied, all of - startAlign, EndAlign, startRange, endRange, minSize, and maxSize - must be given.""" - if "PedConstraint" in kwargs: - self.__constraint = kwargs.get("PedConstraint") - elif "minGeom" in kwargs and "maxGeom" in kwargs: - ming = kwargs.get("minGeom").getPedGeometry() - maxg = kwargs.get("maxGeom").getPedGeometry() - self.__constraint = _ped.constraint_new_from_min_max(ming, maxg) - elif "minGeom" in kwargs: - ming = kwargs.get("minGeom").getPedGeometry() - self.__constraint = _ped.constraint_new_from_min(ming) - elif "maxGeom" in kwargs: - maxg = kwargs.get("maxGeom").getPedGeometry() - self.__constraint = _ped.constraint_new_from_max(maxg) - elif "exactGeom" in kwargs: - exact = kwargs.get("exactGeom").getPedGeometry() - self.__constraint = _ped.constraint_exact(exact) - elif "device" in kwargs: - dev = kwargs.get("device").getPedDevice() - self.__constraint = _ped.constraint_any(dev) - elif "startAlign" in kwargs and "endAlign" in kwargs and \ - "startRange" in kwargs and "endRange" in kwargs and \ - "minSize" in kwargs and "maxSize" in kwargs: - starta = kwargs.get("startAlign").getPedAlignment() - enda = kwargs.get("endAlign").getPedAlignment() - startr = kwargs.get("startRange").getPedGeometry() - endr = kwargs.get("endRange").getPedGeometry() - mins = kwargs.get("minSize") - maxs = kwargs.get("maxSize") - self.__constraint = _ped.Constraint(starta, enda, startr, endr, - mins, maxs) - else: - raise parted.ConstraintException("missing initialization parameters") - - def __eq__(self, other): - return not self.__ne__(other) - - def __ne__(self, other): - if hash(self) == hash(other): - return False - - if type(self) != type(other): - return True - - c1 = self.getPedConstraint() - c2 = other.getPedConstraint() - - return self.minSize != other.minSize \ - or self.maxSize != other.maxSize \ - or c1.start_align != c2.start_align \ - or c1.end_align != c2.end_align \ - or c1.start_range != c2.start_range \ - or c1.end_range != c2.end_range - - startAlign = property( - lambda s: parted.Alignment(PedAlignment=s.__constraint.start_align), - lambda s, v: setattr(s.__constraint, "start_align", v.getPedAlignment())) - - endAlign = property( - lambda s: parted.Alignment(PedAlignment=s.__constraint.end_align), - lambda s, v: setattr(s.__constraint, "end_align", v.getPedAlignment())) - - startRange = property( - lambda s: parted.Geometry(PedGeometry=s.__constraint.start_range), - lambda s, v: setattr(s.__constraint, "start_range", v.getPedGeometry())) - - endRange = property( - lambda s: parted.Geometry(PedGeometry=s.__constraint.end_range), - lambda s, v: setattr(s.__constraint, "end_range", v.getPedGeometry())) - - minSize = property( - lambda s: s.__constraint.min_size, - lambda s, v: setattr(s.__constraint, "min_size", v)) - - maxSize = property( - lambda s: s.__constraint.max_size, - lambda s, v: setattr(s.__constraint, "max_size", v)) - - def __str__(self): - s = ("parted.Constraint instance --\n" - " startAlign: %(startAlign)r endAlign: %(endAlign)r\n" - " startRange: %(startRange)r endRange: %(endRange)r\n" - " minSize: %(minSize)s maxSize: %(maxSize)s\n" - " PedConstraint: %(ped)r" % - {"startAlign": self.startAlign, "endAlign": self.endAlign, - "startRange": self.startRange, "endRange": self.endRange, - "minSize": self.minSize, "maxSize": self.maxSize, - "ped": self.__constraint}) - return s - - @localeC - def intersect(self, b): - """Return a new constraint that is the intersection of self and the - provided constraint b. The returned constraint will therefore be - more restrictive than either input as it will have to satisfy - both.""" - return parted.Constraint(PedConstraint=self.__constraint.intersect(b.getPedConstraint())) - - @localeC - def solveMax(self): - """Return a new geometry that is the largest region satisfying self. - There may be more than one solution, and there are no guarantees as - to which solution will be returned.""" - return parted.Geometry(PedGeometry=self.__constraint.solve_max()) - - @localeC - def solveNearest(self, geom): - """Return a new geometry that is the nearest region to geom that - satisfies self. This function does not guarantee any specific - meaning of 'nearest'.""" - return parted.Geometry(PedGeometry=self.__constraint.solve_nearest(geom.getPedGeometry())) - - @localeC - def isSolution(self, geom): - """Does geom satisfy this constraint?""" - return self.__constraint.is_solution(geom.getPedGeometry()) - - def getPedConstraint(self): - """Return the _ped.Constraint object contained in this Constraint. - For internal module use only.""" - return self.__constraint diff --git a/src/parted/decorators.py b/src/parted/decorators.py deleted file mode 100644 index 737f72c..0000000 --- a/src/parted/decorators.py +++ /dev/null @@ -1,45 +0,0 @@ -# -# Python bindings for libparted (built on top of the _ped Python module). -# -# Copyright (C) 2009 Red Hat, Inc. -# -# This copyrighted material is made available to anyone wishing to use, -# modify, copy, or redistribute it subject to the terms and conditions of -# the GNU General Public License v.2, or (at your option) any later version. -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY expressed or implied, including the implied warranties of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. You should have received a copy of the -# GNU General Public License along with this program; if not, write to the -# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the -# source code or documentation are not subject to the GNU General Public -# License and may only be used or replicated with the express permission of -# Red Hat, Inc. -# -# Red Hat Author(s): Peter Jones -# - -import locale -import functools - -def localeC(fn): - # setlocale is not thread-safe, and anaconda (at least) may call this from - # another thread. This is just a luxury to have untranslated tracebacks, - # so it's not worth tracebacking itself. - def _setlocale(l): - try: - locale.setlocale(locale.LC_MESSAGES, l) - except: - pass - - @functools.wraps(fn) - def new(*args, **kwds): - oldlocale = locale.getlocale(locale.LC_MESSAGES) - _setlocale('C') - try: - ret = fn(*args, **kwds) - finally: - _setlocale(oldlocale) - return ret - return new diff --git a/src/parted/device.py b/src/parted/device.py deleted file mode 100644 index 8cb24fe..0000000 --- a/src/parted/device.py +++ /dev/null @@ -1,354 +0,0 @@ -# -# device.py -# Python bindings for libparted (built on top of the _ped Python module). -# -# Copyright (C) 2009-2013 Red Hat, Inc. -# -# This copyrighted material is made available to anyone wishing to use, -# modify, copy, or redistribute it subject to the terms and conditions of -# the GNU General Public License v.2, or (at your option) any later version. -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY expressed or implied, including the implied warranties of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. You should have received a copy of the -# GNU General Public License along with this program; if not, write to the -# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the -# source code or documentation are not subject to the GNU General Public -# License and may only be used or replicated with the express permission of -# Red Hat, Inc. -# -# Author(s): David Cantrell -# Alex Skinner -# - -import math -import warnings - -import parted -import _ped - -from parted.decorators import localeC - -class Device(object): - """Device() - - Device represents a phyiscal piece of hardware in the system, e.g. a - disk. A Device should be considered a low-level and operating system - specific interface to the hardware. - - A number of read-only properties about the Device are available. - - For information on the individual methods, see help(Device.METHODNAME)""" - - @localeC - def __init__(self, path=None, PedDevice=None): - """Create a new Device object based on the specified path or the - already existing _ped.Device object. You must provide either a - path (e.g., "/dev/sda") or an existing _ped.Device object, but - not both.""" - - if PedDevice: - self.__device = PedDevice - elif path is not None: - self.__device = _ped.device_get(path) - else: - raise parted.DeviceException("no path or PedDevice specified") - - def __eq__(self, other): - return not self.__ne__(other) - - def __ne__(self, other): - if hash(self) == hash(other): - return False - - if type(self) != type(other): - return True - - return self.model != other.model or self.path != other.path or self.type != other.type or self.length != other.length - - def __getCHS(self, geometry): - return (geometry.cylinders, geometry.heads, geometry.sectors) - - @property - def model(self): - """Model name and vendor of this device.""" - return self.__device.model - - @property - def path(self): - """Filesystem node path of this device (e.g., /dev/sda).""" - return self.__device.path - - @property - def type(self): - """Type of this device. An integer constant corresponding - to one of the parted.DEVICE_* values. - """ - return self.__device.type - - @property - def sectorSize(self): - """Sector size (in bytes) for this device.""" - return self.__device.sector_size - - @property - def physicalSectorSize(self): - """Physical sector size (in bytes) for this device. Not always - the same as sectorSize, but is a multiple of sectorSize. - """ - return self.__device.phys_sector_size - - @property - def length(self): - """The size of this device in sectors.""" - return self.__device.length - - @property - def openCount(self): - """How many times the open() method has been called on this device.""" - return self.__device.open_count - - @property - def readOnly(self): - """True if the device is currently in read-only mode, False - otherwise. - """ - return bool(self.__device.read_only) - - @property - def externalMode(self): - """True if external access mode is currently activated on this - device, False otherwise. External access mode has to be used - if you want to use an external command on the device while - you are currently using it in pyparted. - """ - return bool(self.__device.external_mode) - - @property - def dirty(self): - """True if the device is marked dirty, False otherwise.""" - return bool(self.__device.dirty) - - @property - def bootDirty(self): - """True if the device is marked boot dirty, False otherwise.""" - return bool(self.__device.boot_dirty) - - @property - def host(self): - """The host value of this device.""" - return self.__device.host - - @property - def did(self): - """The did value of this device.""" - return self.__device.did - - @property - def busy(self): - """True if this device is busy, False otherwise.""" - return self.__device.is_busy() - - @property - def hardwareGeometry(self): - """A 3-tuple representing the hardware geometry of this device. - The tuple is in order of cylinders, heads, and sectors. - """ - return self.__getCHS(self.__device.hw_geom) - - @property - def biosGeometry(self): - """A 3-tuple representing the BIOS geometry of this device. - The tuple is in order of cylinders, heads, and sectors. - """ - return self.__getCHS(self.__device.bios_geom) - - def __str__(self): - s = ("parted.Device instance --\n" - " model: %(model)s path: %(path)s type: %(type)s\n" - " sectorSize: %(sectorSize)s physicalSectorSize: %(physSectorSize)s\n" - " length: %(length)s openCount: %(openCount)s readOnly: %(readOnly)s\n" - " externalMode: %(external)s dirty: %(dirty)s bootDirty: %(bootDirty)s\n" - " host: %(host)s did: %(did)s busy: %(busy)s\n" - " hardwareGeometry: %(hardwareGeom)s biosGeometry: %(biosGeom)s\n" - " PedDevice: %(ped)r" % - {"model": self.model, "path": self.path, "type": self.type, - "sectorSize": self.sectorSize, "physSectorSize": self.physicalSectorSize, - "length": self.length, "openCount": self.openCount, "readOnly": self.readOnly, - "external": self.externalMode, "dirty": self.dirty, "bootDirty": self.bootDirty, - "host": self.host, "did": self.did, "busy": self.busy, - "hardwareGeom": self.hardwareGeometry, "biosGeom": self.biosGeometry, - "ped": self.__device}) - return s - - @localeC - def clobber(self): - """Remove all identifying signatures of the partition table.""" - return self.__device.clobber() - - @localeC - def open(self): - """Open this Device for read operations.""" - - return self.__device.open() - - @localeC - def close(self): - """Close this Device. Used after open() method calls.""" - - return self.__device.close() - - @localeC - def destroy(self): - """Destroy this Device. Operating system specific.""" - - return self.__device.destroy() - - @localeC - def removeFromCache(self): - """Remove this Device from the internal libparted device cache.""" - - return self.__device.cache_remove() - - @localeC - def beginExternalAccess(self): - """Set up the Device for use by an external program. Call this method - before running an external program that uses the Device.""" - - return self.__device.begin_external_access() - - @localeC - def endExternalAccess(self): - """Turn off external access mode for the Device. Call this method once - your external program has finished using the Device.""" - - return self.__device.end_external_access() - - @localeC - def read(self, start, count): - """From the sector indentified by start, read and return count sectors - from the Device.""" - - return self.__device.read(start, count) - - @localeC - def write(self, buf, start, count): - """From the sector identified by start, write count sectors from - buffer to the Device.""" - - return self.__device.write(buf, start, count) - - @localeC - def sync(self, fast=False): - """Perform a operating-system specific sync(2) operation on the - Device. If fast is True, try to perform a fast sync(2).""" - - if fast: - return self.__device.sync_fast() - else: - return self.__device.sync() - - @localeC - def check(self, start, count): - """From the sector identified by start, perform an operating - system specific check on count sectors.""" - return self.__device.check(start, count) - - @localeC - def startSectorToCylinder(self, sector): - """Return the closest cylinder (round down) to sector on - this Device.""" - (_, heads, sectors) = self.biosGeometry - return long(math.floor((float(sector) / (heads * sectors)) + 1)) - - @localeC - def endSectorToCylinder(self, sector): - """Return the closest cylinder (round up) to sector on - this Device.""" - (_, heads, sectors) = self.biosGeometry - return long(math.ceil(float((sector + 1)) / (heads * sectors))) - - @localeC - def startCylinderToSector(self, cylinder): - """Return the sector corresponding to cylinder as a - starting cylinder on this Device.""" - (_, heads, sectors) = self.biosGeometry - return long((cylinder - 1) * (heads * sectors)) - - @localeC - def endCylinderToSector(self, cylinder): - """Return the sector corresponding to cylinder as an - ending cylinder on this Device.""" - (_, heads, sectors) = self.biosGeometry - return long(((cylinder) * (heads * sectors)) - 1) - - def getSize(self, unit="MB"): - """Return the size of the Device in the unit specified. The unit - is given as a string corresponding to one of the following - abbreviations: b (bytes), KB (kilobytes), MB (megabytes), GB - (gigabytes), TB (terabytes). An invalid unit string will raise a - SyntaxError exception. The default unit is MB.""" - warnings.warn("use the getLength method", DeprecationWarning) - lunit = unit.lower() - - if lunit not in parted._exponent.keys(): - raise SyntaxError("invalid unit %s given" % (unit)) - - size = float(self.__device.length) - size /= math.pow(1024.0, parted._exponent[lunit]) - size *= self.sectorSize - - return size - - @localeC - def getLength(self, unit='sectors'): - """Return the length of the device in sectors. Optionally, a SI or - IEC prefix followed by a 'B' may be given in order to convert the - length into bytes. The allowed values include B, kB, MB, GB, TB, KiB, - MiB, GiB, and TiB.""" - sectors = self.__device.length - if unit == "sectors": - return sectors - return parted.formatBytes(sectors * self.sectorSize, unit) - - @localeC - def getConstraint(self): - """Return a Constraint defining the limitations imposed by - this Device.""" - return parted.Constraint(PedConstraint=self.__device.get_constraint()) - - @property - @localeC - def minimalAlignedConstraint(self): - """Return a Constraint defining the limitations and minimal advisable - alignment imposed by this Device.""" - constraint = self.__device.get_minimal_aligned_constraint() - return parted.Constraint(PedConstraint=constraint) - - @property - @localeC - def optimalAlignedConstraint(self): - """Return a Constraint defining the limitations and optimal - alignment imposed by this Device.""" - constraint = self.__device.get_optimal_aligned_constraint() - return parted.Constraint(PedConstraint=constraint) - - @property - @localeC - def minimumAlignment(self): - """Return an Alignment defining the minimum alignment for this Device.""" - alignment = self.__device.get_minimum_alignment() - return parted.Alignment(PedAlignment=alignment) - - @property - @localeC - def optimumAlignment(self): - """Return an Alignment defining the optimum alignment for this Device.""" - alignment = self.__device.get_optimum_alignment() - return parted.Alignment(PedAlignment=alignment) - - def getPedDevice(self): - """Return the _ped.Device object contained in this Device. - For internal module use only.""" - return self.__device diff --git a/src/parted/disk.py b/src/parted/disk.py deleted file mode 100644 index 3f293e2..0000000 --- a/src/parted/disk.py +++ /dev/null @@ -1,490 +0,0 @@ -# -# disk.py -# Python bindings for libparted (built on top of the _ped Python module). -# -# Copyright (C) 2009-2013 Red Hat, Inc. -# -# This copyrighted material is made available to anyone wishing to use, -# modify, copy, or redistribute it subject to the terms and conditions of -# the GNU General Public License v.2, or (at your option) any later version. -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY expressed or implied, including the implied warranties of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. You should have received a copy of the -# GNU General Public License along with this program; if not, write to the -# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the -# source code or documentation are not subject to the GNU General Public -# License and may only be used or replicated with the express permission of -# Red Hat, Inc. -# -# Author(s): David Cantrell -# Alex Skinner -# - -import _ped -import parted - -from parted.cachedlist import CachedList -from parted.decorators import localeC - -class Disk(object): - """Disk() - - A Disk object describes a type of device in the system. Disks - can hold partitions. A Disk is a basic operating system-specific - object.""" - @localeC - def __init__(self, device=None, PedDisk=None): - """Create a new Disk object from the device and type specified. The - device is a Device object and type is a string matching a key in - the diskType hash.""" - if PedDisk: - self.__disk = PedDisk - - if device is None: - self._device = parted.Device(PedDevice=self.__disk.dev) - else: - self._device = device - elif device is None: - raise parted.DiskException("no device specified") - else: - self.__disk = _ped.Disk(device.getPedDevice()) - self._device = device - - # pylint: disable=W0108 - self._partitions = CachedList(lambda : self.__getPartitions()) - - def _hasSameParts(self, other): - import itertools - - if len(self.partitions) != len(other.partitions): - return False - - partIter = itertools.izip(self.partitions, other.partitions) - while True: - try: - (left, right) = partIter.next() - if left != right: - return False - except StopIteration: - return True - - def __eq__(self, other): - return not self.__ne__(other) - - def __ne__(self, other): - if hash(self) == hash(other): - return False - - if type(self) != type(other): - return True - - return self.device != other.device or not self._hasSameParts(other) - - def __str__(self): - s = ("parted.Disk instance --\n" - " type: %(type)s primaryPartitionCount: %(primaryCount)s\n" - " lastPartitionNumber: %(last)s maxPrimaryPartitionCount: %(max)s\n" - " partitions: %(partitions)s\n" - " device: %(device)r\n" - " PedDisk: %(ped)r" % - {"type": self.type, "primaryCount": self.primaryPartitionCount, - "last": self.lastPartitionNumber, "max": self.maxPrimaryPartitionCount, - "partitions": self.partitions, "device": self.device, - "ped": self.__disk}) - return s - - def __getPartitions(self): - """Construct a list of partitions on the disk. This is called only as - needed from the self.partitions property, which just happens to be - a CachedList.""" - partitions = [] - partition = self.getFirstPartition() - - while partition: - if partition.type & parted.PARTITION_FREESPACE or \ - partition.type & parted.PARTITION_METADATA or \ - partition.type & parted.PARTITION_PROTECTED: - partition = partition.nextPartition() - continue - - partitions.append(partition) - partition = partition.nextPartition() - - return partitions - - @property - @localeC - def primaryPartitionCount(self): - """The number of primary partitions on this disk.""" - return self.__disk.get_primary_partition_count() - - @property - @localeC - def lastPartitionNumber(self): - """The last assigned partition number currently on this disk.""" - return self.__disk.get_last_partition_num() - - @property - @localeC - def maxPrimaryPartitionCount(self): - """The maximum number of primary partitions allowed on this disk.""" - return self.__disk.get_max_primary_partition_count() - - @property - @localeC - def maxSupportedPartitionCount(self): - """The maximum number of partitions allowed on this disk.""" - return self.__disk.get_max_supported_partition_count() - - @property - @localeC - def partitionAlignment(self): - """Partition start address Alignment.""" - alignment = self.__disk.get_partition_alignment() - return parted.Alignment(PedAlignment=alignment) - - @property - @localeC - def maxPartitionLength(self): - """Max Partition Length the disk's label can represent.""" - return self.__disk.max_partition_length() - - @property - @localeC - def maxPartitionStartSector(self): - """Max Partition Start Sector the disk's label can represent.""" - return self.__disk.max_partition_start_sector() - - @localeC - def getFlag(self, flag): - """Get the value of a particular flag on the disk. Valid flags - are the _ped.DISK_* constants. See _ped.disk_flag_get_name() and - _ped.disk_flag_get_by_name() for more help working with disk flags. - """ - return self.__disk.get_flag(flag) - - @localeC - def setFlag(self, flag): - """Set the flag on this disk. On error, an Exception will be raised. - See getFlag() for more help on working with disk flags.""" - return self.__disk.set_flag(flag, 1) - - @localeC - def unsetFlag(self, flag): - """Unset the flag on this disk. On error, an Exception will be raised. - See getFlag() for more help on working with disk flags.""" - return self.__disk.set_flag(flag, 0) - - @localeC - def isFlagAvailable(self, flag): - """Return True if flag is available on this Disk, False - otherwise.""" - return self.__disk.is_flag_available(flag) - - @property - def partitions(self): - """The list of partitions currently on this disk.""" - return self._partitions - - @property - def device(self): - """The underlying Device holding this disk and partitions.""" - return self._device - - type = property(lambda s: s.__disk.type.name, lambda s, v: setattr(s.__disk, "type", parted.diskType[v])) - - @localeC - def duplicate(self): - """Make a deep copy of this Disk.""" - return Disk(PedDisk=self.__disk.duplicate()) - - @localeC - def destroy(self): - """Closes the Disk ensuring all outstanding writes are flushed.""" - return self.__disk.destroy() - - @localeC - def commit(self): - """Writes in-memory changes to a partition table to disk and - informs the operating system of the changes. Equivalent to - calling self.commitToDevice() then self.commitToOS().""" - self.partitions.invalidate() - - return self.__disk.commit() - - @localeC - def commitToDevice(self): - """Write the changes made to the in-memory description of a - partition table to the device.""" - self.partitions.invalidate() - - return self.__disk.commit_to_dev() - - @localeC - def commitToOS(self): - """Tell the operating system kernel about the partition table - layout of this Disk.""" - self.partitions.invalidate() - - return self.__disk.commit_to_os() - - @localeC - def check(self): - """Perform a sanity check on the partition table of this Disk.""" - return self.__disk.check() - - @localeC - def supportsFeature(self, feature): - """Check that the disk type supports the provided feature.""" - return self.__disk.type.check_feature(feature) - - @localeC - def addPartition(self, partition=None, constraint=None): - """Add a new Partition to this Disk with the given Constraint.""" - if constraint: - result = self.__disk.add_partition(partition.getPedPartition(), - constraint.getPedConstraint()) - elif not partition: - raise parted.DiskException("no partition or constraint specified") - else: - result = self.__disk.add_partition(partition.getPedPartition()) - - if result: - partition.geometry = parted.Geometry(PedGeometry=partition.getPedPartition().geom) - self.partitions.invalidate() - return True - else: - return False - - @localeC - def removePartition(self, partition=None): - """Removes specified Partition from this Disk. NOTE: If the - Partition is an extended partition, it must not contain any - logical partitions. Also note that the partition is not - actually destroyed unless you use the deletePartition() - method.""" - if not partition: - raise parted.DiskException("no partition specified") - - if self.__disk.remove_partition(partition.getPedPartition()): - self.partitions.invalidate() - return True - else: - return False - - @localeC - def deletePartition(self, partition): - """Removes specified Partition from this Disk under the same - conditions as removePartition(), but also destroy the - removed Partition.""" - if self.__disk.delete_partition(partition.getPedPartition()): - self.partitions.invalidate() - return True - else: - return False - - @localeC - def deleteAllPartitions(self): - """Removes and destroys all Partitions in this Disk.""" - if self.__disk.delete_all(): - self.partitions.invalidate() - return True - else: - return False - - @localeC - def setPartitionGeometry(self, partition=None, constraint=None, start=None, end=None): - """Sets the Geometry of the specified Partition using the given - Constraint and start and end sectors. Note that this method - does not modify the partition contents, just the partition - table.""" - if not partition or not constraint: - raise parted.DiskException("no partition or constraint specified") - - if not start or not end: - raise parted.DiskException("no start or end geometry specified") - - return self.__disk.set_partition_geom(partition.getPedPartition(), - constraint.getPedConstraint(), - start, end) - - @localeC - def maximizePartition(self, partition=None, constraint=None): - """Grow the Partition's Geometry to the maximum possible subject - to Constraint.""" - if not partition: - raise parted.DiskException("no partition specified") - - if constraint: - return self.__disk.maximize_partition(partition.getPedPartition(), - constraint.getPedConstraint()) - else: - return self.__disk.maximize_partition(partition.getPedPartition()) - - @localeC - def calculateMaxPartitionGeometry(self, partition=None, constraint=None): - """Get the maximum Geometry the Partition can be grown to, - subject to the given Constraint.""" - if not partition: - raise parted.DiskException("no partition specified") - - if constraint: - return parted.Geometry(PedGeometry=self.__disk.get_max_partition_geometry(partition.getPedPartition(), constraint.getPedConstraint())) - else: - return parted.Geometry(PedGeometry=self.__disk.get_max_partition_geometry(partition.getPedPartition())) - - @localeC - def minimizeExtendedPartition(self): - """Reduce the size of the extended partition to a minimum while - still wrapping its logical partitions. If there are no logical - partitions, remove the extended partition.""" - ret = self.__disk.minimize_extended_partition() - - if ret: - self.partitions.invalidate() - - return ret - - @localeC - def getPartitionBySector(self, sector): - """Returns the Partition that contains the sector. If the sector - lies within a logical partition, then the logical partition is - returned (not the extended partition).""" - return parted.Partition(disk=self, PedPartition=self.__disk.get_partition_by_sector(sector)) - - def getMaxLogicalPartitions(self): - """Return the maximum number of logical partitions this Disk - will hold. Returns 0 if there is no extended partition on - the disk, returns 11 when all else fails.""" - if not self.supportsFeature(parted.DISK_TYPE_EXTENDED): - return 0 - - # maximum number of logical partitions per device type - maxLogicalPartitionCount = { - "hd": 59, - "sd": 11, - "ataraid/": 11, - "rd/": 3, - "cciss/": 11, - "i2o/": 11, - "iseries/vd": 3, - "ida/": 11, - "sx8/": 11, - "xvd": 11, - "vd": 11, - "mmcblk": 5 - } - - dev = self.device.path[5:] - for key in maxLogicalPartitionCount.keys(): - if dev.startswith(key): - return maxLogicalPartitionCount[key] - - # XXX: if we don't know about it, should we pretend it can't have - # logicals? probably safer to just use something reasonable - return 11 - - @localeC - def getExtendedPartition(self): - """Return the extended Partition, if any, on this Disk.""" - try: - return parted.Partition(disk=self, PedPartition=self.__disk.extended_partition()) - except: - return None - - def __filterPartitions(self, fn): - return filter(fn, self.partitions) - - def getLogicalPartitions(self): - """Return a list of logical Partitions on this Disk.""" - return self.__filterPartitions(lambda p: p.active and p.type & parted.PARTITION_LOGICAL) - - def getPrimaryPartitions(self): - """Return a list of primary (or normal) Partitions on this Disk.""" - return self.__filterPartitions(lambda p: p.type == parted.PARTITION_NORMAL) - - def getRaidPartitions(self): - """Return a list of RAID (or normal) Partitions on this Disk.""" - return self.__filterPartitions(lambda p: p.active and p.getFlag(parted.PARTITION_RAID)) - - def getLVMPartitions(self): - """Return a list of physical volume-type Partitions on this Disk.""" - return self.__filterPartitions(lambda p: p.active and p.getFlag(parted.PARTITION_LVM)) - - @localeC - def getFreeSpaceRegions(self): - """Return a list of Geometry objects representing the available - free space regions on this Disk.""" - freespace = [] - part = self.__disk.next_partition() - - while part: - if part.type & parted.PARTITION_FREESPACE: - freespace.append(parted.Geometry(PedGeometry=part.geom)) - - part = self.__disk.next_partition(part) - - return freespace - - @localeC - def getFreeSpacePartitions(self): - """Return a list of Partition objects representing the available - free space regions on this Disk.""" - freespace = [] - part = self.__disk.next_partition() - - while part: - if part.type & parted.PARTITION_FREESPACE: - freespace.append(parted.Partition(disk=self, PedPartition=part)) - - part = self.__disk.next_partition(part) - - return freespace - - @localeC - def getFirstPartition(self): - """Return the first Partition object on the disk or None if - there is not one.""" - return parted.Partition(disk=self, PedPartition=self.__disk.next_partition()) - - @localeC - def getPartitionByPath(self, path): - """Return a Partition object associated with the partition device - path, such as /dev/sda1. Returns None if no partition is found.""" - for partition in self.partitions: - if partition.path == path: - return partition - - return None - - def getPedDisk(self): - """Return the _ped.Disk object contained in this Disk. For internal - module use only.""" - return self.__disk - -# collect all disk types and store them in a hash -diskType = {} -__type = _ped.disk_type_get_next() -diskType[__type.name] = __type - -while True: - try: - __type = _ped.disk_type_get_next(__type) - diskType[__type.name] = __type - except: - break - -# collect all disk flags and store them in a hash -diskFlag = {} -__flag = _ped.disk_flag_next(0) -diskFlag[__flag] = _ped.disk_flag_get_name(__flag) -__readFlags = True - -while __readFlags: - __flag = _ped.disk_flag_next(__flag) - if not __flag: - __readFlags = False - else: - diskFlag[__flag] = _ped.disk_flag_get_name(__flag) diff --git a/src/parted/filesystem.py b/src/parted/filesystem.py deleted file mode 100644 index 3c8045c..0000000 --- a/src/parted/filesystem.py +++ /dev/null @@ -1,111 +0,0 @@ -# -# filesystem.py -# Python bindings for libparted (built on top of the _ped Python module). -# -# Copyright (C) 2009-2013 Red Hat, Inc. -# -# This copyrighted material is made available to anyone wishing to use, -# modify, copy, or redistribute it subject to the terms and conditions of -# the GNU General Public License v.2, or (at your option) any later version. -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY expressed or implied, including the implied warranties of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. You should have received a copy of the -# GNU General Public License along with this program; if not, write to the -# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the -# source code or documentation are not subject to the GNU General Public -# License and may only be used or replicated with the express permission of -# Red Hat, Inc. -# -# Author(s): David Cantrell -# Alex Skinner -# - -import _ped -import parted - -from parted.decorators import localeC - -# XXX: add docstrings! - -class FileSystem(object): - # pylint: disable=W0622 - @localeC - def __init__(self, type=None, geometry=None, checked=False, PedFileSystem=None): - if checked: - c = 1 - else: - c = 0 - - if PedFileSystem is None: - if type is None: - raise parted.FileSystemException("no type specified") - elif geometry is None: - raise parted.FileSystemException("no geometry specified") - - self._type = type - self._geometry = geometry - self._checked = checked - self.__fileSystem = _ped.FileSystem(type=fileSystemType[type], geom=geometry.getPedGeometry(), checked=c) - else: - self.__fileSystem = PedFileSystem - self._type = self.__fileSystem.type.name - self._geometry = parted.Geometry(PedGeometry=self.__fileSystem.geom) - - if self.__fileSystem.checked: - self._checked = True - else: - self._checked = False - - def __eq__(self, other): - return not self.__ne__(other) - - def __ne__(self, other): - if hash(self) == hash(other): - return False - - if type(self) != type(other): - return True - - return self.type != other.type or self.geometry != other.geometry - - def __str__(self): - s = ("parted.FileSystem instance --\n" - " type: %(type)s geometry: %(geometry)r checked: %(checked)s\n" - " PedFileSystem: %(ped)r" % - {"type": self.type, "geometry": self.geometry, - "checked": self.checked, "ped": self.__fileSystem}) - return s - - @property - def type(self): - """The type of this filesystem, e.g. ext3.""" - return self._type - - @property - def geometry(self): - """The Geometry object describing this filesystem.""" - return self._geometry - - @property - def checked(self): - """True if this filesystem has been checked, False otherwise.""" - return bool(self._checked) - - def getPedFileSystem(self): - """Return the _ped.FileSystem object contained in this FileSystem. - For internal module use only.""" - return self.__fileSystem - -# collect all filesystem types and store them in a hash -fileSystemType = {} -__type = _ped.file_system_type_get_next() -fileSystemType[__type.name] = __type - -while True: - try: - __type = _ped.file_system_type_get_next(__type) - fileSystemType[__type.name] = __type - except: - break diff --git a/src/parted/geometry.py b/src/parted/geometry.py deleted file mode 100644 index 3316ab9..0000000 --- a/src/parted/geometry.py +++ /dev/null @@ -1,200 +0,0 @@ -# -# geometry.py -# Python bindings for libparted (built on top of the _ped Python module). -# -# Copyright (C) 2009-2013 Red Hat, Inc. -# -# This copyrighted material is made available to anyone wishing to use, -# modify, copy, or redistribute it subject to the terms and conditions of -# the GNU General Public License v.2, or (at your option) any later version. -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY expressed or implied, including the implied warranties of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. You should have received a copy of the -# GNU General Public License along with this program; if not, write to the -# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the -# source code or documentation are not subject to the GNU General Public -# License and may only be used or replicated with the express permission of -# Red Hat, Inc. -# -# Author(s): Chris Lumens -# David Cantrell -# Alex Skinner -# - -import math -import warnings - -import parted -import _ped - -from parted.decorators import localeC - -class Geometry(object): - """Geometry() - - Geometry represents a region on a device in the system - a disk or - partition. It is expressed in terms of a starting sector and a length. - Many methods (read and write methods in particular) throughout pyparted - take in a Geometry object as an argument.""" - @localeC - def __init__(self, device=None, start=None, length=None, end=None, - PedGeometry=None): - """Create a new Geometry object for the given _ped.Device that extends - for length sectors from the start sector. Optionally, an end sector - can also be provided.""" - if PedGeometry: - self.__geometry = PedGeometry - - if device is None: - self._device = parted.Device(PedDevice=self.__geometry.dev) - else: - self._device = device - elif not end: - self._device = device - self.__geometry = _ped.Geometry(self.device.getPedDevice(), start, length) - elif not length and (end > start): - self._device = device - self.__geometry = _ped.Geometry(self.device.getPedDevice(), start, (end - start + 1), end=end) - elif start and length and end and (end > start): - self._device = device - self.__geometry = _ped.Geometry(self.device.getPedDevice(), start, length, end=end) - else: - raise parted.GeometryException("must specify PedGeometry or (device, start, length) or (device, start, end) or (device, start, length, end)") - - def __eq__(self, other): - return not self.__ne__(other) - - def __ne__(self, other): - if hash(self) == hash(other): - return False - - if type(self) != type(other): - return True - - return self.device != other.device or self.start != other.start or self.length != other.length - - def __str__(self): - s = ("parted.Geometry instance --\n" - " start: %(start)s end: %(end)s length: %(length)s\n" - " device: %(device)r PedGeometry: %(ped)r" % - {"start": self.start, "end": self.end, "length": self.length, - "device": self.device, "ped": self.__geometry}) - return s - - @property - def device(self): - """The Device this geometry describes.""" - return self._device - - start = property(lambda s: s.__geometry.start, lambda s, v: s.__geometry.set_start(v)) - end = property(lambda s: s.__geometry.end, lambda s, v: s.__geometry.set_end(v)) - length = property(lambda s: s.__geometry.length, lambda s, v: s.__geometry.set(s.__geometry.start, v)) - - @localeC - def check(self, offset, granularity, count, timer=None): - """Check the region described by self for errors on the disk. - offset -- The beginning of the region to check, in sectors from the - start of the geometry. - granularity -- How sectors should be grouped together - count -- How many sectors from the region to check.""" - if not timer: - return self.__geometry.check(offset, granularity, count) - else: - return self.__geometry.check(offset, granularity, count, timer) - - @localeC - def contains(self, b): - """Return whether Geometry b is contained entirely within self and on - the same physical device.""" - return self.__geometry.test_inside(b.getPedGeometry()) - - @localeC - def containsSector(self, sector): - """Return whether the sectory is contained entirely within self.""" - return self.__geometry.test_sector_inside(sector) - - @localeC - def getSize(self, unit="MB"): - """Return the size of the geometry in the unit specified. The unit - is given as a string corresponding to one of the following - abbreviations: b (bytes), KB (kilobytes), MB (megabytes), GB - (gigabytes), TB (terabytes). An invalid unit string will raise a - SyntaxError exception. The default unit is MB.""" - warnings.warn("use the getLength method", DeprecationWarning) - lunit = unit.lower() - size = self.length * self.device.sectorSize - - if lunit not in parted._exponent.keys(): - raise SyntaxError("invalid unit %s given" % (unit)) - - return (size / math.pow(1024.0, parted._exponent[lunit])) - - @localeC - def getLength(self, unit='sectors'): - """Return the length of the geometry in sectors. Optionally, a SI or - IEC prefix followed by a 'B' may be given in order to convert the - length into bytes. The allowed values include B, kB, MB, GB, TB, KiB, - MiB, GiB, and TiB.""" - sectors = self.length - if unit == "sectors": - return sectors - return parted.formatBytes(sectors * self.device.sectorSize, unit) - - @localeC - def intersect(self, b): - """Return a new Geometry describing the region common to both self - and Geometry b. Raises ArithmeticError if the regions do not - intersect.""" - return Geometry(PedGeometry=self.__geometry.intersect(b.getPedGeometry())) - - @localeC - def map(self, src, sector): - """Given a Geometry src that overlaps with self and a sector inside src, - this method translates the address of the sector into an address - inside self. If self does not contain sector, ArithmeticError will - be raised.""" - return parted.Geometry(PedGeometry=self.__geometry.map(src.getPedGeometry(), sector)) - - @localeC - def overlapsWith(self, b): - """Return whether self and b are on the same device and share at least - some of the same region.""" - try: - self.__geometry.intersect(b.getPedGeometry()) - return True - except ArithmeticError: - return False - - @localeC - def read(self, offset, count): - """Read data from the region described by self. - offset -- The number of sectors from the beginning of the region - (not the beginning of the disk) to read. - count -- The number of sectors to read.""" - return self.__geometry.read(offset, count) - - @localeC - def sync(self, fast=False): - """Flushes all caches on the device described by self. If fast is - True, the flush will be quicked by cache coherency is not - guaranteed.""" - if fast: - return self.__geometry.sync_fast() - else: - return self.__geometry.sync() - - @localeC - def write(self, buf, offset, count): - """Write data into the region described by self. - buf -- The data to be written. - offset -- Where to start writing to region, expressed as the number - of sectors from the start of the region (not the disk). - count -- How many sectors of buf to write out.""" - return self.__geometry.write(buf, offset, count) - - def getPedGeometry(self): - """Return the _ped.Geometry object contained in this Geometry. - For internal module use only.""" - return self.__geometry diff --git a/src/parted/partition.py b/src/parted/partition.py deleted file mode 100644 index 89cb673..0000000 --- a/src/parted/partition.py +++ /dev/null @@ -1,266 +0,0 @@ -# -# partition.py -# Python bindings for libparted (built on top of the _ped Python module). -# -# Copyright (C) 2009-2013 Red Hat, Inc. -# -# This copyrighted material is made available to anyone wishing to use, -# modify, copy, or redistribute it subject to the terms and conditions of -# the GNU General Public License v.2, or (at your option) any later version. -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY expressed or implied, including the implied warranties of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. You should have received a copy of the -# GNU General Public License along with this program; if not, write to the -# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the -# source code or documentation are not subject to the GNU General Public -# License and may only be used or replicated with the express permission of -# Red Hat, Inc. -# -# Author(s): Chris Lumens -# David Cantrell -# Alex Skinner -# - -import math -import warnings - -import _ped -import parted - -from parted.decorators import localeC - -# XXX: add docstrings - -class Partition(object): - # pylint: disable=W0622 - @localeC - def __init__(self, disk=None, type=None, fs=None, geometry=None, PedPartition=None): - if PedPartition is None: - if disk is None: - raise parted.PartitionException("no disk specified") - elif type is None: - raise parted.PartitionException("no type specified") - elif geometry is None: - raise parted.PartitionException("no geometry specified") - - self._fileSystem = fs - self._geometry = geometry - self._disk = disk - - if fs is None: - self.__partition = _ped.Partition(disk.getPedDisk(), type, geometry.start, geometry.end) - else: - self.__partition = _ped.Partition(disk.getPedDisk(), type, geometry.start, geometry.end, parted.fileSystemType[fs.type]) - else: - self.__partition = PedPartition - self._geometry = parted.Geometry(PedGeometry=self.__partition.geom) - - if disk is None: - self._disk = parted.Disk(PedDisk=self.__partition.disk) - else: - self._disk = disk - - if self.__partition.fs_type is None: - self._fileSystem = None - else: - # pylint: disable=E1103 - self._fileSystem = parted.FileSystem(type=self.__partition.fs_type.name, geometry=self._geometry) - - def __eq__(self, other): - return not self.__ne__(other) - - def __ne__(self, other): - if hash(self) == hash(other): - return False - - if type(self) != type(other): - return True - - return self.path != other.path or self.type != other.type or self.geometry != other.geometry or self.fileSystem != other.fileSystem - - def __str__(self): - try: - name = self.name - except parted.PartitionException: - name = None - - s = ("parted.Partition instance --\n" - " disk: %(disk)r fileSystem: %(fileSystem)r\n" - " number: %(number)s path: %(path)s type: %(type)s\n" - " name: %(name)s active: %(active)s busy: %(busy)s\n" - " geometry: %(geometry)r PedPartition: %(ped)r" % - {"disk": self.disk, "fileSystem": self.fileSystem, "geometry": self.geometry, - "number": self.number, "path": self.path, - "type": self.type, "name": name, "active": self.active, - "busy": self.busy, "ped": self.__partition}) - return s - - def __writeOnly(self, prop): - raise parted.WriteOnlyProperty(prop) - - @property - @localeC - def active(self): - """True if the partition is active, False otherwise.""" - return bool(self.__partition.is_active()) - - @property - @localeC - def busy(self): - """True if the partition is active, False otherwise.""" - return bool(self.__partition.is_busy()) - - @property - def disk(self): - """The Disk this partition belongs to.""" - return self._disk - - @property - @localeC - def path(self): - """The filesystem path to this partition's device node.""" - return self.__partition.get_path() - - @property - @localeC - def name(self): - """The name of this partition.""" - try: - return self.__partition.get_name() - except parted.PartitionException: - return None - - @property - def number(self): - """The partition number.""" - return self.__partition.num - - fileSystem = property(lambda s: s._fileSystem, lambda s, v: setattr(s, "_fileSystem", v)) - geometry = property(lambda s: s._geometry, lambda s, v: setattr(s, "_geometry", v)) - system = property(lambda s: s.__writeOnly("system"), lambda s, v: s.__partition.set_system(v)) - type = property(lambda s: s.__partition.type, lambda s, v: setattr(s.__partition, "type", v)) - - @localeC - def getFlag(self, flag): - """Get the value of a particular flag on the partition. Valid flags - are the _ped.PARTITION_* constants. See _ped.flag_get_name() and - _ped.flag_get_by_name() for more help working with partition flags. - """ - return self.__partition.get_flag(flag) - - @localeC - def setFlag(self, flag): - """Set the flag on a partition to the provided value. On error, a - PartitionException will be raised. See getFlag() for more help on - working with partition flags.""" - return self.__partition.set_flag(flag, 1) - - @localeC - def unsetFlag(self, flag): - """Unset the flag on this Partition. On error, a PartitionException - will be raised. See getFlag() for more help on working with - partition flags.""" - return self.__partition.set_flag(flag, 0) - - @localeC - def getMaxGeometry(self, constraint): - """Given a constraint, return the maximum Geometry that self can be - grown to. Raises Partitionexception on error.""" - return parted.Geometry(PedGeometry=self.disk.getPedDisk().get_max_partition_geometry(self.__partition, constraint.getPedConstraint())) - - @localeC - def isFlagAvailable(self, flag): - """Return True if flag is available on this Partition, False - otherwise.""" - return self.__partition.is_flag_available(flag) - - @localeC - def nextPartition(self): - """Return the Partition following this one on the Disk.""" - partition = self.disk.getPedDisk().next_partition(self.__partition) - - if partition is None: - return None - else: - return parted.Partition(disk=self.disk, PedPartition=partition) - - @localeC - def getSize(self, unit="MB"): - """Return the size of the partition in the unit specified. The unit - is given as a string corresponding to one of the following - abbreviations: b (bytes), KB (kilobytes), MB (megabytes), GB - (gigabytes), TB (terabytes). An invalid unit string will raise a - SyntaxError exception. The default unit is MB.""" - warnings.warn("use the getLength method", DeprecationWarning) - return self.geometry.getSize(unit) - - @localeC - def getLength(self, unit='sectors'): - """Return the length of the partition in sectors. Optionally, a SI or - IEC prefix followed by a 'B' may be given in order to convert the - length into bytes. The allowed values include B, kB, MB, GB, TB, KiB, - MiB, GiB, and TiB.""" - return self.geometry.getLength(unit) - - def getFlagsAsString(self): - """Return a comma-separated string representing the flags - on this partition.""" - flags = [] - - for flag in partitionFlag.keys(): - if self.getFlag(flag): - flags.append(partitionFlag[flag]) - - return ', '.join(flags) - - def getMaxAvailableSize(self, unit="MB"): - """Return the maximum size this Partition can grow to by looking - at contiguous freespace partitions. The size is returned in - the unit specified (default is megabytes). The unit is a - string corresponding to one of the following abbreviations: - b (bytes), KB (kilobytes), MB (megabytes), GB (gigabytes), - TB (terabytes). An invalid unit string will raise a - SyntaxError exception.""" - lunit = unit.lower() - - if lunit not in parted._exponent.keys(): - raise SyntaxError("invalid unit %s given" % (unit)) - - maxLength = self.geometry.length - sectorSize = self.geometry.device.sectorSize - - for partition in self.disk.partitions: - if partition.type & parted.PARTITION_FREESPACE: - maxLength += partition.geometry.length - else: - break - - return math.floor(maxLength * math.pow(sectorSize, parted._exponent[lunit])) - - def getDeviceNodeName(self): - """Return the device name for this Partition.""" - return self.path[5:] - - def getPedPartition(self): - """Return the _ped.Partition object contained in this Partition. - For internal module use only.""" - return self.__partition - - def resetNumber(self): - """Reset the partition's number to default""" - return self.__partition.reset_num() - -# collect all partition flags and store them in a hash -partitionFlag = {} -__flag = _ped.partition_flag_next(0) -partitionFlag[__flag] = _ped.partition_flag_get_name(__flag) -__readFlags = True - -while __readFlags: - __flag = _ped.partition_flag_next(__flag) - if not __flag: - __readFlags = False - else: - partitionFlag[__flag] = _ped.partition_flag_get_name(__flag) diff --git a/src/pyconstraint.c b/src/pyconstraint.c deleted file mode 100644 index 3fa9498..0000000 --- a/src/pyconstraint.c +++ /dev/null @@ -1,638 +0,0 @@ -/* - * pyconstraint.c - * - * Copyright (C) 2007-2013 Red Hat, Inc. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions of - * the GNU General Public License v.2, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY expressed or implied, including the implied warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. Any Red Hat trademarks that are incorporated in the - * source code or documentation are not subject to the GNU General Public - * License and may only be used or replicated with the express permission of - * Red Hat, Inc. - * - * Author(s): David Cantrell - * Chris Lumens - * Alex Skinner - */ - -#include - -#include "convert.h" -#include "exceptions.h" -#include "pyconstraint.h" -#include "pygeom.h" -#include "pynatmath.h" -#include "docstrings/pyconstraint.h" -#include "typeobjects/pyconstraint.h" - -/* _ped.Constraint functions */ -void _ped_Constraint_dealloc(_ped_Constraint *self) { - PyObject_GC_UnTrack(self); - - Py_CLEAR(self->start_align); - self->start_align = NULL; - - Py_CLEAR(self->end_align); - self->end_align = NULL; - - Py_CLEAR(self->start_range); - self->start_range = NULL; - - Py_CLEAR(self->end_range); - self->end_range = NULL; - - PyObject_GC_Del(self); -} - -int _ped_Constraint_compare(_ped_Constraint *self, PyObject *obj) { - _ped_Constraint *comp = NULL; - int check = PyObject_IsInstance(obj, (PyObject *) &_ped_Constraint_Type_obj); - - if (PyErr_Occurred()) { - return -1; - } - - if (!check) { - PyErr_SetString(PyExc_ValueError, "object comparing to must be a _ped.Constraint"); - return -1; - } - - comp = (_ped_Constraint *) obj; - if ((_ped_Alignment_Type_obj.tp_richcompare(self->start_align, comp->start_align, Py_EQ)) && - (_ped_Alignment_Type_obj.tp_richcompare(self->end_align, comp->end_align, Py_EQ)) && - (_ped_Geometry_Type_obj.tp_richcompare(self->start_range, comp->start_range, Py_EQ)) && - (_ped_Geometry_Type_obj.tp_richcompare(self->end_range, comp->end_range, Py_EQ)) && - (self->min_size == comp->min_size) && - (self->max_size == comp->max_size)) { - return 0; - } else { - return 1; - } -} - -PyObject *_ped_Constraint_richcompare(_ped_Constraint *a, PyObject *b, int op) { - if (op == Py_EQ || op == Py_NE) { - int rv = _ped_Constraint_compare(a, b); - if (PyErr_Occurred()) - return NULL; - return PyBool_FromLong(op == Py_EQ ? rv == 0 : rv != 0); - } else if ((op == Py_LT) || (op == Py_LE) || - (op == Py_GT) || (op == Py_GE)) { - PyErr_SetString(PyExc_TypeError, "comparison operator not supported for _ped.Constraint"); - return NULL; - } else { - PyErr_SetString(PyExc_ValueError, "unknown richcompare op"); - return NULL; - } -} - -PyObject *_ped_Constraint_str(_ped_Constraint *self) { - char *ret = NULL; - char *start_align = NULL, *end_align = NULL; - char *start_range = NULL, *end_range = NULL; - - start_align = -PyUnicode_AsUTF8(_ped_Alignment_Type_obj.tp_repr(self->start_align)); - if (start_align == NULL) { - return NULL; - } - - end_align = -PyUnicode_AsUTF8(_ped_Alignment_Type_obj.tp_repr(self->end_align)); - if (end_align == NULL) { - return NULL; - } - - start_range = -PyUnicode_AsUTF8(_ped_Geometry_Type_obj.tp_repr(self->start_range)); - if (start_range == NULL) { - return NULL; - } - - end_range = -PyUnicode_AsUTF8(_ped_Geometry_Type_obj.tp_repr(self->end_range)); - if (end_range == NULL) { - return NULL; - } - - if (asprintf(&ret, "_ped.Constraint instance --\n" - " start_align: %s end_align: %s\n" - " start_range: %s end_range: %s\n" - " min_size: %lld max_size: %lld", - start_align, end_align, - start_range, end_range, - self->min_size, self->max_size) == -1) { - return PyErr_NoMemory(); - } - - return Py_BuildValue("s", ret); -} - -int _ped_Constraint_traverse(_ped_Constraint *self, visitproc visit, void *arg) { - int err; - - if (self->start_align) { - if ((err = visit(self->start_align, arg))) { - return err; - } - } - - if (self->end_align) { - if ((err = visit(self->end_align, arg))) { - return err; - } - } - - if (self->start_range) { - if ((err = visit(self->start_range, arg))) { - return err; - } - } - - if (self->end_range) { - if ((err = visit(self->end_range, arg))) { - return err; - } - } - - return 0; -} - -int _ped_Constraint_clear(_ped_Constraint *self) { - Py_CLEAR(self->start_align); - self->start_align = NULL; - - Py_CLEAR(self->end_align); - self->end_align = NULL; - - Py_CLEAR(self->start_range); - self->start_range = NULL; - - Py_CLEAR(self->end_range); - self->end_range = NULL; - - return 0; -} - -int _ped_Constraint_init(_ped_Constraint *self, PyObject *args, - PyObject *kwds) { - static char *kwlist[] = {"start_align", "end_align", "start_range", - "end_range", "min_size", "max_size", NULL}; - PedConstraint *constraint = NULL; - PedAlignment *start_align = NULL, *end_align = NULL; - PedGeometry *start_range = NULL, *end_range = NULL; - - if (kwds == NULL) { - if (!PyArg_ParseTuple(args, "O!O!O!O!LL", - &_ped_Alignment_Type_obj, &self->start_align, - &_ped_Alignment_Type_obj, &self->end_align, - &_ped_Geometry_Type_obj, &self->start_range, - &_ped_Geometry_Type_obj, &self->end_range, - &self->min_size, &self->max_size)) { - self->start_align = self->end_align = NULL; - self->start_range = self->end_range = NULL; - return -1; - } - } else { - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!O!O!O!LL", kwlist, - &_ped_Alignment_Type_obj, - &self->start_align, - &_ped_Alignment_Type_obj, - &self->end_align, - &_ped_Geometry_Type_obj, - &self->start_range, - &_ped_Geometry_Type_obj, - &self->end_range, - &self->min_size, - &self->max_size)) { - self->start_align = self->end_align = NULL; - self->start_range = self->end_range = NULL; - return -2; - } - } - - /* - * try to call libparted with provided information, - * on failure, raise an exception - */ - start_align = _ped_Alignment2PedAlignment(self->start_align); - end_align = _ped_Alignment2PedAlignment(self->end_align); - start_range = _ped_Geometry2PedGeometry(self->start_range); - end_range = _ped_Geometry2PedGeometry(self->end_range); - - constraint = ped_constraint_new(start_align, end_align, - start_range, end_range, - self->min_size, self->max_size); - if (constraint == NULL) { - PyErr_SetString(CreateException, "Could not create new constraint"); - - ped_alignment_destroy(start_align); - ped_alignment_destroy(end_align); - self->start_align = NULL; - self->end_align = NULL; - self->start_range = NULL; - self->end_range = NULL; - return -3; - } - - /* increment reference count for PyObjects read by PyArg_ParseTuple */ - Py_INCREF(self->start_align); - Py_INCREF(self->end_align); - Py_INCREF(self->start_range); - Py_INCREF(self->end_range); - - /* clean up libparted objects we created */ - ped_alignment_destroy(start_align); - ped_alignment_destroy(end_align); - ped_constraint_destroy(constraint); - return 0; -} - -PyObject *_ped_Constraint_get(_ped_Constraint *self, void *closure) { - char *member = (char *) closure; - - if (member == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty _ped.Constraint()"); - return NULL; - } - - if (!strcmp(member, "min_size")) { - return PyLong_FromLong(self->min_size); - } else if (!strcmp(member, "max_size")) { - return PyLong_FromLong(self->max_size); - } else { - PyErr_Format(PyExc_AttributeError, "_ped.Constraint object has no attribute %s", member); - return NULL; - } -} - -int _ped_Constraint_set(_ped_Constraint *self, PyObject *value, void *closure) { - char *member = (char *) closure; - - if (member == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty _ped.Constraint()"); - return -1; - } - - if (!strcmp(member, "min_size")) { - self->min_size = PyLong_AsLong(value); - if (PyErr_Occurred()) { - return -1; - } - } else if (!strcmp(member, "max_size")) { - self->max_size = PyLong_AsLong(value); - if (PyErr_Occurred()) { - return -1; - } - } else { - PyErr_Format(PyExc_AttributeError, "_ped.Constraint object has no attribute %s", member); - return -1; - } - - return 0; -} - -/* 1:1 function mappings for constraint.h in libparted */ -PyObject *py_ped_constraint_new_from_min_max(PyObject *s, PyObject *args) { - PyObject *in_min = NULL, *in_max = NULL; - PedGeometry *out_min = NULL, *out_max = NULL; - PedConstraint *constraint = NULL; - _ped_Constraint *ret = NULL; - - if (!PyArg_ParseTuple(args, "O!O!", &_ped_Geometry_Type_obj, &in_min, - &_ped_Geometry_Type_obj, &in_max)) { - return NULL; - } - - out_min = _ped_Geometry2PedGeometry(in_min); - if (out_min == NULL) { - return NULL; - } - - out_max = _ped_Geometry2PedGeometry(in_max); - if (out_max == NULL) { - return NULL; - } - - /* ped_constraint_new_from_min_max will ASSERT if this isn't enforced. */ - if (!ped_geometry_test_inside(out_max, out_min)) { - PyErr_SetString(CreateException, "min geometry must be contained within max geometry"); - return NULL; - } - - constraint = ped_constraint_new_from_min_max(out_min, out_max); - if (constraint) { - ret = PedConstraint2_ped_Constraint(constraint); - } - else { - PyErr_SetString(CreateException, "Could not create new constraint from min/max"); - return NULL; - } - - ped_constraint_destroy(constraint); - - return (PyObject *) ret; -} - -PyObject *py_ped_constraint_new_from_min(PyObject *s, PyObject *args) { - PyObject *in_min = NULL; - PedGeometry *out_min = NULL; - PedConstraint *constraint = NULL; - _ped_Constraint *ret = NULL; - - if (!PyArg_ParseTuple(args, "O!", &_ped_Geometry_Type_obj, &in_min)) { - return NULL; - } - - out_min = _ped_Geometry2PedGeometry(in_min); - if (out_min == NULL) { - return NULL; - } - - constraint = ped_constraint_new_from_min(out_min); - if (constraint) { - ret = PedConstraint2_ped_Constraint(constraint); - } - else { - PyErr_SetString(CreateException, "Could not create new constraint from min"); - return NULL; - } - - ped_constraint_destroy(constraint); - - return (PyObject *) ret; -} - -PyObject *py_ped_constraint_new_from_max(PyObject *s, PyObject *args) { - PyObject *in_max = NULL; - PedGeometry *out_max = NULL; - PedConstraint *constraint = NULL; - _ped_Constraint *ret = NULL; - - if (!PyArg_ParseTuple(args, "O!", &_ped_Geometry_Type_obj, &in_max)) { - return NULL; - } - - out_max = _ped_Geometry2PedGeometry(in_max); - if (out_max == NULL) { - return NULL; - } - - constraint = ped_constraint_new_from_max(out_max); - if (constraint) { - ret = PedConstraint2_ped_Constraint(constraint); - } - else { - PyErr_SetString(CreateException, "Could not create new constraint from max"); - return NULL; - } - - ped_constraint_destroy(constraint); - - return (PyObject *) ret; -} - -/* XXX: Remove this function at some point in the future. The deprecation - * warning tells people what they should be doing. - */ -PyObject *py_ped_constraint_duplicate(PyObject *s, PyObject *args) { - PedConstraint *constraint = NULL, *dup_constraint = NULL; - _ped_Constraint *ret = NULL; - - constraint = _ped_Constraint2PedConstraint(s); - if (constraint == NULL) { - return NULL; - } - - if (PyErr_WarnEx(PyExc_DeprecationWarning, - "use copy.deepcopy() to duplicate a _ped.Constraint", - 1) == -1) { - return NULL; - } - - dup_constraint = ped_constraint_duplicate(constraint); - ped_constraint_destroy(constraint); - - if (dup_constraint) { - ret = PedConstraint2_ped_Constraint(dup_constraint); - } else { - PyErr_SetString(CreateException, "Could not duplicate constraint"); - return NULL; - } - - ped_constraint_destroy(dup_constraint); - - return (PyObject *) ret; -} - -PyObject *py_ped_constraint_intersect(PyObject *s, PyObject *args) { - PyObject *in_constraintB = NULL; - PedConstraint *constraintA = NULL, *constraintB = NULL; - PedConstraint *constraint = NULL; - _ped_Constraint *ret = NULL; - - if (!PyArg_ParseTuple(args, "O!", &_ped_Constraint_Type_obj, - &in_constraintB)) { - return NULL; - } - - constraintA = _ped_Constraint2PedConstraint(s); - if (constraintA == NULL) { - return NULL; - } - - constraintB = _ped_Constraint2PedConstraint(in_constraintB); - if (constraintB == NULL) { - ped_constraint_destroy(constraintA); - return NULL; - } - - constraint = ped_constraint_intersect(constraintA, constraintB); - - ped_constraint_destroy(constraintA); - ped_constraint_destroy(constraintB); - - if (constraint) { - ret = PedConstraint2_ped_Constraint(constraint); - } - else { - PyErr_SetString(PyExc_ArithmeticError, "Could not find constraint intersection"); - return NULL; - } - - ped_constraint_destroy(constraint); - - return (PyObject *) ret; -} - -PyObject *py_ped_constraint_solve_max(PyObject *s, PyObject *args) { - PedConstraint *constraint = NULL; - PedGeometry *geometry = NULL; - _ped_Geometry *ret = NULL; - - constraint = _ped_Constraint2PedConstraint(s); - if (constraint == NULL) { - return NULL; - } - - geometry = ped_constraint_solve_max(constraint); - - ped_constraint_destroy(constraint); - - if (geometry) { - ret = PedGeometry2_ped_Geometry(geometry); - } - else { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(ConstraintException, partedExnMessage); - } - else - PyErr_SetString(PyExc_ArithmeticError, "Could not find largest region satisfying constraint"); - - return NULL; - } - - return (PyObject *) ret; -} - -PyObject *py_ped_constraint_solve_nearest(PyObject *s, PyObject *args) { - PyObject *in_geometry = NULL; - PedConstraint *constraint = NULL; - PedGeometry *out_geometry = NULL; - PedGeometry *geometry = NULL; - _ped_Geometry *ret = NULL; - - if (!PyArg_ParseTuple(args, "O!", &_ped_Geometry_Type_obj, - &in_geometry)) { - return NULL; - } - - constraint = _ped_Constraint2PedConstraint(s); - if (constraint == NULL) { - return NULL; - } - - out_geometry = _ped_Geometry2PedGeometry(in_geometry); - if (out_geometry == NULL) { - ped_constraint_destroy(constraint); - return NULL; - } - - geometry = ped_constraint_solve_nearest(constraint, out_geometry); - - ped_constraint_destroy(constraint); - - if (geometry) { - ret = PedGeometry2_ped_Geometry(geometry); - } - else { - PyErr_SetString(PyExc_ArithmeticError, "Could not find region nearest to constraint for given geometry"); - return NULL; - } - - return (PyObject *) ret; -} - -PyObject *py_ped_constraint_is_solution(PyObject *s, PyObject *args) { - PyObject *in_geometry = NULL; - PedConstraint *constraint = NULL; - PedGeometry *out_geometry = NULL; - int ret = 0; - - if (!PyArg_ParseTuple(args, "O!", &_ped_Geometry_Type_obj, - &in_geometry)) { - return NULL; - } - - constraint = _ped_Constraint2PedConstraint(s); - if (constraint == NULL) { - return NULL; - } - - out_geometry = _ped_Geometry2PedGeometry(in_geometry); - if (out_geometry == NULL) { - ped_constraint_destroy(constraint); - return NULL; - } - - ret = ped_constraint_is_solution(constraint, out_geometry); - ped_constraint_destroy(constraint); - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_constraint_any(PyObject *s, PyObject *args) { - PyObject *in_device = NULL; - PedDevice *out_device = NULL; - PedConstraint *constraint = NULL; - _ped_Constraint *ret = NULL; - - if (!PyArg_ParseTuple(args, "O!", &_ped_Device_Type_obj, &in_device)) { - return NULL; - } - - out_device = _ped_Device2PedDevice(in_device); - if (out_device == NULL) { - return NULL; - } - - constraint = ped_constraint_any(out_device); - if (constraint) { - ret = PedConstraint2_ped_Constraint(constraint); - } - else { - PyErr_SetString(CreateException, "Could not create new constraint"); - return NULL; - } - - ped_constraint_destroy(constraint); - - return (PyObject *) ret; -} - -PyObject *py_ped_constraint_exact(PyObject *s, PyObject *args) { - PyObject *in_geometry = NULL; - PedGeometry *out_geometry = NULL; - PedConstraint *constraint = NULL; - _ped_Constraint *ret = NULL; - - if (!PyArg_ParseTuple(args, "O!", &_ped_Geometry_Type_obj, &in_geometry)) { - return NULL; - } - - out_geometry = _ped_Geometry2PedGeometry(in_geometry); - if (out_geometry == NULL) { - return NULL; - } - - constraint = ped_constraint_exact(out_geometry); - if (constraint) { - ret = PedConstraint2_ped_Constraint(constraint); - } - else { - PyErr_SetString(CreateException, "Could not create exact constraint"); - return NULL; - } - - ped_constraint_destroy(constraint); - - return (PyObject *) ret; -} - -/* vim:tw=78:ts=4:et:sw=4 - */ diff --git a/src/pydevice.c b/src/pydevice.c deleted file mode 100644 index 88d2214..0000000 --- a/src/pydevice.c +++ /dev/null @@ -1,938 +0,0 @@ -/* - * pydevice.c - * - * Copyright (C) 2007-2013 Red Hat, Inc. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions of - * the GNU General Public License v.2, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY expressed or implied, including the implied warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. Any Red Hat trademarks that are incorporated in the - * source code or documentation are not subject to the GNU General Public - * License and may only be used or replicated with the express permission of - * Red Hat, Inc. - * - * Author(s): David Cantrell - * Chris Lumens - * Alex Skinner - */ - -#include - -#include "convert.h" -#include "exceptions.h" -#include "pyconstraint.h" -#include "pydevice.h" -#include "docstrings/pydevice.h" -#include "typeobjects/pydevice.h" - -/* _ped.CHSGeometry functions */ -void _ped_CHSGeometry_dealloc(_ped_CHSGeometry *self) { - PyObject_GC_UnTrack(self); - PyObject_GC_Del(self); -} - -int _ped_CHSGeometry_compare(_ped_CHSGeometry *self, PyObject *obj) { - _ped_CHSGeometry *comp = NULL; - int check = PyObject_IsInstance(obj, (PyObject *) &_ped_CHSGeometry_Type_obj); - - if (PyErr_Occurred()) { - return -1; - } - - if (!check) { - PyErr_SetString(PyExc_ValueError, "object comparing to must be a _ped.CHSGeometry"); - return -1; - } - - comp = (_ped_CHSGeometry *) obj; - if ((self->cylinders == comp->cylinders) && - (self->heads == comp->heads) && - (self->sectors == comp->sectors)) { - return 0; - } else { - return 1; - } -} - -PyObject *_ped_CHSGeometry_richcompare(_ped_CHSGeometry *a, PyObject *b, - int op) { - if (op == Py_EQ || op == Py_NE) { - int rv = _ped_CHSGeometry_compare(a, b); - if (PyErr_Occurred()) - return NULL; - return PyBool_FromLong(op == Py_EQ ? rv == 0 : rv != 0); - } else if ((op == Py_LT) || (op == Py_LE) || - (op == Py_GT) || (op == Py_GE)) { - PyErr_SetString(PyExc_TypeError, "comparison operator not supported for _ped.CHSGeometry"); - return NULL; - } else { - PyErr_SetString(PyExc_ValueError, "unknown richcompare op"); - return NULL; - } -} - -PyObject *_ped_CHSGeometry_str(_ped_CHSGeometry *self) { - char *ret = NULL; - - if (asprintf(&ret, "_ped.CHSGeometry instance --\n" - " cylinders: %d heads: %d sectors: %d", - self->cylinders, self->heads, self->sectors) == -1) { - return PyErr_NoMemory(); - } - - return Py_BuildValue("s", ret); -} - -int _ped_CHSGeometry_traverse(_ped_CHSGeometry *self, visitproc visit, void *arg) { - return 0; -} - -int _ped_CHSGeometry_clear(_ped_CHSGeometry *self) { - return 0; -} - -PyObject *_ped_CHSGeometry_get(_ped_CHSGeometry *self, void *closure) { - char *member = (char *) closure; - - if (member == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty _ped.CHSGeometry()"); - return NULL; - } - - if (!strcmp(member, "cylinders")) { - return Py_BuildValue("i", self->cylinders); - } else if (!strcmp(member, "heads")) { - return Py_BuildValue("i", self->heads); - } else if (!strcmp(member, "sectors")) { - return Py_BuildValue("i", self->sectors); - } else { - PyErr_Format(PyExc_AttributeError, "_ped.CHSGeometry object has no attribute %s", member); - return NULL; - } -} - -/* _ped.Device functions */ -void _ped_Device_dealloc(_ped_Device *self) { - PyObject_GC_UnTrack(self); - - free(self->model); - free(self->path); - - Py_CLEAR(self->hw_geom); - self->hw_geom = NULL; - - Py_CLEAR(self->bios_geom); - self->bios_geom = NULL; - - PyObject_GC_Del(self); -} - -int _ped_Device_compare(_ped_Device *self, PyObject *obj) { - _ped_Device *comp = NULL; - int check = PyObject_IsInstance(obj, (PyObject *) &_ped_Device_Type_obj); - - if (PyErr_Occurred()) { - return -1; - } - - if (!check) { - PyErr_SetString(PyExc_ValueError, "object comparing to must be a _ped.Device"); - return -1; - } - - comp = (_ped_Device *) obj; - if ((!strcmp(self->model, comp->model)) && - (!strcmp(self->path, comp->path)) && - (self->type == comp->type) && - (self->sector_size == comp->sector_size) && - (self->phys_sector_size == comp->phys_sector_size) && - (self->length == comp->length) && - (self->open_count == comp->open_count) && - (self->read_only == comp->read_only) && - (self->external_mode == comp->external_mode) && - (self->dirty == comp->dirty) && - (self->boot_dirty == comp->dirty) && - (_ped_CHSGeometry_Type_obj.tp_richcompare(self->hw_geom, comp->hw_geom, Py_EQ)) && - (_ped_CHSGeometry_Type_obj.tp_richcompare(self->bios_geom, comp->bios_geom, Py_EQ)) && - (self->host == comp->host) && - (self->did == comp->did)) { - return 0; - } else { - return 1; - } -} - -PyObject *_ped_Device_richcompare(_ped_Device *a, PyObject *b, int op) { - if (op == Py_EQ || op == Py_NE) { - int rv = _ped_Device_compare(a, b); - if (PyErr_Occurred()) - return NULL; - return PyBool_FromLong(op == Py_EQ ? rv == 0 : rv != 0); - } else if ((op == Py_LT) || (op == Py_LE) || - (op == Py_GT) || (op == Py_GE)) { - PyErr_SetString(PyExc_TypeError, "comparison operator not supported for _ped.Device"); - return NULL; - } else { - PyErr_SetString(PyExc_ValueError, "unknown richcompare op"); - return NULL; - } -} - -PyObject *_ped_Device_str(_ped_Device *self) { - char *ret = NULL; - char *hw_geom = NULL, *bios_geom = NULL; - - hw_geom = PyUnicode_AsUTF8(_ped_CHSGeometry_Type_obj.tp_repr(self->hw_geom)); - if (hw_geom == NULL) { - return NULL; - } - - bios_geom = PyUnicode_AsUTF8(_ped_CHSGeometry_Type_obj.tp_repr(self->bios_geom)); - if (bios_geom == NULL) { - return NULL; - } - - if (asprintf(&ret, "_ped.Device instance --\n" - " model: %s path: %s type: %lld\n" - " sector_size: %lld phys_sector_size: %lld\n" - " length: %lld open_count: %d read_only: %d\n" - " external_mode: %d dirty: %d boot_dirty: %d\n" - " host: %hd did: %hd\n" - " hw_geom: %s bios_geom: %s", - self->model, self->path, self->type, - self->sector_size, self->phys_sector_size, - self->length, self->open_count, self->read_only, - self->external_mode, self->dirty, self->boot_dirty, - self->host, self->did, - hw_geom, bios_geom) == -1) { - return PyErr_NoMemory(); - } - - return Py_BuildValue("s", ret); -} - -int _ped_Device_traverse(_ped_Device *self, visitproc visit, void *arg) { - int err; - - if (self->hw_geom) { - if ((err = visit(self->hw_geom, arg))) { - return err; - } - } - - if (self->bios_geom) { - if ((err = visit(self->bios_geom, arg))) { - return err; - } - } - - return 0; -} - -int _ped_Device_clear(_ped_Device *self) { - Py_CLEAR(self->hw_geom); - self->hw_geom = NULL; - - Py_CLEAR(self->bios_geom); - self->bios_geom = NULL; - - return 0; -} - -PyObject *_ped_Device_get(_ped_Device *self, void *closure) { - char *member = (char *) closure; - - if (member == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty _ped.Device()"); - return NULL; - } - - if (!strcmp(member, "model")) { - if (self->model != NULL) - return PyUnicode_FromString(self->model); - else - return PyUnicode_FromString(""); - } else if (!strcmp(member, "path")) { - if (self->path != NULL) - return PyUnicode_FromString(self->path); - else - return PyUnicode_FromString(""); - } else if (!strcmp(member, "type")) { - return PyLong_FromLong(self->type); - } else if (!strcmp(member, "sector_size")) { - return PyLong_FromLong(self->sector_size); - } else if (!strcmp(member, "phys_sector_size")) { - return PyLong_FromLong(self->phys_sector_size); - } else if (!strcmp(member, "length")) { - return PyLong_FromLong(self->length); - } else if (!strcmp(member, "open_count")) { - return Py_BuildValue("i", self->open_count); - } else if (!strcmp(member, "read_only")) { - return Py_BuildValue("i", self->read_only); - } else if (!strcmp(member, "external_mode")) { - return Py_BuildValue("i", self->external_mode); - } else if (!strcmp(member, "dirty")) { - return Py_BuildValue("i", self->dirty); - } else if (!strcmp(member, "boot_dirty")) { - return Py_BuildValue("i", self->boot_dirty); - } else if (!strcmp(member, "host")) { - return Py_BuildValue("h", self->host); - } else if (!strcmp(member, "did")) { - return Py_BuildValue("h", self->did); - } else { - PyErr_Format(PyExc_AttributeError, "_ped.Device object has no attribute %s", member); - return NULL; - } -} - -/* - * Returns the _ped.DiskType for the specified _ped.Device. - * Even though this function is part of pydisk.c, it's a method - * on _ped.Device since it operates on _ped.Device objects and - * not on _ped.Disk objects. - */ -PyObject *py_ped_disk_probe(PyObject *s, PyObject *args) { - PedDevice *device = NULL; - PedDiskType *type = NULL; - _ped_DiskType *ret = NULL; - - device = _ped_Device2PedDevice(s); - if (device) { - type = ped_disk_probe(device); - if (type == NULL) { - PyErr_Format(IOException, "Could not probe device %s", device->path); - return NULL; - } - - ret = PedDiskType2_ped_DiskType(type); - if (ret == NULL) { - return NULL; - } - } - - return (PyObject *) ret; -} - -/* 1:1 function mappings for device.h in libparted */ -PyObject *py_ped_device_probe_all(PyObject *s, PyObject *args) { - ped_device_probe_all(); - - Py_INCREF(Py_None); - return Py_None; -} - -PyObject *py_ped_device_free_all(PyObject *s, PyObject *args) { - ped_device_free_all(); - - Py_INCREF(Py_None); - return Py_None; -} - -PyObject *py_ped_device_get(PyObject *s, PyObject *args) { - PedDevice *device = NULL; - _ped_Device *ret = NULL; - char *path = NULL; - - if (!PyArg_ParseTuple(args, "z", &path)) { - return NULL; - } - - if (path == NULL) { - PyErr_Format(DeviceException, "Could not find device for empty path"); - return NULL; - } - - device = ped_device_get(path); - if (device) { - ret = PedDevice2_ped_Device(device); - } - else { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(IOException, partedExnMessage); - } - else - PyErr_Format(DeviceException, "Could not find device for path %s", path); - - return NULL; - } - - return (PyObject *) ret; -} - -PyObject *py_ped_device_get_next(PyObject *s, PyObject *args) { - PyObject *in_device = NULL; - PedDevice *cur = NULL, *next = NULL; - _ped_Device *ret = NULL; - - if (!PyArg_ParseTuple(args, "|O!", &_ped_Device_Type_obj, &in_device)) { - return NULL; - } - - if (in_device) { - cur = _ped_Device2PedDevice(in_device); - if (!cur) { - return NULL; - } - } - - next = ped_device_get_next(cur); - if (next) { - ret = PedDevice2_ped_Device(next); - return (PyObject *) ret; - } - else { - PyErr_SetNone(PyExc_IndexError); - return NULL; - } -} - -PyObject *py_ped_device_is_busy(PyObject *s, PyObject *args) { - int ret = -1; - PedDevice *device = NULL; - - device = _ped_Device2PedDevice(s); - if (device == NULL) { - return NULL; - } - - ret = ped_device_is_busy(device); - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_device_open(PyObject *s, PyObject *args) { - int ret = -1; - PedDevice *device = NULL; - - device = _ped_Device2PedDevice(s); - if (device == NULL) { - return NULL; - } - - if (device->external_mode) { - PyErr_Format(IOException, "Device %s is already open for external access.", device->path); - return NULL; - } - - ret = ped_device_open(device); - if (ret == 0) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(IOException, partedExnMessage); - } - else - PyErr_Format(IOException, "Could not open device %s", device->path); - - return NULL; - } - - ((_ped_Device *) s)->open_count = device->open_count; - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_device_close(PyObject *s, PyObject *args) { - int ret = -1; - PedDevice *device = NULL; - - device = _ped_Device2PedDevice(s); - if (device == NULL) { - return NULL; - } - - if (!device->open_count) { - PyErr_Format(IOException, "Device %s is not open.", device->path); - return NULL; - } - - if (device->external_mode) { - PyErr_Format(IOException, "Device %s is already open for external access.", device->path); - return NULL; - } - - ret = ped_device_close(device); - if (ret == 0) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(IOException, partedExnMessage); - } - else - PyErr_Format(IOException, "Could not close device %s", device->path); - - return NULL; - } - - ((_ped_Device *) s)->open_count = device->open_count; - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_device_destroy(PyObject *s, PyObject *args) { - _ped_Device *dev = (_ped_Device *) s; - PedDevice *device = NULL; - - device = _ped_Device2PedDevice(s); - if (device == NULL) { - return NULL; - } - - ped_device_destroy(device); - - Py_CLEAR(dev->hw_geom); - dev->hw_geom = NULL; - - Py_CLEAR(dev->bios_geom); - dev->bios_geom = NULL; - - Py_CLEAR(dev); - - Py_INCREF(Py_None); - return Py_None; -} - -PyObject *py_ped_device_cache_remove(PyObject *s, PyObject *args) { - PedDevice *device = NULL; - - device = _ped_Device2PedDevice(s); - if (device == NULL) { - return NULL; - } - - ped_device_cache_remove(device); - - Py_INCREF(Py_None); - return Py_None; -} - -PyObject *py_ped_device_begin_external_access(PyObject *s, PyObject *args) { - int ret = -1; - PedDevice *device = NULL; - - device = _ped_Device2PedDevice(s); - if (device == NULL) { - return NULL; - } - - if (device->external_mode) { - PyErr_Format(IOException, "Device %s is already open for external access.", device->path); - return NULL; - } - - ret = ped_device_begin_external_access(device); - if (ret == 0) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(IOException, partedExnMessage); - } - else - PyErr_Format(IOException, "Could not begin external access mode on device %s", device->path); - - return NULL; - } - - ((_ped_Device *) s)->external_mode = device->external_mode; - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_device_end_external_access(PyObject *s, PyObject *args) { - int ret = -1; - PedDevice *device = NULL; - - device = _ped_Device2PedDevice(s); - if (device == NULL) { - return NULL; - } - - if (!device->external_mode) { - PyErr_Format(IOException, "Device %s is not open for external access.", device->path); - return NULL; - } - - ret = ped_device_end_external_access(device); - if (ret == 0) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(IOException, partedExnMessage); - } - else - PyErr_Format(IOException, "Could not end external access mode on device %s", device->path); - - return NULL; - } - - ((_ped_Device *) s)->external_mode = device->external_mode; - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_device_read(PyObject *s, PyObject *args) { - PyObject *ret = NULL; - PedSector start, count; - PedDevice *device = NULL; - char *out_buf = NULL; - - if (!PyArg_ParseTuple(args, "LL", &start, &count)) { - return NULL; - } - - device = _ped_Device2PedDevice(s); - if (device == NULL) { - return NULL; - } - - if (!device->open_count) { - PyErr_Format(IOException, "Device %s is not open.", device->path); - return NULL; - } - - if (device->external_mode) { - PyErr_Format(IOException, "Device %s is already open for external access.", device->path); - return NULL; - } - - if ((out_buf = malloc(device->sector_size * count)) == NULL) { - return PyErr_NoMemory(); - } - - if (ped_device_read(device, out_buf, start, count) == 0) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(IOException, partedExnMessage); - } - else - PyErr_Format(IOException, "Could not read from device %s", device->path); - - free(out_buf); - return NULL; - } - - ret = PyUnicode_FromString(out_buf); - free(out_buf); - - return ret; -} - -PyObject *py_ped_device_write(PyObject *s, PyObject *args) { - PyObject *in_buf = NULL; - PedSector start, count, ret; - PedDevice *device = NULL; - void *out_buf = NULL; - - if (!PyArg_ParseTuple(args, "OLL", &in_buf, &start, &count)) { - return NULL; - } - - device = _ped_Device2PedDevice(s); - if (device == NULL) { - return NULL; - } - - out_buf = PyCapsule_GetPointer(in_buf, 0); - if (out_buf == NULL) { - return NULL; - } - - if (!device->open_count) { - PyErr_Format(IOException, "Device %s is not open.", device->path); - return NULL; - } - - if (device->external_mode) { - PyErr_Format(IOException, "Device %s is already open for external access.", device->path); - return NULL; - } - - ret = ped_device_write(device, out_buf, start, count); - if (ret == 0) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(IOException, partedExnMessage); - } - else - PyErr_Format(IOException, "Could not write to device %s", device->path); - - return NULL; - } - - return PyLong_FromLong(ret); -} - -PyObject *py_ped_device_sync(PyObject *s, PyObject *args) { - int ret = -1; - PedDevice *device = NULL; - - device = _ped_Device2PedDevice(s); - if (device == NULL) { - return NULL; - } - - if (!device->open_count) { - PyErr_Format(IOException, "Device %s is not open.", device->path); - return NULL; - } - - if (device->external_mode) { - PyErr_Format(IOException, "Device %s is already open for external access.", device->path); - return NULL; - } - - ret = ped_device_sync(device); - if (ret == 0) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(IOException, partedExnMessage); - } - else - PyErr_Format(IOException, "Could not sync device %s", device->path); - - return NULL; - } - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_device_sync_fast(PyObject *s, PyObject *args) { - int ret = -1; - PedDevice *device = NULL; - - device = _ped_Device2PedDevice(s); - if (device == NULL) { - return NULL; - } - - if (!device->open_count) { - PyErr_Format(IOException, "Device %s is not open.", device->path); - return NULL; - } - - if (device->external_mode) { - PyErr_Format(IOException, "Device %s is already open for external access.", device->path); - return NULL; - } - - ret = ped_device_sync_fast(device); - if (ret == 0) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(IOException, partedExnMessage); - } - else - PyErr_Format(IOException, "Could not sync device %s", device->path); - - return NULL; - } - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_device_check(PyObject *s, PyObject *args) { - PedSector start, count, ret; - PedDevice *device = NULL; - char *out_buf = NULL; - - if (!PyArg_ParseTuple(args, "LL", &start, &count)) { - return NULL; - } - - device = _ped_Device2PedDevice(s); - if (device == NULL) { - return NULL; - } - - if (!device->open_count) { - PyErr_Format(IOException, "Device %s is not open.", device->path); - return NULL; - } - - if (device->external_mode) { - PyErr_Format(IOException, "Device %s is already open for external access.", device->path); - return NULL; - } - - if ((out_buf = malloc(device->sector_size * 32)) == NULL) { - return PyErr_NoMemory(); - } - - ret = ped_device_check(device, out_buf, start, count); - free(out_buf); - - return PyLong_FromLong(ret); -} - -PyObject *py_ped_device_get_constraint(PyObject *s, PyObject *args) { - PedDevice *device = NULL; - PedConstraint *constraint = NULL; - _ped_Constraint *ret = NULL; - - device = _ped_Device2PedDevice(s); - if (device == NULL) { - return NULL; - } - - constraint = ped_device_get_constraint(device); - if (constraint) { - ret = PedConstraint2_ped_Constraint(constraint); - } - else { - PyErr_SetString(CreateException, "Could not create constraint"); - return NULL; - } - - ped_constraint_destroy(constraint); - - return (PyObject *) ret; -} - -PyObject *py_ped_device_get_minimal_aligned_constraint(PyObject *s, PyObject *args) { - PedDevice *device = NULL; - PedConstraint *constraint = NULL; - _ped_Constraint *ret = NULL; - - device = _ped_Device2PedDevice(s); - if (device == NULL) { - return NULL; - } - - constraint = ped_device_get_minimal_aligned_constraint(device); - if (!constraint) { - PyErr_SetString(CreateException, "Could not create constraint"); - return NULL; - } - - ret = PedConstraint2_ped_Constraint(constraint); - ped_constraint_destroy(constraint); - - return (PyObject *) ret; -} - -PyObject *py_ped_device_get_optimal_aligned_constraint(PyObject *s, PyObject *args) { - PedDevice *device = NULL; - PedConstraint *constraint = NULL; - _ped_Constraint *ret = NULL; - - device = _ped_Device2PedDevice(s); - if (device == NULL) { - return NULL; - } - - constraint = ped_device_get_optimal_aligned_constraint(device); - if (!constraint) { - PyErr_SetString(CreateException, "Could not create constraint"); - return NULL; - } - - ret = PedConstraint2_ped_Constraint(constraint); - ped_constraint_destroy(constraint); - - return (PyObject *) ret; -} - -PyObject *py_ped_device_get_minimum_alignment(PyObject *s, PyObject *args) { - PedDevice *device = NULL; - PedAlignment *alignment = NULL; - _ped_Alignment *ret = NULL; - - device = _ped_Device2PedDevice(s); - if (device == NULL) { - return NULL; - } - - alignment = ped_device_get_minimum_alignment(device); - if (!alignment) { - PyErr_SetString(CreateException, "Could not get alignment for device"); - return NULL; - } - - ret = PedAlignment2_ped_Alignment(alignment); - ped_alignment_destroy(alignment); - - return (PyObject *) ret; -} - -PyObject *py_ped_device_get_optimum_alignment(PyObject *s, PyObject *args) { - PedDevice *device = NULL; - PedAlignment *alignment = NULL; - _ped_Alignment *ret = NULL; - - device = _ped_Device2PedDevice(s); - if (device == NULL) { - return NULL; - } - - alignment = ped_device_get_optimum_alignment(device); - if (!alignment) { - PyErr_SetString(CreateException, "Could not get alignment for device"); - return NULL; - } - - ret = PedAlignment2_ped_Alignment(alignment); - ped_alignment_destroy(alignment); - - return (PyObject *) ret; -} - -/* vim:tw=78:ts=4:et:sw=4 - */ diff --git a/src/pydisk.c b/src/pydisk.c deleted file mode 100644 index f644a52..0000000 --- a/src/pydisk.c +++ /dev/null @@ -1,2054 +0,0 @@ -/* - * pydisk.c - * - * Copyright (C) 2007-2013 Red Hat, Inc. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions of - * the GNU General Public License v.2, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY expressed or implied, including the implied warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. Any Red Hat trademarks that are incorporated in the - * source code or documentation are not subject to the GNU General Public - * License and may only be used or replicated with the express permission of - * Red Hat, Inc. - * - * Author(s): David Cantrell - * Chris Lumens - * Alex Skinner - */ - -#include - -#include - -#include "convert.h" -#include "exceptions.h" -#include "pydisk.h" -#include "docstrings/pydisk.h" -#include "typeobjects/pydisk.h" - -/* _ped.Partition functions */ -void _ped_Partition_dealloc(_ped_Partition *self) { - PyObject_GC_UnTrack(self); - - Py_CLEAR(self->disk); - self->disk = NULL; - - Py_CLEAR(self->geom); - self->geom = NULL; - - Py_CLEAR(self->fs_type); - self->fs_type = NULL; - - PyObject_GC_Del(self); -} - -int _ped_Partition_compare(_ped_Partition *self, PyObject *obj) { - _ped_Partition *comp = NULL; - int check = PyObject_IsInstance(obj, (PyObject *) &_ped_Partition_Type_obj); - - if (PyErr_Occurred()) { - return -1; - } - - if (!check) { - PyErr_SetString(PyExc_ValueError, "object comparing to must be a _ped.Partition"); - return -1; - } - - comp = (_ped_Partition *) obj; - if ((_ped_Disk_Type_obj.tp_richcompare(self->disk, comp->disk, Py_EQ)) && - (_ped_Geometry_Type_obj.tp_richcompare(self->geom, comp->geom, Py_EQ)) && - (self->ped_partition->num == comp->ped_partition->num) && - (self->type == comp->type) && - (_ped_FileSystemType_Type_obj.tp_richcompare(self->fs_type, comp->fs_type, Py_EQ))) { - return 0; - } else { - return 1; - } -} - -PyObject *_ped_Partition_richcompare(_ped_Partition *a, PyObject *b, int op) { - if (op == Py_EQ) { - if ((_ped_Partition_Type_obj.tp_richcompare((PyObject *) a, b, Py_EQ))) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } - } else if (op == Py_NE) { - if (!(_ped_Partition_Type_obj.tp_richcompare((PyObject *) a, b, Py_EQ))) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } - } else if ((op == Py_LT) || (op == Py_LE) || - (op == Py_GT) || (op == Py_GE)) { - PyErr_SetString(PyExc_TypeError, "comparison operator not supported for _ped.Partition"); - return NULL; - } else { - PyErr_SetString(PyExc_ValueError, "unknown richcompare op"); - return NULL; - } -} - -PyObject *_ped_Partition_str(_ped_Partition *self) { - char *ret = NULL; - char *disk = NULL, *fs_type = NULL, *geom = NULL; - - disk = PyUnicode_AsUTF8(_ped_Disk_Type_obj.tp_repr(self->disk)); - if (disk == NULL) { - return NULL; - } - - fs_type = PyUnicode_AsUTF8(_ped_FileSystemType_Type_obj.tp_repr(self->fs_type)); - if (fs_type == NULL) { - return NULL; - } - - geom = PyUnicode_AsUTF8(_ped_Geometry_Type_obj.tp_repr(self->geom)); - if (geom == NULL) { - return NULL; - } - - if (asprintf(&ret, "_ped.Partition instance --\n" - " disk: %s fs_type: %s\n" - " num: %d type: %d\n" - " geom: %s", - disk, fs_type, self->ped_partition->num, self->type, - geom) == -1) { - return PyErr_NoMemory(); - } - - return Py_BuildValue("s", ret); -} - -int _ped_Partition_traverse(_ped_Partition *self, visitproc visit, void *arg) { - int err; - - if (self->disk) { - if ((err = visit(self->disk, arg))) { - return err; - } - } - - if (self->geom) { - if ((err = visit(self->geom, arg))) { - return err; - } - } - - if (self->fs_type) { - if ((err = visit(self->fs_type, arg))) { - return err; - } - } - - return 0; -} - -int _ped_Partition_clear(_ped_Partition *self) { - Py_CLEAR(self->disk); - self->disk = NULL; - - Py_CLEAR(self->geom); - self->geom = NULL; - - Py_CLEAR(self->fs_type); - self->fs_type = NULL; - - return 0; -} - -int _ped_Partition_init(_ped_Partition *self, PyObject *args, PyObject *kwds) { - static char *kwlist[] = {"disk", "type", "start", "end", "fs_type", NULL}; - PedSector start, end; - PedDisk *disk = NULL; - PedFileSystemType *fstype = NULL; - PedPartition *part = NULL; - - self->fs_type = Py_None; - - if (kwds == NULL) { - if (!PyArg_ParseTuple(args, "O!iLL|O!", - &_ped_Disk_Type_obj, &self->disk, - &self->type, &start, &end, - &_ped_FileSystemType_Type_obj, &self->fs_type)) { - self->disk = self->fs_type = NULL; - return -1; - } - } else { - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!iLL|O!", kwlist, - &_ped_Disk_Type_obj, &self->disk, - &self->type, &start, &end, - &_ped_FileSystemType_Type_obj, &self->fs_type)) { - self->disk = self->fs_type = NULL; - return -1; - } - } - - /* - * try to call libparted with provided information, - * on failure, raise an exception - */ - disk = _ped_Disk2PedDisk(self->disk); - - if (self->fs_type != Py_None) - fstype = _ped_FileSystemType2PedFileSystemType(self->fs_type); - - part = ped_partition_new(disk, self->type, fstype, start, end); - if (part == NULL) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) { - PyErr_SetString(PartitionException, partedExnMessage); - } - } else { - PyErr_Format(PartitionException, "Could not create new partition on device %s", disk->dev->path); - } - - self->disk = self->fs_type = NULL; - return -3; - } - - /* increment reference count for PyObjects read by PyArg_ParseTuple */ - Py_INCREF(self->disk); - Py_INCREF(self->fs_type); - - /* copy in non-PyObject object members generated by libparted */ - self->type = part->type; - - /* - * copy in PyObject object members generated by libparted - * first, we drop the reference count to zero and set it to NULL - * second, we convert the libparted type to a PyObject - */ - Py_CLEAR(self->geom); - self->geom = (PyObject *) PedGeometry2_ped_Geometry(&(part->geom)); - if (self->geom == NULL) { - Py_CLEAR(self->disk); - Py_CLEAR(self->fs_type); - ped_partition_destroy(part); - return -4; - } - - self->ped_partition = part; - - /* On creation the object is not owned by any disk */ - self->_owned = 0; - - return 0; -} - -PyObject *_ped_Partition_get(_ped_Partition *self, void *closure) { - char *member = (char *) closure; - - if (member == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty _ped.Partition()"); - return NULL; - } - - if (!strcmp(member, "num")) { - return Py_BuildValue("i", self->ped_partition->num); - } else if (!strcmp(member, "type")) { - return PyLong_FromLong(self->type); - } else { - PyErr_Format(PyExc_AttributeError, "_ped.Partition object has no attribute %s", member); - return NULL; - } -} - -int _ped_Partition_set(_ped_Partition *self, PyObject *value, void *closure) { - char *member = (char *) closure; - - if (member == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty _ped.Partition()"); - return -1; - } - - if (!strcmp(member, "type")) { - self->type = PyLong_AsLong(value); - if (PyErr_Occurred()) { - return -1; - } - } else { - PyErr_Format(PyExc_AttributeError, "_ped.Partition object has no attribute %s", member); - return -1; - } - - return 0; -} - -/* _ped.Disk functions */ -void _ped_Disk_dealloc(_ped_Disk *self) { - if (self->ped_disk) { - ped_disk_destroy(self->ped_disk); - } - - PyObject_GC_UnTrack(self); - - Py_CLEAR(self->dev); - self->dev = NULL; - - Py_CLEAR(self->type); - self->type = NULL; - - PyObject_GC_Del(self); -} - -int _ped_Disk_compare(_ped_Disk *self, PyObject *obj) { - _ped_Disk *comp = NULL; - int check = PyObject_IsInstance(obj, (PyObject *) &_ped_Disk_Type_obj); - - if (PyErr_Occurred()) { - return -1; - } - - if (!check) { - PyErr_SetString(PyExc_ValueError, "object comparing to must be a _ped.Disk"); - return -1; - } - - comp = (_ped_Disk *) obj; - if ((_ped_Device_Type_obj.tp_richcompare(self->dev, comp->dev, Py_EQ)) && - (_ped_DiskType_Type_obj.tp_richcompare(self->type, comp->type, Py_EQ))) { - return 0; - } else { - return 1; - } -} - -PyObject *_ped_Disk_richcompare(_ped_Disk *a, PyObject *b, int op) { - if (op == Py_EQ || op == Py_NE) { - int rv = _ped_Disk_compare(a, b); - if (PyErr_Occurred()) - return NULL; - return PyBool_FromLong(op == Py_EQ ? rv == 0 : rv != 0); - } else if ((op == Py_LT) || (op == Py_LE) || - (op == Py_GT) || (op == Py_GE)) { - PyErr_SetString(PyExc_TypeError, "comparison operator not supported for _ped.Disk"); - return NULL; - } else { - PyErr_SetString(PyExc_ValueError, "unknown richcompare op"); - return NULL; - } -} - -PyObject *_ped_Disk_str(_ped_Disk *self) { - char *ret = NULL; - char *dev = NULL, *type = NULL; - - dev = PyUnicode_AsUTF8(_ped_Device_Type_obj.tp_repr(self->dev)); - if (dev == NULL) { - return NULL; - } - - type = PyUnicode_AsUTF8(_ped_Device_Type_obj.tp_repr(self->type)); - if (type == NULL) { - return NULL; - } - - if (asprintf(&ret, "_ped.Disk instance --\n dev: %s type: %s", - dev, type) == -1) { - return PyErr_NoMemory(); - } - - return Py_BuildValue("s", ret); -} - -int _ped_Disk_traverse(_ped_Disk *self, visitproc visit, void *arg) { - int err; - - if (self->dev) { - if ((err = visit(self->dev, arg))) { - return err; - } - } - - if (self->type) { - if ((err = visit(self->type, arg))) { - return err; - } - } - - return 0; -} - -int _ped_Disk_clear(_ped_Disk *self) { - Py_CLEAR(self->dev); - self->dev = NULL; - - Py_CLEAR(self->type); - self->type = NULL; - - return 0; -} - -int _ped_Disk_init(_ped_Disk *self, PyObject *args, PyObject *kwds) { - static char *kwlist[] = {"dev", NULL}; - PedDevice *device = NULL; - PedDisk *disk = NULL; - - if (kwds == NULL) { - if (!PyArg_ParseTuple(args, "O!", &_ped_Device_Type_obj, &self->dev)) { - self->dev = NULL; - return -1; - } - } else { - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", kwlist, - &_ped_Device_Type_obj, &self->dev)) { - self->dev = NULL; - return -2; - } - } - - device = _ped_Device2PedDevice(self->dev); - if (device == NULL) { - self->dev = NULL; - return -3; - } - disk = ped_disk_new(device); - - if (disk == NULL) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) { - PyErr_SetString(DiskLabelException, partedExnMessage); - } - } else { - PyErr_Format(IOException, "Failed to read partition table from device %s", device->path); - } - - self->dev = NULL; - return -4; - } - - Py_INCREF(self->dev); - - self->type = (PyObject *) PedDiskType2_ped_DiskType((PedDiskType *) disk->type); - - self->ped_disk = disk; - - return 0; -} - -/* _ped.DiskType functions */ -void _ped_DiskType_dealloc(_ped_DiskType *self) { - PyObject_GC_UnTrack(self); - free(self->name); - PyObject_GC_Del(self); -} - -int _ped_DiskType_compare(_ped_DiskType *self, PyObject *obj) { - _ped_DiskType *comp = NULL; - int check = PyObject_IsInstance(obj, (PyObject *) &_ped_DiskType_Type_obj); - - if (PyErr_Occurred()) { - return -1; - } - - if (!check) { - PyErr_SetString(PyExc_ValueError, "object comparing to must be a _ped.DiskType"); - return -1; - } - - comp = (_ped_DiskType *) obj; - if ((!strcmp(self->name, comp->name)) && - (self->features == comp->features)) { - return 0; - } else { - return 1; - } -} - -PyObject *_ped_DiskType_richcompare(_ped_DiskType *a, PyObject *b, int op) { - if (op == Py_EQ || op == Py_NE) { - int rv = _ped_DiskType_compare(a, b); - if (PyErr_Occurred()) - return NULL; - return PyBool_FromLong(op == Py_EQ ? rv == 0 : rv != 0); - } else if ((op == Py_LT) || (op == Py_LE) || - (op == Py_GT) || (op == Py_GE)) { - PyErr_SetString(PyExc_TypeError, "comparison operator not supported for _ped.DiskType"); - return NULL; - } else { - PyErr_SetString(PyExc_ValueError, "unknown richcompare op"); - return NULL; - } -} - -PyObject *_ped_DiskType_str(_ped_DiskType *self) { - char *ret = NULL; - - if (asprintf(&ret, "_ped.DiskType instance --\n" - " name: %s features: %lld", - self->name, self->features) == -1) { - return PyErr_NoMemory(); - } - - return Py_BuildValue("s", ret); -} - -int _ped_DiskType_traverse(_ped_DiskType *self, visitproc visit, void *arg) { - return 0; -} - -int _ped_DiskType_clear(_ped_DiskType *self) { - return 0; -} - -PyObject *_ped_DiskType_get(_ped_DiskType *self, void *closure) { - char *member = (char *) closure; - - if (member == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty _ped.DiskType()"); - return NULL; - } - - if (!strcmp(member, "name")) { - if (self->name != NULL) - return PyUnicode_FromString(self->name); - else - return PyUnicode_FromString(""); - } else if (!strcmp(member, "features")) { - return PyLong_FromLong(self->features); - } else { - PyErr_Format(PyExc_AttributeError, "_ped.DiskType object has no attribute %s", member); - return NULL; - } -} - -/* 1:1 function mappings for disk.h in libparted */ -PyObject *py_ped_disk_type_get_next(PyObject *s, PyObject *args) { - PyObject *in_type = NULL; - PedDiskType *cur = NULL, *next = NULL; - _ped_DiskType *ret = NULL; - - if (!PyArg_ParseTuple(args, "|O!", &_ped_DiskType_Type_obj, &in_type)) { - return NULL; - } - - if (in_type) { - cur = _ped_DiskType2PedDiskType(in_type); - if (!cur) { - return NULL; - } - } - - next = ped_disk_type_get_next(cur); - if (next) { - ret = PedDiskType2_ped_DiskType(next); - return (PyObject *) ret; - } else { - PyErr_SetNone(PyExc_IndexError); - return NULL; - } -} - -PyObject *py_ped_disk_type_get(PyObject *s, PyObject *args) { - char *in_name = NULL; - PedDiskType *out_type = NULL; - _ped_DiskType *ret = NULL; - - if (!PyArg_ParseTuple(args, "s", &in_name)) { - return NULL; - } - - if (in_name) { - out_type = ped_disk_type_get(in_name); - - if (out_type == NULL) { - PyErr_SetString(UnknownTypeException, in_name); - return NULL; - } - - ret = PedDiskType2_ped_DiskType(out_type); - if (ret == NULL) { - return NULL; - } - - } - - return (PyObject *) ret; -} - -PyObject *py_ped_disk_type_check_feature(PyObject *s, PyObject *args) { - PedDiskType *disktype = NULL; - PedDiskTypeFeature feature = -1; - int ret = 0; - - if (!PyArg_ParseTuple(args, "i", &feature)) { - return NULL; - } - - disktype = _ped_DiskType2PedDiskType(s); - if (disktype) { - ret = ped_disk_type_check_feature(disktype, feature); - } - else { - return NULL; - } - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_disk_clobber(PyObject *s, PyObject *args) { - PedDevice *device = NULL; - int ret = 0; - - device = _ped_Device2PedDevice(s); - if (device == NULL) - return NULL; - - ret = ped_disk_clobber(device); - if (ret == 0) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(IOException, partedExnMessage); - } - else - PyErr_Format(DiskException, "Failed to clobber partition table on device %s", device->path); - - return NULL; - } - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -/* XXX: is this necessary? */ -PyObject *py_ped_disk_duplicate(PyObject *s, PyObject *args) { - PedDisk *disk = NULL, *pass_disk = NULL; - _ped_Disk *ret = NULL; - - disk = _ped_Disk2PedDisk(s); - if (disk) { - pass_disk = ped_disk_duplicate(disk); - if (pass_disk == NULL) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(IOException, partedExnMessage); - } - else - PyErr_Format(DiskException, "Could not duplicate device %s", disk->dev->path); - - return NULL; - } - - ret = PedDisk2_ped_Disk(pass_disk); - if (ret == NULL) { - return NULL; - } - } - else { - return NULL; - } - - return (PyObject *) ret; -} - -/* - * XXX: - * We need to call ped_disk_destroy() to make sure the OS-specific - * free() function is called on the disk. That flushes buffers, - * closes handles, arms, and crosschecks and whatnot. - * - * Similar to py_ped_device_destroy(), we might move the call to - * ped_disk_destroy() to the tp_clear() for _ped.Disk. - */ -PyObject *py_ped_disk_destroy(PyObject *s, PyObject *args) { - PedDisk *disk = NULL; - - disk = _ped_Disk2PedDisk(s); - if (disk == NULL) { - return NULL; - } - - ped_disk_destroy(disk); - Py_CLEAR(s); - - Py_INCREF(Py_None); - return Py_None; -} - -PyObject *py_ped_disk_commit(PyObject *s, PyObject *args) { - PedDisk *disk = NULL; - int ret = 0; - - disk = _ped_Disk2PedDisk(s); - if (disk) { - ret = ped_disk_commit(disk); - if (ret == 0) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(IOException, partedExnMessage); - } - else - PyErr_Format(DiskException, "Could not commit to disk %s, (%s)", - disk->dev->path, __func__); - - return NULL; - } - } - else { - return NULL; - } - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_disk_commit_to_dev(PyObject *s, PyObject *args) { - PedDisk *disk = NULL; - int ret = 0; - - disk = _ped_Disk2PedDisk(s); - if (disk) { - ret = ped_disk_commit_to_dev(disk); - if (ret == 0) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(IOException, partedExnMessage); - } - else - PyErr_Format(DiskException, "Could not commit to disk %s, (%s)", - disk->dev->path, __func__); - - return NULL; - } - } - else { - return NULL; - } - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_disk_commit_to_os(PyObject *s, PyObject *args) { - PedDisk *disk = NULL; - int ret = 0; - - disk = _ped_Disk2PedDisk(s); - if (disk) { - ret = ped_disk_commit_to_os(disk); - if (ret == 0) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(IOException, partedExnMessage); - } - else - PyErr_Format(DiskException, "Could not commit to disk %s, (%s)", - disk->dev->path, __func__); - - return NULL; - } - } - else { - return NULL; - } - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_disk_check(PyObject *s, PyObject *args) { - PedDisk *disk = NULL; - int ret = 0; - - disk = _ped_Disk2PedDisk(s); - if (disk) { - ret = ped_disk_check(disk); - if (ret == 0) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(IOException, partedExnMessage); - } - else - PyErr_Format(DiskException, "Could not check disk %s", disk->dev->path); - - return NULL; - } - } - else { - return NULL; - } - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_disk_print(PyObject *s, PyObject *args) { - PedDisk *disk = NULL; - - disk = _ped_Disk2PedDisk(s); - if (disk) { - ped_disk_print(disk); - } - else { - return NULL; - } - - Py_INCREF(Py_None); - return Py_None; -} - -PyObject *py_ped_disk_get_primary_partition_count(PyObject *s, PyObject *args) { - PedDisk *disk = NULL; - int ret = 0; - - disk = _ped_Disk2PedDisk(s); - if (disk) { - ret = ped_disk_get_primary_partition_count(disk); - } - else { - return NULL; - } - - return PyLong_FromLong(ret); -} - -PyObject *py_ped_disk_get_last_partition_num(PyObject *s, PyObject *args) { - PedDisk *disk = NULL; - int ret = 0; - - disk = _ped_Disk2PedDisk(s); - if (disk) { - ret = ped_disk_get_last_partition_num(disk); - } - else { - return NULL; - } - - return PyLong_FromLong(ret); -} - -PyObject *py_ped_disk_get_max_primary_partition_count(PyObject *s, - PyObject *args) { - PedDisk *disk = NULL; - int ret = 0; - - disk = _ped_Disk2PedDisk(s); - if (disk) { - ret = ped_disk_get_max_primary_partition_count(disk); - } - else { - return NULL; - } - - return PyLong_FromLong(ret); -} - -PyObject *py_ped_disk_get_max_supported_partition_count(PyObject *s, - PyObject *args) { - PedDisk *disk = NULL; - int max = 0; - - disk = _ped_Disk2PedDisk(s); - if (disk) { - if (ped_disk_get_max_supported_partition_count(disk, &max) == true) { - return Py_BuildValue("i", max); - } - } - - Py_INCREF(Py_None); - return Py_None; -} - -PyObject *py_ped_disk_get_partition_alignment(PyObject *s, PyObject *args) { - PedDisk *disk = NULL; - PedAlignment *alignment = NULL; - _ped_Alignment *ret = NULL; - - disk = _ped_Disk2PedDisk(s); - if (!disk) - return NULL; - - alignment = ped_disk_get_partition_alignment(disk); - if (!alignment) { - PyErr_SetString(CreateException, "Could not get alignment for device"); - return NULL; - } - - ret = PedAlignment2_ped_Alignment(alignment); - ped_alignment_destroy(alignment); - - return (PyObject *) ret; -} - -PyObject *py_ped_disk_max_partition_length(PyObject *s, PyObject *args) { - PedDisk *disk = NULL; - - disk = _ped_Disk2PedDisk(s); - if (!disk) - return NULL; - - return PyLong_FromUnsignedLong(ped_disk_max_partition_length(disk)); -} - -PyObject *py_ped_disk_max_partition_start_sector(PyObject *s, PyObject *args) { - PedDisk *disk = NULL; - - disk = _ped_Disk2PedDisk(s); - if (!disk) - return NULL; - - return PyLong_FromUnsignedLong(ped_disk_max_partition_start_sector(disk)); -} - -PyObject *py_ped_disk_set_flag(PyObject *s, PyObject *args) { - int ret, flag, state; - PedDisk *disk = NULL; - - if (!PyArg_ParseTuple(args, "ii", &flag, &state)) { - return NULL; - } - - disk = _ped_Disk2PedDisk(s); - if (disk == NULL) { - return NULL; - } - - ret = ped_disk_set_flag(disk, flag, state); - if (ret == 0) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(DiskException, partedExnMessage); - } - else - PyErr_Format(DiskException, "Could not set flag on disk %s", disk->dev->path); - - return NULL; - } - - Py_RETURN_TRUE; -} - -PyObject *py_ped_disk_get_flag(PyObject *s, PyObject *args) { - int flag; - PedDisk *disk = NULL; - - if (!PyArg_ParseTuple(args, "i", &flag)) { - return NULL; - } - - disk = _ped_Disk2PedDisk(s); - if (disk == NULL) { - return NULL; - } - - if (ped_disk_get_flag(disk, flag)) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_disk_is_flag_available(PyObject *s, PyObject *args) { - int flag; - PedDisk *disk = NULL; - - if (!PyArg_ParseTuple(args, "i", &flag)) { - return NULL; - } - - disk = _ped_Disk2PedDisk(s); - if (disk == NULL) { - return NULL; - } - - if (ped_disk_is_flag_available(disk, flag)) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_disk_flag_get_name(PyObject *s, PyObject *args) { - int flag; - char *ret = NULL; - - if (!PyArg_ParseTuple(args, "i", &flag)) { - return NULL; - } - - if ((flag < PED_DISK_FIRST_FLAG) || (flag > PED_DISK_LAST_FLAG)) { - PyErr_SetString(PyExc_ValueError, "Invalid flag provided."); - return NULL; - } - - ret = (char *) ped_disk_flag_get_name(flag); - if (ret == NULL) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(DiskException, partedExnMessage); - } - else - PyErr_Format(DiskException, "Could not get disk flag name for %d", flag); - - return NULL; - } - - return PyUnicode_FromString(ret); -} - -PyObject *py_ped_disk_flag_get_by_name(PyObject *s, PyObject *args) { - char *name = NULL; - - if (!PyArg_ParseTuple(args, "s", &name)) { - return NULL; - } - - return PyLong_FromLong(ped_disk_flag_get_by_name(name)); -} - -PyObject *py_ped_disk_flag_next(PyObject *s, PyObject *args) { - int flag; - - if (!PyArg_ParseTuple(args, "i", &flag)) { - return NULL; - } - - return Py_BuildValue("i", ped_disk_flag_next(flag)); -} - -/* - * XXX: - * We need to call ped_disk_destroy() to make sure the OS-specific - * free() function is called on the disk. That flushes buffers, - * closes handles, arms, and crosschecks and whatnot. - * - * Similar to py_ped_device_destroy(), we might move the call to - * ped_disk_destroy() to the tp_clear() for _ped.Disk. - */ -PyObject *py_ped_partition_destroy(_ped_Partition *s, PyObject *args) { - PedPartition *partition = NULL; - - partition = _ped_Partition2PedPartition(s); - if (partition == NULL) { - return NULL; - } - - ped_partition_destroy(partition); - Py_CLEAR(s); - - Py_INCREF(Py_None); - return Py_None; -} - -PyObject *py_ped_partition_is_active(_ped_Partition *s, PyObject *args) { - PedPartition *partition = NULL; - int ret = 0; - - partition = _ped_Partition2PedPartition(s); - if (partition) { - ret = ped_partition_is_active(partition); - } - else { - return NULL; - } - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_partition_set_flag(_ped_Partition *s, PyObject *args) { - int in_state = -1; - PedPartition *part = NULL; - int flag; - int ret = 0; - - if (!PyArg_ParseTuple(args, "ii", &flag, &in_state)) { - return NULL; - } - - part = _ped_Partition2PedPartition(s); - if (part == NULL) { - return NULL; - } - - if (part && flag && in_state > -1) { - ret = ped_partition_set_flag(part, flag, in_state); - if (ret == 0) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(PartitionException, partedExnMessage); - } - else - PyErr_Format(PartitionException, "Could not set flag on partition %s%d", part->disk->dev->path, part->num); - - return NULL; - } - } - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_partition_get_flag(_ped_Partition *s, PyObject *args) { - PedPartition *part = NULL; - int flag; - int ret = -1; - - if (!PyArg_ParseTuple(args, "i", &flag)) { - return NULL; - } - - part = _ped_Partition2PedPartition(s); - if (part == NULL) { - return NULL; - } - - /* ped_partition_get_flag will assert on this. */ - if (!ped_partition_is_active(part)) { - PyErr_Format(PartitionException, "Could not get flag on inactive partition %s%d", part->disk->dev->path, part->num); - return NULL; - } - - ret = ped_partition_get_flag(part, flag); - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_partition_is_flag_available(_ped_Partition *s, PyObject *args) { - PedPartition *part = NULL; - int flag; - int ret = 0; - - if (!PyArg_ParseTuple(args, "i", &flag)) { - return NULL; - } - - part = _ped_Partition2PedPartition(s); - if (part == NULL) { - return NULL; - } - - if (!ped_partition_is_active(part)) { - PyErr_Format(PartitionException, "Flag is not available on inactive partition %s%d", part->disk->dev->path, part->num); - return NULL; - } - - ret = ped_partition_is_flag_available(part, flag); - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_partition_set_system(_ped_Partition *s, PyObject *args) { - PyObject *in_fstype = NULL; - PedPartition *part = NULL; - PedFileSystemType *out_fstype = NULL; - int ret = 0; - - if (!PyArg_ParseTuple(args, "O!", &_ped_FileSystemType_Type_obj, &in_fstype)) { - return NULL; - } - - part = _ped_Partition2PedPartition(s); - if (part == NULL) { - return NULL; - } - - out_fstype = _ped_FileSystemType2PedFileSystemType(in_fstype); - if (out_fstype == NULL) { - return NULL; - } - - /* ped_partition_set_system will assert on this. */ - if (!ped_partition_is_active(part)) { - PyErr_Format(PartitionException, "Could not set system flag on inactive partition %s%d", part->disk->dev->path, part->num); - return NULL; - } - - ret = ped_partition_set_system(part, out_fstype); - if (ret == 0) { - PyErr_Format(PartitionException, "Could not set system flag on partition %s%d", part->disk->dev->path, part->num); - return NULL; - } - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_partition_set_name(_ped_Partition *s, PyObject *args) { - PedPartition *part = NULL; - char *in_name = NULL; - int ret = 0; - - if (!PyArg_ParseTuple(args, "s", &in_name)) { - return NULL; - } - - part = _ped_Partition2PedPartition(s); - if (part == NULL) { - return NULL; - } - - /* ped_partition_set_name will assert on this. */ - if (!ped_partition_is_active(part)) { - PyErr_Format(PartitionException, "Could not set system flag on inactive partition %s%d", part->disk->dev->path, part->num); - return NULL; - } - - if (part) { - ret = ped_partition_set_name(part, in_name); - if (ret == 0) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(PartitionException, partedExnMessage); - } - else - PyErr_Format(PartitionException, "Could not set name on partition %s%d", part->disk->dev->path, part->num); - - return NULL; - } - } - else { - return NULL; - } - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_partition_get_name(_ped_Partition *s, PyObject *args) { - PedPartition *part = NULL; - char *ret = NULL; - - part = _ped_Partition2PedPartition(s); - if (part == NULL) { - return NULL; - } - - /* ped_partition_get_name will assert on this. */ - if (!ped_partition_is_active(part)) { - PyErr_Format(PartitionException, "Could not get name on inactive partition %s%d", part->disk->dev->path, part->num); - return NULL; - } - - if (part) { - ret = (char *) ped_partition_get_name(part); - if (ret == NULL) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(PartitionException, partedExnMessage); - } - else - PyErr_Format(PartitionException, "Could not read name on partition %s%d", part->disk->dev->path, part->num); - - return NULL; - } - } - else { - return NULL; - } - - return PyUnicode_FromString(ret); -} - -PyObject *py_ped_partition_is_busy(_ped_Partition *s, PyObject *args) { - PedPartition *part = NULL; - int ret = 0; - - part = _ped_Partition2PedPartition(s); - if (part) { - ret = ped_partition_is_busy(part); - } - else { - return NULL; - } - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_partition_get_path(_ped_Partition *s, PyObject *args) { - PedPartition *part = NULL; - char *ret = NULL; - - part = _ped_Partition2PedPartition(s); - if (part) { - ret = ped_partition_get_path(part); - if (ret == NULL) { - PyErr_Format(PartitionException, "Could not get path for partition %s%d", part->disk->dev->path, part->num); - return NULL; - } - } - else { - return NULL; - } - - return PyUnicode_FromString(ret); -} - -PyObject *py_ped_partition_reset_num(_ped_Partition *s, PyObject *args) { - PedPartition *part = NULL; - - part = _ped_Partition2PedPartition(s); - if (part == NULL) { - Py_RETURN_FALSE; - } - - part->num = -1; - - Py_RETURN_TRUE; -} - - -PyObject *py_ped_partition_type_get_name(PyObject *s, PyObject *args) { - long type; - char *ret = NULL; - - if (!PyArg_ParseTuple(args, "i", &type)) { - return NULL; - } - - if (type) { - ret = (char *) ped_partition_type_get_name(type); - } - - if (ret != NULL) - return PyUnicode_FromString(ret); - else - return PyUnicode_FromString(""); -} - -PyObject *py_ped_partition_flag_get_name(PyObject *s, PyObject *args) { - int flag; - char *ret = NULL; - - if (!PyArg_ParseTuple(args, "i", &flag)) { - return NULL; - } - - if ((flag < PED_PARTITION_FIRST_FLAG) || (flag > PED_PARTITION_LAST_FLAG)) { - PyErr_SetString(PyExc_ValueError, "Invalid flag provided."); - return NULL; - } - - if (flag) { - ret = (char *) ped_partition_flag_get_name(flag); - - if (!ret) { - /* Re-raise the libparted exception. */ - partedExnRaised = 0; - return NULL; - } - } - - return PyUnicode_FromString(ret); -} - -PyObject *py_ped_partition_flag_get_by_name(PyObject *s, PyObject *args) { - char *name = NULL; - - if (!PyArg_ParseTuple(args, "s", &name)) { - return NULL; - } - - return PyLong_FromLong(ped_partition_flag_get_by_name(name)); -} - -PyObject *py_ped_partition_flag_next(PyObject *s, PyObject *args) { - int flag; - - if (!PyArg_ParseTuple(args, "i", &flag)) { - return NULL; - } - - return Py_BuildValue("i", ped_partition_flag_next(flag)); -} - -PyObject *py_ped_disk_add_partition(PyObject *s, PyObject *args) { - _ped_Partition *in_part = NULL; - PyObject *in_constraint = NULL; - PedDisk *disk = NULL; - PedPartition *out_part = NULL; - PedConstraint *out_constraint = NULL; - int ret = 0; - - if (!PyArg_ParseTuple(args, "O!|O!",&_ped_Partition_Type_obj, - &in_part, &_ped_Constraint_Type_obj, &in_constraint)) { - return NULL; - } - - disk = _ped_Disk2PedDisk(s); - if (disk == NULL) { - return NULL; - } - - /* Its non-sense to add an owned partition */ - if (in_part->_owned == 1) { - PyErr_SetString(PartitionException, "Attempting to add a partition " - "that is already owned by a disk."); - return NULL; - } - - - out_part = _ped_Partition2PedPartition(in_part); - if (out_part == NULL) { - return NULL; - } - - if (out_part->disk != disk) { - PyErr_SetString(PartitionException, "Cannot add a partition to another disk then the one used for creating the partition"); - return NULL; - } - - if (in_constraint) { - out_constraint = _ped_Constraint2PedConstraint(in_constraint); - if (out_constraint == NULL) { - return NULL; - } - } - - ret = ped_disk_add_partition(disk, out_part, out_constraint); - - if (out_constraint) - ped_constraint_destroy(out_constraint); - - if (ret == 0) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(PartitionException, partedExnMessage); - } - else - PyErr_Format(PartitionException, "Could not create partition %s%d", out_part->disk->dev->path, out_part->num); - - return NULL; - } - - /* update our _ped.Partition object with out_part values */ - in_part->type = out_part->type; - in_part->_owned = 1; - *((_ped_Geometry *)in_part->geom)->ped_geometry = out_part->geom; - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_disk_remove_partition(PyObject *s, PyObject *args) { - _ped_Partition *in_part = NULL; - PedDisk *disk = NULL; - PedPartition *out_part = NULL; - int ret = 0; - - if (!PyArg_ParseTuple(args, "O!", &_ped_Partition_Type_obj, &in_part)) { - return NULL; - } - - disk = _ped_Disk2PedDisk(s); - if (disk == NULL) { - return NULL; - } - - /* Its non-sense to remove an unowned partition */ - if (in_part->_owned == 0) { - PyErr_SetString(PartitionException, "Attempting to remove a partition " - "that is not owned by any disk."); - return NULL; - } - - out_part = _ped_Partition2PedPartition(in_part); - if (out_part == NULL) { - return NULL; - } - - if (out_part->disk != disk) { - PyErr_SetString(PartitionException, "Partition is not part of the disk it is being removed from"); - return NULL; - } - - if (out_part->part_list != NULL) { - PedPartition *part; - for (part = out_part->part_list; part; part = part->next) { - if (ped_partition_is_active(part)) - break; - } - if (part) { - PyErr_SetString(PartitionException, "Attempting to remove an extended partition that still contains logical partitions"); - return NULL; - } - } - - ret = ped_disk_remove_partition(disk, out_part); - if (ret == 0) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(PartitionException, partedExnMessage); - } - else - PyErr_Format(PartitionException, "Could not remove partition %s%d", out_part->disk->dev->path, out_part->num); - - return NULL; - } - - in_part->_owned = 0; - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_disk_delete_partition(PyObject *s, PyObject *args) { - return py_ped_disk_remove_partition(s, args); -} - -PyObject *py_ped_disk_delete_all(PyObject *s, PyObject *args) { - PedDisk *disk = NULL; - int ret = 0; - - disk = _ped_Disk2PedDisk(s); - if (disk) { - ret = ped_disk_delete_all(disk); - if (ret == 0) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(PartitionException, partedExnMessage); - } - else - PyErr_Format(PartitionException, "Could not remove all partitions on %s", disk->dev->path); - - return NULL; - } - } - else { - return NULL; - } - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_disk_set_partition_geom(PyObject *s, PyObject *args) { - _ped_Partition *in_part = NULL; - PyObject *in_constraint = NULL; - PedDisk *disk = NULL; - PedPartition *out_part = NULL; - PedConstraint *out_constraint = NULL; - PedSector start, end; - int ret = 0; - - if (!PyArg_ParseTuple(args, "O!OLL", &_ped_Partition_Type_obj, &in_part, - &in_constraint, &start, &end)) { - return NULL; - } - - if (in_constraint != Py_None && !PyObject_IsInstance(in_constraint, - (PyObject *)&_ped_Constraint_Type_obj)) { - PyErr_SetString(PyExc_ValueError, "invalid constraint type"); - return NULL; - } - - disk = _ped_Disk2PedDisk(s); - if (disk == NULL) { - return NULL; - } - - out_part = _ped_Partition2PedPartition(in_part); - if (out_part == NULL) { - return NULL; - } - - if (out_part->disk != disk) { - PyErr_SetString(PartitionException, "partition.disk does not match disk"); - return NULL; - } - - if (in_constraint != Py_None) { - out_constraint = _ped_Constraint2PedConstraint(in_constraint); - if (out_constraint == NULL) { - return NULL; - } - } - - ret = ped_disk_set_partition_geom(disk, out_part, out_constraint, - start, end); - - if (out_constraint) - ped_constraint_destroy(out_constraint); - - if (ret == 0) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(PartitionException, partedExnMessage); - } - else - PyErr_Format(PartitionException, "Could not set geometry on %s%d", disk->dev->path, out_part->num); - - return NULL; - } - - *((_ped_Geometry *)in_part->geom)->ped_geometry = out_part->geom; - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_disk_maximize_partition(PyObject *s, PyObject *args) { - _ped_Partition *in_part = NULL; - PyObject *in_constraint = NULL; - PedDisk *disk = NULL; - PedPartition *out_part = NULL; - PedConstraint *out_constraint = NULL; - int ret = 0; - - if (!PyArg_ParseTuple(args, "O!|O!", &_ped_Partition_Type_obj, &in_part, - &_ped_Constraint_Type_obj, &in_constraint)) { - return NULL; - } - - disk = _ped_Disk2PedDisk(s); - if (disk == NULL) { - return NULL; - } - - out_part = _ped_Partition2PedPartition(in_part); - if (out_part == NULL) { - return NULL; - } - - if (out_part->disk != disk) { - PyErr_SetString(PartitionException, "partition.disk does not match disk"); - return NULL; - } - - if (in_constraint) { - out_constraint = _ped_Constraint2PedConstraint(in_constraint); - if (out_constraint == NULL) { - return NULL; - } - } - - ret = ped_disk_maximize_partition(disk, out_part, out_constraint); - - if (out_constraint) - ped_constraint_destroy(out_constraint); - - if (ret == 0) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(PartitionException, partedExnMessage); - } - else - PyErr_Format(PartitionException, "Could not maximize partition size for %s%d", disk->dev->path, out_part->num); - - return NULL; - } - - *((_ped_Geometry *)in_part->geom)->ped_geometry = out_part->geom; - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_disk_get_max_partition_geometry(PyObject *s, PyObject *args) { - _ped_Partition *in_part = NULL; - PyObject *in_constraint = NULL; - PedDisk *disk = NULL; - PedPartition *out_part = NULL; - PedConstraint *out_constraint = NULL; - PedGeometry *pass_geom = NULL; - _ped_Geometry *ret = NULL; - - if (!PyArg_ParseTuple(args, "O!|O!", &_ped_Partition_Type_obj, &in_part, - &_ped_Constraint_Type_obj, &in_constraint)) { - return NULL; - } - - disk = _ped_Disk2PedDisk(s); - if (disk == NULL) { - return NULL; - } - - out_part = _ped_Partition2PedPartition(in_part); - if (out_part == NULL) { - return NULL; - } - - if (out_part->disk != disk) { - PyErr_SetString(PartitionException, "partition.disk does not match disk"); - return NULL; - } - - if (in_constraint) { - out_constraint = _ped_Constraint2PedConstraint(in_constraint); - if (out_constraint == NULL) { - return NULL; - } - } - - pass_geom = ped_disk_get_max_partition_geometry(disk, out_part, - out_constraint); - if (out_constraint) - ped_constraint_destroy(out_constraint); - - if (pass_geom == NULL) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(PartitionException, partedExnMessage); - } - else - PyErr_Format(PartitionException, "Could not get maximum partition size for %s%d", disk->dev->path, out_part->num); - - return NULL; - } - - ret = PedGeometry2_ped_Geometry(pass_geom); - if (ret == NULL) { - return NULL; - } - - return (PyObject *) ret; -} - -PyObject *py_ped_disk_minimize_extended_partition(PyObject *s, PyObject *args) { - PedDisk *disk = NULL; - int ret = 0; - - disk = _ped_Disk2PedDisk(s); - if (disk) { - ret = ped_disk_minimize_extended_partition(disk); - if (ret == 0) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(PartitionException, partedExnMessage); - } - else - PyErr_Format(PartitionException, "Could not shrink extended partition on %s", disk->dev->path); - - return NULL; - } - } - else { - return NULL; - } - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_disk_next_partition(PyObject *s, PyObject *args) { - _ped_Partition *in_part = NULL; - PedDisk *disk = NULL; - PedPartition *out_part = NULL; - PedPartition *pass_part = NULL; - _ped_Partition *ret = NULL; - - if (!PyArg_ParseTuple(args, "|O!", &_ped_Partition_Type_obj, &in_part)) { - return NULL; - } - - disk = _ped_Disk2PedDisk(s); - if (disk == NULL) { - return NULL; - } - - if (in_part) { - out_part = _ped_Partition2PedPartition(in_part); - if (out_part == NULL) { - return NULL; - } - - if (out_part->disk != disk) { - PyErr_SetString(PartitionException, "partition.disk does not match disk"); - return NULL; - } - } - - pass_part = ped_disk_next_partition(disk, out_part); - if (pass_part == NULL) { - Py_INCREF(Py_None); - return Py_None; - } - - ret = PedPartition2_ped_Partition(pass_part, (_ped_Disk *)s); - if (ret == NULL) { - return NULL; - } - - ret->_owned = 1; - return (PyObject *) ret; -} - -PyObject *py_ped_disk_get_partition(PyObject *s, PyObject *args) { - int num; - PedDisk *disk = NULL; - PedPartition *pass_part = NULL; - _ped_Partition *ret = NULL; - - if (!PyArg_ParseTuple(args, "i", &num)) { - return NULL; - } - - disk = _ped_Disk2PedDisk(s); - if (disk) { - pass_part = ped_disk_get_partition(disk, num); - if (pass_part == NULL) { - PyErr_SetString(PartitionException, "Partition does not exist"); - return NULL; - } - - ret = PedPartition2_ped_Partition(pass_part, (_ped_Disk *)s); - if (ret == NULL) { - return NULL; - } - } - else { - return NULL; - } - - ret->_owned = 1; - return (PyObject *) ret; -} - -PyObject *py_ped_disk_get_partition_by_sector(PyObject *s, PyObject *args) { - PedDisk *disk = NULL; - PedSector sector; - PedPartition *pass_part = NULL; - _ped_Partition *ret = NULL; - - if (!PyArg_ParseTuple(args, "L", §or)) { - return NULL; - } - - disk = _ped_Disk2PedDisk(s); - if (disk == NULL) { - return NULL; - } - - pass_part = ped_disk_get_partition_by_sector(disk, sector); - if (pass_part == NULL) { - PyErr_SetString(PartitionException, "Partition does not exist"); - return NULL; - } - - ret = PedPartition2_ped_Partition(pass_part, (_ped_Disk *)s); - if (ret == NULL) { - return NULL; - } - - ret->_owned = 1; - return (PyObject *) ret; -} - -PyObject *py_ped_disk_extended_partition(PyObject *s, PyObject *args) { - PedDisk *disk = NULL; - PedPartition *pass_part = NULL; - _ped_Partition *ret = NULL; - - disk = _ped_Disk2PedDisk(s); - if (disk) { - pass_part = ped_disk_extended_partition(disk); - if (pass_part == NULL) { - PyErr_SetString(PartitionException, "Extended partition does not exist"); - return NULL; - } - - ret = PedPartition2_ped_Partition(pass_part, (_ped_Disk *)s); - if (ret == NULL) { - return NULL; - } - } - else { - return NULL; - } - - ret->_owned = 1; - return (PyObject *) ret; -} - -PyObject *py_ped_disk_new_fresh(PyObject *s, PyObject *args) { - _ped_Device *in_device = NULL; - _ped_DiskType *in_type = NULL; - PedDevice *device = NULL; - PedDiskType *type = NULL; - PedDisk *disk = NULL; - _ped_Disk *ret = NULL; - - if (!PyArg_ParseTuple(args, "O!O!", &_ped_Device_Type_obj, &in_device, - &_ped_DiskType_Type_obj, &in_type)) { - return NULL; - } - - if ((device = _ped_Device2PedDevice((PyObject *) in_device)) == NULL) { - return NULL; - } - - if ((type = _ped_DiskType2PedDiskType((PyObject *) in_type)) == NULL) { - return NULL; - } - - if ((disk = ped_disk_new_fresh(device, type)) == NULL) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(DiskException, partedExnMessage); - } else { - PyErr_Format(DiskException, "Could not create new disk label on %s", disk->dev->path); - } - - return NULL; - } - - ret = PedDisk2_ped_Disk(disk); - return (PyObject *) ret; -} - -PyObject *py_ped_disk_new(PyObject *s, PyObject *args) { - _ped_Device *in_device = NULL; - PedDevice *device = NULL; - PedDisk *disk = NULL; - _ped_Disk *ret = NULL; - - if (!PyArg_ParseTuple(args, "O!", &_ped_Device_Type_obj, &in_device)) { - return NULL; - } - - if ((device = _ped_Device2PedDevice((PyObject *) in_device)) == NULL) { - return NULL; - } - - if ((disk = ped_disk_new(device)) == NULL) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(DiskException, partedExnMessage); - } else { - PyErr_Format(DiskException, "Could not create new disk label on %s", disk->dev->path); - } - - return NULL; - } - - ret = PedDisk2_ped_Disk(disk); - return (PyObject *) ret; -} - -/* vim:tw=78:ts=4:et:sw=4 - */ diff --git a/src/pyfilesys.c b/src/pyfilesys.c deleted file mode 100644 index d854b28..0000000 --- a/src/pyfilesys.c +++ /dev/null @@ -1,391 +0,0 @@ -/* - * pyfilesys.c - * - * Copyright (C) 2007-2013 Red Hat, Inc. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions of - * the GNU General Public License v.2, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY expressed or implied, including the implied warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. Any Red Hat trademarks that are incorporated in the - * source code or documentation are not subject to the GNU General Public - * License and may only be used or replicated with the express permission of - * Red Hat, Inc. - * - * Author(s): David Cantrell - * Chris Lumens - * Alex Skinner - */ - -#include - -#include "convert.h" -#include "exceptions.h" -#include "pydevice.h" -#include "pyfilesys.h" -#include "pygeom.h" -#include "docstrings/pyfilesys.h" -#include "typeobjects/pyfilesys.h" - -/* _ped.FileSystemType functions */ -void _ped_FileSystemType_dealloc(_ped_FileSystemType *self) { - PyObject_GC_UnTrack(self); - free(self->name); - PyObject_GC_Del(self); -} - -int _ped_FileSystemType_compare(_ped_FileSystemType *self, PyObject *obj) { - _ped_FileSystemType *comp = NULL; - int check = PyObject_IsInstance(obj, (PyObject *) &_ped_FileSystemType_Type_obj); - - if (PyErr_Occurred()) { - return -1; - } - - if (!check) { - PyErr_SetString(PyExc_ValueError, "object comparing to must be a _ped.FileSystemType"); - return -1; - } - - comp = (_ped_FileSystemType *) obj; - if (!strcmp(self->name, comp->name)) { - return 0; - } else { - return 1; - } -} - -PyObject *_ped_FileSystemType_richcompare(_ped_FileSystemType *a, PyObject *b, - int op) { - if (op == Py_EQ || op == Py_NE) { - int rv = _ped_FileSystemType_compare(a, b); - if (PyErr_Occurred()) - return NULL; - return PyBool_FromLong(op == Py_EQ ? rv == 0 : rv != 0); - } else if ((op == Py_LT) || (op == Py_LE) || - (op == Py_GT) || (op == Py_GE)) { - PyErr_SetString(PyExc_TypeError, "comparison operator not supported for _ped.FileSystemType"); - return NULL; - } else { - PyErr_SetString(PyExc_ValueError, "unknown richcompare op"); - return NULL; - } -} - -PyObject *_ped_FileSystemType_str(_ped_FileSystemType *self) { - char *ret = NULL; - - if (asprintf(&ret, "_ped.FileSystemType instance --\n" - " name: %s", - self->name) == -1) { - return PyErr_NoMemory(); - } - - return Py_BuildValue("s", ret); -} - -int _ped_FileSystemType_traverse(_ped_FileSystemType *self, visitproc visit, void *arg) { - return 0; -} - -int _ped_FileSystemType_clear(_ped_FileSystemType *self) { - return 0; -} - -PyObject *_ped_FileSystemType_get(_ped_FileSystemType *self, void *closure) { - char *member = (char *) closure; - - if (member == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty _ped.FileSystemType()"); - return NULL; - } - - if (!strcmp(member, "name")) { - if (self->name != NULL) - return PyUnicode_FromString(self->name); - else - return PyUnicode_FromString(""); - } else { - PyErr_Format(PyExc_AttributeError, "_ped.FileSystemType object has no attribute %s", member); - return NULL; - } -} - -/* _ped.FileSystem functions */ -void _ped_FileSystem_dealloc(_ped_FileSystem *self) { - PyObject_GC_UnTrack(self); - - Py_CLEAR(self->type); - self->type = NULL; - - Py_CLEAR(self->geom); - self->geom = NULL; - - PyObject_GC_Del(self); -} - -int _ped_FileSystem_compare(_ped_FileSystem *self, PyObject *obj) { - _ped_FileSystem *comp = NULL; - int check = PyObject_IsInstance(obj, (PyObject *) &_ped_FileSystem_Type_obj); - - if (PyErr_Occurred()) { - return -1; - } - - if (!check) { - PyErr_SetString(PyExc_ValueError, "object comparing to must be a _ped.FileSystem"); - return -1; - } - - comp = (_ped_FileSystem *) obj; - if ((_ped_FileSystemType_Type_obj.tp_richcompare(self->type, comp->type, Py_EQ)) && - (_ped_Geometry_Type_obj.tp_richcompare(self->geom, comp->geom, Py_EQ)) && - (self->checked == comp->checked)) { - return 0; - } else { - return 1; - } - -} - -PyObject *_ped_FileSystem_richcompare(_ped_FileSystem *a, PyObject *b, int op) { - if (op == Py_EQ || op == Py_NE) { - int rv = _ped_FileSystem_compare(a, b); - if (PyErr_Occurred()) - return NULL; - return PyBool_FromLong(op == Py_EQ ? rv == 0 : rv != 0); - } else if ((op == Py_LT) || (op == Py_LE) || - (op == Py_GT) || (op == Py_GE)) { - PyErr_SetString(PyExc_TypeError, "comparison operator not supported for _ped.FileSystem"); - return NULL; - } else { - PyErr_SetString(PyExc_ValueError, "unknown richcompare op"); - return NULL; - } -} - -PyObject *_ped_FileSystem_str(_ped_FileSystem *self) { - char *ret = NULL; - char *type = NULL, *geom = NULL; - - type = PyUnicode_AsUTF8(_ped_FileSystem_Type_obj.tp_repr(self->type)); - if (type == NULL) { - return NULL; - } - - geom = PyUnicode_AsUTF8(_ped_Geometry_Type_obj.tp_repr(self->geom)); - if (geom == NULL) { - return NULL; - } - - if (asprintf(&ret, "_ped.FileSystem instance --\n" - " type: %s geom: %s\n" - " checked: %d", - type, geom, self->checked) == -1) { - return PyErr_NoMemory(); - } - - return Py_BuildValue("s", ret); -} - -int _ped_FileSystem_traverse(_ped_FileSystem *self, visitproc visit, void *arg) { - int err; - - if (self->type) { - if ((err = visit(self->type, arg))) { - return err; - } - } - - if (self->geom) { - if ((err = visit(self->geom, arg))) { - return err; - } - } - - return 0; -} - -int _ped_FileSystem_clear(_ped_FileSystem *self) { - Py_CLEAR(self->type); - self->type = NULL; - - Py_CLEAR(self->geom); - self->geom = NULL; - - return 0; -} - -int _ped_FileSystem_init(_ped_FileSystem *self, PyObject *args, - PyObject *kwds) { - static char *kwlist[] = {"type", "geom", "checked", NULL}; - - self->checked = 0; - - if (kwds == NULL) { - if (!PyArg_ParseTuple(args, "O!O!|i", - &_ped_FileSystemType_Type_obj, &self->type, - &_ped_Geometry_Type_obj, &self->geom, - &self->checked)) { - self->type = self->geom = NULL; - return -1; - } - } else { - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!O!|i", kwlist, - &_ped_FileSystemType_Type_obj, &self->type, - &_ped_Geometry_Type_obj, &self->geom, - &self->checked)) { - self->type = self->geom = NULL; - return -2; - } - } - - Py_INCREF(self->type); - Py_INCREF(self->geom); - self->ped_filesystem = NULL; - return 0; -} - -PyObject *_ped_FileSystem_get(_ped_FileSystem *self, void *closure) { - char *member = (char *) closure; - - if (member == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty _ped.FileSystem()"); - return NULL; - } - - if (!strcmp(member, "checked")) { - return PyLong_FromLong(self->checked); - } else { - PyErr_Format(PyExc_AttributeError, "_ped.FileSystem object has no attribute %s", member); - return NULL; - } -} - -/* 1:1 function mappings for filesys.h in libparted */ -PyObject *py_ped_file_system_type_get(PyObject *s, PyObject *args) { - PedFileSystemType *fstype = NULL; - _ped_FileSystemType *ret = NULL; - char *name = NULL; - - if (!PyArg_ParseTuple(args, "s", &name)) { - return NULL; - } - - fstype = ped_file_system_type_get(name); - if (fstype) { - ret = PedFileSystemType2_ped_FileSystemType(fstype); - return (PyObject *) ret; - } - else { - PyErr_SetString(UnknownTypeException, name); - return NULL; - } -} - -PyObject *py_ped_file_system_type_get_next(PyObject *s, PyObject *args) { - PyObject *in_fstype = NULL; - PedFileSystemType *cur = NULL, *next = NULL; - _ped_FileSystemType *ret = NULL; - - if (!PyArg_ParseTuple(args, "|O!", &_ped_FileSystemType_Type_obj, &in_fstype)) { - return NULL; - } - - if (in_fstype) { - cur = _ped_FileSystemType2PedFileSystemType(in_fstype); - if (!cur) { - return NULL; - } - } - - next = ped_file_system_type_get_next(cur); - if (next) { - ret = PedFileSystemType2_ped_FileSystemType(next); - return (PyObject *) ret; - } else { - PyErr_SetNone(PyExc_IndexError); - return NULL; - } -} - -PyObject *py_ped_file_system_probe_specific(PyObject *s, PyObject *args) { - PyObject *in_geom = NULL, *in_fstype = NULL; - PedFileSystemType *fstype = NULL; - PedGeometry *out_geom = NULL, *geom = NULL; - _ped_Geometry *ret = NULL; - - if (!PyArg_ParseTuple(args, "O!O!", &_ped_FileSystemType_Type_obj, - &in_fstype, &_ped_Geometry_Type_obj, &in_geom)) { - return NULL; - } - - fstype = _ped_FileSystemType2PedFileSystemType(in_fstype); - if (!fstype) { - return NULL; - } - - out_geom = _ped_Geometry2PedGeometry(in_geom); - if (!out_geom) { - return NULL; - } - - geom = ped_file_system_probe_specific(fstype, out_geom); - if (geom) { - ret = PedGeometry2_ped_Geometry(geom); - } else { - /* libparted swallows exceptions here (I think) and just returns - * NULL if the match is not made. Reset exception flag and return - * None. - */ - if (partedExnRaised) { - partedExnRaised = 0; - } - - Py_INCREF(Py_None); - return Py_None; - } - - return (PyObject *) ret; -} - -PyObject *py_ped_file_system_probe(PyObject *s, PyObject *args) { - PyObject *in_geom = NULL; - PedGeometry *out_geom = NULL; - PedFileSystemType *fstype = NULL; - _ped_FileSystemType *ret = NULL; - - if (!PyArg_ParseTuple(args, "O!", &_ped_Geometry_Type_obj, &in_geom)) { - return NULL; - } - - out_geom = _ped_Geometry2PedGeometry(in_geom); - if (!out_geom) { - return NULL; - } - - fstype = ped_file_system_probe(out_geom); - if (fstype) { - ret = PedFileSystemType2_ped_FileSystemType(fstype); - } - else { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(IOException, partedExnMessage); - } - else - PyErr_SetString(FileSystemException, "Failed to find any filesystem in given geometry"); - - return NULL; - } - - return (PyObject *) ret; -} diff --git a/src/pygeom.c b/src/pygeom.c deleted file mode 100644 index 20ed673..0000000 --- a/src/pygeom.c +++ /dev/null @@ -1,754 +0,0 @@ -/* - * pygeom.c - * - * Copyright (C) 2007-2013 Red Hat, Inc. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions of - * the GNU General Public License v.2, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY expressed or implied, including the implied warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. Any Red Hat trademarks that are incorporated in the - * source code or documentation are not subject to the GNU General Public - * License and may only be used or replicated with the express permission of - * Red Hat, Inc. - * - * Author(s): David Cantrell - * Chris Lumens - * Alex Skinner - */ - -#include - -#include "convert.h" -#include "exceptions.h" -#include "pygeom.h" -#include "pynatmath.h" -#include "docstrings/pygeom.h" -#include "typeobjects/pygeom.h" - -/* _ped.Geometry functions */ -void _ped_Geometry_dealloc(_ped_Geometry *self) { - if (self->ped_geometry) - ped_geometry_destroy(self->ped_geometry); - - PyObject_GC_UnTrack(self); - - Py_CLEAR(self->dev); - self->dev = NULL; - - PyObject_GC_Del(self); -} - -int _ped_Geometry_compare(_ped_Geometry *self, PyObject *obj) { - _ped_Geometry *comp = NULL; - int check = PyObject_IsInstance(obj, (PyObject *) &_ped_Geometry_Type_obj); - - if (PyErr_Occurred()) { - return -1; - } - - if (!check) { - PyErr_SetString(PyExc_ValueError, "object comparing to must be a _ped.Geometry"); - return -1; - } - - comp = (_ped_Geometry *) obj; - if (PyObject_RichCompareBool(self->dev, comp->dev, Py_EQ) && - (self->ped_geometry->start == comp->ped_geometry->start) && - (self->ped_geometry->length == comp->ped_geometry->length) && - (self->ped_geometry->end == comp->ped_geometry->end)) { - return 0; - } else { - return 1; - } -} - -PyObject *_ped_Geometry_richcompare(_ped_Geometry *a, PyObject *b, int op) { - if (op == Py_EQ || op == Py_NE) { - int rv = _ped_Geometry_compare(a, b); - if (PyErr_Occurred()) - return NULL; - return PyBool_FromLong(op == Py_EQ ? rv == 0 : rv != 0); - } else if ((op == Py_LT) || (op == Py_LE) || - (op == Py_GT) || (op == Py_GE)) { - PyErr_SetString(PyExc_TypeError, "comparison operator not supported for _ped.Geometry"); - return NULL; - } else { - PyErr_SetString(PyExc_ValueError, "unknown richcompare op"); - return NULL; - } -} - -PyObject *_ped_Geometry_str(_ped_Geometry *self) { - char *ret = NULL; - char *dev = NULL; - - dev = PyUnicode_AsUTF8(_ped_Device_Type_obj.tp_repr(self->dev)); - if (dev == NULL) { - return NULL; - } - - if (asprintf(&ret, "_ped.Geometry instance --\n" - " start: %lld end: %lld length: %lld\n" - " device: %s", - self->ped_geometry->start, self->ped_geometry->end, - self->ped_geometry->length, dev) == -1) { - return PyErr_NoMemory(); - } - - return Py_BuildValue("s", ret); -} - -int _ped_Geometry_traverse(_ped_Geometry *self, visitproc visit, void *arg) { - int err; - - if (self->dev) { - if ((err = visit(self->dev, arg))) { - return err; - } - } - - return 0; -} - -int _ped_Geometry_clear(_ped_Geometry *self) { - Py_CLEAR(self->dev); - self->dev = NULL; - - return 0; -} - -int _ped_Geometry_init(_ped_Geometry *self, PyObject *args, PyObject *kwds) { - static char *kwlist[] = {"dev", "start", "length", "end", NULL}; - PedDevice *device = NULL; - long long start, length, end; - - self->dev = NULL; - self->ped_geometry = NULL; - - if (kwds == NULL) { - if (!PyArg_ParseTuple(args, "O!LL|L", &_ped_Device_Type_obj, &self->dev, - &start, &length, &end)) { - self->dev = NULL; - return -1; - } - } else { - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!LL|L", kwlist, - &_ped_Device_Type_obj, &self->dev, - &start, &length, &end)) { - self->dev = NULL; - return -2; - } - } - - device = _ped_Device2PedDevice(self->dev); - if (device == NULL) { - self->dev = NULL; - return -3; - } - self->ped_geometry = ped_geometry_new(device, start, length); - - if (self->ped_geometry == NULL) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) { - PyErr_SetString(CreateException, partedExnMessage); - } - } else { - PyErr_SetString(CreateException, "Could not create new geometry"); - } - - self->dev = NULL; - return -3; - } - - Py_INCREF(self->dev); - - return 0; -} - -PyObject *_ped_Geometry_get(_ped_Geometry *self, void *closure) { - char *member = (char *) closure; - - if (member == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty _ped.Geometry()"); - return NULL; - } - - if (!strcmp(member, "start")) { - return PyLong_FromLong(self->ped_geometry->start); - } else if (!strcmp(member, "length")) { - return PyLong_FromLong(self->ped_geometry->length); - } else if (!strcmp(member, "end")) { - return PyLong_FromLong(self->ped_geometry->end); - } else { - PyErr_Format(PyExc_AttributeError, "_ped.Geometry object has no attribute %s", member); - return NULL; - } -} - -int _ped_Geometry_set(_ped_Geometry *self, PyObject *value, void *closure) { - char *member = (char *) closure; - long long val; - int ret; - - if (member == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty _ped.Geometry()"); - return -1; - } - - if (!strcmp(member, "start")) { - val = PyLong_AsLong(value); - if (PyErr_Occurred()) { - return -1; - } - ret = ped_geometry_set_start(self->ped_geometry, val); - } else if (!strcmp(member, "length")) { - val = PyLong_AsLong(value); - if (PyErr_Occurred()) { - return -1; - } - ret = ped_geometry_set(self->ped_geometry, self->ped_geometry->start, - val); - } else if (!strcmp(member, "end")) { - val = PyLong_AsLong(value); - if (PyErr_Occurred()) { - return -1; - } - ret = ped_geometry_set_end(self->ped_geometry, val); - } else { - PyErr_Format(PyExc_AttributeError, "_ped.Geometry object has no attribute %s", member); - return -1; - } - - if (ret == 0) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_Occurred()) { - PyErr_SetString(PyExc_ValueError, partedExnMessage); - } - } else { - PyErr_SetString(PyExc_ValueError, "Could not set geometry"); - } - return -1; - } - - return 0; -} - -/* 1:1 function mappings for geom.h in libparted */ -PyObject *py_ped_geometry_duplicate(PyObject *s, PyObject *args) { - PedGeometry *geometry = NULL, *geom = NULL; - _ped_Geometry *ret = NULL; - - geometry = _ped_Geometry2PedGeometry(s); - if (geometry == NULL) { - return NULL; - } - - geom = ped_geometry_duplicate(geometry); - if (geom) { - ret = PedGeometry2_ped_Geometry(geom); - } - else { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(CreateException, partedExnMessage); - } - else - PyErr_SetString(CreateException, "Could not duplicate geometry"); - - return NULL; - } - - return (PyObject *) ret; -} - -PyObject *py_ped_geometry_intersect(PyObject *s, PyObject *args) { - PyObject *in_b = NULL; - PedGeometry *out_a = NULL, *out_b = NULL, *geom = NULL; - _ped_Geometry *ret = NULL; - - if (!PyArg_ParseTuple(args, "O!", &_ped_Geometry_Type_obj, &in_b)) { - return NULL; - } - - out_a = _ped_Geometry2PedGeometry(s); - if (out_a == NULL) { - return NULL; - } - - out_b = _ped_Geometry2PedGeometry(in_b); - if (out_b == NULL) { - return NULL; - } - - geom = ped_geometry_intersect (out_a, out_b); - if (geom) { - ret = PedGeometry2_ped_Geometry(geom); - } - else { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(CreateException, partedExnMessage); - } - else - PyErr_SetString(PyExc_ArithmeticError, "Could not find geometry intersection"); - - return NULL; - } - - return (PyObject *) ret; -} - -PyObject *py_ped_geometry_set(PyObject *s, PyObject *args) { - int ret = -1; - PedGeometry *geom = NULL; - PedSector start, length; - - if (!PyArg_ParseTuple(args, "LL", &start, &length)) { - return NULL; - } - - geom = _ped_Geometry2PedGeometry(s); - if (geom == NULL) { - return NULL; - } - - ret = ped_geometry_set(geom, start, length); - if (ret == 0) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(CreateException, partedExnMessage); - } - else - PyErr_SetString(CreateException, "Could not create new geometry"); - - return NULL; - } - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_geometry_set_start(PyObject *s, PyObject *args) { - int ret = -1; - PedGeometry *geom = NULL; - PedSector start; - - if (!PyArg_ParseTuple(args, "L", &start)) { - return NULL; - } - - geom = _ped_Geometry2PedGeometry(s); - if (geom == NULL) { - return NULL; - } - - ret = ped_geometry_set_start(geom, start); - if (ret == 0) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(CreateException, partedExnMessage); - } - else - PyErr_SetString(CreateException, "Could not create new geometry"); - - return NULL; - } - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_geometry_set_end(PyObject *s, PyObject *args) { - int ret = -1; - PedGeometry *geom = NULL; - PedSector end; - - if (!PyArg_ParseTuple(args, "L", &end)) { - return NULL; - } - - geom = _ped_Geometry2PedGeometry(s); - if (geom == NULL) { - return NULL; - } - - ret = ped_geometry_set_end(geom, end); - if (ret == 0) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(CreateException, partedExnMessage); - } - else - PyErr_SetString(CreateException, "Could not create new geometry"); - - return NULL; - } - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_geometry_test_overlap(PyObject *s, PyObject *args) { - int ret = -1; - PyObject *in_b = NULL; - PedGeometry *out_a = NULL, *out_b = NULL; - - if (!PyArg_ParseTuple(args, "O!", &_ped_Geometry_Type_obj, &in_b)) { - return NULL; - } - - out_a = _ped_Geometry2PedGeometry(s); - if (out_a == NULL) { - return NULL; - } - - out_b = _ped_Geometry2PedGeometry(in_b); - if (out_b == NULL) { - return NULL; - } - - ret = ped_geometry_test_overlap(out_a, out_b); - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_geometry_test_inside(PyObject *s, PyObject *args) { - int ret = -1; - PyObject *in_b = NULL; - PedGeometry *out_a = NULL, *out_b = NULL; - - if (!PyArg_ParseTuple(args, "O!", &_ped_Geometry_Type_obj, &in_b)) { - return NULL; - } - - out_a = _ped_Geometry2PedGeometry(s); - if (out_a == NULL) { - return NULL; - } - - out_b = _ped_Geometry2PedGeometry(in_b); - if (out_b == NULL) { - return NULL; - } - - ret = ped_geometry_test_inside(out_a, out_b); - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_geometry_test_equal(PyObject *s, PyObject *args) { - int ret = -1; - PyObject *in_b = NULL; - PedGeometry *out_a = NULL, *out_b = NULL; - - if (!PyArg_ParseTuple(args, "O!", &_ped_Geometry_Type_obj, &in_b)) { - return NULL; - } - - out_a = _ped_Geometry2PedGeometry(s); - if (out_a == NULL) { - return NULL; - } - - out_b = _ped_Geometry2PedGeometry(in_b); - if (out_b == NULL) { - return NULL; - } - - ret = ped_geometry_test_equal(out_a, out_b); - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_geometry_test_sector_inside(PyObject *s, PyObject *args) { - int ret = -1; - PedGeometry *geom = NULL; - PedSector sector; - - if (!PyArg_ParseTuple(args, "L", §or)) { - return NULL; - } - - geom = _ped_Geometry2PedGeometry(s); - if (geom == NULL) { - return NULL; - } - - ret = ped_geometry_test_sector_inside(geom, sector); - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_geometry_read(PyObject *s, PyObject *args) { - PyObject *ret = NULL; - PedGeometry *geom = NULL; - char *out_buf = NULL; - PedSector offset, count; - - if (!PyArg_ParseTuple(args, "LL", &offset, &count)) { - return NULL; - } - - geom = _ped_Geometry2PedGeometry(s); - if (geom == NULL) { - return NULL; - } - - /* py_device_read will ASSERT if the device isn't open yet. */ - if (geom->dev->open_count <= 0) { - PyErr_SetString(IOException, "Attempting to read from a unopened device"); - return NULL; - } - - /* And then py_geometry_read will ASSERT on these things too. */ - if (offset < 0 || count < 0) { - PyErr_SetString(IOException, "offset and count cannot be negative."); - return NULL; - } - - if ((out_buf = malloc(geom->dev->sector_size * count)) == NULL) { - return PyErr_NoMemory(); - } - - if (ped_geometry_read(geom, out_buf, offset, count) == 0) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(IOException, partedExnMessage); - } - else - PyErr_SetString(IOException, "Could not read from given region"); - - free(out_buf); - return NULL; - } - - ret = PyUnicode_FromString(out_buf); - free(out_buf); - - return ret; -} - -PyObject *py_ped_geometry_sync(PyObject *s, PyObject *args) { - int ret = -1; - PedGeometry *geom = NULL; - - geom = _ped_Geometry2PedGeometry(s); - if (geom == NULL) { - return NULL; - } - - ret = ped_geometry_sync(geom); - if (ret == 0) { - PyErr_SetString(IOException, "Could not sync"); - return NULL; - } - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_geometry_sync_fast(PyObject *s, PyObject *args) { - int ret = -1; - PedGeometry *geom = NULL; - - geom = _ped_Geometry2PedGeometry(s); - if (geom == NULL) { - return NULL; - } - - ret = ped_geometry_sync_fast(geom); - if (ret == 0) { - PyErr_SetString(IOException, "Could not sync"); - return NULL; - } - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_geometry_write(PyObject *s, PyObject *args) { - int ret = -1; - char *in_buf = NULL; - PedGeometry *geom = NULL; - PedSector offset, count; - - if (!PyArg_ParseTuple(args, "sLL", &in_buf, &offset, &count)) { - return NULL; - } - - geom = _ped_Geometry2PedGeometry(s); - if (geom == NULL) { - return NULL; - } - - /* py_device_write will ASSERT if the device isn't open yet. */ - if (geom->dev->open_count <= 0) { - PyErr_SetString(IOException, "Attempting to write to a unopened device"); - return NULL; - } - - /* And then py_geometry_wriet will ASSERT on these things too. */ - if (offset < 0 || count < 0) { - PyErr_SetString(IOException, "offset and count cannot be negative."); - return NULL; - } - - ret = ped_geometry_write(geom, in_buf, offset, count); - if (ret == 0) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_ExceptionMatches(PartedException) && - !PyErr_ExceptionMatches(PyExc_NotImplementedError)) - PyErr_SetString(IOException, partedExnMessage); - } - else - PyErr_SetString(IOException, "Could not write to given region"); - - return NULL; - } - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_geometry_check(PyObject *s, PyObject *args) { - PyObject *in_timer = NULL; - PedGeometry *geom = NULL; - PedSector offset, granularity, count, ret; - PedTimer *out_timer = NULL; - char *out_buf = NULL; - - if (!PyArg_ParseTuple(args, "LLL|O!", &offset, &granularity, &count, - &_ped_Timer_Type_obj, &in_timer)) { - return NULL; - } - - geom = _ped_Geometry2PedGeometry(s); - if (geom == NULL) { - return NULL; - } - - if (!geom->dev->open_count) { - PyErr_Format(IOException, "Device %s is not open.", geom->dev->path); - return NULL; - } - - if (geom->dev->external_mode) { - PyErr_Format(IOException, "Device %s is already open for external access.", geom->dev->path); - return NULL; - } - - if (in_timer) - out_timer = _ped_Timer2PedTimer(in_timer); - else - out_timer = NULL; - - if ((out_buf = malloc(geom->dev->sector_size * 32)) == NULL) { - ped_timer_destroy(out_timer); - return PyErr_NoMemory(); - } - - ret = ped_geometry_check(geom, out_buf, 32, offset, - granularity, count, out_timer); - ped_timer_destroy(out_timer); - free(out_buf); - - return PyLong_FromLong(ret); -} - -PyObject *py_ped_geometry_map(PyObject *s, PyObject *args) { - int ret = -1; - PyObject *in_dst = NULL; - PedGeometry *out_dst = NULL, *src = NULL; - PedSector sector; - - if (!PyArg_ParseTuple(args, "O!L", &_ped_Geometry_Type_obj, &in_dst, - §or)) { - return NULL; - } - - src = _ped_Geometry2PedGeometry(s); - if (src == NULL) { - return NULL; - } - - out_dst = _ped_Geometry2PedGeometry(in_dst); - if (out_dst == NULL) { - return NULL; - } - - ret = ped_geometry_map(out_dst, src, sector); - if (ret == -1) { - PyErr_SetString(PyExc_ArithmeticError, "Sector must exist within region given by geometry"); - return NULL; - } - - return Py_BuildValue("i", ret); -} - -/* vim:tw=78:ts=4:et:sw=4 - */ diff --git a/src/pynatmath.c b/src/pynatmath.c deleted file mode 100644 index bb84cfb..0000000 --- a/src/pynatmath.c +++ /dev/null @@ -1,354 +0,0 @@ -/* - * pynatmath.c - * - * Copyright (C) 2007-2013 Red Hat, Inc. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions of - * the GNU General Public License v.2, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY expressed or implied, including the implied warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. Any Red Hat trademarks that are incorporated in the - * source code or documentation are not subject to the GNU General Public - * License and may only be used or replicated with the express permission of - * Red Hat, Inc. - * - * Author(s): David Cantrell - * Chris Lumens - * Alex Skinner - */ - -#include - -#include "convert.h" -#include "exceptions.h" -#include "pydevice.h" -#include "pynatmath.h" -#include "docstrings/pynatmath.h" -#include "typeobjects/pynatmath.h" - -/* _ped.Alignment functions */ -void _ped_Alignment_dealloc(_ped_Alignment *self) { - PyObject_GC_UnTrack(self); - PyObject_GC_Del(self); -} - -int _ped_Alignment_compare(_ped_Alignment *self, PyObject *obj) { - _ped_Alignment *comp = NULL; - int check = PyObject_IsInstance(obj, (PyObject *) &_ped_Alignment_Type_obj); - - if (PyErr_Occurred()) { - return -1; - } - - if (!check) { - PyErr_SetString(PyExc_ValueError, "object comparing to must be a _ped.Alignment"); - return -1; - } - - comp = (_ped_Alignment *) obj; - if ((self->offset == comp->offset) && - (self->grain_size == comp->grain_size)) { - return 0; - } else { - return 1; - } -} - -PyObject *_ped_Alignment_richcompare(_ped_Alignment *a, PyObject *b, int op) { - if (op == Py_EQ || op == Py_NE) { - int rv = _ped_Alignment_compare(a, b); - if (PyErr_Occurred()) - return NULL; - return PyBool_FromLong(op == Py_EQ ? rv == 0 : rv != 0); - } else if ((op == Py_LT) || (op == Py_LE) || - (op == Py_GT) || (op == Py_GE)) { - PyErr_SetString(PyExc_TypeError, "comparison operator not supported for _ped.Alignment"); - return NULL; - } else { - PyErr_SetString(PyExc_ValueError, "unknown richcompare op"); - return NULL; - } -} - -PyObject *_ped_Alignment_str(_ped_Alignment *self) { - char *ret = NULL; - - if (asprintf(&ret, "_ped.Alignment instance --\n" - " offset: %lld grain_size: %lld", - self->offset, self->grain_size) == -1) { - return PyErr_NoMemory(); - } - - return Py_BuildValue("s", ret); -} - -int _ped_Alignment_traverse(_ped_Alignment *self, visitproc visit, void *arg) { - return 0; -} - -int _ped_Alignment_clear(_ped_Alignment *self) { - return 0; -} - -int _ped_Alignment_init(_ped_Alignment *self, PyObject *args, PyObject *kwds) { - static char *kwlist[] = {"offset", "grain_size", NULL}; - PedAlignment *alignment = NULL; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "LL", kwlist, - &self->offset, &self->grain_size)) { - return -1; - } else { - alignment = ped_alignment_new(self->offset, self->grain_size); - if (!alignment) { - PyErr_SetString(CreateException, "Could not create new alignment"); - return -1; - } - - self->offset = alignment->offset; - self->grain_size = alignment->grain_size; - - ped_alignment_destroy(alignment); - return 0; - } -} - -PyObject *_ped_Alignment_get(_ped_Alignment *self, void *closure) { - char *member = (char *) closure; - - if (member == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty _ped.Alignment()"); - return NULL; - } - - if (!strcmp(member, "offset")) { - return PyLong_FromLong(self->offset); - } else if (!strcmp(member, "grain_size")) { - return PyLong_FromLong(self->grain_size); - } else { - PyErr_Format(PyExc_AttributeError, "_ped.Alignment object has no attribute %s", member); - return NULL; - } -} - -int _ped_Alignment_set(_ped_Alignment *self, PyObject *value, void *closure) { - char *member = (char *) closure; - - if (member == NULL) { - return -1; - } - - if (!strcmp(member, "offset")) { - self->offset = PyLong_AsLong(value); - if (PyErr_Occurred()) { - return -1; - } - } else if (!strcmp(member, "grain_size")) { - self->grain_size = PyLong_AsLong(value); - if (PyErr_Occurred()) { - return -1; - } - } else { - return -1; - } - - return 0; -} - -/* 1:1 function mappings for natmath.h in libparted */ -PyObject *py_ped_alignment_duplicate(PyObject *s, PyObject *args) { - PedAlignment *alignment = NULL, *align = NULL; - _ped_Alignment *ret = NULL; - - alignment = _ped_Alignment2PedAlignment(s); - if (alignment == NULL) { - return NULL; - } - - align = ped_alignment_duplicate(alignment); - - ped_alignment_destroy(alignment); - - if (align) { - ret = PedAlignment2_ped_Alignment(align); - } - else { - PyErr_SetString(CreateException, "Could not duplicate alignment"); - return NULL; - } - - ped_alignment_destroy(align); - - return (PyObject *) ret; -} - -PyObject *py_ped_alignment_intersect(PyObject *s, PyObject *args) { - PyObject *in_b = NULL; - PedAlignment *out_a = NULL, *out_b = NULL, *align = NULL; - _ped_Alignment *ret = NULL; - - if (!PyArg_ParseTuple(args, "O!", &_ped_Alignment_Type_obj, &in_b)) { - return NULL; - } - - out_a = _ped_Alignment2PedAlignment(s); - if (out_a == NULL) { - return NULL; - } - - out_b = _ped_Alignment2PedAlignment(in_b); - if (out_b == NULL) { - return NULL; - } - - align = ped_alignment_intersect(out_a, out_b); - - ped_alignment_destroy(out_a); - ped_alignment_destroy(out_b); - - if (align) { - ret = PedAlignment2_ped_Alignment(align); - } - else { - PyErr_SetString(PyExc_ArithmeticError, "Could not find alignment intersection"); - return NULL; - } - - ped_alignment_destroy(align); - - return (PyObject *) ret; -} - -PyObject *py_ped_alignment_align_up(PyObject *s, PyObject *args) { - PyObject *in_geom = NULL; - PedAlignment *align = NULL; - PedGeometry *out_geom = NULL; - PedSector sector, ret; - - if (!PyArg_ParseTuple(args, "O!L", &_ped_Geometry_Type_obj, &in_geom, §or)) { - return NULL; - } - - align = _ped_Alignment2PedAlignment(s); - if (align == NULL) { - return NULL; - } - - out_geom = _ped_Geometry2PedGeometry(in_geom); - if (out_geom == NULL) { - return NULL; - } - - ret = ped_alignment_align_up(align, out_geom, sector); - - ped_alignment_destroy(align); - - if (ret == -1) { - PyErr_SetString(PyExc_ArithmeticError, "Could not align up to sector"); - return NULL; - } - - return PyLong_FromLong(ret); -} - -PyObject *py_ped_alignment_align_down(PyObject *s, PyObject *args) { - PyObject *in_geom = NULL; - PedAlignment *align = NULL; - PedGeometry *out_geom = NULL; - PedSector sector, ret; - - if (!PyArg_ParseTuple(args, "O!L", &_ped_Geometry_Type_obj, &in_geom, §or)) { - return NULL; - } - - align = _ped_Alignment2PedAlignment(s); - if (align == NULL) { - return NULL; - } - - out_geom = _ped_Geometry2PedGeometry(in_geom); - if (out_geom == NULL) { - return NULL; - } - - ret = ped_alignment_align_down(align, out_geom, sector); - - ped_alignment_destroy(align); - - if (ret == -1) { - PyErr_SetString(PyExc_ArithmeticError, "Could not align down to sector"); - return NULL; - } - - return PyLong_FromLong(ret); -} - -PyObject *py_ped_alignment_align_nearest(PyObject *s, PyObject *args) { - PyObject *in_geom = NULL; - PedAlignment *align = NULL; - PedGeometry *out_geom = NULL; - PedSector sector, ret; - - if (!PyArg_ParseTuple(args, "O!L", &_ped_Geometry_Type_obj, &in_geom, §or)) { - return NULL; - } - - align = _ped_Alignment2PedAlignment(s); - if (align == NULL) { - return NULL; - } - - out_geom = _ped_Geometry2PedGeometry(in_geom); - if (out_geom == NULL) { - return NULL; - } - - ret = ped_alignment_align_nearest(align, out_geom, sector); - - ped_alignment_destroy(align); - - if (ret == -1) { - PyErr_SetString(PyExc_ArithmeticError, "Could not align to closest sector"); - return NULL; - } - - return PyLong_FromLong(ret); -} - -PyObject *py_ped_alignment_is_aligned(PyObject *s, PyObject *args) { - int ret = -1; - PyObject *in_geom = NULL; - PedAlignment *align = NULL; - PedGeometry *out_geom = NULL; - PedSector sector; - - if (!PyArg_ParseTuple(args, "O!L", &_ped_Geometry_Type_obj, &in_geom, §or)) { - return NULL; - } - - align = _ped_Alignment2PedAlignment(s); - if (align == NULL) { - return NULL; - } - - out_geom = _ped_Geometry2PedGeometry(in_geom); - if (out_geom == NULL) { - return NULL; - } - - ret = ped_alignment_is_aligned(align, out_geom, sector); - ped_alignment_destroy(align); - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -/* vim:tw=78:ts=4:et:sw=4 - */ diff --git a/src/pytimer.c b/src/pytimer.c deleted file mode 100644 index b9b3277..0000000 --- a/src/pytimer.c +++ /dev/null @@ -1,345 +0,0 @@ -/* - * pytimer.c - * - * Copyright (C) 2007-2013 Red Hat, Inc. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions of - * the GNU General Public License v.2, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY expressed or implied, including the implied warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. Any Red Hat trademarks that are incorporated in the - * source code or documentation are not subject to the GNU General Public - * License and may only be used or replicated with the express permission of - * Red Hat, Inc. - * - * Author(s): David Cantrell - * Chris Lumens - * Alex Skinner - */ - -#include - -#include "convert.h" -#include "exceptions.h" -#include "pytimer.h" -#include "typeobjects/pytimer.h" - -/* _ped.Timer functions */ -void _ped_Timer_dealloc(_ped_Timer *self) { - PyObject_GC_UnTrack(self); - free(self->state_name); - PyObject_GC_Del(self); -} - -int _ped_Timer_compare(_ped_Timer *self, PyObject *obj) { - _ped_Timer *comp = NULL; - int check = PyObject_IsInstance(obj, (PyObject *) &_ped_Timer_Type_obj); - - if (PyErr_Occurred()) { - return -1; - } - - if (!check) { - PyErr_SetString(PyExc_ValueError, "object comparing to must be a _ped.Timer"); - return -1; - } - - comp = (_ped_Timer *) obj; - if ((self->frac == comp->frac) && - (self->start == comp->start) && - (self->now == comp->now) && - (self->predicted_end == comp->predicted_end) && - (!strcmp(self->state_name, comp->state_name)) && - (self->handler == comp->handler) && - (self->context == comp->context)) { - return 0; - } else { - return 1; - } -} - -PyObject *_ped_Timer_richcompare(_ped_Timer *a, PyObject *b, int op) { - if (op == Py_EQ || op == Py_NE) { - int rv = _ped_Timer_compare(a, b); - if (PyErr_Occurred()) - return NULL; - return PyBool_FromLong(op == Py_EQ ? rv == 0 : rv != 0); - } else if ((op == Py_LT) || (op == Py_LE) || - (op == Py_GT) || (op == Py_GE)) { - PyErr_SetString(PyExc_TypeError, "comparison operator not supported for _ped.Timer"); - return NULL; - } else { - PyErr_SetString(PyExc_ValueError, "unknown richcompare op"); - return NULL; - } -} - -PyObject *_ped_Timer_str(_ped_Timer *self) { - char *ret = NULL; - - if (asprintf(&ret, "_ped.Timer instance --\n" - " start: %s now: %s\n" - " predicted_end: %s frac: %f\n" - " state_name: %s", - ctime(&(self->start)), ctime(&(self->now)), - ctime(&(self->predicted_end)), self->frac, - self->state_name) == -1) { - return PyErr_NoMemory(); - } - - return Py_BuildValue("s", ret); -} - -int _ped_Timer_traverse(_ped_Timer *self, visitproc visit, void *arg) { - return 0; -} - -int _ped_Timer_clear(_ped_Timer *self) { - return 0; -} - -int _ped_Timer_init(_ped_Timer *self, PyObject *args, PyObject *kwds) { - static char *kwlist[] = {"frac", "start", "now", "predicted_end", - "state_name", NULL}; - - self->state_name = NULL; - - /* XXX: timers aren't really done yet in pyparted */ - PyErr_SetString(PyExc_NotImplementedError, NULL); - return -1; - - if (kwds == NULL) { - if (!PyArg_ParseTuple(args, "|fdddz", &self->frac, &self->start, - &self->now, &self->predicted_end, - &self->state_name)) - return -1; - } else { - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|fdddz", kwlist, - &self->frac, &self->start, &self->now, - &self->predicted_end, &self->state_name)) - return -2; - } - - /* self->state_name now points to the internal buffer of a PyUnicode object, - * which may be freed when its refcount drops to zero, so strdup it. - */ - if (self->state_name) { - self->state_name = strdup(self->state_name); - if (!self->state_name) { - PyErr_NoMemory(); - return -3; - } - } - - return 0; -} - -PyObject *_ped_Timer_get(_ped_Timer *self, void *closure) { - char *member = (char *) closure; - - if (member == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty _ped.Timer()"); - return NULL; - } - - if (!strcmp(member, "frac")) { - return Py_BuildValue("f", self->frac); - } else if (!strcmp(member, "start")) { - return Py_BuildValue("d", self->start); - } else if (!strcmp(member, "now")) { - return Py_BuildValue("d", self->now); - } else if (!strcmp(member, "predicted_end")) { - return Py_BuildValue("d", self->predicted_end); - } else if (!strcmp(member, "state_name")) { - if (self->state_name != NULL) - return PyUnicode_FromString(self->state_name); - else - return PyUnicode_FromString(""); - } else { - PyErr_Format(PyExc_AttributeError, "_ped.Timer object has no attribute %s", member); - return NULL; - } -} - -int _ped_Timer_set(_ped_Timer *self, PyObject *value, void *closure) { - char *member = (char *) closure; - - if (member == NULL) { - PyErr_SetString(PyExc_TypeError, "Empty _ped.Timer()"); - return -1; - } - - if (!strcmp(member, "frac")) { - if (!PyArg_ParseTuple(value, "f", &self->frac)) { - return -1; - } - } else if (!strcmp(member, "start")) { - self->start = PyFloat_AsDouble(value); - if (PyErr_Occurred()) { - return -1; - } - } else if (!strcmp(member, "now")) { - self->now = PyFloat_AsDouble(value); - if (PyErr_Occurred()) { - return -1; - } - } else if (!strcmp(member, "predicted_end")) { - self->predicted_end = PyFloat_AsDouble(value); - if (PyErr_Occurred()) { - return -1; - } - } else if (!strcmp(member, "state_name")) { - self->state_name = PyUnicode_AsUTF8(value); - if (PyErr_Occurred()) { - return -1; - } - /* self->state_name now points to the internal buffer of a PyUnicode obj - * which may be freed when its refcount drops to zero, so strdup it. - */ - if (self->state_name) { - self->state_name = strdup(self->state_name); - if (!self->state_name) { - PyErr_NoMemory(); - return -2; - } - } - } else { - PyErr_Format(PyExc_AttributeError, "_ped.Timer object has no attribute %s", member); - return -1; - } - - return 0; -} - -/* 1:1 function mappings for timer.h in libparted */ -PyObject *py_ped_timer_destroy(PyObject *s, PyObject *args) { - Py_CLEAR(s); - - Py_INCREF(Py_None); - return Py_None; -} - -PyObject *py_ped_timer_new_nested(PyObject *s, PyObject *args) { - float nest_frac; - PedTimer *parent = NULL, *timer = NULL; - _ped_Timer *ret = NULL; - - if (!PyArg_ParseTuple(args, "f", &nest_frac)) - return NULL; - - parent = _ped_Timer2PedTimer(s); - if (parent == NULL) { - return NULL; - } - - timer = ped_timer_new_nested(parent, nest_frac); - - ped_timer_destroy(parent); - - if (timer) { - ret = PedTimer2_ped_Timer(timer); - } - else { - PyErr_SetString(CreateException, "Could not create new nested timer"); - return NULL; - } - - ped_timer_destroy(timer); - - return (PyObject *) ret; -} - -PyObject *py_ped_timer_destroy_nested(PyObject *s, PyObject *args) { - PedTimer *timer = NULL; - - timer = _ped_Timer2PedTimer(s); - if (timer == NULL) { - return NULL; - } - - ped_timer_destroy_nested(timer); - ped_timer_destroy(timer); - Py_CLEAR(s); - - Py_INCREF(Py_None); - return Py_None; -} - -PyObject *py_ped_timer_touch(PyObject *s, PyObject *args) { - PedTimer *timer = NULL; - - timer = _ped_Timer2PedTimer(s); - if (timer == NULL) { - return NULL; - } - - ped_timer_touch(timer); - ped_timer_destroy(timer); - - Py_INCREF(Py_None); - return Py_None; -} - -PyObject *py_ped_timer_reset(PyObject *s, PyObject *args) { - PedTimer *timer = NULL; - - timer = _ped_Timer2PedTimer(s); - if (timer == NULL) { - return NULL; - } - - ped_timer_reset(timer); - ped_timer_destroy(timer); - - Py_INCREF(Py_None); - return Py_None; -} - -PyObject *py_ped_timer_update(PyObject *s, PyObject *args) { - float frac; - PedTimer *timer = NULL; - - if (!PyArg_ParseTuple(args, "f", &frac)) - return NULL; - - timer = _ped_Timer2PedTimer(s); - if (timer == NULL) { - return NULL; - } - - ped_timer_update(timer, frac); - ped_timer_destroy(timer); - - Py_INCREF(Py_None); - return Py_None; -} - -PyObject *py_ped_timer_set_state_name(PyObject *s, PyObject *args) { - char *str = NULL; - PedTimer *timer = NULL; - - if (!PyArg_ParseTuple(args, "z", &str)) { - return NULL; - } - - timer = _ped_Timer2PedTimer(s); - if (timer == NULL) { - return NULL; - } - - ped_timer_set_state_name(timer, str); - - ped_timer_destroy(timer); - free(str); - - Py_INCREF(Py_None); - return Py_None; -} - -/* vim:tw=78:ts=4:et:sw=4 - */ diff --git a/src/pyunit.c b/src/pyunit.c deleted file mode 100644 index 9212387..0000000 --- a/src/pyunit.c +++ /dev/null @@ -1,315 +0,0 @@ -/* - * pyunit.c - * - * Copyright (C) 2007-2013 Red Hat, Inc. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions of - * the GNU General Public License v.2, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY expressed or implied, including the implied warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the - * GNU General Public License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. Any Red Hat trademarks that are incorporated in the - * source code or documentation are not subject to the GNU General Public - * License and may only be used or replicated with the express permission of - * Red Hat, Inc. - * - * Author(s): David Cantrell - * Chris Lumens - * Alex Skinner - */ - -#include - -#include "convert.h" -#include "exceptions.h" -#include "pydevice.h" -#include "pyunit.h" - -/* 1:1 function mappings for unit.h in libparted */ -PyObject *py_ped_unit_set_default(PyObject *s, PyObject *args) { - int unit; - - if (!PyArg_ParseTuple(args, "i", &unit)) { - return NULL; - } - - if (unit < PED_UNIT_FIRST || unit > PED_UNIT_LAST) { - PyErr_SetString(PyExc_ValueError, "Invalid unit provided."); - return NULL; - } - - ped_unit_set_default(unit); - - Py_INCREF(Py_None); - return Py_None; -} - -PyObject *py_ped_unit_get_default(PyObject *s, PyObject *args) { - return PyLong_FromLong(ped_unit_get_default()); -} - -PyObject *py_ped_unit_get_size(PyObject *s, PyObject *args) { - long long ret = -1; - PedDevice *dev = NULL; - int unit; - - if (!PyArg_ParseTuple(args, "i", &unit)) - return NULL; - - if (unit < PED_UNIT_FIRST || unit > PED_UNIT_LAST) { - PyErr_SetString(PyExc_ValueError, "Invalid unit provided."); - return NULL; - } - - dev = _ped_Device2PedDevice(s); - if (dev == NULL) { - return NULL; - } - - ret = ped_unit_get_size(dev, unit); - if (ret == 0) { - if (partedExnRaised) { - partedExnRaised = 0; - - if (!PyErr_Occurred()) { - PyErr_SetString(PyExc_ValueError, partedExnMessage); - } - } else { - PyErr_SetString(PyExc_ValueError, "Could not get size"); - } - - return NULL; - } - - return PyLong_FromLongLong(ret); -} - -PyObject *py_ped_unit_get_name(PyObject *s, PyObject *args) { - const char *name; - int unit; - - if (!PyArg_ParseTuple(args, "i", &unit)) { - return NULL; - } - - if (unit < PED_UNIT_FIRST || unit > PED_UNIT_LAST) { - PyErr_SetString(PyExc_ValueError, "Invalid unit provided."); - return NULL; - } - - /* - * DO NOT free the result from ped_unit_get_name(), it's a pointer to - * a value in the static unit_names[] array in libparted. - */ - name = ped_unit_get_name(unit); - if (name != NULL) { - return PyUnicode_FromString(name); - } else { - return PyUnicode_FromString(""); - } -} - -PyObject *py_ped_unit_get_by_name(PyObject *s, PyObject *args) { - int ret; - char *name = NULL; - - if (!PyArg_ParseTuple(args, "z", &name)) { - return NULL; - } - - ret = ped_unit_get_by_name(name); - if (ret < PED_UNIT_FIRST || ret > PED_UNIT_LAST) { - PyErr_SetString(UnknownTypeException, name); - return NULL; - } - - return Py_BuildValue("i", ret); -} - -PyObject *py_ped_unit_format_custom_byte(PyObject *s, PyObject *args) { - PyObject *ret = NULL; - char *pedret = NULL; - PedSector sector; - int unit; - PedDevice *out_dev = NULL; - - if (!PyArg_ParseTuple(args, "Li", §or, &unit)) { - return NULL; - } - - if (unit < PED_UNIT_FIRST || unit > PED_UNIT_LAST) { - PyErr_SetString(PyExc_ValueError, "Invalid unit provided."); - return NULL; - } - - out_dev = _ped_Device2PedDevice(s); - if (out_dev == NULL) { - return NULL; - } - - pedret = ped_unit_format_custom_byte(out_dev, sector, unit); - if (pedret != NULL) { - ret = PyUnicode_FromString(pedret); - free(pedret); - } else { - ret = PyUnicode_FromString(""); - } - - return ret; -} - -PyObject *py_ped_unit_format_byte(PyObject *s, PyObject *args) { - PyObject *ret = NULL; - char *pedret = NULL; - PedSector sector; - PedDevice *out_dev = NULL; - - if (!PyArg_ParseTuple(args, "L", §or)) { - return NULL; - } - - out_dev = _ped_Device2PedDevice(s); - if (out_dev == NULL) { - return NULL; - } - - pedret = ped_unit_format_byte(out_dev, sector); - if (pedret != NULL) { - ret = PyUnicode_FromString(pedret); - free(pedret); - } else { - ret = PyUnicode_FromString(""); - } - - return ret; -} - -PyObject *py_ped_unit_format_custom(PyObject *s, PyObject *args) { - PyObject *ret = NULL; - char *pedret = NULL; - PedDevice *out_dev = NULL; - PedSector sector; - int unit; - - if (!PyArg_ParseTuple(args, "Li", §or, &unit)) { - return NULL; - } - - out_dev = _ped_Device2PedDevice(s); - if (out_dev == NULL) { - return NULL; - } - - pedret = ped_unit_format_custom(out_dev, sector, unit); - if (pedret != NULL) { - ret = PyUnicode_FromString(pedret); - free(pedret); - } else { - ret = PyUnicode_FromString(""); - } - - return ret; -} - -PyObject *py_ped_unit_format(PyObject *s, PyObject *args) { - PyObject *ret = NULL; - char *pedret = NULL; - PedDevice *out_dev = NULL; - PedSector sector; - - if (!PyArg_ParseTuple(args, "L", §or)) { - return NULL; - } - - out_dev = _ped_Device2PedDevice(s); - if (out_dev == NULL) { - return NULL; - } - - pedret = ped_unit_format(out_dev, sector); - if (pedret != NULL) { - ret = PyUnicode_FromString(pedret); - free(pedret); - } else { - ret = PyUnicode_FromString(""); - } - - return ret; -} - -PyObject *py_ped_unit_parse(PyObject *s, PyObject *args) { - int ret; - char *str = NULL; - PedDevice *out_dev = NULL; - PedSector sector; - PyObject *in_geom = NULL; - PedGeometry *out_geom = NULL; - - if (!PyArg_ParseTuple(args, "zLO!", &str, §or, - &_ped_Geometry_Type_obj, &in_geom)) { - return NULL; - } - - out_dev = _ped_Device2PedDevice(s); - if (out_dev == NULL) { - return NULL; - } - - out_geom = _ped_Geometry2PedGeometry(in_geom); - if (out_geom == NULL) { - return NULL; - } - - ret = ped_unit_parse(str, out_dev, §or, &out_geom); - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyObject *py_ped_unit_parse_custom(PyObject *s, PyObject *args) { - int ret; - char *str = NULL; - PedDevice *out_dev = NULL; - int unit; - PedSector sector; - PyObject *in_geom = NULL; - PedGeometry *out_geom = NULL; - - if (!PyArg_ParseTuple(args, "ziLO!", &str, &unit, §or, - &_ped_Geometry_Type_obj, &in_geom)) { - return NULL; - } - - if (unit < PED_UNIT_FIRST || unit > PED_UNIT_LAST) { - PyErr_SetString(PyExc_ValueError, "Invalid unit provided."); - return NULL; - } - - out_dev = _ped_Device2PedDevice(s); - if (out_dev == NULL) { - return NULL; - } - - out_geom = _ped_Geometry2PedGeometry(in_geom); - if (out_geom == NULL) { - return NULL; - } - - ret = ped_unit_parse_custom(str, out_dev, unit, §or, &out_geom); - - if (ret) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -/* vim:tw=78:ts=4:et:sw=4 - */ diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/baseclass.py b/tests/baseclass.py deleted file mode 100644 index 0fd5f2c..0000000 --- a/tests/baseclass.py +++ /dev/null @@ -1,195 +0,0 @@ -# -# Copyright (C) 2008-2011 Red Hat, Inc. -# -# This copyrighted material is made available to anyone wishing to use, -# modify, copy, or redistribute it subject to the terms and conditions of -# the GNU General Public License v.2, or (at your option) any later version. -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY expressed or implied, including the implied warranties of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. You should have received a copy of the -# GNU General Public License along with this program; if not, write to the -# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the -# source code or documentation are not subject to the GNU General Public -# License and may only be used or replicated with the express permission of -# Red Hat, Inc. -# -# Red Hat Author(s): Chris Lumens -# David Cantrell - -import _ped -import parted -import os -import tempfile -import unittest - -# Base class for any test case that requires a temp device node -class RequiresDeviceNode(unittest.TestCase): - def setUp(self): - (fd, self.path) = tempfile.mkstemp(prefix="temp-device-") - f = os.fdopen(fd) - f.seek(140000) - os.write(fd, b"0") - - def tearDown(self): - os.unlink(self.path) - -# Base class for any test case that requires a _ped.Device or parted.Device -# object first. -class RequiresDevice(RequiresDeviceNode): - def setUp(self): - RequiresDeviceNode.setUp(self) - self._device = _ped.device_get(self.path) - self.device = parted.getDevice(self.path) - -# Base class for any test case that requires a filesystem on a device. -class RequiresFileSystem(unittest.TestCase): - def setUp(self): - self._fileSystemType = {} - type = _ped.file_system_type_get_next() - self._fileSystemType[type.name] = type - - while True: - try: - type = _ped.file_system_type_get_next(type) - self._fileSystemType[type.name] = type - except: - break - - (fd, self.path,) = tempfile.mkstemp(prefix="temp-device-") - f = os.fdopen(fd) - f.seek(140000) - os.write(fd, b"0") - f.close() - - os.system("/sbin/mke2fs -F -q %s" % (self.path,)) - - self._device = _ped.device_get(self.path) - self._geometry = _ped.Geometry(self._device, 0, self._device.length - 1) - - def tearDown(self): - os.unlink(self.path) - -# Base class for certain alignment tests that require a _ped.Device -class RequiresDeviceAlignment(RequiresDevice): - def setUp(self): - RequiresDevice.setUp(self) - - def roundDownTo(self, sector, grain_size): - if sector < 0: - shift = sector % grain_size + grain_size - else: - shift = sector % grain_size - - return sector - shift - - def roundUpTo(self, sector, grain_size): - if sector % grain_size: - return self.roundDownTo(sector, grain_size) + grain_size - else: - return sector - - def closestInsideGeometry(self, alignment, geometry, sector): - if alignment.grain_size == 0: - if alignment.is_aligned(geometry, sector) and \ - ((geometry is None) or geometry.test_sector_inside(sector)): - return sector - else: - return -1 - - if sector < geometry.start: - sector += self.roundUpTo(geometry.start - sector, - alignment.grain_size) - - if sector > geometry.end: - sector -= self.roundUpTo(sector - geometry.end, - alignment.grain_size) - - if not geometry.test_sector_inside(sector): - return -1 - - return sector - - def closest(self, sector, a, b): - if a == -1: - return b - - if b == -1: - return a - - if abs(sector - a) < abs(sector - b): - return a - else: - return b - -# Base class for any test case that requires a labeled device -class RequiresLabeledDevice(RequiresDevice): - def setUp(self): - RequiresDevice.setUp(self) - os.system("/sbin/parted -s %s mklabel msdos" % (self.path,)) - -# Base class for any test case that requires a _ped.Disk or parted.Disk. -class RequiresDisk(RequiresDevice): - def setUp(self): - RequiresDevice.setUp(self) - self._disk = _ped.disk_new_fresh(self._device, _ped.disk_type_get("msdos")) - self.disk = parted.Disk(PedDisk=self._disk) - -# Base class for any test case that requires a filesystem made and mounted. -class RequiresMount(RequiresDevice): - def mkfs(self): - os.system("/sbin/mkfs.ext2 -F -q %s" % self.path) - - def doMount(self): - self.mountpoint = tempfile.mkdtemp() - os.system("/sbin/mount -o loop %s %s" % (self.path, self.mountpoint)) - - def tearDown(self): - os.system("/sbin/umount %s" % self.mountpoint) - os.rmdir(self.mountpoint) - RequiresDevice.tearDown(self) - -# Base class for any test case that requires a _ped.Partition. -class RequiresPartition(RequiresDisk): - def setUp(self): - RequiresDisk.setUp(self) - self._part = _ped.Partition(disk=self._disk, type=_ped.PARTITION_NORMAL, - start=0, end=100, fs_type=_ped.file_system_type_get("ext2")) - -# Base class for any test case that requires a hash table of all -# _ped.DiskType objects available -class RequiresDiskTypes(unittest.TestCase): - def setUp(self): - self.disktype = {} - type = _ped.disk_type_get_next() - self.disktype[type.name] = type - - while True: - try: - type = _ped.disk_type_get_next(type) - self.disktype[type.name] = type - except: - break - -# Base class for any test case that requires a list being built via successive -# calls of some function. The function must raise IndexError when there's no -# more output to add to the return list. This class is most useful for all -# those _get_next methods. -class BuildList: - def getDeviceList(self, func): - lst = [] - prev = None - - while True: - try: - if not prev: - prev = func() - else: - prev = func(prev) - - lst.append(prev) - except IndexError: - break - - return lst diff --git a/tests/test__ped_alignment.py b/tests/test__ped_alignment.py deleted file mode 100755 index 8da6d82..0000000 --- a/tests/test__ped_alignment.py +++ /dev/null @@ -1,229 +0,0 @@ -# -# Copyright (C) 2008-2011 Red Hat, Inc. -# -# This copyrighted material is made available to anyone wishing to use, -# modify, copy, or redistribute it subject to the terms and conditions of -# the GNU General Public License v.2, or (at your option) any later version. -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY expressed or implied, including the implied warranties of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. You should have received a copy of the -# GNU General Public License along with this program; if not, write to the -# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the -# source code or documentation are not subject to the GNU General Public -# License and may only be used or replicated with the express permission of -# Red Hat, Inc. -# -# Red Hat Author(s): Chris Lumens -# David Cantrell -# - -import _ped -import unittest -from tests.baseclass import * - -# One class per method, multiple tests per class. For these simple methods, -# that seems like good organization. More complicated methods may require -# multiple classes and their own test suite. -class AlignmentNewTestCase(unittest.TestCase): - def runTest(self): - # Check that not passing args to _ped.Alignment.__init__ is caught. - self.assertRaises(TypeError, _ped.Alignment) - - # And then the correct ways of creating a _ped.Alignment. - self.assertIsInstance(_ped.Alignment(0, 100), _ped.Alignment) - self.assertIsInstance(_ped.Alignment(offset=0, grain_size=100), _ped.Alignment) - -class AlignmentGetSetTestCase(unittest.TestCase): - def setUp(self): - self.a = _ped.Alignment(27, 49) - - def runTest(self): - # Test that passing the args to __init__ works. - self.assertIsInstance(self.a, _ped.Alignment) - self.assertEqual(self.a.offset, 27) - self.assertEqual(self.a.grain_size, 49) - - # Test that setting directly and getting with getattr works. - self.a.offset = 10 - self.a.grain_size = 90 - - self.assertEqual(getattr(self.a, "offset"), 10) - self.assertEqual(getattr(self.a, "grain_size"), 90) - - # Check that setting with setattr and getting directly works. - setattr(self.a, "offset", 20) - setattr(self.a, "grain_size", 80) - - self.assertEqual(self.a.offset, 20) - self.assertEqual(self.a.grain_size, 80) - - # Check that values have the right type. - self.assertRaises(TypeError, setattr, self.a, "offset", "string") - - # Check that looking for invalid attributes fails properly. - self.assertRaises(AttributeError, getattr, self.a, "blah") - -class AlignmentDuplicateTestCase(unittest.TestCase): - def setUp(self): - self.a = _ped.Alignment(27, 49) - - def runTest(self): - self.dup = self.a.duplicate() - self.assertEqual(self.a.offset, self.dup.offset) - self.assertEqual(self.a.grain_size, self.dup.grain_size) - -class AlignmentIntersectTestCase(unittest.TestCase): - def setUp(self): - self.trivialA = _ped.Alignment(47, 0) - self.trivialB = _ped.Alignment(47, 0) - - self.complexA = _ped.Alignment(512, 3) - self.complexB = _ped.Alignment(256, 4) - - def orderAlignments(self, a, b): - if a.grain_size < b.grain_size: - tmp = a - a = b - b = tmp - - return (a, b) - - # from libparted/cs/natmath.c - def extendedEuclid(self, a, b): - if b == 0: - gcd = a - x = 1 - y = 0 - return (gcd, x, y) - - (tmp_gcd, tmp_x, tmp_y) = self.extendedEuclid(b, a % b) - gcd = tmp_gcd - x = tmp_y - y = tmp_x - (a / b) * tmp_y - return (gcd, x, y) - - def runTest(self): - # trivial test first, result should be a duplicate of trivialA - trivial = self.trivialA.intersect(self.trivialB) - self.assertEqual(trivial.offset, self.trivialA.offset) - self.assertEqual(trivial.grain_size, self.trivialA.grain_size) - - # complex test second, see libparted/cs/natmath.c for an explanation - # of the math behind computing the intersection of two alignments - (verifyA, verifyB) = self.orderAlignments(self.complexA, self.complexB) - (gcd, x, y) = self.extendedEuclid(verifyA.grain_size, - verifyB.grain_size) - delta_on_gcd = (verifyB.offset - verifyA.offset) / gcd - new_offset = verifyA.offset + x * delta_on_gcd * verifyA.grain_size - new_grain_size = verifyA.grain_size * verifyB.grain_size / gcd - - complex = self.complexA.intersect(self.complexB) - self.assertEqual(new_offset, complex.offset) - self.assertEqual(new_grain_size, complex.grain_size) - -class AlignmentAlignUpTestCase(RequiresDeviceAlignment): - def setUp(self): - RequiresDeviceAlignment.setUp(self) - self.trivialA = _ped.Alignment(10, 0) - self.complexA = _ped.Alignment(512, 34) - self.geometry = _ped.Geometry(self._device, start=0, length=100) - self.sector = 47 - - def runTest(self): - # trivial test case first, grain_size is zero - expected = self.closestInsideGeometry(self.trivialA, self.geometry, - self.trivialA.offset) - result = self.trivialA.align_up(self.geometry, self.sector) - self.assertEqual(result, expected) - - # complex test case second, grain_size is not zero - tmp = self.roundUpTo(self.sector - self.complexA.offset, - self.complexA.grain_size) + self.complexA.offset - expected = self.closestInsideGeometry(self.complexA, self.geometry, tmp) - result = self.complexA.align_up(self.geometry, self.sector) - self.assertEqual(result, expected) - -class AlignmentAlignDownTestCase(RequiresDeviceAlignment): - def setUp(self): - RequiresDeviceAlignment.setUp(self) - self.trivialA = _ped.Alignment(10, 0) - self.complexA = _ped.Alignment(512, 34) - self.geometry = _ped.Geometry(self._device, start=0, length=100) - self.sector = 47 - - def runTest(self): - # trivial test case first, grain_size is zero - expected = self.closestInsideGeometry(self.trivialA, self.geometry, - self.trivialA.offset) - result = self.trivialA.align_down(self.geometry, self.sector) - self.assertEqual(result, expected) - - # complex test case second, grain_size is not zero - tmp = self.roundDownTo(self.sector - self.complexA.offset, - self.complexA.grain_size) + self.complexA.offset - expected = self.closestInsideGeometry(self.complexA, self.geometry, tmp) - result = self.complexA.align_down(self.geometry, self.sector) - self.assertEqual(result, expected) - -class AlignmentAlignNearestTestCase(RequiresDeviceAlignment): - def setUp(self): - RequiresDeviceAlignment.setUp(self) - self.trivialA = _ped.Alignment(10, 0) - self.complexA = _ped.Alignment(512, 34) - self.geometry = _ped.Geometry(self._device, start=0, length=100) - self.sector = 47 - - def runTest(self): - # trivial test case first, grain_size is zero - tmp = self.closestInsideGeometry(self.trivialA, self.geometry, - self.trivialA.offset) - expected = self.closest(self.sector, tmp, tmp) - result = self.trivialA.align_nearest(self.geometry, self.sector) - self.assertEqual(result, expected) - - # complex test case second, grain_size is not zero - tmpA = self.roundUpTo(self.sector - self.complexA.offset, - self.complexA.grain_size) + self.complexA.offset - tmpA = self.closestInsideGeometry(self.complexA, self.geometry, tmpA) - - tmpB = self.roundDownTo(self.sector - self.complexA.offset, - self.complexA.grain_size) + self.complexA.offset - tmpB = self.closestInsideGeometry(self.complexA, self.geometry, tmpB) - - expected = self.closest(self.sector, tmpA, tmpB) - result = self.complexA.align_nearest(self.geometry, self.sector) - self.assertEqual(result, expected) - -class AlignmentIsAlignedTestCase(RequiresDevice): - def setUp(self): - RequiresDevice.setUp(self) - self.g = _ped.Geometry(self._device, start=0, length=100) - self.a = _ped.Alignment(10, 0) - - def runTest(self): - # Test a couple ways of passing bad arguments. - self.assertRaises(TypeError, self.a.is_aligned, None, 12) - self.assertRaises(TypeError, self.a.is_aligned, self.g, None) - - # Sector must be inside the geometry. - self.assertFalse(self.a.is_aligned(self.g, 400)) - - # If grain_size is 0, sector must be the same as offset. - self.assertTrue(self.a.is_aligned(self.g, 10)) - self.assertFalse(self.a.is_aligned(self.g, 0)) - self.assertFalse(self.a.is_aligned(self.g, 47)) - - # If grain_size is anything else, there's real math involved. - self.a.grain_size = 5 - self.assertTrue(self.a.is_aligned(self.g, 20)) - self.assertFalse(self.a.is_aligned(self.g, 23)) - -class AlignmentStrTestCase(unittest.TestCase): - def setUp(self): - self.alignment = _ped.Alignment(10, 0) - - def runTest(self): - expected = "_ped.Alignment instance --\n offset: 10 grain_size: 0" - self.assertEqual(str(self.alignment), expected) diff --git a/tests/test__ped_chsgeometry.py b/tests/test__ped_chsgeometry.py deleted file mode 100755 index 31a04b1..0000000 --- a/tests/test__ped_chsgeometry.py +++ /dev/null @@ -1,55 +0,0 @@ -# -# Copyright (C) 2008-2011 Red Hat, Inc. -# -# This copyrighted material is made available to anyone wishing to use, -# modify, copy, or redistribute it subject to the terms and conditions of -# the GNU General Public License v.2, or (at your option) any later version. -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY expressed or implied, including the implied warranties of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. You should have received a copy of the -# GNU General Public License along with this program; if not, write to the -# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the -# source code or documentation are not subject to the GNU General Public -# License and may only be used or replicated with the express permission of -# Red Hat, Inc. -# -# Red Hat Author(s): Chris Lumens -# David Cantrell -# - -import _ped -import unittest - -from tests.baseclass import * - -# One class per method, multiple tests per class. For these simple methods, -# that seems like good organization. More complicated methods may require -# multiple classes and their own test suite. -class CHSGeometryNewTestCase(unittest.TestCase): - def runTest(self): - # You're not allowed to create a new CHSGeometry object by hand. - self.assertRaises(TypeError, _ped.CHSGeometry) - -class CHSGeometryGetSetTestCase(RequiresDevice): - def runTest(self): - # A device has a CHSGeometry, so we can use that to attempt accessing - # parameters. - chs = self._device.hw_geom - self.assertIsInstance(chs, _ped.CHSGeometry) - - # All attributes are read-only. - self.assertRaises(AttributeError, setattr, chs, "cylinders", 47) - self.assertRaises(AttributeError, setattr, chs, "heads", 47) - self.assertRaises(AttributeError, setattr, chs, "sectors", 47) - - self.assertIsInstance(chs.cylinders, int) - self.assertIsInstance(chs.heads, int) - self.assertIsInstance(chs.sectors, int) - -class CHSGeometryStrTestCase(RequiresDevice): - def runTest(self): - expected = "_ped.CHSGeometry instance --\n cylinders: %d heads: %d sectors: %d" % (self._device.hw_geom.cylinders, self._device.hw_geom.heads, self._device.hw_geom.sectors,) - result = str(self._device.hw_geom) - self.assertEqual(result, expected) diff --git a/tests/test__ped_constraint.py b/tests/test__ped_constraint.py deleted file mode 100755 index 10ecb90..0000000 --- a/tests/test__ped_constraint.py +++ /dev/null @@ -1,221 +0,0 @@ -# -# Copyright (C) 2009-2011 Red Hat, Inc. -# -# This copyrighted material is made available to anyone wishing to use, -# modify, copy, or redistribute it subject to the terms and conditions of -# the GNU General Public License v.2, or (at your option) any later version. -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY expressed or implied, including the implied warranties of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. You should have received a copy of the -# GNU General Public License along with this program; if not, write to the -# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the -# source code or documentation are not subject to the GNU General Public -# License and may only be used or replicated with the express permission of -# Red Hat, Inc. -# -# Red Hat Author(s): Chris Lumens -# David Cantrell -# - -import _ped -import unittest - -from tests.baseclass import * - -# One class per method, multiple tests per class. For these simple methods, -# that seems like good organization. More complicated methods may require -# multiple classes and their own test suite. -class ConstraintNewTestCase(RequiresDevice): - def runTest(self): - align1 = _ped.Alignment(10, 5) - align2 = _ped.Alignment(10, 5) - geom1 = _ped.Geometry(self._device, 0, 50) - geom2 = _ped.Geometry(self._device, 25, 50) - - # Check that not passing enough args to _ped.Constraint.__init__ is caught. - self.assertRaises(TypeError, _ped.Constraint) - self.assertRaises(TypeError, _ped.Constraint, align1, align2) - - # Or the parameters in the wrong order. - self.assertRaises(TypeError, _ped.Constraint, align1, align2, 10, 100, - geom1, geom2) - - # And then the correct way of creating a _ped.Constraint. - c = _ped.Constraint(align1, align2, geom1, geom2, 10, 100) - self.assertIsInstance(c, _ped.Constraint) - -class ConstraintGetSetTestCase(RequiresDevice): - def setUp(self): - RequiresDevice.setUp(self) - align1 = _ped.Alignment(10, 5) - align2 = _ped.Alignment(10, 5) - geom1 = _ped.Geometry(self._device, 0, 50) - geom2 = _ped.Geometry(self._device, 25, 50) - - self.c = _ped.Constraint(align1, align2, geom1, geom2, min_size=10, - max_size=100) - - def runTest(self): - # Test that passing the kwargs to __init__ works. - self.assertEqual(self.c.min_size, 10) - self.assertEqual(self.c.max_size, 100) - self.assertIsInstance(self.c.start_align, _ped.Alignment) - self.assertIsInstance(self.c.end_align, _ped.Alignment) - self.assertIsInstance(self.c.start_range, _ped.Geometry) - self.assertIsInstance(self.c.end_range, _ped.Geometry) - - # Test that setting directly and getting with getattr works. - self.c.min_size = 15 - self.c.max_size = 75 - - self.assertEqual(getattr(self.c, "min_size"), 15) - self.assertEqual(getattr(self.c, "max_size"), 75) - self.assertIsInstance(getattr(self.c, "start_align"), _ped.Alignment) - self.assertIsInstance(getattr(self.c, "end_align"), _ped.Alignment) - self.assertIsInstance(getattr(self.c, "start_range"), _ped.Geometry) - self.assertIsInstance(getattr(self.c, "end_range"), _ped.Geometry) - - # Test that setting with setattr and getting directly works. - setattr(self.c, "min_size", 10) - setattr(self.c, "max_size", 90) - - self.assertEqual(self.c.min_size, 10) - self.assertEqual(self.c.max_size, 90) - - # Test that values have the right type. - self.assertRaises(TypeError, setattr, self.c, "min_size", "string") - - # Test that looking for invalid attributes fails properly. - self.assertRaises(AttributeError, getattr, self.c, "blah") - - # We really shouldn't be allowed to overwrite objects stored in a - # _ped.Constraint, but for now there's no way to prevent it. - self.c.end_range = 47 - self.assertEqual(self.c.end_range, 47) - -class ConstraintDuplicateTestCase(RequiresDevice): - def setUp(self): - RequiresDevice.setUp(self) - align1 = _ped.Alignment(10, 0) - align2 = _ped.Alignment(10, 0) - geom1 = _ped.Geometry(self._device, 0, 50) - geom2 = _ped.Geometry(self._device, 25, 50) - - self.c = _ped.Constraint(align1, align2, geom1, geom2, min_size=10, - max_size=100) - - def runTest(self): - self.dup = self.c.duplicate() - self.assertEqual(self.c.min_size, self.dup.min_size) - self.assertEqual(self.c.max_size, self.dup.max_size) - - # duplicate methods should do a deepcopy, so self.dup should have - # different references, but the same contents. - self.assertNotEqual(repr(self.c), repr(self.dup)) - - self.assertNotEqual(repr(self.c.start_align), repr(self.dup.start_align)) - self.assertEqual(self.c.start_align.offset, self.dup.start_align.offset) - self.assertEqual(self.c.start_align.grain_size, self.dup.start_align.grain_size) - - self.assertNotEqual(repr(self.c.end_align), repr(self.dup.end_align)) - self.assertEqual(self.c.end_align.offset, self.dup.end_align.offset) - self.assertEqual(self.c.end_align.grain_size, self.dup.end_align.grain_size) - - self.assertNotEqual(repr(self.c.start_range), repr(self.dup.start_range)) - self.assertNotEqual(repr(self.c.start_range.dev), repr(self.dup.start_range.dev)) - self.assertEqual(self.c.start_range.dev.path, self.dup.start_range.dev.path) - self.assertEqual(self.c.start_range.start, self.dup.start_range.start) - self.assertEqual(self.c.start_range.length, self.dup.start_range.length) - self.assertEqual(self.c.start_range.end, self.dup.start_range.end) - - self.assertNotEqual(repr(self.c.end_range), repr(self.dup.end_range)) - self.assertNotEqual(repr(self.c.end_range.dev), repr(self.dup.end_range.dev)) - self.assertEqual(self.c.end_range.dev.path, self.dup.end_range.dev.path) - self.assertEqual(self.c.end_range.start, self.dup.end_range.start) - self.assertEqual(self.c.end_range.length, self.dup.end_range.length) - self.assertEqual(self.c.end_range.end, self.dup.end_range.end) - -class ConstraintIntersectTestCase(RequiresDevice): - def setUp(self): - RequiresDevice.setUp(self) - align1 = _ped.Alignment(10, 0) - align2 = _ped.Alignment(10, 0) - geom1 = _ped.Geometry(self._device, 0, 50) - geom2 = _ped.Geometry(self._device, 25, 50) - - self.c1 = _ped.Constraint(align1, align2, geom1, geom2, min_size=10, - max_size=100) - - geom3 = _ped.Geometry(self._device, 10, 50) - geom4 = _ped.Geometry(self._device, 30, 40) - self.c2 = _ped.Constraint(align1, align2, geom3, geom4, min_size=10, - max_size=100) - - def runTest(self): - startAlign = self.c1.start_align.intersect(self.c2.start_align) - endAlign = self.c1.end_align.intersect(self.c2.end_align) - startRange = self.c1.start_range.intersect(self.c2.start_range) - endRange = self.c1.end_range.intersect(self.c2.end_range) - minSize = max(self.c1.min_size, self.c2.min_size) - maxSize = min(self.c1.max_size, self.c2.max_size) - - if not startAlign or not endAlign or not startRange or not endRange: - expected = None - else: - expected = _ped.Constraint(startAlign, endAlign, - startRange, endRange, - min_size=minSize, max_size=maxSize) - - result = self.c1.intersect(self.c2) - self.assertEqual(result, expected) - -class ConstraintSolveMaxTestCase(RequiresDevice): - def setUp(self): - RequiresDevice.setUp(self) - self.c1 = self._device.get_constraint() - - def runTest(self): - result = self.c1.solve_max() - self.assertEqual(result.dev, self._device) - self.assertGreaterEqual(result.length, self._device.length - 1) - -class ConstraintSolveNearestTestCase(RequiresDevice): - def setUp(self): - RequiresDevice.setUp(self) - self.c1 = self._device.get_constraint() - self.g1 = _ped.Geometry(self._device, 1, 8) - - def runTest(self): - result = self.c1.solve_nearest(self.g1) - self.assertEqual(result, self.g1) - -class ConstraintIsSolutionTestCase(RequiresDevice): - def setUp(self): - RequiresDevice.setUp(self) - self.c1 = self._device.get_constraint() - self.g1 = _ped.Geometry(self._device, 1, 8) - - def runTest(self): - self.assertTrue(self.c1.is_solution(self.g1)) - -class ConstraintStrTestCase(RequiresDevice): - def setUp(self): - RequiresDevice.setUp(self) - align1 = _ped.Alignment(10, 0) - align2 = _ped.Alignment(10, 0) - geom1 = _ped.Geometry(self._device, 0, 50) - geom2 = _ped.Geometry(self._device, 25, 50) - - self.c1 = _ped.Constraint(align1, align2, geom1, geom2, min_size=10, - max_size=100) - def runTest(self): - result = str(self.c1).split('\n') - - self.assertEqual(result[0], '_ped.Constraint instance --') - self.assertTrue(result[1].startswith(' start_align: <_ped.Alignment object at ')) - self.assertNotEqual(result[1].find(' end_align: <_ped.Alignment object at '), -1) - self.assertTrue(result[2].startswith(' start_range: <_ped.Geometry object at ')) - self.assertNotEqual(result[2].find(' end_range: <_ped.Geometry object at '), -1) - self.assertEqual(result[3], ' min_size: 10 max_size: 100') diff --git a/tests/test__ped_device.py b/tests/test__ped_device.py deleted file mode 100755 index e39f60a..0000000 --- a/tests/test__ped_device.py +++ /dev/null @@ -1,368 +0,0 @@ -# -# Copyright (C) 2009-2011 Red Hat, Inc. -# -# This copyrighted material is made available to anyone wishing to use, -# modify, copy, or redistribute it subject to the terms and conditions of -# the GNU General Public License v.2, or (at your option) any later version. -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY expressed or implied, including the implied warranties of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. You should have received a copy of the -# GNU General Public License along with this program; if not, write to the -# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the -# source code or documentation are not subject to the GNU General Public -# License and may only be used or replicated with the express permission of -# Red Hat, Inc. -# -# Red Hat Author(s): Chris Lumens -# David Cantrell -# - -import _ped -import unittest - -from tests.baseclass import * - -# One class per method, multiple tests per class. For these simple methods, -# that seems like good organization. More complicated methods may require -# multiple classes and their own test suite. -class DeviceNewTestCase(unittest.TestCase): - def runTest(self): - # You're not allowed to create a new Device object by hand. - self.assertRaises(TypeError, _ped.Device) - -class DeviceGetSetTestCase(RequiresDevice): - def runTest(self): - # All attributes should be readable, but none should be writeable. - for attr in ["model", "path", "type", "sector_size", "phys_sector_size", - "length", "open_count", "read_only", "external_mode", - "dirty", "boot_dirty", "host", "did"]: - self.assertNotEqual(getattr(self._device, attr), None) - self.assertRaises(AttributeError, setattr, self._device, attr, 47) - -class DeviceIsBusyTestCase(RequiresDevice): - def runTest(self): - # Devices aren't busy until they're mounted. - self.assertFalse(self._device.is_busy()) - -# TODO: need to figure out how to make a loopback device look mounted to -# libparted -# self.mkfs() -# self.doMount() -# self.assertTrue(self._device.is_busy()) - -class DeviceOpenTestCase(RequiresDevice): - def runTest(self): - self.assertTrue(self._device.open()) - self.assertEqual(self._device.open_count, 1) - self._device.close() - - # Not allowed to open a device that's already been opened for external - # access, so test that now. - self._device.begin_external_access() - self.assertRaises(_ped.IOException, self._device.open) - self._device.end_external_access() - self.assertTrue(self._device.open()) - - # You're allowed to open a device multiple times. It's already been - # opened once above. Try to open it again and make sure the count is - # is right. - self.assertTrue(self._device.open()) - self.assertEqual(self._device.open_count, 2) - self._device.close() - self._device.close() - -class DeviceCloseTestCase(RequiresDevice): - def runTest(self): - self._device.open() - self.assertTrue(self._device.close()) - self.assertEqual(self._device.open_count, 0) - - # Not allowed to close a device that's already been opened for external - # access, so test that now. - self._device.open() - self._device.begin_external_access() - self.assertRaises(_ped.IOException, self._device.close) - self._device.end_external_access() - self.assertTrue(self._device.close()) - - # Test opening a device multiple times and then closing it too many. - self._device.open() - self._device.open() - self.assertEqual(self._device.open_count, 2) - self._device.close() - self.assertEqual(self._device.open_count, 1) - self._device.close() - self.assertEqual(self._device.open_count, 0) - self.assertRaises(_ped.IOException, self._device.close) - -@unittest.skip("Unimplemented test case.") -class DeviceDestroyTestCase(RequiresDevice): - def runTest(self): - # XXX: still broken, need to fix destroy function in pydevice.c - #self.assertEqual(self._device.destroy(), None) - self.fail("Unimplemented test case.") - -class DeviceCacheRemoveTestCase(RequiresDevice): - def runTest(self): - self.assertEqual(self._device.cache_remove(), None) - -class DeviceBeginExternalAccessTestCase(RequiresDevice): - def runTest(self): - # First test external access on a device that's not open. - self.assertEqual(self._device.external_mode, 0) - self.assertTrue(self._device.begin_external_access()) - self.assertEqual(self._device.external_mode, 1) - self.assertEqual(self._device.open_count, 0) - - # Now stop external access, open the device, and re-test. - self._device.end_external_access() - self._device.open() - self.assertEqual(self._device.open_count, 1) - self.assertTrue(self._device.begin_external_access()) - self.assertEqual(self._device.open_count, 1) - self._device.end_external_access() - self._device.close() - -class DeviceEndExternalAccessTestCase(RequiresDevice): - def runTest(self): - # Attempt to end external access on a device that never had it begun. - self.assertRaises(_ped.IOException, self._device.end_external_access) - - # Now test external access on a device that's not open. - self._device.begin_external_access() - self.assertEqual(self._device.external_mode, 1) - self.assertEqual(self._device.open_count, 0) - self.assertTrue(self._device.end_external_access()) - self.assertEqual(self._device.external_mode, 0) - self.assertEqual(self._device.open_count, 0) - - # Now on a device that's open. - self._device.open() - self._device.begin_external_access() - self.assertEqual(self._device.external_mode, 1) - self.assertEqual(self._device.open_count, 1) - self.assertTrue(self._device.end_external_access()) - self.assertEqual(self._device.external_mode, 0) - self.assertEqual(self._device.open_count, 1) - self._device.close() - -@unittest.skip("Unimplemented test case.") -class DeviceReadTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DeviceWriteTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -class DeviceSyncTestCase(RequiresDevice): - def runTest(self): - # Can't sync a device that's not open or is in external mode. - self.assertRaises(_ped.IOException, self._device.sync) - - self._device.open() - self._device.begin_external_access() - self.assertRaises(_ped.IOException, self._device.sync) - - # But this call should work. - self._device.end_external_access() - self.assertTrue(self._device.sync()) - self._device.close() - -class DeviceSyncFastTestCase(RequiresDevice): - def runTest(self): - # Can't sync a device that's not open or is in external mode. - self.assertRaises(_ped.IOException, self._device.sync_fast) - - self._device.open() - self._device.begin_external_access() - self.assertRaises(_ped.IOException, self._device.sync_fast) - - # But this call should work. - self._device.end_external_access() - self.assertTrue(self._device.sync_fast()) - self._device.close() - -class DeviceCheckTestCase(RequiresDevice): - def runTest(self): - self._device.open() - self.assertEqual(self._device.check(0, 20), 20) - self._device.close() - -class DeviceGetConstraintTestCase(RequiresDevice): - def runTest(self): - # XXX: This test case would be a lot more useful testing on real - # hardware with unusual sector sizes. - self.assertIsInstance(self._device.get_constraint(), _ped.Constraint) - -class DeviceGetMinimalAlignedConstraintTestCase(RequiresDevice): - def runTest(self): - # XXX: This test case would be a lot more useful testing on real - # hardware with unusual sector sizes. - constraint = self._device.get_minimal_aligned_constraint() - self.assertIsInstance(constraint, _ped.Constraint) - self.assertEqual(constraint.start_align.offset, 0) - self.assertEqual(constraint.start_align.grain_size, 1) - self.assertEqual(constraint.end_align.offset, 0) - self.assertEqual(constraint.end_align.grain_size, 1) - -class DeviceGetOptimalAlignedConstraintTestCase(RequiresDevice): - def runTest(self): - # XXX: This test case would be a lot more useful testing on real - # hardware with unusual sector sizes. - constraint = self._device.get_minimal_aligned_constraint() - self.assertIsInstance(constraint, _ped.Constraint) - self.assertEqual(constraint.start_align.offset, 0) - self.assertEqual(constraint.start_align.grain_size, 1) - self.assertEqual(constraint.end_align.offset, 0) - self.assertEqual(constraint.end_align.grain_size, 1) - -class DeviceGetMinimumAlignmentTestCase(RequiresDevice): - def runTest(self): - # XXX: This test case would be a lot more useful testing on real - # hardware with unusual sector sizes. - alignment = self._device.get_minimum_alignment() - self.assertIsInstance(alignment, _ped.Alignment) - self.assertEqual(alignment.grain_size, 1) - self.assertEqual(alignment.offset, 0) - -class DeviceGetOptimumAlignmentTestCase(RequiresDevice): - def runTest(self): - # XXX: This test case would be a lot more useful testing on real - # hardware with unusual sector sizes. - alignment = self._device.get_optimum_alignment() - self.assertIsInstance(alignment, _ped.Alignment) - self.assertEqual(alignment.grain_size, 2048) - self.assertEqual(alignment.offset, 0) - -class UnitFormatCustomByteTestCase(RequiresDevice): - def setUp(self): - RequiresDevice.setUp(self) - pr = "%f" % (47.0 / self._device.unit_get_size(_ped.UNIT_PERCENT),) - self.pairs = [(_ped.UNIT_SECTOR, '0s',), - (_ped.UNIT_BYTE, '47B',), - (_ped.UNIT_KILOBYTE, '0.05kB',), - (_ped.UNIT_MEGABYTE, '0.00MB',), - (_ped.UNIT_GIGABYTE, '0.00GB',), - (_ped.UNIT_TERABYTE, '0.00TB',), - (_ped.UNIT_COMPACT, '47.0B',), - (_ped.UNIT_CYLINDER, '0cyl',), - (_ped.UNIT_CHS, '0,0,0',), - (_ped.UNIT_PERCENT, pr[:4] + "%",), - (_ped.UNIT_KIBIBYTE, '0.05kiB',), - (_ped.UNIT_MEBIBYTE, '0.00MiB',), - (_ped.UNIT_GIBIBYTE, '0.00GiB',), - (_ped.UNIT_TEBIBYTE, '0.00TiB',)] - - def runTest(self): - for (unit, expected,) in self.pairs: - self.assertEqual(self._device.unit_format_custom_byte(47, unit), - expected) - -class UnitFormatByteTestCase(RequiresDevice): - def setUp(self): - RequiresDevice.setUp(self) - pr = "%f" % (47.0 / self._device.unit_get_size(_ped.UNIT_PERCENT),) - self._initialDefault = _ped.unit_get_default() - self.pairs = [(_ped.UNIT_SECTOR, '0s',), - (_ped.UNIT_BYTE, '47B',), - (_ped.UNIT_KILOBYTE, '0.05kB',), - (_ped.UNIT_MEGABYTE, '0.00MB',), - (_ped.UNIT_GIGABYTE, '0.00GB',), - (_ped.UNIT_TERABYTE, '0.00TB',), - (_ped.UNIT_COMPACT, '47.0B',), - (_ped.UNIT_CYLINDER, '0cyl',), - (_ped.UNIT_CHS, '0,0,0',), - (_ped.UNIT_PERCENT, pr[:4] + "%",), - (_ped.UNIT_KIBIBYTE, '0.05kiB',), - (_ped.UNIT_MEBIBYTE, '0.00MiB',), - (_ped.UNIT_GIBIBYTE, '0.00GiB',), - (_ped.UNIT_TEBIBYTE, '0.00TiB',)] - - def runTest(self): - for (unit, expected) in self.pairs: - _ped.unit_set_default(unit) - result = self._device.unit_format_byte(47) - self.assertEqual(result, expected) - - def tearDown(self): - _ped.unit_set_default(self._initialDefault) - -class UnitFormatCustomTestCase(RequiresDevice): - def setUp(self): - RequiresDevice.setUp(self) - sector_size = self._device.sector_size - size = self._device.unit_get_size(_ped.UNIT_PERCENT) - pr = "%f" % ((47.0 * sector_size) / size,) - self.pairs = [(_ped.UNIT_SECTOR, '47s',), - (_ped.UNIT_BYTE, '24064B',), - (_ped.UNIT_KILOBYTE, '24.1kB',), - (_ped.UNIT_MEGABYTE, '0.02MB',), - (_ped.UNIT_GIGABYTE, '0.00GB',), - (_ped.UNIT_TERABYTE, '0.00TB',), - (_ped.UNIT_COMPACT, '24.1kB',), - (_ped.UNIT_CYLINDER, '0cyl',), - (_ped.UNIT_CHS, '0,1,15',), - (_ped.UNIT_PERCENT, pr[:4] + "%",), - (_ped.UNIT_KIBIBYTE, '23.5kiB',), - (_ped.UNIT_MEBIBYTE, '0.02MiB',), - (_ped.UNIT_GIBIBYTE, '0.00GiB',), - (_ped.UNIT_TEBIBYTE, '0.00TiB',)] - - def runTest(self): - for (unit, expected) in self.pairs: - result = self._device.unit_format_custom(47, unit) - self.assertEqual(result, expected) - -class UnitFormatTestCase(RequiresDevice): - def setUp(self): - RequiresDevice.setUp(self) - sector_size = self._device.sector_size - size = self._device.unit_get_size(_ped.UNIT_PERCENT) - pr = "%f" % ((47.0 * sector_size) / size,) - self._initialDefault = _ped.unit_get_default() - self.pairs = [(_ped.UNIT_SECTOR, '47s',), - (_ped.UNIT_BYTE, '24064B',), - (_ped.UNIT_KILOBYTE, '24.1kB',), - (_ped.UNIT_MEGABYTE, '0.02MB',), - (_ped.UNIT_GIGABYTE, '0.00GB',), - (_ped.UNIT_TERABYTE, '0.00TB',), - (_ped.UNIT_COMPACT, '24.1kB',), - (_ped.UNIT_CYLINDER, '0cyl',), - (_ped.UNIT_CHS, '0,1,15',), - (_ped.UNIT_PERCENT, pr[:4] + "%",), - (_ped.UNIT_KIBIBYTE, '23.5kiB',), - (_ped.UNIT_MEBIBYTE, '0.02MiB',), - (_ped.UNIT_GIBIBYTE, '0.00GiB',), - (_ped.UNIT_TEBIBYTE, '0.00TiB',)] - - def runTest(self): - for (unit, expected) in self.pairs: - _ped.unit_set_default(unit) - result = self._device.unit_format(47) - self.assertEqual(result, expected) - - def tearDown(self): - _ped.unit_set_default(self._initialDefault) - -@unittest.skip("Unimplemented test case.") -class UnitParseTestCase(unittest.TestCase): - # TODO - def runTest(self): - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class UnitParseCustomTestCase(unittest.TestCase): - # TODO - def runTest(self): - self.fail("Unimplemented test case.") - -class DeviceStrTestCase(RequiresDevice): - def runTest(self): - expected = "_ped.Device instance --\n model: %s path: %s type: %d\n sector_size: %d phys_sector_size: %d\n length: %d open_count: %d read_only: %d\n external_mode: %d dirty: %d boot_dirty: %d\n host: %d did: %d\n hw_geom: %s bios_geom: %s" % (self._device.model, self._device.path, self._device.type, self._device.sector_size, self._device.phys_sector_size, self._device.length, self._device.open_count, self._device.read_only, self._device.external_mode, self._device.dirty, self._device.boot_dirty, self._device.host, self._device.did, repr(self._device.hw_geom), repr(self._device.bios_geom),) - self.assertEqual(str(self._device), expected) diff --git a/tests/test__ped_disk.py b/tests/test__ped_disk.py deleted file mode 100755 index ce791d6..0000000 --- a/tests/test__ped_disk.py +++ /dev/null @@ -1,227 +0,0 @@ -# -# Copyright (C) 2009-2011 Red Hat, Inc. -# -# This copyrighted material is made available to anyone wishing to use, -# modify, copy, or redistribute it subject to the terms and conditions of -# the GNU General Public License v.2, or (at your option) any later version. -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY expressed or implied, including the implied warranties of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. You should have received a copy of the -# GNU General Public License along with this program; if not, write to the -# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the -# source code or documentation are not subject to the GNU General Public -# License and may only be used or replicated with the express permission of -# Red Hat, Inc. -# -# Red Hat Author(s): Chris Lumens -# David Cantrell -# - -import _ped -import unittest - -from tests.baseclass import * - -# One class per method, multiple tests per class. For these simple methods, -# that seems like good organization. More complicated methods may require -# multiple classes and their own test suite. -class DiskNewUnlabeledTestCase(RequiresDevice): - def runTest(self): - self.assertRaises(_ped.DiskLabelException, _ped.Disk, self._device) - -class DiskNewLabeledTestCase(RequiresLabeledDevice): - def runTest(self): - result = _ped.Disk(self._device) - self.assertIsInstance(result, _ped.Disk) - self.assertEqual(result.type.name, 'msdos') - -@unittest.skip("Unimplemented test case.") -class DiskGetSetTestCase(unittest.TestCase): - # TODO - def runTest(self): - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskClobberTestCase(unittest.TestCase): - # TODO - def runTest(self): - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskClobberExcludeTestCase(unittest.TestCase): - # TODO - def runTest(self): - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskDuplicateTestCase(unittest.TestCase): - # TODO - def runTest(self): - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskDestroyTestCase(unittest.TestCase): - # TODO - def runTest(self): - self.fail("Unimplemented test case.") - -class DiskCommitTestCase(RequiresDisk): - def runTest(self): - self.assertTrue(self._disk.commit()) - -class DiskCommitToDevTestCase(RequiresDisk): - def runTest(self): - self.assertTrue(self._disk.commit_to_dev()) - -class DiskCommitToOsTestCase(RequiresDisk): - def runTest(self): - self.assertTrue(self._disk.commit_to_os()) - -class DiskCheckTestCase(RequiresDisk): - def runTest(self): - self.assertTrue(self._disk.check()) - -@unittest.skip("Unimplemented test case.") -class DiskPrintTestCase(unittest.TestCase): - # TODO - def runTest(self): - self.fail("Unimplemented test case.") - -class DiskGetPrimaryPartitionCountTestCase(RequiresDisk): - def runTest(self): - # XXX: this could probably test more - self.assertEqual(self._disk.get_primary_partition_count(), 0) - -class DiskGetLastPartitionNumTestCase(RequiresDisk): - def runTest(self): - # XXX: this could probably test more - self.assertEqual(self._disk.get_last_partition_num(), -1) - -class DiskGetMaxPrimaryPartitionCountTestCase(RequiresDisk): - def runTest(self): - self.assertEqual(self._disk.get_max_primary_partition_count(), 4) - -class DiskGetMaxSupportedPartitionCountTestCase(RequiresDisk): - def runTest(self): - self.assertEqual(self._disk.get_max_supported_partition_count(), 64) - -class DiskGetPartitionAlignmentTestCase(RequiresDisk): - def runTest(self): - alignment = self._disk.get_partition_alignment() - self.assertIsInstance(alignment, _ped.Alignment) - # These 2 tests assume an MSDOS label as given by RequiresDisk - self.assertEqual(alignment.offset, 0) - self.assertEqual(alignment.grain_size, 1) - -class DiskMaxPartitionLengthTestCase(RequiresDisk): - def runTest(self): - # This test assumes an MSDOS label as given by RequiresDisk - self.assertEqual(self._disk.max_partition_length(), 4294967295) - -class DiskMaxPartitionStartSectorTestCase(RequiresDisk): - def runTest(self): - # This test assumes an MSDOS label as given by RequiresDisk - self.assertEqual(self._disk.max_partition_start_sector(), 4294967295) - -class DiskSetFlagTestCase(RequiresDisk): - def runTest(self): - # These 2 tests assume an MSDOS label as given by RequiresDisk - self._disk.set_flag(_ped.DISK_CYLINDER_ALIGNMENT, 1) - self.assertEqual(self._disk.get_flag(_ped.DISK_CYLINDER_ALIGNMENT), True) - self._disk.set_flag(_ped.DISK_CYLINDER_ALIGNMENT, 0) - self.assertEqual(self._disk.get_flag(_ped.DISK_CYLINDER_ALIGNMENT), False) - -class DiskGetFlagTestCase(RequiresDisk): - def runTest(self): - flag = self._disk.get_flag(_ped.DISK_CYLINDER_ALIGNMENT) - self.assertIsInstance(flag, bool) - -class DiskIsFlagAvailableTestCase(RequiresDisk): - def runTest(self): - # We don't know which flags should be available and which shouldn't, - # but we can at least check that there aren't any tracebacks from - # trying all of the valid ones. - for flag in [_ped.DISK_CYLINDER_ALIGNMENT, _ped.DISK_GPT_PMBR_BOOT]: - self.assertIsInstance(self._disk.is_flag_available(flag), bool) - - # However, an invalid flag should definitely not be available. - self.assertFalse(self._disk.is_flag_available(1000)) - -@unittest.skip("Unimplemented test case.") -class DiskAddPartitionTestCase(unittest.TestCase): - # TODO - def runTest(self): - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskRemovePartitionTestCase(unittest.TestCase): - # TODO - def runTest(self): - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskDeletePartitionTestCase(unittest.TestCase): - # TODO - def runTest(self): - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskDeleteAllTestCase(unittest.TestCase): - # TODO - def runTest(self): - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskSetPartitionGeomTestCase(unittest.TestCase): - # TODO - def runTest(self): - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskMaxmimzePartitionTestCase(unittest.TestCase): - # TODO - def runTest(self): - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskGetMaxPartitionGeoemtryTestCase(unittest.TestCase): - # TODO - def runTest(self): - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskMinimizeExtendedPartitionTestCase(unittest.TestCase): - # TODO - def runTest(self): - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskNextPartitionTestCase(unittest.TestCase): - # TODO - def runTest(self): - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskGetPartitionTestCase(unittest.TestCase): - # TODO - def runTest(self): - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskGetPartitionBySectorTestCase(unittest.TestCase): - # TODO - def runTest(self): - self.fail("Unimplemented test case.") - -class DiskExtendedPartitionTestCase(RequiresDisk): - def runTest(self): - self.assertRaises(_ped.PartitionException, - self._disk.extended_partition) - -class DiskStrTestCase(RequiresDisk): - def runTest(self): - expected = "_ped.Disk instance --\n dev: %s type: %s" % \ - (repr(self._disk.dev), repr(self._disk.type),) - self.assertEqual(expected, str(self._disk)) diff --git a/tests/test__ped_disktype.py b/tests/test__ped_disktype.py deleted file mode 100755 index 1f78493..0000000 --- a/tests/test__ped_disktype.py +++ /dev/null @@ -1,87 +0,0 @@ -# -# Copyright (C) 2009-2011 Red Hat, Inc. -# -# This copyrighted material is made available to anyone wishing to use, -# modify, copy, or redistribute it subject to the terms and conditions of -# the GNU General Public License v.2, or (at your option) any later version. -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY expressed or implied, including the implied warranties of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. You should have received a copy of the -# GNU General Public License along with this program; if not, write to the -# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the -# source code or documentation are not subject to the GNU General Public -# License and may only be used or replicated with the express permission of -# Red Hat, Inc. -# -# Red Hat Author(s): Chris Lumens -# David Cantrell -# - -import _ped -import sys -import unittest -from tests.baseclass import * - -# One class per method, multiple tests per class. For these simple methods, -# that seems like good organization. More complicated methods may require -# multiple classes and their own test suite. -class DiskTypeNewTestCase(unittest.TestCase): - def runTest(self): - # You're not allowed to create a new DiskType object by hand. - self.assertRaises(TypeError, _ped.DiskType) - -class DiskTypeGetSetTestCase(RequiresDiskTypes): - def runTest(self): - # All attributes are read-only. - for name in self.disktype.keys(): - t = self.disktype[name] - - self.assertRaises(AttributeError, setattr, t, "name", "fakename") - self.assertRaises(AttributeError, setattr, t, "features", 47) - - if sys.version_info >= (3,): - bigint = int - uni = str - else: - bigint = long - uni = unicode - self.assertIsInstance(t.name, uni) - self.assertEqual(t.name, name) - self.assertIsInstance(t.features, bigint) - -class DiskTypeCheckFeatureTestCase(RequiresDiskTypes): - def runTest(self): - # The following types have no features [that libparted supports] - for name in ['aix', 'sun', 'bsd', 'loop']: - self.assertFalse(self.disktype[name].check_feature(_ped.DISK_TYPE_EXTENDED)) - self.assertFalse(self.disktype[name].check_feature(_ped.DISK_TYPE_PARTITION_NAME)) - - # The following types support DISK_TYPE_EXTENDED - for name in ['msdos']: - self.assertTrue(self.disktype[name].check_feature(_ped.DISK_TYPE_EXTENDED)) - self.assertFalse(self.disktype[name].check_feature(_ped.DISK_TYPE_PARTITION_NAME)) - - # The following types support DISK_TYPE_PARTITION_NAME - for name in ['amiga', 'gpt', 'mac', 'pc98']: - self.assertFalse(self.disktype[name].check_feature(_ped.DISK_TYPE_EXTENDED)) - self.assertTrue(self.disktype[name].check_feature(_ped.DISK_TYPE_PARTITION_NAME)) - - # The following types support all features - for name in ['dvh']: - self.assertTrue(self.disktype[name].check_feature(_ped.DISK_TYPE_EXTENDED)) - self.assertTrue(self.disktype[name].check_feature(_ped.DISK_TYPE_PARTITION_NAME)) - -class DiskTypeStrTestCase(RequiresDiskTypes): - def runTest(self): - self.assertEqual(str(self.disktype['msdos']), '_ped.DiskType instance --\n name: msdos features: 1') - self.assertEqual(str(self.disktype['aix']), '_ped.DiskType instance --\n name: aix features: 0') - self.assertEqual(str(self.disktype['sun']), '_ped.DiskType instance --\n name: sun features: 0') - self.assertEqual(str(self.disktype['amiga']), '_ped.DiskType instance --\n name: amiga features: 2') - self.assertEqual(str(self.disktype['gpt']), '_ped.DiskType instance --\n name: gpt features: 2') - self.assertEqual(str(self.disktype['mac']), '_ped.DiskType instance --\n name: mac features: 2') - self.assertEqual(str(self.disktype['bsd']), '_ped.DiskType instance --\n name: bsd features: 0') - self.assertEqual(str(self.disktype['pc98']), '_ped.DiskType instance --\n name: pc98 features: 2') - self.assertEqual(str(self.disktype['loop']), '_ped.DiskType instance --\n name: loop features: 0') - self.assertEqual(str(self.disktype['dvh']), '_ped.DiskType instance --\n name: dvh features: 3') diff --git a/tests/test__ped_filesystem.py b/tests/test__ped_filesystem.py deleted file mode 100755 index 74e8a61..0000000 --- a/tests/test__ped_filesystem.py +++ /dev/null @@ -1,43 +0,0 @@ -# -# Copyright (C) 2009-2011 Red Hat, Inc. -# -# This copyrighted material is made available to anyone wishing to use, -# modify, copy, or redistribute it subject to the terms and conditions of -# the GNU General Public License v.2, or (at your option) any later version. -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY expressed or implied, including the implied warranties of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. You should have received a copy of the -# GNU General Public License along with this program; if not, write to the -# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the -# source code or documentation are not subject to the GNU General Public -# License and may only be used or replicated with the express permission of -# Red Hat, Inc. -# -# Red Hat Author(s): Chris Lumens -# David Cantrell -# -import _ped -import unittest - -# One class per method, multiple tests per class. For these simple methods, -# that seems like good organization. More complicated methods may require -# multiple classes and their own test suite. -@unittest.skip("Unimplemented test case.") -class FileSystemNewTestCase(unittest.TestCase): - # TODO - def runTest(self): - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class FileSystemGetSetTestCase(unittest.TestCase): - # TODO - def runTest(self): - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class FileSystemStrTestCase(unittest.TestCase): - # TODO - def runTest(self): - self.fail("Unimplemented test case.") diff --git a/tests/test__ped_filesystemtype.py b/tests/test__ped_filesystemtype.py deleted file mode 100755 index 02373b2..0000000 --- a/tests/test__ped_filesystemtype.py +++ /dev/null @@ -1,45 +0,0 @@ -# -# Copyright (C) 2009-2011 Red Hat, Inc. -# -# This copyrighted material is made available to anyone wishing to use, -# modify, copy, or redistribute it subject to the terms and conditions of -# the GNU General Public License v.2, or (at your option) any later version. -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY expressed or implied, including the implied warranties of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. You should have received a copy of the -# GNU General Public License along with this program; if not, write to the -# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the -# source code or documentation are not subject to the GNU General Public -# License and may only be used or replicated with the express permission of -# Red Hat, Inc. -# -# Red Hat Author(s): Chris Lumens -# -import _ped -import unittest - -# One class per method, multiple tests per class. For these simple methods, -# that seems like good organization. More complicated methods may require -# multiple classes and their own test suite. -class FileSystemTypeNewTestCase(unittest.TestCase): - def runTest(self): - # You can't create a FileSystemType by hand. - self.assertRaises(TypeError, _ped.FileSystemType) - -class FileSystemTypeGetSetTestCase(unittest.TestCase): - def runTest(self): - fstype = _ped.file_system_type_get("ext3") - - self.assertIsInstance(fstype, _ped.FileSystemType) - self.assertEqual(fstype.name, "ext3") - self.assertEqual(getattr(fstype, "name"), "ext3") - self.assertRaises(AttributeError, setattr, fstype, "name", "vfat") - self.assertRaises(AttributeError, getattr, fstype, "junk") - -class FileSystemTypeStrTestCase(unittest.TestCase): - def runTest(self): - fstype = _ped.file_system_type_get("ext3") - - self.assertEqual(str(fstype), "_ped.FileSystemType instance --\n name: ext3") diff --git a/tests/test__ped_geometry.py b/tests/test__ped_geometry.py deleted file mode 100755 index ccd5252..0000000 --- a/tests/test__ped_geometry.py +++ /dev/null @@ -1,377 +0,0 @@ -# -# Copyright (C) 2008-2011 Red Hat, Inc. -# -# This copyrighted material is made available to anyone wishing to use, -# modify, copy, or redistribute it subject to the terms and conditions of -# the GNU General Public License v.2, or (at your option) any later version. -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY expressed or implied, including the implied warranties of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. You should have received a copy of the -# GNU General Public License along with this program; if not, write to the -# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the -# source code or documentation are not subject to the GNU General Public -# License and may only be used or replicated with the express permission of -# Red Hat, Inc. -# -# Red Hat Author(s): Chris Lumens -# - -import _ped -import unittest -from tests.baseclass import * - -# One class per method, multiple tests per class. For these simple methods, -# that seems like good organization. More complicated methods may require -# multiple classes and their own test suite. -class GeometryNewTestCase(RequiresDevice): - def runTest(self): - # Check that not passing args to _ped.Geometry.__init__ is caught. - self.assertRaises(TypeError, _ped.Geometry) - - # Or passing in the parameters in the wrong order. - self.assertRaises(TypeError, _ped.Geometry, 0, self._device, 100) - - # And then the correct ways of creating a _ped.Geometry. - self.assertIsInstance(_ped.Geometry(self._device, 0, 100), _ped.Geometry) - self.assertIsInstance(_ped.Geometry(self._device, 0, 100, 101), _ped.Geometry) - -class GeometryGetSetTestCase(RequiresDevice): - def setUp(self): - RequiresDevice.setUp(self) - self.g = _ped.Geometry(self._device, start=0, length=100) - - def runTest(self): - # Test that passing the kwargs to __init__ works. - self.assertIsInstance(self.g, _ped.Geometry) - self.assertEqual(self.g.start, 0) - self.assertEqual(self.g.length, 100) - self.assertEqual(self.g.end, 99) - - # Test that setting directly and getting with getattr works. - self.g.start = 10 - self.g.length = 90 - self.g.end = 99 - - self.assertEqual(getattr(self.g, "start"), 10) - self.assertEqual(getattr(self.g, "length"), 90) - self.assertEqual(getattr(self.g, "end"), 99) - - # Check that setting with setattr and getting directly works. - setattr(self.g, "start", 20) - setattr(self.g, "length", 80) - setattr(self.g, "end", 99) - - self.assertEqual(self.g.start, 20) - self.assertEqual(self.g.length, 80) - self.assertEqual(self.g.end, 99) - - # Check that values have the right type. - self.assertRaises(TypeError, setattr, self.g, "start", "string") - - # Check that looking for invalid attributes fails properly. - self.assertRaises(AttributeError, getattr, self.g, "blah") - -class GeometryDuplicateTestCase(RequiresDevice): - def setUp(self): - RequiresDevice.setUp(self) - self.g = _ped.Geometry(self._device, start=0, length=100) - - def runTest(self): - self.dup = self.g.duplicate() - self.assertEqual(self.g.start, self.dup.start) - self.assertEqual(self.g.length, self.dup.length) - self.assertEqual(self.g.end, self.dup.end) - -class GeometryIntersectTestCase(RequiresDevice): - def setUp(self): - RequiresDevice.setUp(self) - self.g1 = _ped.Geometry(self._device, start=0, length=100) - self.g2 = _ped.Geometry(self._device, start=0, length=100) - - def runTest(self): - # g1 and g2 are the same, so their intersection is the same - self.i = self.g1.intersect(self.g2) - self.assertEqual(self.i.start, self.g1.start) - self.assertEqual(self.i.end, self.g1.end) - self.assertEqual(self.i.length, self.g1.length) - - # g2 is the second half of g1, so their intersection is the same as g2. - self.g2.set_start(50) - self.i = self.g1.intersect(self.g2) - self.assertEqual(self.i.start, self.g2.start) - self.assertEqual(self.i.end, self.g2.end) - self.assertEqual(self.i.length, self.g2.length) - - # g2 only partially overlaps the end of g1, so they have a more - # interesting intersection. - self.g1.set_end(75) - self.i = self.g1.intersect(self.g2) - self.assertEqual(self.i.start, self.g2.start) - self.assertEqual(self.i.end, self.g1.end) - self.assertEqual(self.i.length, 26) - - # g1 and g2 do not overlap at all, so they have no intersection. - self.g1.set(0, 25) - self.g2.set(50, 100) - self.assertRaises(ArithmeticError, self.g1.intersect, self.g2) - -class GeometrySetTestCase(RequiresDevice): - def setUp(self): - RequiresDevice.setUp(self) - self.g = _ped.Geometry(self._device, start=0, length=100) - - def runTest(self): - self.assertEqual(self.g.start, 0) - self.assertEqual(self.g.length, 100) - - # Setting a negative for either value, or a length past the end of - # the device should fail. - self.assertRaises(_ped.CreateException, self.g.set, 100, -1000) - -class GeometrySetStartTestCase(RequiresDevice): - def setUp(self): - RequiresDevice.setUp(self) - self.g = _ped.Geometry(self._device, start=0, length=100) - - def runTest(self): - self.g.set_start(10) - self.assertEqual(self.g.start, 10) - self.assertEqual(self.g.length, 90) - self.assertEqual(self.g.end, 99) - -class GeometrySetEndTestCase(RequiresDevice): - def setUp(self): - RequiresDevice.setUp(self) - self.g = _ped.Geometry(self._device, start=0, length=100) - - def runTest(self): - self.g.set_end(50) - self.assertEqual(self.g.start, 0) - self.assertEqual(self.g.length, 51) - self.assertEqual(self.g.end, 50) - - # Setting a negative end or or before the start should fail. - self.assertRaises(_ped.CreateException, self.g.set_end, -1) - self.g.set_start(10) - self.assertRaises(_ped.CreateException, self.g.set_end, 5) - -class GeometryTestOverlapTestCase(RequiresDevice): - def setUp(self): - RequiresDevice.setUp(self) - self.g1 = _ped.Geometry(self._device, start=0, length=100) - self.g2 = _ped.Geometry(self._device, start=50, length=100) - - def runTest(self): - # g2 occupies the second half of g1, so they overlap. - self.assertTrue(self.g1.test_overlap(self.g2)) - - # g2 is entirely contained within g1, so they overlap. - self.g2.set_end(75) - self.assertTrue(self.g1.test_overlap(self.g2)) - - # g1 goes from inside g2 to the end, so they overlap. - self.g1.set_start(60) - self.assertTrue(self.g1.test_overlap(self.g2)) - - # g2 exists entirely before g1, so they do not overlap. - self.g2.set(10, 10) - self.assertFalse(self.g1.test_overlap(self.g2)) - -class GeometryTestInsideTestCase(RequiresDevice): - def setUp(self): - RequiresDevice.setUp(self) - self.g1 = _ped.Geometry(self._device, start=0, length=100) - self.g2 = _ped.Geometry(self._device, start=0, length=100) - - def runTest(self): - # g1 and g2 are the same, so they exist inside each other. - self.assertTrue(self.g1.test_inside(self.g2)) - self.assertTrue(self.g2.test_inside(self.g1)) - - # g2 is entirely contained within g1, so it's inside. - self.g2.set_end(75) - self.assertTrue(self.g1.test_inside(self.g2)) - self.assertFalse(self.g2.test_inside(self.g1)) - - # g1 goes from inside g2 to the end, so it's not inside. - self.g1.set_start(60) - self.assertFalse(self.g1.test_inside(self.g2)) - self.assertFalse(self.g2.test_inside(self.g1)) - - # g2 exists entirely before g1, so it's not inside. - self.g2.set(10, 10) - self.assertFalse(self.g1.test_inside(self.g2)) - self.assertFalse(self.g2.test_inside(self.g1)) - -class GeometryTestEqualTestCase(RequiresDevice): - def setUp(self): - RequiresDevice.setUp(self) - self.g1 = _ped.Geometry(self._device, start=0, length=100) - self.g2 = _ped.Geometry(self._device, start=0, length=100) - - def runTest(self): - # g1 and g2 have the same start and end. - self.assertTrue(self.g1.test_equal(self.g2)) - - # g1 and g2 have the same end, but different starts. - self.g2.set_start(5) - self.assertFalse(self.g1.test_equal(self.g2)) - - # g1 and g2 have the same start, but different ends. - self.g2.set_start(5) - self.g2.set_end(50) - self.assertFalse(self.g1.test_equal(self.g2)) - -class GeometryTestSectorInsideTestCase(RequiresDevice): - def setUp(self): - RequiresDevice.setUp(self) - self.g = _ped.Geometry(self._device, start=10, length=100) - - def runTest(self): - # First check the boundary conditions. - self.assertTrue(self.g.test_sector_inside(10)) - self.assertTrue(self.g.test_sector_inside(109)) - self.assertFalse(self.g.test_sector_inside(110)) - - # Then some sectors that are obviously out. - self.assertFalse(self.g.test_sector_inside(0)) - self.assertFalse(self.g.test_sector_inside(1000)) - self.assertFalse(self.g.test_sector_inside(-1)) - -class GeometryReadTestCase(RequiresDevice): - def setUp(self): - RequiresDevice.setUp(self) - self.g = _ped.Geometry(self._device, start=10, length=100) - - def runTest(self): - # First try to read from a device that isn't open yet. - self.assertRaises(_ped.IOException, self.g.read, 0, 10) - - # Our initial device is just full of zeros, so this should read a - # whole lot of nothing. - self._device.open() - self.assertEqual(self.g.read(0, 10), "") - - # Test bad parameter passing. - self.assertRaises(_ped.IOException, self.g.read, -10, 10) - self.assertRaises(_ped.IOException, self.g.read, 0, -10) - self.assertRaises(TypeError, self.g.read, None, None) - - # Can't read past the end of the geometry. - self.assertRaises(_ped.IOException, self.g.read, 200, 1) - self.assertRaises(_ped.IOException, self.g.read, 0, 200) - - # Now try writing something to the device, then reading to see if - # we get the same thing back. - self.g.write("1111111111", 0, 1) - self.assertEqual(self.g.read(0, 10), "1111111111") - - # Write five bytes from the string to the geometry, so there's only - # one byte present. So, only one "2" should be there when we read. - self.g.write("2", 20, 5) - self.assertEqual(self.g.read(20, 5), "2") - self.assertEqual(self.g.read(20, 1), "2") - - self._device.close() - -class GeometrySyncTestCase(RequiresDevice): - def setUp(self): - RequiresDevice.setUp(self) - self.g = _ped.Geometry(self._device, start=0, length=100) - - def runTest(self): - self._device.open() - - # XXX: I don't know of a better way to test this method. - self.g.write("1111111111", 0, 1) - self.assertEqual(self.g.sync(), 1) - - self._device.close() - -class GeometrySyncFastTestCase(RequiresDevice): - def setUp(self): - RequiresDevice.setUp(self) - self.g = _ped.Geometry(self._device, start=0, length=100) - - def runTest(self): - self._device.open() - - # XXX: I don't know of a better way to test this method. - self.g.write("1111111111", 0, 1) - self.assertEqual(self.g.sync_fast(), 1) - - self._device.close() - -class GeometryWriteTestCase(RequiresDevice): - def setUp(self): - RequiresDevice.setUp(self) - self.g = _ped.Geometry(self._device, start=10, length=100) - - def runTest(self): - # First try to write to a device that isn't open yet. - self.assertRaises(_ped.IOException, self.g.write, "X", 0, 10) - - # Now try a real write and make sure we (1) don't get an error code - # and (2) the data actually ends up on the device. - self._device.open() - self.assertNotEqual(self.g.write("X", 0, 10), 0) - self.assertEqual(self.g.read(0, 10), "X") - self.assertNotEqual(self.g.write("XXXXXXXXXX", 0, 10), 0) - self.assertEqual(self.g.read(0, 10), "XXXXXXXXXX") - - # Test bad parameter passing. - self.assertRaises(_ped.IOException, self.g.write, "X", -10, 10) - self.assertRaises(_ped.IOException, self.g.write, "X", 0, -10) - self.assertRaises(TypeError, self.g.write, None, None, None) - - # Can't write past the end of the geometry. - self.assertRaises(_ped.IOException, self.g.write, "X", 200, 1) - self.assertRaises(_ped.IOException, self.g.write, "X", 0, 200) - - self._device.close() - -class GeometryCheckTestCase(RequiresDevice): - def setUp(self): - RequiresDevice.setUp(self) - self.g = _ped.Geometry(self._device, start=10, length=100) - - def runTest(self): - # trivial test case first - self.assertRaises(_ped.IOException, self.g.check, 0, 0, 0) - - self._device.open() - - self.assertEqual(self.g.check(0, 0, 10), 0) - self.assertEqual(self.g.check(0, 0, 50), 0) - - self._device.close() - -class GeometryMapTestCase(RequiresDevice): - def setUp(self): - RequiresDevice.setUp(self) - self.g1 = _ped.Geometry(self._device, start=10, length=100) - self.g2 = _ped.Geometry(self._device, start=10, length=90) - - def runTest(self): - # write a word to the device starting at sector 25 - self._device.open() - self.g1.write("UNITTEST", 25, 8) - - val1 = self.g2.read(self.g2.map(self.g1, 25), 8) - val2 = self.g1.read(25, 8) - self.assertEqual(val1, val2) - - self._device.close() - -class GeometryStrTestCase(RequiresDevice): - def setUp(self): - RequiresDevice.setUp(self) - self.g = _ped.Geometry(self._device, start=10, length=100) - - def runTest(self): - lines = str(self.g).split('\n') - self.assertEqual(lines[0], '_ped.Geometry instance --') - self.assertEqual(lines[1], ' start: 10 end: 109 length: 100') - self.assertRegexpMatches(lines[2], '^ device: <_ped.Device object at .*') diff --git a/tests/test__ped_partition.py b/tests/test__ped_partition.py deleted file mode 100755 index b8b7cb5..0000000 --- a/tests/test__ped_partition.py +++ /dev/null @@ -1,194 +0,0 @@ -# -# Copyright (C) 2009-2014 Red Hat, Inc. -# -# This copyrighted material is made available to anyone wishing to use, -# modify, copy, or redistribute it subject to the terms and conditions of -# the GNU General Public License v.2, or (at your option) any later version. -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY expressed or implied, including the implied warranties of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. You should have received a copy of the -# GNU General Public License along with this program; if not, write to the -# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the -# source code or documentation are not subject to the GNU General Public -# License and may only be used or replicated with the express permission of -# Red Hat, Inc. -# -# Red Hat Author(s): Chris Lumens -# - -import _ped -import unittest - -from tests.baseclass import * - -# One class per method, multiple tests per class. For these simple methods, -# that seems like good organization. More complicated methods may require -# multiple classes and their own test suite. -class PartitionNewTestCase(RequiresDisk): - def runTest(self): - # Check that not passing args to _ped.Partition.__init__ is caught. - self.assertRaises(TypeError, _ped.Partition) - - # Or passing the arguments in the wrong order. - self.assertRaises(TypeError, _ped.Partition, _ped.file_system_type_get("ext2"), - _ped.PARTITION_NORMAL, self._disk, 0, 100) - - part = _ped.Partition(self._disk, _ped.PARTITION_NORMAL, 0, 100, - _ped.file_system_type_get("ext2")) - self.assertIsInstance(part, _ped.Partition) - - # You don't need to pass a filesystem type at all, since this partition - # might be FREESPACE or METADATA. - part = _ped.Partition(self._disk, _ped.PARTITION_NORMAL, 0, 100) - self.assertIsInstance(part, _ped.Partition) - -class PartitionGetSetTestCase(RequiresPartition): - def runTest(self): - # Test that passing the kwargs to __init__ works. - self.assertEqual(self._part.disk, self._disk) - self.assertIsInstance(self._part.geom, _ped.Geometry) - self.assertEqual(self._part.type, _ped.PARTITION_NORMAL) - self.assertEqual(self._part.fs_type.name, "ext2") - - # Test that setting the RW attributes directly works. - self._part.type = _ped.PARTITION_EXTENDED - self.assertEqual(getattr(self._part, "type"), _ped.PARTITION_EXTENDED) - - # Test that setting the RO attributes directly doesn't work. - exn = (AttributeError, TypeError) - self.assertRaises(exn, setattr, self._part, "num", 1) - self.assertRaises(exn, setattr, self._part, "fs_type", - _ped.file_system_type_get("fat32")) - self.assertRaises(exn, setattr, self._part, "geom", - _ped.Geometry(self._device, 10, 20)) - self.assertRaises(exn, setattr, self._part, "disk", self._disk) - - # Check that values have the right type. - self.assertRaises(exn, setattr, self._part, "type", "blah") - - # Check that looking for invalid attributes fails properly. - self.assertRaises(AttributeError, getattr, self._part, "blah") - -@unittest.skip("Unimplemented test case.") -class PartitionDestroyTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -class PartitionIsActiveTestCase(RequiresPartition): - def runTest(self): - # A partition is active as long as it's not METADATA or FREE. - for ty in [_ped.PARTITION_NORMAL, _ped.PARTITION_LOGICAL, - _ped.PARTITION_EXTENDED, _ped.PARTITION_PROTECTED]: - self._part.type = ty - self.assertTrue(self._part.is_active()) - - for ty in [_ped.PARTITION_FREESPACE, _ped.PARTITION_METADATA]: - # Can't have a partition of these two types that also has a - # filesystem type associated with it. libparted doesn't like - # that combination. - self._part = _ped.Partition(self._disk, ty, 0, 100) - self.assertFalse(self._part.is_active()) - -@unittest.skip("Unimplemented test case.") -class PartitionSetFlagTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class PartitionGetFlagTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -class PartitionIsFlagAvailableTestCase(RequiresPartition): - def runTest(self): - # We don't know which flags should be available and which shouldn't, - # but we can at least check that there aren't any tracebacks from - # trying all of the valid ones. - for f in ['PARTITION_BOOT', 'PARTITION_ROOT', 'PARTITION_SWAP', - 'PARTITION_HIDDEN', 'PARTITION_RAID', 'PARTITION_LVM', - 'PARTITION_LBA', 'PARTITION_HPSERVICE', - 'PARTITION_PALO', 'PARTITION_PREP', - 'PARTITION_MSFT_RESERVED', - 'PARTITION_APPLE_TV_RECOVERY', - 'PARTITION_BIOS_GRUB', 'PARTITION_DIAG', - 'PARTITION_MSFT_DATA', 'PARTITION_IRST', - 'PARTITION_ESP']: - if not hasattr(_ped, f): - continue - attr = getattr(_ped, f) - self.assertIsInstance(self._part.is_flag_available(attr), bool) - - # However, an invalid flag should definitely not be available. - self.assertFalse(self._part.is_flag_available(1000)) - - # Partitions that are inactive should not have any available flags. - self._part = _ped.Partition(self._disk, _ped.PARTITION_FREESPACE, 0, 100) - self.assertRaises(_ped.PartitionException, self._part.is_flag_available, - _ped.PARTITION_BOOT) - -class PartitionSetSystemTestCase(RequiresPartition): - def runTest(self): - self.assertTrue(self._part.set_system(_ped.file_system_type_get("fat32"))) - - self.assertRaises(TypeError, self._part.set_system, 47) - - # Partitions that are inactive cannot have the system type set. - self._part = _ped.Partition(self._disk, _ped.PARTITION_FREESPACE, 0, 100) - self.assertRaises(_ped.PartitionException, self._part.set_system, - _ped.file_system_type_get("ext2")) - -class PartitionSetNameTestCase(RequiresPartition): - def runTest(self): - # The DOS disklabel does not support naming. - self.assertRaises(_ped.PartitionException, self._part.set_name, "blah") - - # These should work. - self._disk = _ped.disk_new_fresh(self._device, _ped.disk_type_get("mac")) - self._part = _ped.Partition(self._disk, _ped.PARTITION_NORMAL, 0, 100, - _ped.file_system_type_get("fat32")) - self.assertTrue(self._part.set_name("blah")) - self.assertEqual(self._part.get_name(), "blah") - - # Partitions that are inactive won't work. - self._part = _ped.Partition(self._disk, _ped.PARTITION_FREESPACE, 0, 100) - self.assertRaises(_ped.PartitionException, self._part.get_name) - -class PartitionGetNameTestCase(RequiresPartition): - def runTest(self): - # The DOS disklabel does not support naming. - self.assertRaises(_ped.PartitionException, self._part.get_name) - - # Partitions that are inactive won't work either. - self._part = _ped.Partition(self._disk, _ped.PARTITION_FREESPACE, 0, 100) - self.assertRaises(_ped.PartitionException, self._part.get_name) - - # Mac disk labels do support naming, but there still has to be a name. - self._disk = _ped.disk_new_fresh(self._device, _ped.disk_type_get("mac")) - self._part = _ped.Partition(self._disk, _ped.PARTITION_NORMAL, 0, 100, - _ped.file_system_type_get("fat32")) - self.assertEqual(self._part.get_name(), "untitled") - - # Finally, Mac disk labels with a name will work. - self._part.set_name("blah") - self.assertEqual(self._part.get_name(), "blah") - -@unittest.skip("Unimplemented test case.") -class PartitionIsBusyTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -class PartitionGetPathTestCase(RequiresPartition): - def runTest(self): - self.assertNotEqual(self._part.get_path(), "") - -@unittest.skip("Unimplemented test case.") -class PartitionStrTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") diff --git a/tests/test__ped_ped.py b/tests/test__ped_ped.py deleted file mode 100755 index a9e54ce..0000000 --- a/tests/test__ped_ped.py +++ /dev/null @@ -1,399 +0,0 @@ -# -# Test cases for the methods in the _ped module itself - just the pyunit -# and pynatmath files. -# -# Copyright (C) 2008-2014 Red Hat, Inc. -# -# This copyrighted material is made available to anyone wishing to use, -# modify, copy, or redistribute it subject to the terms and conditions of -# the GNU General Public License v.2, or (at your option) any later version. -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY expressed or implied, including the implied warranties of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. You should have received a copy of the -# GNU General Public License along with this program; if not, write to the -# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the -# source code or documentation are not subject to the GNU General Public -# License and may only be used or replicated with the express permission of -# Red Hat, Inc. -# -# Red Hat Author(s): Chris Lumens -# David Cantrell -# - -import _ped -import unittest -import os -import tempfile - -from tests.baseclass import * - -# One class per method, multiple tests per class. For these simple methods, -# that seems like good organization. More complicated methods may require -# multiple classes and their own test suite. -class PartitionFlagGetNameTestCase(unittest.TestCase): - def runTest(self): - for f in ['PARTITION_BOOT', 'PARTITION_ROOT', 'PARTITION_SWAP', - 'PARTITION_HIDDEN', 'PARTITION_RAID', 'PARTITION_LVM', - 'PARTITION_LBA', 'PARTITION_HPSERVICE', - 'PARTITION_PALO', 'PARTITION_PREP', - 'PARTITION_MSFT_RESERVED', - 'PARTITION_APPLE_TV_RECOVERY', - 'PARTITION_BIOS_GRUB', 'PARTITION_DIAG', - 'PARTITION_MSFT_DATA', 'PARTITION_IRST', - 'PARTITION_ESP']: - if not hasattr(_ped, f): - continue - attr = getattr(_ped, f) - self.assertNotEqual(_ped.partition_flag_get_name(attr), "", "Could not get name for flag _ped.%s" % f) - - self.assertRaises(ValueError, _ped.partition_flag_get_name, -1) - self.assertRaises(ValueError, _ped.partition_flag_get_name, 1000) - -class PartitionFlagGetByNameTestCase(unittest.TestCase): - def runTest(self): - for f in ["boot", "root", "swap", "hidden", "raid", "lvm", "lba", - "hp-service", "palo", "prep", "msftres", "bios_grub", - "msftdata", "irst", "esp"]: - self.assertNotEqual(_ped.partition_flag_get_by_name(f), "", "Could not get flag %s" % f) - - self.assertEqual(_ped.partition_flag_get_by_name("nosuchflag"), 0) - -class PartitionFlagNextTestCase(unittest.TestCase): - def runTest(self): - # We should get TypeError when the parameter is invalid - self.assertRaises(TypeError, _ped.partition_flag_next) - self.assertRaises(TypeError, _ped.partition_flag_next, 'blah') - - # First flag is 0, keep getting flags until we loop back around - # to zero. Make sure each flag we get is an integer. - flag = _ped.partition_flag_next(0) - self.assertEqual(type(flag).__name__, 'int') - - while True: - flag = _ped.partition_flag_next(flag) - if not flag: - break - self.assertEqual(type(flag).__name__, 'int') - -class DiskFlagGetNameTestCase(unittest.TestCase): - def runTest(self): - for f in [_ped.DISK_CYLINDER_ALIGNMENT]: - self.assertNotEqual(_ped.disk_flag_get_name(f), "", "Could not get name for flag %s" % f) - - self.assertRaises(ValueError, _ped.disk_flag_get_name, -1) - self.assertRaises(ValueError, _ped.disk_flag_get_name, 1000) - -class DiskFlagGetByNameTestCase(unittest.TestCase): - def runTest(self): - for f in ["cylinder_alignment"]: - self.assertNotEqual(_ped.disk_flag_get_by_name(f), 0, "Could not get flag %s" % f) - - self.assertEqual(_ped.disk_flag_get_by_name("nosuchflag"), 0) - -class DiskFlagNextTestCase(unittest.TestCase): - def runTest(self): - # We should get TypeError when the parameter is invalid - self.assertRaises(TypeError, _ped.disk_flag_next) - self.assertRaises(TypeError, _ped.disk_flag_next, 'blah') - - # First flag is 0, keep getting flags until we loop back around - # to zero. Make sure each flag we get is an integer. - flag = _ped.disk_flag_next(0) - self.assertEqual(type(flag).__name__, 'int') - - while True: - flag = _ped.disk_flag_next(flag) - if not flag: - break - self.assertEqual(type(flag).__name__, 'int') - -class ConstraintNewFromMinMaxTestCase(RequiresDevice): - def runTest(self): - self.assertRaises(TypeError, _ped.constraint_new_from_min_max, None) - - # min is required to be within max, so test various combinations of - # that not being the case. - self.assertRaises(_ped.CreateException, _ped.constraint_new_from_min_max, - _ped.Geometry(self._device, 0, 10), - _ped.Geometry(self._device, 15, 25)) - self.assertRaises(_ped.CreateException, _ped.constraint_new_from_min_max, - _ped.Geometry(self._device, 10, 20), - _ped.Geometry(self._device, 15, 25)) - - # Now test a correct call. - min = _ped.Geometry(self._device, 10, 20) - max = _ped.Geometry(self._device, 0, 30) - constraint = _ped.constraint_new_from_min_max(min, max) - - self.assertIsInstance(constraint, _ped.Constraint) - self.assertTrue(constraint.is_solution(_ped.Geometry(self._device, 10, 20))) - self.assertFalse(constraint.is_solution(_ped.Geometry(self._device, 11, 20))) - self.assertTrue(constraint.is_solution(_ped.Geometry(self._device, 5, 25))) - self.assertTrue(constraint.is_solution(_ped.Geometry(self._device, 0, 30))) - self.assertFalse(constraint.is_solution(_ped.Geometry(self._device, 0, 35))) - -class ConstraintNewFromMinTestCase(RequiresDevice): - def runTest(self): - self.assertRaises(TypeError, _ped.constraint_new_from_min, None) - - min = _ped.Geometry(self._device, 10, 20) - constraint = _ped.constraint_new_from_min(min) - - self.assertIsInstance(constraint, _ped.Constraint) - self.assertTrue(constraint.is_solution(_ped.Geometry(self._device, 10, 20))) - self.assertTrue(constraint.is_solution(_ped.Geometry(self._device, 5, 25))) - self.assertFalse(constraint.is_solution(_ped.Geometry(self._device, 11, 19))) - self.assertFalse(constraint.is_solution(_ped.Geometry(self._device, 15, 25))) - -class ConstraintNewFromMaxTestCase(RequiresDevice): - def runTest(self): - self.assertRaises(TypeError, _ped.constraint_new_from_max, None) - - max = _ped.Geometry(self._device, 10, 20) - constraint = _ped.constraint_new_from_max(max) - - self.assertIsInstance(constraint, _ped.Constraint) - self.assertTrue(constraint.is_solution(_ped.Geometry(self._device, 10, 20))) - self.assertFalse(constraint.is_solution(_ped.Geometry(self._device, 5, 25))) - self.assertTrue(constraint.is_solution(_ped.Geometry(self._device, 11, 19))) - self.assertFalse(constraint.is_solution(_ped.Geometry(self._device, 15, 25))) - -class ConstraintAnyTestCase(RequiresDevice): - def runTest(self): - self.assertRaises(TypeError, _ped.constraint_any, None) - - constraint = _ped.constraint_any(self._device) - self.assertIsInstance(constraint, _ped.Constraint) - - for testGeom in [_ped.Geometry(self._device, 0, 5), - _ped.Geometry(self._device, 10, 25), - _ped.Geometry(self._device, 0, 100)]: - self.assertTrue(constraint.is_solution(testGeom)) - -class ConstraintExactTestCase(RequiresDevice): - def runTest(self): - geom = _ped.Geometry(self._device, 0, 100) - - self.assertRaises(TypeError, _ped.constraint_exact, None) - - constraint = _ped.constraint_exact(geom) - self.assertIsInstance(constraint, _ped.Constraint) - - for testGeom in [_ped.Geometry(self._device, 1, 100), - _ped.Geometry(self._device, 0, 99), - _ped.Geometry(self._device, 10, 20), - _ped.Geometry(self._device, 50, 101)]: - self.assertFalse(constraint.is_solution(testGeom)) - - self.assertTrue(constraint.is_solution(_ped.Geometry(self._device, 0, 100))) - -class DeviceGetTestCase(RequiresDevice): - def runTest(self): - # Try getting the device we just made. - self.assertIsInstance(_ped.device_get(self.path), _ped.Device) - - # Try getting a device that doesn't exist. - self.assertRaises(_ped.IOException, _ped.device_get, "/blah/whatever") - self.assertRaises(_ped.IOException, _ped.device_get, "") - self.assertRaises(_ped.DeviceException, _ped.device_get, None) - -@unittest.skip('Requires root') -class DeviceGetNextTestCase(unittest.TestCase, BuildList): - def runTest(self): - # Make sure there are some devices in the system first and then - # make a list out of them. That's easier to work with. - _ped.device_probe_all() - lst = self.getDeviceList(_ped.device_get_next) - - # Now the test cases. - self.assertGreater(len(lst), 0) - self.assertRaises(TypeError, _ped.device_get_next, None) - - for ele in lst: - self.assertIsInstance(ele, _ped.Device) - - self.assertRaises(IndexError, _ped.device_get_next, lst[-1]) - -class DeviceProbeAllTestCase(RequiresDevice, BuildList): - def runTest(self): - # Since we inherit from RequiresDevice, we can test that the temp - # device we created is in the results list. I can't really think of - # any other way to test this method except by getting a list of devices - # via some other mechanism and comparing that to the device_probe_all - # results. - _ped.device_probe_all() - lst = self.getDeviceList(_ped.device_get_next) - - self.assertGreater(len(lst), 0) - self.assertGreater( - len([e for e in lst if e.path.startswith("/tmp/temp-device-")]), 0) - -class DeviceFreeAllTestCase(RequiresDevice): - def runTest(self): - _ped.device_probe_all() - self.assertEqual(_ped.device_free_all(), None) - -class DiskTypeGetTestCase(unittest.TestCase): - def runTest(self): - for d in ["aix", "amiga", "bsd", "dvh", "gpt", "loop", "mac", "msdos", - "pc98","sun"]: - t = _ped.disk_type_get(d) - self.assertIsInstance(t, _ped.DiskType) - self.assertEqual(t.name, d) - - self.assertRaises(_ped.UnknownTypeException, _ped.disk_type_get, "nosuch") - -class DiskTypeGetNextTestCase(unittest.TestCase, BuildList): - def runTest(self): - lst = self.getDeviceList(_ped.disk_type_get_next) - self.assertGreater(len(lst), 0) - self.assertRaises(TypeError, _ped.device_get_next, None) - - for ele in lst: - self.assertIsInstance(ele, _ped.DiskType) - - self.assertRaises(IndexError, _ped.disk_type_get_next, lst[-1]) - -class FileSystemProbeTestCase(RequiresFileSystem): - def runTest(self): - type = _ped.file_system_probe(self._geometry) - - for name in self._fileSystemType.keys(): - if name == 'ext2': - self.assertEqual(type.name, name) - else: - self.assertNotEqual(type.name, name) - -class FileSystemProbeSpecificTestCase(RequiresFileSystem): - def runTest(self): - for (name, type,) in self._fileSystemType.items(): - if name == 'ext2': - result = _ped.file_system_probe_specific(type, self._geometry) - - # XXX: this should work - # we're getting - # ValueError: object comparing to must be a _ped.Geometry - # at runtime. works fine in pdb. - #self.assertEqual(result, self._geometry) - - self.assertIsInstance(result, _ped.Geometry) - self.assertEqual(result.start, self._geometry.start) - self.assertLessEqual(result.end, self._geometry.end) - self.assertLessEqual(result.length, self._geometry.length) - self.assertEqual(result.dev, self._device) - else: - result = _ped.file_system_probe_specific(type, self._geometry) - self.assertEqual(result, None) - -class FileSystemTypeGetTestCase(unittest.TestCase): - def runTest(self): - for f in ["affs0", "amufs", "apfs1", "asfs", "btrfs", "ext2", "ext3", "ext4", "fat16", - "fat32", "hfs", "hfs+", "hfsx", "hp-ufs", "jfs", "linux-swap", - "ntfs", "reiserfs", "sun-ufs", "xfs"]: - # may be missing some filesystem types depending on the parted - # build on the test system - try: - t = _ped.file_system_type_get(f) - self.assertIsInstance(_ped.file_system_type_get(f), _ped.FileSystemType, "Could not get fs type %s" % f) - except _ped.UnknownTypeException: - pass - - self.assertRaises(_ped.UnknownTypeException, _ped.file_system_type_get, "nosuch") - -class FileSystemTypeGetNextTestCase(unittest.TestCase, BuildList): - def runTest(self): - lst = self.getDeviceList(_ped.file_system_type_get_next) - self.assertGreater(len(lst), 0) - self.assertRaises(TypeError, _ped.file_system_type_get_next, None) - - for ele in lst: - self.assertIsInstance(ele, _ped.FileSystemType) - - self.assertRaises(IndexError, _ped.file_system_type_get_next, lst[-1]) - -class PartitionTypeGetNameTestCase(unittest.TestCase): - def runTest(self): - for t in [_ped.PARTITION_METADATA, _ped.PARTITION_FREESPACE, - _ped.PARTITION_EXTENDED, _ped.PARTITION_LOGICAL]: - self.assertNotEqual(_ped.partition_type_get_name(t), "", "Could not get name for flag %s" % t) - -class UnitSetDefaultTestCase(unittest.TestCase): - def setUp(self): - self._initialDefault = _ped.unit_get_default() - - def tearDown(self): - _ped.unit_set_default(self._initialDefault) - - def runTest(self): - for v in [_ped.UNIT_BYTE, _ped.UNIT_CHS, _ped.UNIT_COMPACT, - _ped.UNIT_CYLINDER, _ped.UNIT_GIBIBYTE, _ped.UNIT_GIGABYTE, - _ped.UNIT_KIBIBYTE, _ped.UNIT_KILOBYTE, _ped.UNIT_MEBIBYTE, - _ped.UNIT_MEGABYTE, _ped.UNIT_PERCENT, _ped.UNIT_SECTOR, - _ped.UNIT_TEBIBYTE, _ped.UNIT_TERABYTE]: - _ped.unit_set_default(v) - self.assertEqual(_ped.unit_get_default(), v, "Could not set unit default to %s" % v) - - self.assertRaises(ValueError, _ped.unit_set_default, -1) - self.assertRaises(ValueError, _ped.unit_set_default, 1000) - -class UnitGetDefaultTestCase(unittest.TestCase): - def runTest(self): - self.assertGreaterEqual(_ped.unit_get_default(), 0) - -class UnitGetSizeTestCase(RequiresDevice): - def runTest(self): - self.assertEqual(self._device.unit_get_size(_ped.UNIT_SECTOR), 512) - self.assertEqual(self._device.unit_get_size(_ped.UNIT_BYTE), 1) - self.assertEqual(self._device.unit_get_size(_ped.UNIT_KILOBYTE), 1000) - self.assertEqual(self._device.unit_get_size(_ped.UNIT_MEGABYTE), 1000000) - self.assertEqual(self._device.unit_get_size(_ped.UNIT_GIGABYTE), 1000000000) - self.assertEqual(self._device.unit_get_size(_ped.UNIT_TERABYTE), 1000000000000) - self.assertEqual(self._device.unit_get_size(_ped.UNIT_KIBIBYTE), 1024) - self.assertEqual(self._device.unit_get_size(_ped.UNIT_MEBIBYTE), 1048576) - self.assertEqual(self._device.unit_get_size(_ped.UNIT_GIBIBYTE), 1073741824) - self.assertEqual(self._device.unit_get_size(_ped.UNIT_TEBIBYTE), 1099511627776) - self.assertEqual(self._device.unit_get_size(_ped.UNIT_CYLINDER), 65536) - self.assertEqual(self._device.unit_get_size(_ped.UNIT_CHS), 512) - self.assertEqual(self._device.unit_get_size(_ped.UNIT_PERCENT), self._device.length * self._device.sector_size // 100) - self.assertRaises(ValueError, self._device.unit_get_size, _ped.UNIT_COMPACT) - -class UnitGetNameTestCase(unittest.TestCase): - def runTest(self): - self.assertEqual(_ped.unit_get_name(_ped.UNIT_BYTE), 'B') - self.assertEqual(_ped.unit_get_name(_ped.UNIT_CHS), 'chs') - self.assertEqual(_ped.unit_get_name(_ped.UNIT_COMPACT), 'compact') - self.assertEqual(_ped.unit_get_name(_ped.UNIT_CYLINDER), 'cyl') - self.assertEqual(_ped.unit_get_name(_ped.UNIT_GIBIBYTE), 'GiB') - self.assertEqual(_ped.unit_get_name(_ped.UNIT_GIGABYTE), 'GB') - self.assertEqual(_ped.unit_get_name(_ped.UNIT_KIBIBYTE), 'kiB') - self.assertEqual(_ped.unit_get_name(_ped.UNIT_KILOBYTE), 'kB') - self.assertEqual(_ped.unit_get_name(_ped.UNIT_MEBIBYTE), 'MiB') - self.assertEqual(_ped.unit_get_name(_ped.UNIT_MEGABYTE), 'MB') - self.assertEqual(_ped.unit_get_name(_ped.UNIT_PERCENT), '%') - self.assertEqual(_ped.unit_get_name(_ped.UNIT_SECTOR), 's') - self.assertEqual(_ped.unit_get_name(_ped.UNIT_TEBIBYTE), 'TiB') - self.assertEqual(_ped.unit_get_name(_ped.UNIT_TERABYTE), 'TB') - - self.assertRaises(ValueError, _ped.unit_get_name, -1) - self.assertRaises(ValueError, _ped.unit_get_name, 1000) - -class UnitGetByNameTestCase(unittest.TestCase): - def runTest(self): - self.assertEqual(_ped.unit_get_by_name('B'), _ped.UNIT_BYTE) - self.assertEqual(_ped.unit_get_by_name('chs'), _ped.UNIT_CHS) - self.assertEqual(_ped.unit_get_by_name('compact'), _ped.UNIT_COMPACT) - self.assertEqual(_ped.unit_get_by_name('cyl'), _ped.UNIT_CYLINDER) - self.assertEqual(_ped.unit_get_by_name('GiB'), _ped.UNIT_GIBIBYTE) - self.assertEqual(_ped.unit_get_by_name('GB'), _ped.UNIT_GIGABYTE) - self.assertEqual(_ped.unit_get_by_name('kiB'), _ped.UNIT_KIBIBYTE) - self.assertEqual(_ped.unit_get_by_name('kB'), _ped.UNIT_KILOBYTE) - self.assertEqual(_ped.unit_get_by_name('MiB'), _ped.UNIT_MEBIBYTE) - self.assertEqual(_ped.unit_get_by_name('MB'), _ped.UNIT_MEGABYTE) - self.assertEqual(_ped.unit_get_by_name('%'), _ped.UNIT_PERCENT) - self.assertEqual(_ped.unit_get_by_name('s'), _ped.UNIT_SECTOR) - self.assertEqual(_ped.unit_get_by_name('TiB'), _ped.UNIT_TEBIBYTE) - self.assertEqual(_ped.unit_get_by_name('TB'), _ped.UNIT_TERABYTE) - - self.assertRaises(_ped.UnknownTypeException, _ped.unit_get_by_name, "blargle") diff --git a/tests/test_parted_alignment.py b/tests/test_parted_alignment.py deleted file mode 100755 index 87a2049..0000000 --- a/tests/test_parted_alignment.py +++ /dev/null @@ -1,161 +0,0 @@ -# -# Test cases for the methods in the parted.alignment module itself -# -# Copyright (C) 2009-2011 Red Hat, Inc. -# -# This copyrighted material is made available to anyone wishing to use, -# modify, copy, or redistribute it subject to the terms and conditions of -# the GNU General Public License v.2, or (at your option) any later version. -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY expressed or implied, including the implied warranties of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. You should have received a copy of the -# GNU General Public License along with this program; if not, write to the -# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the -# source code or documentation are not subject to the GNU General Public -# License and may only be used or replicated with the express permission of -# Red Hat, Inc. -# -# Red Hat Author(s): David Cantrell -# - -import _ped -import parted -import unittest -from tests.baseclass import * - -# One class per method, multiple tests per class. For these simple methods, -# that seems like good organization. More complicated methods may require -# multiple classes and their own test suite. -class AlignmentNewTestCase(unittest.TestCase): - def setUp(self): - self.pa = _ped.Alignment(0, 100) - - def runTest(self): - # Check that not passing args to parted.Alignment.__init__ is caught. - self.assertRaises(parted.AlignmentException, parted.Alignment) - - # And then the correct ways of creating a parted.Alignment - a = parted.Alignment(offset=0, grainSize=100) - self.assertIsInstance(a, parted.Alignment) - - b = parted.Alignment(PedAlignment=self.pa) - self.assertIsInstance(b, parted.Alignment) - - # Test for _ped.Alignment equality - self.assertEqual(b.getPedAlignment(), self.pa) - -class AlignmentGetSetTestCase(unittest.TestCase): - def setUp(self): - self.a = parted.Alignment(offset=27, grainSize=49) - - def runTest(self): - # Test that passing the args to __init__ works. - self.assertIsInstance(self.a, parted.Alignment) - self.assertEqual(self.a.offset, 27) - self.assertEqual(self.a.grainSize, 49) - - # Test that setting directly and getting with getattr works. - self.a.offset = 10 - self.a.grainSize = 90 - - self.assertEqual(getattr(self.a, "offset"), 10) - self.assertEqual(getattr(self.a, "grainSize"), 90) - - # Check that setting with setattr and getting directly works. - setattr(self.a, "offset", 20) - setattr(self.a, "grainSize", 80) - - self.assertEqual(self.a.offset, 20) - self.assertEqual(self.a.grainSize, 80) - - # Check that values have the right type. - self.assertRaises(TypeError, setattr, self.a, "offset", "string") - - # Check that looking for invalid attributes fails properly. - self.assertRaises(AttributeError, getattr, self.a, "blah") - -@unittest.skip("Unimplemented test case.") -class AlignmentIntersectTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class AlignmentAlignUpTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class AlignmentAlignDownTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class AlignmentAlignNearestTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -class AlignmentIsAlignedTestCase(RequiresDevice): - def setUp(self): - RequiresDevice.setUp(self) - self.g = parted.Geometry(device=self.device, start=0, length=100) - self.a = parted.Alignment(offset=10, grainSize=0) - - def runTest(self): - # Test a couple ways of passing bad arguments. - self.assertRaises(TypeError, self.a.isAligned, None, 12) - self.assertRaises(TypeError, self.a.isAligned, self.g, None) - - # Sector must be inside the geometry. - self.assertFalse(self.a.isAligned(self.g, 400)) - - # If grain_size is 0, sector must be the same as offset. - self.assertTrue(self.a.isAligned(self.g, 10)) - self.assertFalse(self.a.isAligned(self.g, 0)) - self.assertFalse(self.a.isAligned(self.g, 47)) - - # If grain_size is anything else, there's real math involved. - self.a.grainSize = 5 - self.assertTrue(self.a.isAligned(self.g, 20)) - self.assertFalse(self.a.isAligned(self.g, 23)) - -class AlignmentGetPedAlignmentTestCase(unittest.TestCase): - def setUp(self): - self.pa = _ped.Alignment(0, 100) - self.alignment = parted.Alignment(PedAlignment=self.pa) - - def runTest(self): - # Test to make sure we get a _ped.Alignment - self.assertIsInstance(self.alignment.getPedAlignment(), _ped.Alignment) - - # Test for _ped.Alignment equality - self.assertEqual(self.alignment.getPedAlignment(), self.pa) - -@unittest.skip("Unimplemented test case.") -class AlignmentStrTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -# And then a suite to hold all the test cases for this module. -def suite(): - suite = unittest.TestSuite() - suite.addTest(AlignmentNewTestCase()) - suite.addTest(AlignmentGetSetTestCase()) - suite.addTest(AlignmentIntersectTestCase()) - suite.addTest(AlignmentAlignUpTestCase()) - suite.addTest(AlignmentAlignDownTestCase()) - suite.addTest(AlignmentAlignNearestTestCase()) - suite.addTest(AlignmentIsAlignedTestCase()) - suite.addTest(AlignmentGetPedAlignmentTestCase()) - suite.addTest(AlignmentStrTestCase()) - return suite - -s = suite() -if __name__ == "__main__": - unittest.main(defaultTest='s', verbosity=2) diff --git a/tests/test_parted_constraint.py b/tests/test_parted_constraint.py deleted file mode 100755 index 67e45a1..0000000 --- a/tests/test_parted_constraint.py +++ /dev/null @@ -1,174 +0,0 @@ -# -# Test cases for the methods in the parted.constraint module itself -# -# Copyright (C) 2009-2011 Red Hat, Inc. -# -# This copyrighted material is made available to anyone wishing to use, -# modify, copy, or redistribute it subject to the terms and conditions of -# the GNU General Public License v.2, or (at your option) any later version. -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY expressed or implied, including the implied warranties of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. You should have received a copy of the -# GNU General Public License along with this program; if not, write to the -# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the -# source code or documentation are not subject to the GNU General Public -# License and may only be used or replicated with the express permission of -# Red Hat, Inc. -# -# Red Hat Author(s): David Cantrell -# - -import _ped -import parted -import unittest -from tests.baseclass import * - -# One class per method, multiple tests per class. For these simple methods, -# that seems like good organization. More complicated methods may require -# multiple classes and their own test suite. -class ConstraintNewTestCase(RequiresDevice): - def runTest(self): - align1 = parted.Alignment(offset=10, grainSize=5) - align2 = parted.Alignment(offset=10, grainSize=5) - geom1 = parted.Geometry(device=self.device, start=0, length=50) - geom2 = parted.Geometry(device=self.device, start=0, length=100) - - # Check that not passing enough args to parted.Constraint.__init__ - # is caught. - self.assertRaises(parted.ConstraintException, parted.Constraint) - self.assertRaises(parted.ConstraintException, parted.Constraint, - startAlign=align1, endAlign=align2) - - # And then the correct ways of creating a _ped.Constraint. - c = parted.Constraint(minGeom=geom1, maxGeom=geom2) - self.assertIsInstance(c, parted.Constraint) - - c = parted.Constraint(minGeom=geom1) - self.assertIsInstance(c, parted.Constraint) - - c = parted.Constraint(maxGeom=geom2) - self.assertIsInstance(c, parted.Constraint) - - c = parted.Constraint(exactGeom=geom1) - self.assertIsInstance(c, parted.Constraint) - - c = parted.Constraint(device=self.device) - self.assertIsInstance(c, parted.Constraint) - - c = parted.Constraint(startAlign=align1, endAlign=align2, - startRange=geom1, endRange=geom2, - minSize=10, maxSize=100) - self.assertIsInstance(c, parted.Constraint) - - # Use a _ped.Constraint as the initializer - pc = _ped.Constraint(align1.getPedAlignment(), - align2.getPedAlignment(), - geom1.getPedGeometry(), - geom2.getPedGeometry(), - 10, 100) - c = parted.Constraint(PedConstraint=pc) - self.assertIsInstance(c, parted.Constraint) - self.assertEqual(c.getPedConstraint(), pc) - -class ConstraintGetSetTestCase(RequiresDevice): - def setUp(self): - RequiresDevice.setUp(self) - align1 = parted.Alignment(offset=10, grainSize=5) - align2 = parted.Alignment(offset=10, grainSize=5) - geom1 = parted.Geometry(device=self.device, start=0, length=50) - geom2 = parted.Geometry(device=self.device, start=25, length=50) - - self.c = parted.Constraint(startAlign=align1, endAlign=align2, - startRange=geom1, endRange=geom2, - minSize=10, maxSize=100) - - def runTest(self): - # Test that properties work - self.assertEqual(self.c.minSize, 10) - self.assertEqual(self.c.maxSize, 100) - self.assertIsInstance(self.c.startAlign, parted.Alignment) - self.assertIsInstance(self.c.endAlign, parted.Alignment) - self.assertIsInstance(self.c.startRange, parted.Geometry) - self.assertIsInstance(self.c.endRange, parted.Geometry) - - # Test that setting directly and getting with getattr works. - self.c.minSize = 15 - self.c.maxSize = 75 - - self.assertEqual(getattr(self.c, "minSize"), 15) - self.assertEqual(getattr(self.c, "maxSize"), 75) - self.assertIsInstance(getattr(self.c, "startAlign"), parted.Alignment) - self.assertIsInstance(getattr(self.c, "endAlign"), parted.Alignment) - self.assertIsInstance(getattr(self.c, "startRange"), parted.Geometry) - self.assertIsInstance(getattr(self.c, "endRange"), parted.Geometry) - - # Test that setting with setattr and getting directly works. - setattr(self.c, "minSize", 10) - setattr(self.c, "maxSize", 90) - - self.assertEqual(self.c.minSize, 10) - self.assertEqual(self.c.maxSize, 90) - - # Test that values have the right type. - self.assertRaises(TypeError, setattr, self.c, "minSize", "string") - - # Test that looking for invalid attributes fails properly. - self.assertRaises(AttributeError, getattr, self.c, "blah") - - self.assertRaises(AttributeError, setattr, self.c, "startRange", 47) - self.assertRaises(AttributeError, setattr, self.c, "endRange", 47) - -@unittest.skip("Unimplemented test case.") -class ConstraintIntersectTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class ConstraintSolveMaxTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class ConstraintSolveNearestTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class ConstraintIsSolutionTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class ConstraintGetPedConstraintTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class ConstraintStrTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -# And then a suite to hold all the test cases for this module. -def suite(): - suite = unittest.TestSuite() - suite.addTest(ConstraintNewTestCase()) - suite.addTest(ConstraintGetSetTestCase()) - suite.addTest(ConstraintIntersectTestCase()) - suite.addTest(ConstraintSolveMaxTestCase()) - suite.addTest(ConstraintSolveNearestTestCase()) - suite.addTest(ConstraintIsSolutionTestCase()) - suite.addTest(ConstraintGetPedConstraintTestCase()) - suite.addTest(ConstraintStrTestCase()) - return suite - -s = suite() -if __name__ == "__main__": - unittest.main(defaultTest='s', verbosity=2) diff --git a/tests/test_parted_device.py b/tests/test_parted_device.py deleted file mode 100755 index fbd021a..0000000 --- a/tests/test_parted_device.py +++ /dev/null @@ -1,190 +0,0 @@ -# -# Test cases for the methods in the parted.device module itself -# -# Copyright (C) 2009-2011 Red Hat, Inc. -# -# This copyrighted material is made available to anyone wishing to use, -# modify, copy, or redistribute it subject to the terms and conditions of -# the GNU General Public License v.2, or (at your option) any later version. -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY expressed or implied, including the implied warranties of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. You should have received a copy of the -# GNU General Public License along with this program; if not, write to the -# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the -# source code or documentation are not subject to the GNU General Public -# License and may only be used or replicated with the express permission of -# Red Hat, Inc. -# -# Red Hat Author(s): David Cantrell -# - -import _ped -import parted -import unittest -from tests.baseclass import * - -# One class per method, multiple tests per class. For these simple methods, -# that seems like good organization. More complicated methods may require -# multiple classes and their own test suite. -@unittest.skip("Unimplemented test case.") -class DeviceNewTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DeviceGetSetTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DeviceOpenTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DeviceCloseTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DeviceDestroyTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DeviceRemoveFromCacheTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DeviceBeginExternalAccessTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DeviceEndExternalAccessTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DeviceReadTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DeviceWriteTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DeviceSyncTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DeviceCheckTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DeviceStartSectorToCylinderTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DeviceEndSectorToCylinderTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DeviceStartCylinderToSectorTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DeviceEndCylinderToSectorTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DeviceGetSizeTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -class DeviceGetLengthTestCase(RequiresDevice): - def runTest(self): - self.assertEqual(self.device.getLength(), self.device.length) - -@unittest.skip("Unimplemented test case.") -class DeviceGetSizeAsSectorsTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DeviceGetConstraintTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DeviceGetPedDeviceTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DeviceStrTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -# And then a suite to hold all the test cases for this module. -def suite(): - suite = unittest.TestSuite() - suite.addTest(DeviceNewTestCase()) - suite.addTest(DeviceGetSetTestCase()) - suite.addTest(DeviceOpenTestCase()) - suite.addTest(DeviceCloseTestCase()) - suite.addTest(DeviceDestroyTestCase()) - suite.addTest(DeviceRemoveFromCacheTestCase()) - suite.addTest(DeviceBeginExternalAccessTestCase()) - suite.addTest(DeviceEndExternalAccessTestCase()) - suite.addTest(DeviceReadTestCase()) - suite.addTest(DeviceWriteTestCase()) - suite.addTest(DeviceSyncTestCase()) - suite.addTest(DeviceCheckTestCase()) - suite.addTest(DeviceStartSectorToCylinderTestCase()) - suite.addTest(DeviceEndSectorToCylinderTestCase()) - suite.addTest(DeviceStartCylinderToSectorTestCase()) - suite.addTest(DeviceEndCylinderToSectorTestCase()) - suite.addTest(DeviceGetSizeTestCase()) - suite.addTest(DeviceGetLengthTestCase()) - suite.addTest(DeviceGetSizeAsSectorsTestCase()) - suite.addTest(DeviceGetConstraintTestCase()) - suite.addTest(DeviceGetPedDeviceTestCase()) - suite.addTest(DeviceStrTestCase()) - return suite - -s = suite() -if __name__ == "__main__": - unittest.main(defaultTest='s', verbosity=2) diff --git a/tests/test_parted_disk.py b/tests/test_parted_disk.py deleted file mode 100755 index 8fcd5e4..0000000 --- a/tests/test_parted_disk.py +++ /dev/null @@ -1,303 +0,0 @@ -# -# Test cases for the methods in the parted.disk module itself -# -# Copyright (C) 2009 Red Hat, Inc. -# -# This copyrighted material is made available to anyone wishing to use, -# modify, copy, or redistribute it subject to the terms and conditions of -# the GNU General Public License v.2, or (at your option) any later version. -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY expressed or implied, including the implied warranties of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. You should have received a copy of the -# GNU General Public License along with this program; if not, write to the -# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the -# source code or documentation are not subject to the GNU General Public -# License and may only be used or replicated with the express permission of -# Red Hat, Inc. -# -# Red Hat Author(s): David Cantrell -# - -import parted -import unittest - -from tests.baseclass import * - -# One class per method, multiple tests per class. For these simple methods, -# that seems like good organization. More complicated methods may require -# multiple classes and their own test suite. -@unittest.skip("Unimplemented test case.") -class DiskNewTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskGetSetTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskClobberTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskDuplicateTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskDestroyTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskCommitTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskCommitToDeviceTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskCommitToOSTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskCheckTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskSupportsFeatureTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskAddPartitionTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskRemovePartitionTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskDeletePartitionTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskDeleteAllPartitionsTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskSetPartitionGeometryTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskMaximizePartitionTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskCalculateMaxPartitionGeometryTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskMinimizeExtendedPartitionTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskGetPartitionBySectorTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskGetMaxLogicalPartitionsTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskGetMaxSupportedPartitionCountTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -class DiskMaxPartitionLengthTestCase(RequiresDisk): - def runTest(self): - # This test assumes an MSDOS label as given by RequiresDisk - self.assertEqual(self.disk.maxPartitionLength, 4294967295) - -class DiskMaxPartitionStartSectorTestCase(RequiresDisk): - def runTest(self): - # This test assumes an MSDOS label as given by RequiresDisk - self.assertEqual(self.disk.maxPartitionStartSector, 4294967295) - -class DiskGetFlagTestCase(RequiresDisk): - def runTest(self): - flag = self.disk.getFlag(parted.DISK_CYLINDER_ALIGNMENT) - self.assertIsInstance(flag, bool) - -class DiskSetFlagTestCase(RequiresDisk): - def runTest(self): - # This test assumes an MSDOS label as given by RequiresDisk - self.disk.setFlag(parted.DISK_CYLINDER_ALIGNMENT) - flag = self.disk.getFlag(parted.DISK_CYLINDER_ALIGNMENT) - self.assertEqual(flag, True) - -class DiskUnsetFlagTestCase(RequiresDisk): - def runTest(self): - # This test assumes an MSDOS label as given by RequiresDisk - self.disk.unsetFlag(parted.DISK_CYLINDER_ALIGNMENT) - flag = self.disk.getFlag(parted.DISK_CYLINDER_ALIGNMENT) - self.assertEqual(flag, False) - -class DiskIsFlagAvailableTestCase(RequiresDisk): - def runTest(self): - # This test assumes an MSDOS label as given by RequiresDisk - available = self.disk.isFlagAvailable(parted.DISK_CYLINDER_ALIGNMENT) - self.assertEqual(available, True) - -@unittest.skip("Unimplemented test case.") -class DiskGetExtendedPartitionTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskGetLogicalPartitionsTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskGetPrimaryPartitionsTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskGetRaidPartitionsTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskGetLVMPartitionsTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskGetFreeSpaceRegionsTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskGetFreeSpacePartitionsTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskGetFirstPartitionTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskGetPartitionByPathTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskGetPedDiskTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class DiskStrTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -# And then a suite to hold all the test cases for this module. -def suite(): - suite = unittest.TestSuite() - suite.addTest(DiskNewTestCase()) - suite.addTest(DiskGetSetTestCase()) - suite.addTest(DiskClobberTestCase()) - suite.addTest(DiskDuplicateTestCase()) - suite.addTest(DiskDestroyTestCase()) - suite.addTest(DiskCommitTestCase()) - suite.addTest(DiskCommitToDeviceTestCase()) - suite.addTest(DiskCommitToOSTestCase()) - suite.addTest(DiskCheckTestCase()) - suite.addTest(DiskSupportsFeatureTestCase()) - suite.addTest(DiskAddPartitionTestCase()) - suite.addTest(DiskRemovePartitionTestCase()) - suite.addTest(DiskDeletePartitionTestCase()) - suite.addTest(DiskDeleteAllPartitionsTestCase()) - suite.addTest(DiskSetPartitionGeometryTestCase()) - suite.addTest(DiskMaximizePartitionTestCase()) - suite.addTest(DiskCalculateMaxPartitionGeometryTestCase()) - suite.addTest(DiskMinimizeExtendedPartitionTestCase()) - suite.addTest(DiskGetPartitionBySectorTestCase()) - suite.addTest(DiskGetMaxLogicalPartitionsTestCase()) - suite.addTest(DiskGetMaxSupportedPartitionCountTestCase()) - suite.addTest(DiskMaxPartitionLengthTestCase()) - suite.addTest(DiskMaxPartitionStartSectorTestCase()) - suite.addTest(DiskGetFlagTestCase()) - suite.addTest(DiskSetFlagTestCase()) - suite.addTest(DiskUnsetFlagTestCase()) - suite.addTest(DiskIsFlagAvailableTestCase()) - suite.addTest(DiskGetExtendedPartitionTestCase()) - suite.addTest(DiskGetLogicalPartitionsTestCase()) - suite.addTest(DiskGetPrimaryPartitionsTestCase()) - suite.addTest(DiskGetRaidPartitionsTestCase()) - suite.addTest(DiskGetLVMPartitionsTestCase()) - suite.addTest(DiskGetFreeSpaceRegionsTestCase()) - suite.addTest(DiskGetFreeSpacePartitionsTestCase()) - suite.addTest(DiskGetFirstPartitionTestCase()) - suite.addTest(DiskGetPartitionByPathTestCase()) - suite.addTest(DiskGetPedDiskTestCase()) - suite.addTest(DiskStrTestCase()) - return suite - -s = suite() -if __name__ == "__main__": - unittest.main(defaultTest='s', verbosity=2) diff --git a/tests/test_parted_filesystem.py b/tests/test_parted_filesystem.py deleted file mode 100755 index 7446cbf..0000000 --- a/tests/test_parted_filesystem.py +++ /dev/null @@ -1,64 +0,0 @@ -# -# Test cases for the methods in the parted.filesystem module itself -# -# Copyright (C) 2009-2011 Red Hat, Inc. -# -# This copyrighted material is made available to anyone wishing to use, -# modify, copy, or redistribute it subject to the terms and conditions of -# the GNU General Public License v.2, or (at your option) any later version. -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY expressed or implied, including the implied warranties of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. You should have received a copy of the -# GNU General Public License along with this program; if not, write to the -# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the -# source code or documentation are not subject to the GNU General Public -# License and may only be used or replicated with the express permission of -# Red Hat, Inc. -# -# Red Hat Author(s): David Cantrell -# - -import parted -import unittest - -# One class per method, multiple tests per class. For these simple methods, -# that seems like good organization. More complicated methods may require -# multiple classes and their own test suite. -@unittest.skip("Unimplemented test case.") -class FileSystemNewTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class FileSystemGetSetTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class FileSystemGetPedFileSystemTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class FileSystemStrTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -# And then a suite to hold all the test cases for this module. -def suite(): - suite = unittest.TestSuite() - suite.addTest(FileSystemNewTestCase()) - suite.addTest(FileSystemGetSetTestCase()) - suite.addTest(FileSystemGetPedFileSystemTestCase()) - suite.addTest(FileSystemStrTestCase()) - return suite - -s = suite() -if __name__ == "__main__": - unittest.main(defaultTest='s', verbosity=2) diff --git a/tests/test_parted_geometry.py b/tests/test_parted_geometry.py deleted file mode 100755 index eceb6ab..0000000 --- a/tests/test_parted_geometry.py +++ /dev/null @@ -1,152 +0,0 @@ -# -# Test cases for the methods in the parted.geometry module itself -# -# Copyright (C) 2009-2011 Red Hat, Inc. -# -# This copyrighted material is made available to anyone wishing to use, -# modify, copy, or redistribute it subject to the terms and conditions of -# the GNU General Public License v.2, or (at your option) any later version. -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY expressed or implied, including the implied warranties of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. You should have received a copy of the -# GNU General Public License along with this program; if not, write to the -# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the -# source code or documentation are not subject to the GNU General Public -# License and may only be used or replicated with the express permission of -# Red Hat, Inc. -# -# Red Hat Author(s): David Cantrell -# - -import parted -import unittest - -from tests.baseclass import * - -# One class per method, multiple tests per class. For these simple methods, -# that seems like good organization. More complicated methods may require -# multiple classes and their own test suite. -@unittest.skip("Unimplemented test case.") -class GeometryNewTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class GeometryGetSetTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class GeometryCheckTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class GeometryContainsTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class GeometryContainsSectorTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class GeometryEqualTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class GeometryGetSizeTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -class GeometryGetLengthTestCase(RequiresDevice): - def runTest(self): - length = 137 - geom = parted.Geometry(self.device, start=100, length=length) - - self.assertEqual(geom.getLength(), geom.length) - self.assertEqual(geom.getLength(), length) - -@unittest.skip("Unimplemented test case.") -class GeometryIntersectTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class GeometryMapTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class GeometryOverlapsWithTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class GeometryReadTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class GeometrySyncTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class GeometryWriteTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class GeometryGetPedGeometryTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class GeometryStrTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -# And then a suite to hold all the test cases for this module. -def suite(): - suite = unittest.TestSuite() - suite.addTest(GeometryNewTestCase()) - suite.addTest(GeometryGetSetTestCase()) - suite.addTest(GeometryCheckTestCase()) - suite.addTest(GeometryContainsTestCase()) - suite.addTest(GeometryContainsSectorTestCase()) - suite.addTest(GeometryEqualTestCase()) - suite.addTest(GeometryGetSizeTestCase()) - suite.addTest(GeometryGetLengthTestCase()) - suite.addTest(GeometryIntersectTestCase()) - suite.addTest(GeometryMapTestCase()) - suite.addTest(GeometryOverlapsWithTestCase()) - suite.addTest(GeometryReadTestCase()) - suite.addTest(GeometrySyncTestCase()) - suite.addTest(GeometryWriteTestCase()) - suite.addTest(GeometryGetPedGeometryTestCase()) - suite.addTest(GeometryStrTestCase()) - return suite - -s = suite() -if __name__ == "__main__": - unittest.main(defaultTest='s', verbosity=2) diff --git a/tests/test_parted_parted.py b/tests/test_parted_parted.py deleted file mode 100755 index f61962d..0000000 --- a/tests/test_parted_parted.py +++ /dev/null @@ -1,162 +0,0 @@ -# -# Test cases for the methods in the parted module itself -# -# Copyright (C) 2009-2011 Red Hat, Inc. -# -# This copyrighted material is made available to anyone wishing to use, -# modify, copy, or redistribute it subject to the terms and conditions of -# the GNU General Public License v.2, or (at your option) any later version. -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY expressed or implied, including the implied warranties of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. You should have received a copy of the -# GNU General Public License along with this program; if not, write to the -# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the -# source code or documentation are not subject to the GNU General Public -# License and may only be used or replicated with the express permission of -# Red Hat, Inc. -# -# Red Hat Author(s): David Cantrell -# - -from __future__ import division - -import _ped -import parted -import unittest -from tests.baseclass import * - -# One class per method, multiple tests per class. For these simple methods, -# that seems like good organization. More complicated methods may require -# multiple classes and their own test suite. -class FormatBytesTestCase(unittest.TestCase): - def runTest(self): - self.assertRaises(SyntaxError, parted.formatBytes, 57, "GIB") - self.assertEqual(1e-24, parted.formatBytes(1, "YB")) - self.assertEqual(1/2**80, parted.formatBytes(1, "YiB")) - self.assertEqual(1, parted.formatBytes(1, 'B')) - self.assertEqual(1, parted.formatBytes(1e24, 'YB')) - self.assertEqual(1, parted.formatBytes(2**80, 'YiB')) - -class BytesToSectorsTestCase(unittest.TestCase): - def runTest(self): - self.assertRaises(SyntaxError, parted.sizeToSectors, 9, "yb", 1) - self.assertEqual(int(parted.sizeToSectors(7777.0, "B", 512)), - parted.sizeToSectors(7777.0, "B", 512)) - -class GetLabelsTestCase(unittest.TestCase): - def runTest(self): - self.assertGreater(len(parted.getLabels()), 0) - self.assertSetEqual(parted.getLabels('ppcc'), set()) - self.assertSetEqual(parted.getLabels('sparc6'), set()) - self.assertSetEqual(parted.getLabels('i586'), {'gpt', 'msdos'}) - self.assertSetEqual(parted.getLabels('s390'), {'dasd', 'msdos'}) - self.assertSetEqual(parted.getLabels('s390x'), {'dasd', 'msdos'}) - self.assertSetEqual(parted.getLabels('sparc'), {'sun'}) - self.assertSetEqual(parted.getLabels('sparc64'), {'sun'}) - self.assertSetEqual(parted.getLabels('ppc'), {'amiga', 'gpt', 'mac', 'msdos'}) - self.assertSetEqual(parted.getLabels('ppc64'), {'amiga', 'gpt', 'mac', 'msdos'}) - self.assertSetEqual(parted.getLabels('ppc64le'), {'gpt', 'msdos'}) - self.assertSetEqual(parted.getLabels('alpha'), {'bsd', 'msdos'}) - self.assertSetEqual(parted.getLabels('ia64'), {'gpt', 'msdos'}) - self.assertSetEqual(parted.getLabels('aarch64'), {'gpt', 'msdos'}) - self.assertSetEqual(parted.getLabels('armv7l'), {'gpt', 'msdos'}) - -class GetDeviceTestCase(RequiresDeviceNode): - def runTest(self): - # Check that a DiskException is raised for an invalid path - self.assertRaises(parted.DeviceException, parted.getDevice, None) - self.assertRaises(parted.IOException, parted.getDevice, "") - self.assertRaises(parted.IOException, parted.getDevice, "/dev/whatever") - - # Check that we get a parted.Device back - self.assertIsInstance(parted.getDevice(self.path), parted.Device) - - # Make sure the device node paths match - self.assertEqual(parted.getDevice(self.path).path, self.path) - -class GetAllDevicesTestCase(unittest.TestCase): - def setUp(self): - self.devices = parted.getAllDevices() - - def runTest(self): - # Check self.devices and see that it's a list - self.assertEqual(type(self.devices).__name__, 'list') - - # And make sure each element of the list is a parted.Device - map(lambda s: self.assertIsInstance(s, parted.Device), self.devices) - -@unittest.skip("Unimplemented test case.") -class ProbeForSpecificFileSystemTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class ProbeFileSystemTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -class FreshDiskTestCase(RequiresDevice): - def runTest(self): - # Make sure we get SyntaxError when using an invalid disk type - self.assertRaises(KeyError, parted.freshDisk, self.device, 'cheese') - self.assertRaises(KeyError, parted.freshDisk, self.device, 'crackers') - - # Create a new disk for each disk type key, verify each one - # XXX: Skip over dvh for now (SGI disk label), which doesn't seem to have - # working libparted support. If anyone with an SGI cares, patches welcome. - for key in parted.diskType.keys(): - if key in ['dvh', 'aix']: - continue - disk = parted.freshDisk(self.device, key) - self.assertIsInstance(disk, parted.Disk) - self.assertEqual(disk.type, key) - - # Create a new disk each disk type value, verify each one - for value in parted.diskType.values(): - if value.name in ['dvh', 'aix']: - continue - disk = parted.freshDisk(self.device, value) - self.assertIsInstance(disk, parted.Disk) - self.assertEqual(parted.diskType[disk.type], value) - -@unittest.skip("Unimplemented test case.") -class IsAlignToCylindersTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class ToggleAlignToCylindersTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -class VersionTestCase(unittest.TestCase): - def runTest(self): - ver = parted.version() - self.assertEqual(ver['libparted'], _ped.libparted_version()) - self.assertEqual(ver['pyparted'], _ped.pyparted_version()) - -# And then a suite to hold all the test cases for this module. -def suite(): - suite = unittest.TestSuite() - suite.addTest(FormatBytesTestCase()) - suite.addTest(BytesToSectorsTestCase()) - suite.addTest(GetLabelsTestCase()) - suite.addTest(GetDeviceTestCase()) - suite.addTest(GetAllDevicesTestCase()) - suite.addTest(ProbeForSpecificFileSystemTestCase()) - suite.addTest(ProbeFileSystemTestCase()) - suite.addTest(FreshDiskTestCase()) - suite.addTest(IsAlignToCylindersTestCase()) - suite.addTest(ToggleAlignToCylindersTestCase()) - suite.addTest(VersionTestCase()) - return suite - -s = suite() -if __name__ == "__main__": - unittest.main(defaultTest='s', verbosity=2) diff --git a/tests/test_parted_partition.py b/tests/test_parted_partition.py deleted file mode 100755 index 5452a93..0000000 --- a/tests/test_parted_partition.py +++ /dev/null @@ -1,150 +0,0 @@ -# -# Test cases for the methods in the parted.partition module itself -# -# Copyright (C) 2009-2011 Red Hat, Inc. -# -# This copyrighted material is made available to anyone wishing to use, -# modify, copy, or redistribute it subject to the terms and conditions of -# the GNU General Public License v.2, or (at your option) any later version. -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY expressed or implied, including the implied warranties of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. You should have received a copy of the -# GNU General Public License along with this program; if not, write to the -# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the -# source code or documentation are not subject to the GNU General Public -# License and may only be used or replicated with the express permission of -# Red Hat, Inc. -# -# Red Hat Author(s): David Cantrell -# - -import parted -import unittest - -from tests.baseclass import * - -# One class per method, multiple tests per class. For these simple methods, -# that seems like good organization. More complicated methods may require -# multiple classes and their own test suite. -@unittest.skip("Unimplemented test case.") -class PartitionNewTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class PartitionGetSetTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class PartitionGetFlagTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class PartitionSetFlagTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class PartitionUnsetFlagTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class PartitionGetMaxGeometryTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class PartitionIsFlagAvailableTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class PartitionNextPartitionTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class PartitionGetSizeTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -class PartitionGetLengthTestCase(RequiresDisk): - def runTest(self): - length = 100 - geom = parted.Geometry(self.device, start=100, length=length) - part = parted.Partition(self.disk, parted.PARTITION_NORMAL, geometry=geom) - constraint = parted.Constraint(exactGeom=geom) - self.disk.addPartition(part, constraint) - self.disk.commit() - part = self.disk.partitions[0] - - self.assertEqual(part.getLength(), part.geometry.length) - self.assertEqual(part.getLength(), length) - -@unittest.skip("Unimplemented test case.") -class PartitionGetFlagsAsStringTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class PartitionGetMaxAvailableSizeTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class PartitionGetDeviceNodeNameTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class PartitionGetPedPartitionTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -@unittest.skip("Unimplemented test case.") -class PartitionStrTestCase(unittest.TestCase): - def runTest(self): - # TODO - self.fail("Unimplemented test case.") - -# And then a suite to hold all the test cases for this module. -def suite(): - suite = unittest.TestSuite() - suite.addTest(PartitionNewTestCase()) - suite.addTest(PartitionGetSetTestCase()) - suite.addTest(PartitionGetFlagTestCase()) - suite.addTest(PartitionSetFlagTestCase()) - suite.addTest(PartitionUnsetFlagTestCase()) - suite.addTest(PartitionGetMaxGeometryTestCase()) - suite.addTest(PartitionIsFlagAvailableTestCase()) - suite.addTest(PartitionNextPartitionTestCase()) - suite.addTest(PartitionGetSizeTestCase()) - suite.addTest(PartitionGetLengthTestCase()) - suite.addTest(PartitionGetFlagsAsStringTestCase()) - suite.addTest(PartitionGetMaxAvailableSizeTestCase()) - suite.addTest(PartitionGetDeviceNodeNameTestCase()) - suite.addTest(PartitionGetPedPartitionTestCase()) - suite.addTest(PartitionStrTestCase()) - return suite - -s = suite() -if __name__ == "__main__": - unittest.main(defaultTest='s', verbosity=2)