def play_file(filename: str) -> int: """Outputs console error code, if any, as int""" from os import name as os_name if os_name == 'nt': # Windows NT from winsound import PlaySound, SND_FILENAME PlaySound(filename, SND_FILENAME) return 0 if os_name == 'posix': # Linux OR Mac... probably from os import system from platform import system as get_os_name if get_os_name() == 'Linux': return system(f'aplay {filename}') if get_os_name() == 'Darwin': # Mac return system(f'afplay {filename}') if get_os_name() == 'Haiku': return system(f'media_client play {filename}') if get_os_name()[-3:] == 'BSD': for command in 'vlc aplay cmus moc mpv mplayer mplayer2'.split(): if not system(f'{command} {filename}'): return 0 else: return 32512 elif os_name == 'os2': return system(f'fmgplay {filename}') # unknown OS, try to use pygame import pygame # unfortunately no 32-bit support # play audio file with pygame pygame.mixer.init() pygame.mixer.music.load(filename) pygame.mixer.music.play() pygame.quit() return 0
async def start_automatic(self, scan_filter: GatewayScanFilter): """Start GatewayScanner and connect to the found device.""" gatewayscanner = GatewayScanner(self.xknx, scan_filter=scan_filter) gateways = await gatewayscanner.scan() if not gateways: raise XKNXException("No Gateways found") gateway = gateways[0] if gateway.supports_tunnelling: await self.start_tunnelling(gateway.local_ip, gateway.ip_addr, gateway.port) elif gateway.supports_routing: bind_to_multicast_addr = get_os_name() != "Darwin" # = Mac OS await self.start_routing(gateway.local_ip, bind_to_multicast_addr)
async def start_automatic(self, scan_filter: GatewayScanFilter): """Start GatewayScanner and connect to the found device.""" gatewayscanner = GatewayScanner(self.xknx, scan_filter=scan_filter) gateways = await gatewayscanner.scan() if not gateways: raise XKNXException("No Gateways found") gateway = gateways[0] if gateway.supports_tunnelling and \ scan_filter.routing is not True: await self.start_tunnelling(gateway.local_ip, gateway.ip_addr, gateway.port, self.connection_config.auto_reconnect, self.connection_config.auto_reconnect_wait) elif gateway.supports_routing: bind_to_multicast_addr = get_os_name() != "Darwin" # = Mac OS await self.start_routing(gateway.local_ip, bind_to_multicast_addr)
def calculate_jvm_xmx(): """ Calculate JVM heap size for ltm.jar execution. """ os_name = get_os_name() if os_name == 'Linux': res = subprocess.run(['free', '-g'], stdout=subprocess.PIPE) res = res.stdout.decode('utf-8') size_gb = int(res.split('Mem:')[1].split()[0]) # Darwin represents macOS here. elif os_name == 'Darwin': res = subprocess.run(['sysctl', 'hw.memsize'], stdout=subprocess.PIPE) res = res.stdout.decode('utf-8') size_gb = int(res.split(': ')[1]) // (2**30) # Other platforms, e.g., Windows. else: size_gb = 8 # no optimization for other platforms yet. return size_gb - 2
(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, see <http://www.gnu.org/licenses/>. """ from platform import system as get_os_name from setuptools import Extension, find_packages, setup from setuptools.command.build_ext import build_ext as _build_ext # Configure the compiler based on the OS if get_os_name().lower() == "darwin": os_compile_flags = ["-mmacosx-version-min=10.9"] else: os_compile_flags = [] # Required for the automatic installation of numpy class build_ext(_build_ext): def finalize_options(self): _build_ext.finalize_options(self) # Prevent numpy from thinking it is still in its setup process: __builtins__.__NUMPY_SETUP__ = False import numpy self.include_dirs.append(numpy.get_include()) solver_module = Extension('mmit.core.solver', language="c++",