| 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | # Copyright (c) 2021-2022, The Monero Project |
| 4 | |
| 5 | # |
| 6 | # All rights reserved. |
| 7 | # |
| 8 | # Redistribution and use in source and binary forms, with or without modification, are |
| 9 | # permitted provided that the following conditions are met: |
| 10 | # |
| 11 | # 1. Redistributions of source code must retain the above copyright notice, this list of |
| 12 | # conditions and the following disclaimer. |
| 13 | # |
| 14 | # 2. Redistributions in binary form must reproduce the above copyright notice, this list |
| 15 | # of conditions and the following disclaimer in the documentation and/or other |
| 16 | # materials provided with the distribution. |
| 17 | # |
| 18 | # 3. Neither the name of the copyright holder nor the names of its contributors may be |
| 19 | # used to endorse or promote products derived from this software without specific |
| 20 | # prior written permission. |
| 21 | # |
| 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY |
| 23 | # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 24 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL |
| 25 | # THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 26 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 27 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 29 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF |
| 30 | # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | |
| 32 | """ |
| 33 | Help determine how much CPU power is available at the given time |
| 34 | by running numerical calculations |
| 35 | """ |
| 36 | |
| 37 | from __future__ import print_function |
| 38 | import subprocess |
| 39 | import psutil |
| 40 | import os |
| 41 | import errno |
| 42 | |
| 43 | def available_ram_gb(): |
| 44 | ram_bytes = psutil.virtual_memory().available |
| 45 | kilo = 1024.0 |
| 46 | ram_gb = ram_bytes / kilo**3 |
| 47 | return ram_gb |
| 48 | |
| 49 | def get_time_pi_seconds(cores, app_dir='.'): |
| 50 | app_path = '{}/cpu_power_test'.format(app_dir) |
| 51 | time_calc = subprocess.check_output([app_path, str(cores)]) |
| 52 | decoded = time_calc.decode('utf-8') |
| 53 | miliseconds = int(decoded) |
| 54 | |
| 55 | return miliseconds / 1000.0 |
| 56 | |
| 57 | def remove_file(name): |
| 58 | WALLET_DIRECTORY = os.environ['WALLET_DIRECTORY'] |
| 59 | assert WALLET_DIRECTORY != '' |
| 60 | try: |
| 61 | os.unlink(WALLET_DIRECTORY + '/' + name) |
| 62 | except OSError as e: |
| 63 | if e.errno != errno.ENOENT: |
| 64 | raise |
| 65 | |
| 66 | def get_file_path(name): |
| 67 | WALLET_DIRECTORY = os.environ['WALLET_DIRECTORY'] |
| 68 | assert WALLET_DIRECTORY != '' |
| 69 | return WALLET_DIRECTORY + '/' + name |
| 70 | |
| 71 | def remove_wallet_files(name): |
| 72 | for suffix in ['', '.keys', '.background', '.background.keys', '.address.txt']: |
| 73 | remove_file(name + suffix) |
| 74 | |
| 75 | def file_exists(name): |
| 76 | WALLET_DIRECTORY = os.environ['WALLET_DIRECTORY'] |
| 77 | assert WALLET_DIRECTORY != '' |
| 78 | return os.path.isfile(WALLET_DIRECTORY + '/' + name) |