def main(): from sys import platform grains = {} grains.update(_user()) grains.update(_shell()) grains.update(_home()) if platform.lower() == 'darwin': grains.update(_pythons()) grains.update(_programs("cmake")) grains.update(_programs("git")) grains.update(_programs("pcre", "pcregrep")) grains.update(_mac_version()) grains.update(_gccs()) elif platform.lower() == 'linux2': pythons = {'[email protected]': '/usr/', '[email protected]': '/usr'} grains.update({'[email protected]': '/usr/', '[email protected]': '/usr'}) grains.update({'pythons': pythons}) grains.update({'gits': {'[email protected]': '/usr/'}}) grains.update({ 'gccs': { '[email protected]': { 'cc': '/usr/bin/gcc-5', 'cxx': '/usr/bin/g++-5' } } }) grains.update({"mac_version": "Linux"}) return grains
def calculate_version(): from sys import platform on_windows = ('win' in platform.lower() and not 'darwin' in platform.lower()) use_shell = not on_windows try: git_revision = subprocess.check_output("""git show -s --format="%ci %h" HEAD""", shell=use_shell).decode('ascii').rstrip() date, time, utc_offset, short_hash = git_revision.split(' ') date = date.replace('-', '.').strip() # make date an acceptable version string short_hash = short_hash.strip() # remove newline and any other whitespace short_hash = int(short_hash, 16) # So that it's a valid PEP 440 version identifier dirty = bool(subprocess.call("git diff-files --quiet --", shell=use_shell)) dirty = dirty or bool(subprocess.call("git diff-index --cached --quiet HEAD --", shell=use_shell)) version = '{0}.dev{1}'.format(date, short_hash) if dirty: version += '+dirty' exec('putative__version__ = "{0}"'.format(version)) # see if this will raise an error for some reason except Exception as e: # If any of the above failed for any reason whatsoever, fall back on this dumb version, unless we're on a CI from os import getenv print('\nThe `calculate_version` function failed to get the git version.') print('Maybe your version of python (<2.7?) is too old. Here\'s the exception:') print(e) if getenv('CI') is not None: if getenv('CI').lower() == 'true': print('Raising exception because environment variable `CI` is "{0}"'.format(getenv('CI'))) raise e print('This should not be a problem, unless you need an accurate version number.') print('Continuing on, in spite of it all...\n') from datetime import datetime date = datetime.now().isoformat().split('T')[0] date = date.replace('-', '.').strip() version = '0.0.0.dev' + date return version
def can_handle_current_platform(self): """Returns true if this platform object can handle the server this process is running on. @return: True if this platform instance can handle the current server. @rtype: bool """ return _platform.lower().startswith('linux')
def __init__(self): self.db = ["database", "OS", "encoders", "inject"] self.ret = [] #self.magic = os.sep.join((os.getcwd()).split(os.sep)[:len((os.getcwd()).split(os.sep))-1]) self.magic = os.getcwd()+os.sep+"shell" if 'win' not in platform.lower(): self.magic = '/usr/share/shellsploit/'+os.sep
def __init__(self): self.db = ["database", "OS", "encoders", "inject"] self.ret = [] self.magic = getcwd()+sep+"shell" if 'win' not in platform.lower(): self.magic = '/usr/share/shellsploit/'+sep self.ignore = ["BFDBackdoors", "pyminifier", "__pycache__"] self.decide = False
def detectOS(): from sys import platform if architectureDetect() == 32: if platform.lower() == "linux" or platform == "linux2": return "linux86" #elif platform.lower() == "darwin": #print "mac osx" elif platform.lower() == "win32": return "windows" elif platform.lower() == "sunos": return "solarisx86" elif "freebsd" in platform.lower(): return "freebsdx86" elif "openbsd" in platform.lower(): return "openbsdx86" #I will fix it soon :( elif architectureDetect() == 64: if "freebsd" in platform.lower(): return "freebsdx64" elif "win32" in platform.lower(): return "windows" else: #This is can be possible ? .. print ("Not supported architecture ..")
def getMayaPy(*keywords): version='' shortNames=\ { 'v':'version' } for k in keywords: if k in locals(): exec(k+'=keywords[k]') elif k in shortNames: exec(shortNames[k]+'=keywords[k]') mayaNative=False for m in modules: if type(modules[m]).__name__=='module' and modules[m].__name__.lower()=='maya': _mayaNative=True if not mayaNative: mayaAppDirs={} mayaBinDirs={} mayaPyDirs={} versionRE=re.compile('[Mm]aya[0-9\.]*[0-9\.]') #for pyDir in findFile('maya/__init__.py',sp='[Mm]aya[0-9\.]*[0-9\.]',a=True) if len(mayaPyDirs)>0: if version=='': version=v sys.path.append(os.path.dirname(mayaPyDirs[version])) os.environ['MAYA_LOCATION']=mayaPyDirs[version] if 'linux' in platform.lower(): if 'LD_LIBRARY_PATH' in os.environ: if platform[:3].lower()=='win': os.environ['LD_LIBRARY_PATH']+=';' else: os.environ['LD_LIBRARY_PATH']+=':' else: os.environ['LD_LIBRARY_PATH']='' os.environ['LD_LIBRARY_PATH']+=os.path.dirname(sys.path[-1]) import maya.standalone maya.standalone.initialize()
def update_remote_file(self): print '********** update_remote_file ************' content_iter = self.read_file_contents() ack = stub.update_file(content_iter, _TIMEOUT_SECONDS) if ack.file_path != self.path or ack.num_bytes != os.stat(self.transaction_path).st_size: print '********** File Update Error ************' raise OSError("File Update Error") else: # Setting the mtime in client to reflect the server # This avoid a fetch call after every update print '********** File Update mtime form server ************ %s' % ack.server_mtime.mtime os.utime(self.transaction_path, (os.stat(self.transaction_path).st_atime, ack.server_mtime.mtime)) self.fsync('linux' in _platform.lower()) os.rename(self.transaction_path, self.cache_path)
def get_token(self, url): token = '' path = os.getcwd() if _platform == "Windows" or _platform == "win32": # Check if we are on 32 or 64 bit file_name= 'chromedriver.exe' if _platform.lower() == "darwin": file_name= 'chromedriver' if _platform.lower() == "linux" or _platform.lower() == "linux2": file_name = 'chromedriver' full_path = '' if os.path.isfile(path + '/' + file_name): # check local dir first full_path = path + '/' + file_name if full_path == '': self.bot.logger.error(file_name + ' is needed for manual captcha solving! Please place it in the bots root directory') sys.exit(1) try: driver = webdriver.Chrome(full_path) driver.set_window_size(600, 600) except Exception: self.bot.logger.error('Error with Chromedriver, please ensure it is the latest version.') sys.exit(1) driver.get(url) elem = driver.find_element_by_class_name("g-recaptcha") driver.execute_script("arguments[0].scrollIntoView(true);", elem) self.bot.logger.info('You have 1 min to solve the Captcha') try: WebDriverWait(driver, 60).until(EC.text_to_be_present_in_element_value((By.NAME, "g-recaptcha-response"), "")) token = driver.execute_script("return grecaptcha.getResponse()") driver.close() except TimeoutException, err: self.bot.logger.error('Timed out while trying to solve captcha')
def __init__(self): self.db = ["database", "OS", "encoders", "inject"] self.ret = [] if 'win' in platform.lower(): for root, dirs, files in walk(exec_prefix+"\\Lib\\site-packages\\", topdown=True): for x in dirs: if x.startswith("cmdline_shellsploit"): self.magic = exec_prefix+"\\Lib\\site-packages\\"+x+sep+"shell" self.control = True break if self.control == True: break else: self.magic = '/usr/share/shellsploit/'+sep self.ignore = ["BFDBackdoors", "pyminifier", "__pycache__"] self.decide = False
def darwin_call(*args, **kwargs): if platform.lower() != "darwin": raise OSError("Function %s only works on macOS." % (call)) return call(*args, **kwargs)
def __init__(self): self.db = ["database", "OS", "encoders", "inject"] self.ret = [] self.magic = os.getcwd() + os.sep + "shell" if 'win' not in platform.lower(): self.magic = '/usr/share/shellsploit/' + os.sep
''' from setuptools import setup, find_packages from setuptools.command.install import install from distutils.extension import Extension from Cython.Distutils import build_ext from Cython.Build import cythonize from glob import glob import numpy as np from os import name as os_name from sys import argv, platform from mazelib import __version__ # CONSTANTS FORCE_FLAGS = ['-f', '--f', '--force'] FORCE_REBUILD = True if any([f in argv for f in FORCE_FLAGS]) else False IS_WINDOWS = True if (os_name.lower() == 'nt' or 'win' in platform.lower()) else False COMP_DIRS = {'language_level': 3, 'boundscheck': False, 'initializedcheck': False, 'cdivision': True} # find all the extension modules in the project sep = '\\' if IS_WINDOWS else '/' ext_modules = [Extension(p[:-4].replace(sep, '.'), [p, p[:-2] + 'y'], include_dirs=[np.get_include(), '.']) for p in glob(sep.join(['mazelib', '*', '*.pxd']))] # perform the actual build/install setup( cmdclass={ 'install': install, 'build_ext': build_ext, }, name='mazelib',
''' Created on Jun 13, 2018 Modified on June 24, 2018 for separate images Modified on Oct 11, 2019 to remove garbage added (but not logged) by KS @author: pmackenz ''' import numpy as np from sys import platform import matplotlib if "win" in platform.lower(): matplotlib.use('TkAgg') else: matplotlib.use('Agg') import matplotlib.pyplot as plt import matplotlib.cm as cm import matplotlib.colors as colors import os from Mappings import Mappings # global settings RESULTS = "../" class Plotter(object): ''' variables: self.particlesPresent # boolean
# Needed to build Cython from distutils.core import setup from Cython.Build import cythonize # Change to newest gcc on Darwin import os from sys import platform if platform.lower() == 'darwin': os.environ['CC'] = 'gcc-5' # Do the build setup(ext_modules=cythonize('auxC.pyx')) setup(ext_modules=cythonize('mainC.pyx'))
https://docs.djangoproject.com/en/3.0/ref/settings/ """ from sys import platform import os try: import configparser except: from six.moves import configparser # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) path1=os.path.expanduser("~") linux_user1="" if "linux" in platform.lower(): linux_user1=os.popen('whoami').read().rstrip() if linux_user1.lower() == "root": path1="/var/www" config_file = os.path.join(path1, '.case320k') config = configparser.ConfigParser() config.read(config_file) config=config._sections SECRET_KEY=config['settings']['secret_key'] STRIPE_SECRET_KEY =config['stripe']['stripe_secret_key'] STRIPE_PUBLISHABLE_KEY =config['stripe']['stripe_publishable_key'] #SECRET_KEY = os.environ['SECRET_KEY'] # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
def __init__(self, parent, id, title): self.progress = None # Current progress dialog (or None) self.logname = None wx.Frame.__init__(self,parent,id,title) if platform=='win32': self.SetIcon(wx.Icon(executable, wx.BITMAP_TYPE_ICO)) elif platform.lower().startswith('linux'): # PNG supported by GTK icons=wx.IconBundle() icons.AddIconFromFile('Resources/%s.png' % appname, wx.BITMAP_TYPE_PNG) icons.AddIconFromFile('Resources/%s-128.png'% appname, wx.BITMAP_TYPE_PNG) self.SetIcons(icons) elif platform=='darwin': # icon pulled from Resources via Info.plist (except for MessageBox icon). Need minimal menu menubar = wx.MenuBar() helpmenu = wx.Menu() helpmenu.Append(wx.ID_HELP, '%s Help\tCtrl-?' % appname) wx.EVT_MENU(self, wx.ID_HELP, self.onHelp) helpmenu.Append(wx.ID_ABOUT, 'About %s' % appname) wx.EVT_MENU(self, wx.ID_ABOUT, self.onAbout) # ID_EXIT moved to application menu helpmenu.Append(wx.ID_EXIT, u'Quit %s\tCtrl-Q' % appname) wx.EVT_MENU(self, wx.ID_EXIT, self.onClose) menubar.Append(helpmenu, '&Help') self.SetMenuBar(menubar) panel0 = wx.Panel(self,-1) panel1 = wx.Panel(panel0,-1) panel2 = wx.Panel(panel0,-1) panel3 = wx.Panel(panel0,-1) # 1st panel self.fspath=wx.TextCtrl(panel1, -1, fspath) self.fsbrowse=wx.Button(panel1, FSBROWSE, browse) self.lbpath=wx.TextCtrl(panel1, -1, lbpath) self.lbbrowse=wx.Button(panel1, LBBROWSE, browse) self.xppath=wx.TextCtrl(panel1, -1, xppath) self.xpbrowse=wx.Button(panel1, XPBROWSE, browse) grid1 = wx.FlexGridSizer(3, 3, 7, 7) grid1.AddGrowableCol(1,proportion=1) grid1.SetFlexibleDirection(wx.HORIZONTAL) grid1.Add(wx.StaticText(panel1, -1, "MSFS scenery location: "), 0, wx.ALIGN_CENTER_VERTICAL) grid1.Add(self.fspath, 1, wx.ALIGN_CENTER_VERTICAL|wx.ALL|wx.EXPAND, pad) grid1.Add(self.fsbrowse, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, pad) grid1.Add(wx.StaticText(panel1, -1, "Additional MSFS libraries: "), 0, wx.ALIGN_CENTER_VERTICAL) grid1.Add(self.lbpath, 1, wx.ALIGN_CENTER_VERTICAL|wx.ALL|wx.EXPAND, pad) grid1.Add(self.lbbrowse, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, pad) grid1.Add(wx.StaticText(panel1, -1, "X-Plane scenery location: "), 0, wx.ALIGN_CENTER_VERTICAL) grid1.Add(self.xppath, 1, wx.ALIGN_CENTER_VERTICAL|wx.ALL|wx.EXPAND, pad) grid1.Add(self.xpbrowse, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, pad) panel1.SetSizer(grid1) wx.EVT_BUTTON(self, FSBROWSE, self.onFSbrowse) wx.EVT_BUTTON(self, LBBROWSE, self.onLBbrowse) wx.EVT_BUTTON(self, XPBROWSE, self.onXPbrowse) # 2nd panel self.xpver = wx.RadioBox(panel2,-1, "Minimum X-Plane version:", choices=["v8", "v9", "v10"]) self.xpver.SetSelection(2) # v10 default self.season = wx.RadioBox(panel2,-1, "Season:", choices=["Spring", "Summer", "Autumn", "Winter"]) self.dumplib= wx.CheckBox(panel2,-1, "Just extract library objects") # use panel and sizer so tab order works normally box2 = wx.BoxSizer(wx.HORIZONTAL) box2.Add(self.xpver, 0) box2.Add(self.season, 0, wx.LEFT, 10) box2.Add([0,0], 1, wx.LEFT, 10) # push following buttons to right box2.Add(self.dumplib, 0, wx.TOP|wx.EXPAND, 8) panel2.SetSizer(box2) wx.EVT_CHECKBOX(self, self.dumplib.GetId(), self.onDump) # 3rd panel - adjust order of buttons per Windows or Mac conventions if platform=='darwin': button31=wx.Button(panel3, wx.ID_EXIT) button32=wx.Button(panel3, wx.ID_APPLY, "Convert") button33=wx.Button(panel3, wx.ID_HELP) box3 = wx.BoxSizer(wx.HORIZONTAL) box3.Add([24,0], 0) # cosmetic - balance button31 box3.Add([0,0], 1) # push following buttons to right box3.Add(button31, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, pad) box3.Add([6,0], 0) # cosmetic box3.Add(button32, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, pad) box3.Add([0,0], 1) # push following buttons to right box3.Add(button33, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, pad) button32.SetDefault() else: button31=wx.Button(panel3, wx.ID_HELP) if platform=='win32': button32=wx.Button(panel3, wx.ID_EXIT) else: button32=wx.Button(panel3, wx.ID_CLOSE) button33=wx.Button(panel3, wx.ID_APPLY, "Convert") box3 = wx.BoxSizer(wx.HORIZONTAL) box3.Add(button31, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, pad) box3.Add([0,0], 1) # push following buttons to right box3.Add(button32, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, pad) box3.Add([6,0], 0) # cosmetic box3.Add(button33, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, pad) button33.SetDefault() panel3.SetSizer(box3) wx.EVT_BUTTON(self, wx.ID_HELP, self.onHelp) wx.EVT_BUTTON(self, wx.ID_APPLY, self.onConvert) wx.EVT_BUTTON(self, wx.ID_CLOSE, self.onClose) wx.EVT_BUTTON(self, wx.ID_EXIT, self.onClose) # Top level box0 = wx.BoxSizer(wx.VERTICAL) box0.Add(panel1, 0, wx.ALL|wx.EXPAND, 7) box0.Add(panel2, 0, wx.ALL|wx.EXPAND, 7) box0.Add(panel3, 0, wx.ALL|wx.EXPAND, 7) panel0.SetSizer(box0) border = wx.BoxSizer() border.Add(panel0, 1, wx.EXPAND) self.SetSizer(border) # Go sz=self.GetBestSize() if wx.VERSION<(2,6): # Hack - Can't get min size to work properly in 2.5 height=sz.height+42 else: height=sz.height self.SetSize((800, height)) # +50 is a hack cos I can't work out how to change minsize of TextCtrl self.SetSizeHints(sz.width, height, -1, height) self.Show(True) if platform=='darwin': # Change name on application menu. Can't do this in wx. try: # Carbon from Carbon import Menu Menu.GetMenuHandle(1).SetMenuTitleWithCFString(appname) # wxMac always uses id 1. except: try: # Cocoa import AppKit # doesn't work: AppKit.NSApp.mainMenu().itemAtIndex_(0).submenu().setTitle_(appname) http://www.mail-archive.com/[email protected]/msg43196.html AppKit.NSBundle.mainBundle().infoDictionary()['CFBundleName']=appname except: if __debug__: print_exc() if newfsroot: myMessageBox('Install MSFS sceneries under: \n%s ' % newfsroot, 'Created a fake MSFS installation.', wx.ICON_INFORMATION|wx.OK, self)
def clear_screen(): system("cls") if "win" in platform.lower() else system("clear")
def create_web_files( catalog_root_directory='.', relative_directory_path=None, public_json_directory='web/public', public_file_listings_directory='web/public_file_listings', public_links_directory='web/links', private_json_directory='web/private', public_directory_patterns=[r'Catalog'], excluded_directory_patterns=[r'^\.', r'^Attic', r'.*Links$'], public_altname_patterns=[r"""^SXS:""", r"""^BHNS:""", r"""^NSNS:"""], private_altname_patterns=[ r"""^SXS:""", r"""^BHNS:""", r"""^NSNS:""", r"""^PRIVATE:""", r""".+""" ]): """Function to create the files needed by the website's catalog pages 1) Create a directory symlinking public runs to data files 2) Generate JSON for public runs 3) Generate JSON for private runs 4) Generate JSON describing metadata fields This function totally ignores hidden files, the `Attic` directory, and any directory ending in `Links`. Only directories found within top-level directories matching any of the regexes given in `public_directory_patterns` will be put into the public dataset; all others will be put into the private dataset. """ import os from sys import platform import subprocess import math import re import collections import json from . import (read_catalog, drop_all_but_highest_levs, key_by_alternative_name, symlink_runs, metadata_fields, _mkdir_recursively) if relative_directory_path is None: relative_directory_path = os.path.join('..', '..') # Compile regex patterns and create functions for matching the various inputs public_directory_patterns = [ re.compile(pattern) for pattern in public_directory_patterns ] def is_public(directory): for pattern in public_directory_patterns: if pattern.match(directory): return True return False excluded_directory_patterns = [ re.compile(pattern) for pattern in excluded_directory_patterns ] def exclude(directory): for pattern in excluded_directory_patterns: if pattern.match(directory): return True return False public_altname_patterns = [ re.compile(pattern) for pattern in public_altname_patterns ] def first_public_match(names): for pattern in public_altname_patterns: for name in names: if pattern.match(name): return name return '' private_altname_patterns = [ re.compile(pattern) for pattern in private_altname_patterns ] def first_private_match(names): for pattern in private_altname_patterns: for name in names: if pattern.match(name): return name return '' # Figure out which directories are public and which are private catalog_root_directory = os.path.expanduser(catalog_root_directory) public_dirs = [ os.path.normpath(os.path.join(catalog_root_directory, d)) for d in os.listdir(catalog_root_directory) if os.path.isdir(os.path.join(catalog_root_directory, d)) and is_public(d) and not exclude(d) ] private_dirs = [ os.path.normpath(os.path.join(catalog_root_directory, d)) for d in os.listdir(catalog_root_directory) if os.path.isdir(os.path.join(catalog_root_directory, d)) and not is_public(d) and not exclude(d) ] # Assemble the public parts of the catalog, symlinking for each directory, and getting the catalogs public_catalog = collections.OrderedDict() for directory in public_dirs: replacement = os.path.join( relative_directory_path, os.path.relpath(directory, catalog_root_directory)) sub_catalog = symlink_runs( source_directory=directory, target_directory=public_links_directory, remove_old_target_dir=False, alternative_name_patterns=public_altname_patterns, exclude_patterns=excluded_directory_patterns, use_relative_links=True, relative_directory_path=replacement, verbosity=1) public_catalog.update(sub_catalog) # Get the private catalogs private_catalog = collections.OrderedDict() for directory in private_dirs: sub_catalog = read_catalog( directory, ignore_invalid_lines=True, suppress_errors=True, exclude_patterns=excluded_directory_patterns) sub_catalog = drop_all_but_highest_levs(sub_catalog) sub_catalog = key_by_alternative_name( sub_catalog, alternative_name_patterns=private_altname_patterns, allow_ugly_keys=True) private_catalog.update(sub_catalog) # Rearrange the catalogs to be lists of OrderedDicts for JSON def modify_metadata(key, metadata): """Add 'name', 'object_types', and '*_mass_ratio' fields, and expand three-vectors to four separate fields""" m = [('name', key)] for k in metadata: v = metadata[k] if isinstance( v, list) and len(v) == 3 and (isinstance(v[0], float) and isinstance(v[1], float) and isinstance(v[2], float)): m += [(k + '_mag', math.sqrt(v[0]**2 + v[1]**2 + v[2]**2)), (k + '_x', v[0]), (k + '_y', v[1]), (k + '_z', v[2])] else: if k == 'object1': # Insert combined type first if 'object2' in metadata: m += [('object_types', ''.join( sorted([ metadata[k].upper(), metadata['object2'].upper() ])))] if k == 'initial_mass1': # Insert mass ratio first if 'initial_mass2' in metadata: try: m += [('initial_mass_ratio', metadata[k] / metadata['initial_mass2'])] except: pass if k == 'reference_mass1': # Insert mass ratio first if 'reference_mass2' in metadata: try: m += [('reference_mass_ratio', metadata[k] / metadata['reference_mass2'])] except: pass m += [(k, v)] return collections.OrderedDict(m) public_catalog = [ modify_metadata(key, metadata) for key in public_catalog for metadata in [public_catalog[key]] ] private_catalog = [ modify_metadata(key, metadata) for key in private_catalog for metadata in [private_catalog[key]] ] # public_catalog = [collections.OrderedDict([('name', key)] + [(k, val[k]) for k in val]) # for key in public_catalog for val in [public_catalog[key]]] # private_catalog = [collections.OrderedDict([('name', key)] + [(k, val[k]) for k in val]) # for key in private_catalog for val in [private_catalog[key]]] # Get date of last git change try: on_windows = ('win' in platform.lower() and not 'darwin' in platform.lower()) use_shell = not on_windows git_revision = subprocess.check_output( """git show -s --format="%ci" HEAD""", cwd=catalog_root_directory, shell=use_shell).decode('ascii').rstrip() date, time, utc_offset = git_revision.split(' ') last_changed = date + ' ' + time except Exception as e: last_changed = '' # Make sure the directories we want are present _mkdir_recursively(public_json_directory) _mkdir_recursively(private_json_directory) # Finally, output the JSON files with open(os.path.join(public_json_directory, 'catalog_info.json'), 'w') as f: catalog_info = { 'title': 'SXS Gravitational Waveform Database', 'subtitle': 'Completed Simulations', 'documentation': True, 'news': True, 'last_changed': last_changed, 'fields': metadata_fields } json.dump(catalog_info, f, indent=4) with open(os.path.join(public_json_directory, 'catalog.json'), 'w') as f: json.dump(public_catalog, f, indent=4) write_file_listings(public_catalog, public_file_listings_directory, public_links_directory) with open(os.path.join(private_json_directory, 'catalog.json'), 'w') as f: json.dump(private_catalog, f, indent=4)
def is_linux(self): if not platform.lower().find("linux") == 0: IS_LINUX = True
#!/usr/bin/env python # Copyright (c) 2019, Michael Boyle # See LICENSE file for details: <https://github.com/moble/quaternion/blob/master/LICENSE> from os import getenv # Construct the version number from the date and time this python version was created. from os import environ from sys import platform on_windows = "win" in platform.lower() and not "darwin" in platform.lower() if "package_version" in environ: version = environ["package_version"] print(f"Setup.py using environment version='{version}'") else: print("The variable 'package_version' was not present in the environment") try: # For cases where this is being installed from git. This gives the true version number. from subprocess import check_output if on_windows: version = check_output( """git log -1 --format=%cd --date=format:'%Y.%m.%d.%H.%M.%S'""", shell=False) version = version.decode("ascii").strip().replace(".0", ".").replace( "'", "") else: try: from subprocess import DEVNULL as devnull
def on_windows(): from sys import platform return 'win' in platform.lower() and not 'darwin' in platform.lower()
def ConvertToPython(xml=False, request=None, guiLog=False, path=None, literalPath=None, dumpXml=False, dumpToFile=False, dumpFilePath=None): print "### Please review the generated cmdlets before deployment.\n" global displayXml, outFileFlag, outFilePath, outFile displayXml = dumpXml outFileFlag = dumpToFile outFilePath = dumpFilePath if outFileFlag in _AffirmativeList: if outFilePath: print "### Script Output is in file < " + outFilePath + " >" outFile = open(outFilePath, 'w') outFile.close() #outFile = open(r"c:\work.txt", 'w+') else: print "Please profide dumpFilePath" return if xml in _AffirmativeList: if guiLog in _AffirmativeList: print "parameter <xml> takes precedence over <guiLog>" if request: GenerateCmdlets(request) elif path or literalPath: IfPathOrLiteralPath(path, literalPath, False) else: print "Please provide request" return elif guiLog in _AffirmativeList: if path or literalPath: IfPathOrLiteralPath(path, literalPath, True) else: print "Please provide path or literalPath" else: from sys import platform as _platform if _platform.lower() == "linux" or _platform.lower() == "linux2": # linux logFilePath = GetUCSDefaultLogpathLinux() elif _platform.lower() == "darwin": # OS X logFilePath = GetUCSDefaultLogpathOSX() elif _platform.lower() == "win32" or _platform.lower() == "win64": # Windows... logFilePath = GetUCSDefaultLogpathWindows() elif "cygwin" in _platform.lower(): # Cygwin logFilePath = GetUCSDefaultLogpathCygwin() else: print "[Error]: Unsupported OS:", _platform logFilePath = None return ## Get the latest logfile #logFilePath = r"C:\Users\ragupta4\AppData\LocalLow\Sun\Java\Deployment\log\.ucsm" #files = [ file for file in glob.glob(logFilePath + "\\" + "*") if os.path.isfile(file)] os.chdir(logFilePath) files = [ file for file in glob.glob("centrale_*.log") if os.path.isfile(file) ] files.sort(key=lambda x: os.path.getmtime(x), reverse=True) lastUpdatedFile = files[0] fileStream = open(lastUpdatedFile, 'r') ## read the file till the end cnt = 0 for line in fileStream: cnt += 1 ## Wait indefinitely until receive new line of set and then again wait while True: line = fileStream.readline() if line: FindXmlRequestsInFile_test(fileStream, True) time.sleep(2) fileStream.close() #if outFilePath: #outFile.close() print "### End of Convert-To-Python ###"
def hardlink(source, linkName): if not dll.CreateHardLinkW(linkName, source, None): raise OSError("code %d" % dll.GetLastError()) def symlink(source, linkName): if not dll.CreateSymbolicLinkW(linkName, source, 0): raise OSError("code %d" % dll.GetLastError()) except Exception, ex: hardlink = symlink = None print "%s: %s\nWARNING: Filesystem links will not be available.\nPlease run on UNIX or Windows Vista or later.\n" % ( ex.__class__.__name__, ex, ) isWindows = platform.lower().startswith("win") TITLE = "VimeoCrawler v1.82 (c) 2013-2015 Vasily Zakharov [email protected]" OPTION_NAMES = ("directory", "login", "max-items", "retries", "set-language", "preset", "timeout", "webdriver") FIELD_NAMES = ( "targetDirectory", "credentials", "maxItems", "retryCount", "setLanguage", "setPreset", "timeout", "driverName", ) SHORT_OPTIONS = "".join(("%c:" % option[0]) for option in OPTION_NAMES) + "hvnfzc"
def start(self, security=True): """ start the MongoDB server """ mode = self.data['MODE'] if mode == "running": return if mode == 'docker': from cloudmesh.mongo.MongoDocker import MongoDocker mongo = MongoDocker() mongo.start(auth=security) # mongo.wait() # mongo.ps() return auth = "" if security: auth = "--auth" mongo_host = self.data['MONGO_HOST'] if platform.lower() == 'win32': try: # command = 'where mongo' # proc = subprocess.Popen(command, shell=True, # stdin=subprocess.PIPE, # stdout=subprocess.PIPE) # out, err = proc.communicate() # print ("MMM", command) # print ("O", out) # print ("E", err) # if out == b'': # Console.error("mongo command not found") # sys.exit() mongo_runner = f"\"{self.mongo_home}\\bin\mongod\" {auth} " \ f"--bind_ip {mongo_host}" \ f" --dbpath \"{self.mongo_path}\" --logpath \"{self.mongo_log}\mongod.log\"" print(mongo_runner) if not os.path.isfile(f'{self.mongo_path}/invisible.vbs'): with open(f'{self.mongo_path}/invisible.vbs', 'w') as f: f.write( 'CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False' ) if not os.path.isfile(f'{self.mongo_path}/mongo_starter.bat'): with open(f'{self.mongo_path}/mongo_starter.bat', 'w') as f: f.write(mongo_runner) script = f'wscript.exe \"{self.mongo_path}/invisible.vbs\" \"{self.mongo_path}/mongo_starter.bat\"' print(script) p = subprocess.Popen(script, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) result = "mongod child process should be started successfully." except Exception as e: result = "Mongo in windows could not be started: \n\n" + str(e) else: try: script = f"mongod {auth} --bind_ip {mongo_host}" \ f" --dbpath {self.mongo_path} --logpath {self.mongo_log}/mongod.log --fork" result = Script.run(script) except Exception as e: result = "Mongo could not be started." + str(e) if "successfully" in result: print(Console.ok(result)) else: print(Console.error(result))
M2CMD_CARD_WAITREADY = 0x00004000 M2CMD_DATA_STARTDMA = 0x00010000 M2CMD_DATA_WAITDMA = 0x00020000 M2CMD_DATA_STOPDMA = 0x00040000 M2CMD_DATA_POLL = 0x00080000 SPC_M2STATUS = 110 SPC_DATA_AVAIL_USER_LEN = 200 SPC_DATA_AVAIL_USER_POS = 201 SPC_DATA_AVAIL_CARD_LEN = 202 # ====== Library binding ======== double_reg = [SPC_SAMPLERATE] # Place here the registers that hold 64 bits data new_buffer = create_string_buffer # To allow to create a buffer without ctypes if "linux" in platform.lower(): mod = cdll.LoadLibrary("libspcm_linux.so") else: mod = windll.LoadLibrary("C:\\Windows\\system32\\spcm_win64.dll") class SpectrumError(Exception): pass dwGetErrorInfo_i32 = mod.spcm_dwGetErrorInfo_i32 dwGetErrorInfo_i32.argtype = [c_void_p,POINTER(c_uint32),POINTER(c_int32),c_char_p] dwGetErrorInfo_i32.restype = c_uint32 def check(h,code): if code == 0: return print("Error: return code=",code)
def status(self): """ check the MongoDB status returns a json object with status: and pid: command """ mode = self.data['MODE'] if mode == 'docker': from cloudmesh.mongo.MongoDocker import MongoDocker mongo = MongoDocker() state = mongo.status() if platform.lower() == 'win32': script = """ tasklist /FO LIST /FI "IMAGENAME eq mongod.exe" """ output = Script.run(script) if 'INFO: No tasks are running which match the specified criteria.' in output: result = None else: result = {} for row in output.split('\n'): if ': ' in row: key, value = row.split(': ') result[key.strip()] = value.strip() if result is None: state = dotdict({ "status": "error", "message": "No mongod running", "output": None }) else: state = dotdict({ "status": "ok", "message": "running", "output": None }) process = { "pid": str(result['PID']), "command": result['Image Name'] } output = {} # # TODO: there was a bug here, please check, it was only str() # output[str(result['PID'])] = process state["output"] = output else: result = find_process("mongod") if result is None: state = dotdict({ "status": "error", "message": "No mongod running", "output": None }) output = None else: state = dotdict({ "status": "ok", "message": "running", "output": None }) output = {} for p in result: p = dotdict(p) process = {"pid": str(p.pid), "command": p.command} output[str(p.pid)] = process state["output"] = output return state
def isWindows(): return platform.lower().startswith('win')
#`zenity --file-selection --title %string% --window-icon %path% ...` # `--multiple` permits multi-selection # `--separator %string%` return separator for --multiple [Def: "|"] # # `--directory` can only select a directory # # `--save` # `--filename %basename%` initial filename to save as for `--save` # `--confirm-overwrite` confirmation popup if selection exists with `--save` # global _zenity_available _zenity_available = False if sysplatform.lower().startswith("linux"): tmp, prtz = None, None try: tmp = subprocess.check_output(['zenity', '--version'], stderr=subprocess.STDOUT, universal_newlines=True) tmp = tmp.split('\n', 1)[0].strip() if tmp.count('.') >= 1: prtz = tmp.split('.') if prtz[0].isdigit(): prtz[0] = int(prtz[0]) else: prtz[0] = None if prtz[1].isdigit(): prtz[1] = int(prtz[1]) else:
def ssh(self, vm=None, command=None): def key_selector(keys): """ This is a helper method for ssh key selection THIS IS JUST A SAFETY MEASURE, PLEASE DON'T MIND IT :param keys: :return: """ tmp_keys = keys[:] # indices = range(1,len(tmp_keys)+1) for key_idx, key in enumerate(keys): key['idx'] = key_idx + 1 print(Printer.flatwrite(tmp_keys, sort_keys=["idx"], order=['idx', 'KeyName', 'KeyFingerprint'], header=['Index', 'Key Name', "Key Fingerprint"], output="table", humanize=None) ) # Console.msg("Please select one of the AWS key indices from the table above: ") picked = 0 while picked < 1 or picked > len(keys): try: picked = int(input( "Please select one of the AWS key indices from the table above: ")) except ValueError: pass return keys[picked - 1] cm = CmDatabase() ip = vm['public_ips'] try: key_name = vm['KeyName'] keys = cm.find_all_by_name(name=key_name, kind="key") for k in keys: if 'location' in k.keys(): if 'private' in k['location'].keys(): key = k['location']['private'] break except (KeyError, IndexError): aws_keys = cm.find(kind='key', cloud='aws') if len(aws_keys) == 0: Console.error( f"Could not find a key for the AWS instance '{vm['name']}'") Console.error( f"Use `cms help key` to learn how to add and upload a key for AWS") return aws_key = key_selector(aws_keys) for sshkey in cm.find_all_by_name(name=aws_key['KeyName'], kind="key"): if "location" in sshkey.keys(): key = sshkey['location']['private'] break user = "******" # needs to be set on creation. if command is None: command = "" if user is None: location = ip else: location = user + '@' + ip cmd = "ssh " \ "-o StrictHostKeyChecking=no " \ "-o UserKnownHostsFile=/dev/null " \ f"-i {key} {location} {command}" cmd = cmd.strip() print(cmd) # VERBOSE(cmd) if command == "": if platform.lower() == 'win32': class disable_file_system_redirection: _disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection _revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection def __enter__(self): self.old_value = ctypes.c_long() self.success = self._disable( ctypes.byref(self.old_value)) def __exit__(self, type, value, traceback): if self.success: self._revert(self.old_value) with disable_file_system_redirection(): os.system(cmd) else: os.system(cmd) else: if platform.lower() == 'win32': class disable_file_system_redirection: _disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection _revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection def __enter__(self): self.old_value = ctypes.c_long() self.success = self._disable( ctypes.byref(self.old_value)) def __exit__(self, type, value, traceback): if self.success: self._revert(self.old_value) with disable_file_system_redirection(): ssh = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) else: ssh = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) result = ssh.stdout.read().decode("utf-8") if not result: error = ssh.stderr.readlines() print("ERROR: %s" % error) else: return result
def get_local_packages(): """ A function to get Packages locally from a machine - Linux or Windows""" packages = [] package_names = [] if platform.lower() == "linux" or platform.lower() == "linux2": query = '\{"name":"%{NAME}","version":"%{VERSION}","install_date":"%{installtime:date}","vendor":"%{VENDOR}"\},' command = f"rpm -qa --qf '{query}'" command = command.split() p_open = Popen(command, stdout=PIPE, stderr=PIPE, encoding="utf8") output, error = p_open.communicate() return output[:-1] if platform.lower() == "win32": import traceback import io import wmi import winreg def get_keys(h_key, s_sub_key): """ A function to read registry keys :input HKEY_LOCAL_MACHINE :input: subKeyCLSID """ with winreg.OpenKey(h_key, s_sub_key, 0, winreg.KEY_READ | winreg.KEY_WOW64_64KEY) as key: idx = 0 while True: try: yield winreg.EnumKey(key, idx) except BaseException: # No more indices break idx += 1 def get_packages(s_sub_key, packages=""): """ A function to get locally from registry """ h_key = winreg.HKEY_LOCAL_MACHINE for key_name in get_keys(h_key, s_sub_key): with winreg.OpenKey(h_key, "\\".join([s_sub_key, key_name]), 0, winreg.KEY_READ | winreg.KEY_WOW64_64KEY) as key: i = 0 temp_package = {} while True: try: name, val, key_type = winreg.EnumValue(key, i) if name == "DisplayName": temp_package['name'] = val elif name == "Publisher": temp_package['vendor'] = val elif name == "InstallDate": temp_package['install_date'] = val elif name == "DisplayVersion": temp_package['version'] = val except BaseException: break i += 1 if len(temp_package.keys()) > 1: temp_output = json.dumps(temp_package) packages += f"{temp_output}," return packages packages = get_packages( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\") packages = get_packages( "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\", packages) return packages[:-1] else: raise Exception( f"Script is meant for linux and Windows exclusivly and you are running {platform}")
I need to remove db/ external/ datasets/ and testing_ref/ Is that OK? [Y/n] """ ans = raw_input(msg) if ans and ans not in 'Yy': print 'Setup aborted.' exit() for d in old_directories: if exists(d): cmd = 'rm -rf ' + d print cmd system(cmd) # I don't know how reliable this is: mac_osx = (platform.lower() == "darwin") if mac_osx: print 'Detected mac_osx operating system -- if not, hardcode mac_osx=False in setup.py' def download_web_file(address): newfile = address.split('/')[-1] if exists(newfile): print 'download_web_file: {} already exists, delete it to re-download' return ## try with wget cmd = 'wget ' + address print cmd
def do_init(self, args, arguments): """ :: Usage: init [CLOUD] [--debug] init yaml Description: Initializes cloudmesh while using data from ~/.cloudmesh/cloudmesh.yaml. If no cloud is specified a number of local collections are created. If a cloud is specified it also uploads the information about images, flavors, vms. It also uploads the security groups defined by default to the cloud. Bug: cms init cms init On Windows you have to run the cms init command twice upon first installation """ ssh_key = path_expand("~/.ssh/id_rsa.pub") if not os.path.exists(ssh_key): Console.error(f"The ssh key {ssh_key} does not exist.") print() Console.info( "cms init is a convenient program to set up cloudmesh" " with defaukt values. Please make sure you use ssh-keygen" " to set up the keys.\n\n" " Additionally we recommend that you use. \n\n" " cms test\n\n" " to identify other issues\n") return "" config = Config() if config["cloudmesh.profile.user"] == "TBD": Console.info( "cms init is a convenient program to set up cloudmesh" " with defaukt values. Please make sure you use in your" " ~/.cloudmesh/yaml file a valid value for\n\n" " cloudmesh.profile.user\n\n" " This name is aslo used as keyname in the cloud providers\n\n" " Additionally we recommend that you use. \n\n" " cms test\n\n" " to identify other issues\n") return "" if arguments.CLOUD == "yaml": location = path_expand("~/.cloudmesh/cloudmesh.yaml") path = Path(location) if path.is_file(): print() if yn_choice( "The file ~/.cloudmesh/cloudmesh.yaml exists, do you wnat to overwrite it", default='n'): config.fetch() print() Console.ok("File cloudmesh.yaml downloaded from Github") else: print() Console.warning("Download canceled") print() else: variables = Variables() if config["cloudmesh.data.mongo.MODE"] != 'running': try: print("MongoDB stop") MongoDBController().stop() except: Console.ok("MongoDB is not running. ok") machine = platform.lower() location = path_expand(config[ f'cloudmesh.data.mongo.MONGO_DOWNLOAD.{machine}.MONGO_PATH']) try: print("deleting:", location) shutil.rmtree(location) print("MongoDB folder deleted") except Exception as e: Console.error(f"Could not delete {location}") if platform == 'win32': print(e) Console.error(f"Please try to run cms init again ... ") return "" print("MongoDB create") os.system("cms admin mongo create") os.system("cms admin mongo start") else: print("MongoDB is on \"running\" mode!") print("Dropping cloudmesh database...") cm_db = CmDatabase() cm_db.connect() cm_db.drop_database() user = config["cloudmesh.profile.user"] secgroup = "flask" print("Set key") if user == "TBD": Console.error( "the user is not set in the yaml file for cloudmesh.profile.user") sys.exit() variables["key"] = user Console.ok("Config Security Initialization") Shell.execute("cms", ["config", "secinit"]) os.system("cms key add") os.system("cms sec load") if arguments.CLOUD is not None: cloud = arguments.CLOUD variables['cloud'] = cloud os.system(f"cms key upload {user} --cloud={cloud}") os.system(f"cms flavor list --refresh") os.system(f"cms image list --refresh") os.system(f"cms vm list --refresh") os.system(f"cms sec group load {secgroup} --cloud={cloud}") os.system(f"cms set secgroup={secgroup}") if arguments.debug: variables['debug'] = True variables['timer'] = 'on' variables['trace'] = True variables['verbose'] = '10' print() print("Variables") print() for name in variables: value = variables[name] print(f" {name}={value}")
def get_local_mounts(): """ Gets the local mounts of a given windows or linux system """ output = "" if platform.lower() == "linux" or platform.lower() == "linux2": # bash output eqivalent of: # df -hP | sed ':a;N;$!ba;s/\n/;/g' | sed 's/ \{1,\}/,/g' | sed -e "s/ # /,/g" p_open = Popen(['df', '-hP'], stdout=PIPE, stderr=PIPE, encoding='utf-8') temp_output, error = p_open.communicate() for line in temp_output.split("\n"): temp_str = "" for item in line.split(" "): if item: temp_str += item + "," output += temp_str[:-1] + ";" elif platform.lower() == "win32": # Local Mounts command = [ 'C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\powershell.exe', '-ExecutionPolicy', 'Unrestricted', 'Get-WmiObject', 'Win32_Volume', '|', 'ConvertTo-Json' ] p_open = Popen(command, stdout=PIPE, stderr=PIPE, encoding='utf-8') temp_output, error = p_open.communicate() if len(error) > 0: logging.error("X-RAY Local Mount Error: {}".format(error)) else: if len(temp_output) > 0: temp_json = json.loads(temp_output) for drive in temp_json: try: used = int(drive['Capacity']) - int(drive['FreeSpace']) percent = (used / float(drive['Capacity'])) * 100 percentage_used = "{:.2f}%".format(percent) except BaseException: used = "None" percentage_used = "None" try: temp_str = "{Label},{Capacity},{used},{FreeSpace},{percentage_used},{Name};".format( used=used, percentage_used=percentage_used, **drive) output += temp_str except Exception as error: logging.error(error) # NAS Shares command = [ 'C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\powershell.exe', '-ExecutionPolicy', 'Unrestricted', 'Get-WmiObject', 'Win32_MappedLogicalDisk', '|', 'ConvertTo-Json' ] p_open = Popen(command, stdout=PIPE, stderr=PIPE, encoding='utf-8') temp_output, error = p_open.communicate() if len(error) > 0: logging.error("X-RAY NAS Mount Error: {}".format(error)) else: if len(temp_output) > 0: temp_json = json.loads(temp_output) for drive in temp_json: try: used = int(drive['Size']) - int(drive['FreeSpace']) percent = (used / float(drive['Size'])) * 100 percentage_used = "{:.2f}%".format(percent) except BaseException: used = "None" percentage_used = "None" try: temp_str = "{VolumeName},{Size},{used},{FreeSpace},{percentage_used},{ProviderName};".format( used=used, percentage_used=percentage_used, **drive) output += temp_str except Exception as error: logging.error(error) return output[:-1]
#!/usr/bin/env python """ github.com/w13b3 """ import os import glob from sys import platform, argv, version_info # set some variables. max_mtime = 0 debug_list = [] latest_ran_debug = "" os_platform = platform.lower() # Get the repository path. debug_file = "debug.txt" repository = r"/mnt/c/REPOSITORY/" if os_platform != "linux": repository = r"C:\REPOSITORY\" # Search in repository. for glob in glob.glob(os.path.join(repository)): for root, dirs, files in os.walk(glob): if debug_file in files: # Get time of last time it was edited. debug_path = str(os.path.join(root, debug_file)) latest_debug = os.path.getmtime(debug_path) if latest_debug > max_mtime: max_mtime = latest_debug latest_ran_debug = debug_path
class __CatalogReader: """Class to help manage and hide reading data from the data catalog.""" # Catalog abstraction instance __catalog: Catalog # True once initialized (configured) __initialized = False # Reader methods that have been allowed __readers: dict = {} # Application logger instance __logger = logging.getLogger() # Path to configuration file. if platform.lower() != 'windows': __configuration_path: str = os.path.join(os.getenv("HOME"), '.dataframez/configuration.yml') else: __configuration_path: str = os.path.join(os.getenv("USERPROFILE"), '.dataframez/configuration.yml') @classmethod def __initialize(cls): if not cls.__initialized: cls.__configure_catalog() cls.__configure_reader_methods() cls.__initialized = True @classmethod def read(cls, entry_name: str, version: int = 0, **kwargs) -> pd.DataFrame: """ Read from data catalog given the data asset catalog name and the version. Args: entry_name: Name of data catalog entry version: Version of data asset **kwargs: Returns: """ cls.__initialize() asset_info = cls.__catalog.read(entry_name=entry_name, version=version) return cls.__readers[asset_info['type']](asset_info, **kwargs) @classmethod def __configure_catalog(cls) -> None: """Constructor method that calls factory to create catalog instance.""" # When a configuration already exists, load it with open(cls.__configuration_path, 'r') as stream: registry_configuration = yaml.safe_load(stream)['configurations']['catalog'] # Load the configuration cls.__catalog = pf.create(key=registry_configuration['type'], configuration=registry_configuration['conf']) @classmethod def __configure_reader_methods(cls): """Constructor method to populate allowed reader methods""" # ----------- create local registry of all writers ---------- # # Load configuration with open(cls.__configuration_path, 'r') as config_stream: configuration = yaml.safe_load(stream=config_stream)['configurations'] for key, value in configuration['writers'].items(): if value['conf']['allowed']: cls.__readers[key.lower()] = pf.create(key=value['type'].lower(), library='dataframez', configuration=value['conf']).read @classmethod def list_assets(cls) -> list: return cls.__catalog.get_assets()
from statsmodels.tools.sm_exceptions import PerfectSeparationError try: import cvxopt has_cvxopt = True except ImportError: has_cvxopt = False DECIMAL_14 = 14 DECIMAL_10 = 10 DECIMAL_9 = 9 DECIMAL_4 = 4 DECIMAL_3 = 3 DECIMAL_2 = 2 DECIMAL_1 = 1 DECIMAL_0 = 0 iswindows = 'win' in platform.lower() class CheckModelResults(object): """ res2 should be the test results from RModelWrap or the results as defined in model_results_data """ def test_params(self): assert_almost_equal(self.res1.params, self.res2.params, DECIMAL_4) def test_conf_int(self): assert_almost_equal(self.res1.conf_int(), self.res2.conf_int, DECIMAL_4) def test_zstat(self):
def __init__(self, host_list = []): self.operating_system = "windows" if "win" in platform.lower() else "linux" self.server_list = host_list self.nmap_result = []
INTEGER, BINARY, OptimizationStatus, EQUAL, LESS_OR_EQUAL, GREATER_OR_EQUAL, SearchEmphasis, LP_Method, ) try: found = False lib_path = None if "GUROBI_HOME" in environ: if platform.lower().startswith("win"): libfile = glob( os.path.join(os.environ["GUROBI_HOME"], "bin\\gurobi[0-9][0-9].dll")) else: libfile = glob( os.path.join(os.environ["GUROBI_HOME"], "lib/libgurobi[0-9][0-9].*")) if not libfile: libfile = glob( os.path.join( os.environ["GUROBI_HOME"], "lib/libgurobi.so.[0-9].[0-9].*", )) if libfile:
from sys import exit from random import randint import os from sys import platform as _platform if _platform.lower() in ["linux", "linux2", "darwin"]: os.system("clear") elif _platform.lower() in ["windows", "win32"]: os.system("cls") else: print "Unknown OS - Run at your own risk" class Scene(object): def enter(self): exit(1) def choose(self): remarks = [ "Seriously? Learn how to type...Try again!", "Try typing without your boxing gloves on...", "Sigh, I can tell we'll be at this all day. Try again!", "To err is human...but you're just an idiot. Try again!." ] return remarks [randint(0, len(remarks)-1)] class Engine(object): def __init__(self, scene_map): self.scene_map = scene_map
try: # Requests HTTP library import requests if requests.__version__.split('.') < ['2', '5']: raise ImportError('Requests version %s < 2.5' % requests.__version__) except ImportError as ex: requests = None print("%s: %s\nWARNING: Video size information will not be available.\nPlease install Requests v2.5 or later: https://pypi.python.org/pypi/requests\n" % (ex.__class__.__name__, ex)) try: # Filesystem symbolic links configuration from os import link as hardlink, symlink except ImportError: hardlink = symlink = None print("%s: %s\nWARNING: Filesystem links will not be available.\nPlease run on UNIX or on Python 3.2 under Windows Vista or later.\n" % (ex.__class__.__name__, ex)) isWindows = platform.lower().startswith('win') TITLE = 'VimeoCrawler v3.0 (c) 2013-2014 Vasily Zakharov [email protected]' OPTION_NAMES = ('directory', 'login', 'max-items', 'retries', 'set-language', 'timeout', 'webdriver') FIELD_NAMES = ('targetDirectory', 'credentials', 'maxItems', 'retryCount', 'setLanguage', 'timeout', 'driverName') SHORT_OPTIONS = ''.join(('%c:' % option[0]) for option in OPTION_NAMES) + 'hvnfz' LONG_OPTIONS = tuple(('%s=' % option) for option in OPTION_NAMES) + ('help', 'verbose', 'no-download', 'no-folders', 'no-filesize', 'hard-links') USAGE_INFO = '''Usage: python VimeoCrawler.py [options] [start URL or video ID] The crawler checks the specified URL and processes the specified video, album, channel or the whole account, trying to locate the highest available quality file for each video. For every video found a file is downloaded to the target directory.
#!/usr/bin/env python # Copyright (c) 2018, Michael Boyle # See LICENSE file for details: <https://github.com/moble/quaternion/blob/master/LICENSE> # Construct the version number from the date and time this python version was created. from os import environ from sys import platform on_windows = ('win' in platform.lower() and not 'darwin' in platform.lower()) if "package_version" in environ: version = environ["package_version"] print("Setup.py using environment version='{0}'".format(version)) else: print("The variable 'package_version' was not present in the environment") try: # For cases where this is being installed from git. This gives the true version number. from subprocess import check_output if on_windows: version = check_output("""git log -1 --format=%cd --date=format:'%Y.%m.%d.%H.%M.%S'""", shell=False) version = version.decode('ascii').strip().replace('.0', '.').replace("'", "") else: try: from subprocess import DEVNULL as devnull version = check_output("""git log -1 --format=%cd --date=format:'%Y.%-m.%-d.%-H.%-M.%-S'""", shell=True, stderr=devnull) except AttributeError: from os import devnull version = check_output("""git log -1 --format=%cd --date=format:'%Y.%-m.%-d.%-H.%-M.%-S'""", shell=True, stderr=devnull) version = version.decode('ascii').rstrip() print("Setup.py using git log version='{0}'".format(version)) except Exception: # For cases where this isn't being installed from git. This gives the wrong version number,
""" import numpy as np from numpy.testing import * from scikits.statsmodels.discrete.discrete_model import * import scikits.statsmodels.api as sm from sys import platform from nose import SkipTest from results.results_discrete import Spector DECIMAL_4 = 4 DECIMAL_3 = 3 DECIMAL_2 = 2 DECIMAL_1 = 1 DECIMAL_0 = 0 iswindows = 'win' in platform.lower() class CheckModelResults(object): """ res2 should be the test results from RModelWrap or the results as defined in model_results_data """ def test_params(self): assert_almost_equal(self.res1.params, self.res2.params, DECIMAL_4) def test_conf_int(self): assert_almost_equal(self.res1.conf_int(), self.res2.conf_int, DECIMAL_4) def test_zstat(self): assert_almost_equal(self.res1.tvalues, self.res2.z, DECIMAL_4)
bRIGHT = 2 bCENTER = 4 bJUSTIFIED = 8 _d_a = bCENTER _d_s = tuple( [(str(bCENTER),('+','-','c','a','h','m'))] + [(str(k), ()) for k in [bLEFT,bRIGHT,bJUSTIFIED]] ) def _gen_dflt(setting, plat=''): """ 'setting': alignment|sections| """ if _sysplatform.lower().startswith('darwin'): _d_a = bLEFT|bRIGHT _d_s = ( (str(bLEFT), ('h','m')) , (str(bRIGHT), ('-','c','a','+')) ) elif _sysplatform.lower().startswith('win32') or _sysplatform == 'win': _d_a = bRIGHT _d_s = tuple( [ (str(bRIGHT), dict(_d_s)[str(bCENTER)]) ] + [(str(k), ()) for k in [bLEFT,bCENTER,bJUSTIFIED]] ) class DuplicateButtonError(RuntimeError): pass class ButtonGroup(ttk.Frame,object): default_alignment = _d_a default_sections = _d_s
#!/usr/bin/python from os import getenv, listdir from os.path import basename, dirname, expanduser, exists, isdir, join, normpath, pardir import sys # for path from sys import argv, exit, platform, getfilesystemencoding, version_info if platform.lower().startswith('linux') and not getenv("DISPLAY"): print "Can't run: DISPLAY is not set" exit(1) try: if platform=='darwin' and basename(sys.path[0])=='MacOS': sys.path.insert(0, join(sys.path[0], '%d%d' % version_info[:2])) argv[0]=basename(argv[0]) # wx doesn't like non-ascii chars in argv[0] import wx except: import Tkinter, tkMessageBox Tkinter.Tk().withdraw() tkMessageBox.showerror("Error", "wxPython is not installed.\nThis application requires wxPython 2.8 or later.") exit(1) from dopublish import publish from utils import * from version import appname, appversion # wx 3 requires a MainLoop for Dialogs to work - so hack up a dummy frame and invoke MainLoop. class MyApp(wx.App):
def ConvertToPython(xml=False,request=None,guiLog=False,path=None,literalPath=None,dumpXml=False,dumpToFile=False,dumpFilePath=None): print "### Please review the generated cmdlets before deployment.\n" global displayXml, outFileFlag, outFilePath, outFile displayXml=dumpXml outFileFlag=dumpToFile outFilePath=dumpFilePath if outFileFlag in _AffirmativeList: if outFilePath: print "### Script Output is in file < " + outFilePath + " >" outFile = open(outFilePath, 'w') outFile.close() #outFile = open(r"c:\work.txt", 'w+') else: print "Please profide dumpFilePath" return if xml in _AffirmativeList: if guiLog in _AffirmativeList: print "parameter <xml> takes precedence over <guiLog>" if request: GenerateCmdlets(request) elif path or literalPath: IfPathOrLiteralPath(path,literalPath,False) else: print "Please provide request" return elif guiLog in _AffirmativeList: if path or literalPath: IfPathOrLiteralPath(path,literalPath,True) else: print "Please provide path or literalPath" else: from sys import platform as _platform if _platform.lower() == "linux" or _platform.lower() == "linux2": # linux logFilePath = GetUCSDefaultLogpathLinux() elif _platform.lower() == "darwin": # OS X logFilePath = GetUCSDefaultLogpathOSX() elif _platform.lower() == "win32" or _platform.lower() == "win64": # Windows... logFilePath = GetUCSDefaultLogpathWindows() elif "cygwin" in _platform.lower(): # Cygwin logFilePath = GetUCSDefaultLogpathCygwin() else: print "[Error]: Unsupported OS:",_platform logFilePath = None return ## Get the latest logfile #logFilePath = r"C:\Users\ragupta4\AppData\LocalLow\Sun\Java\Deployment\log\.ucsm" #files = [ file for file in glob.glob(logFilePath + "\\" + "*") if os.path.isfile(file)] os.chdir(logFilePath) files = [ file for file in glob.glob("centrale_*.log") if os.path.isfile(file)] files.sort(key=lambda x: os.path.getmtime(x), reverse=True) lastUpdatedFile = files[0] fileStream = open(lastUpdatedFile, 'r') ## read the file till the end cnt = 0 for line in fileStream: cnt += 1 ## Wait indefinitely until receive new line of set and then again wait while True: line = fileStream.readline() if line: FindXmlRequestsInFile_test(fileStream, True) time.sleep(2) fileStream.close() #if outFilePath: #outFile.close() print "### End of Convert-To-Python ###"
create and manipulate arrays of quaternions. The usual algebraic operations (addition and multiplication) are available, along with numerous properties like norm and various types of distance measures between two quaternions. There are also additional functions like "squad" and "slerp" interpolation, and conversions to and from axis-angle, matrix, and Euler-angle representations of rotations. The core of the code is written in C for speed. """ from sys import platform from setuptools import Extension, setup import numpy as np # Set this first for easier replacement version = "2021.3.11.10.41.35" if "win" in platform.lower() and not "darwin" in platform.lower(): extra_compile_args = ["/O2"] else: extra_compile_args = ["-O3", "-w"] extensions = [ Extension( name= "quaternion.numpy_quaternion", # This is the name of the object file that will be compiled sources=["src/quaternion.c", "src/numpy_quaternion.c"], depends=[ "src/quaternion.c", "src/quaternion.h", "src/numpy_quaternion.c" ], include_dirs=[np.get_include(), "src"], extra_compile_args=extra_compile_args, ),
import os from sys import platform as _platform ##################################docker config################################# docker_url_linux = "unix://var/run/docker.sock" docker_url_other = "tcp://localhost:4243" docker_url = docker_url_linux if _platform.lower().startswith("linux") else docker_url_other #mapped_port_in = 80 # for apache mapped_port_in = 8888 # for node mapped_port_out = 49160 report_verbosity = "DEBUG" spoiled_mode = False browser_visible = False timeout = 5 ################################################################################ ###################################file config################################## current_path = os.path.dirname(os.path.realpath(__file__)) ## results default folder results_filename = current_path + "/reports/TestResults.csv" ##input dirs applications_path = current_path + "/data/targets/applications/" configurations_path = current_path + "/data/targets/configurations/" containers_path = current_path + "/data/targets/containers/" exploits_path = current_path + "/data/exploits/"
def calculate_hash_512(src_filename, target_path, idflag): """ SHA512 Hash Digest """ if debugFlag: stime = time.time() sha512_hash = hashlib.sha512() src_filepath = os.path.join(os.getcwd(), src_filename) try: with open(src_filepath, "r") as sf: statinfo = os.stat(src_filepath) block_size = 100 * (2**20) #Magic number: 100 * 1MB blocks nb_blocks = (statinfo.st_size / block_size) + 1 cnt_blocks = 0 if _platform.lower() == "linux" or _platform.lower() == "linux2": l = len(src_filepath.split('/')) target_file_path = os.path.join(target_path, src_filepath.split('/')[l - 1]) elif _platform.lower() == "win32": l = len(src_filepath.split('\\')) target_file_path = os.path.join( target_path, src_filepath.split('\\')[l - 1]) if idflag: print "\nCopying %s to %s, generating c4id..." % ( src_filepath, target_file_path) else: print "\nCopying %s to %s" % (src_filepath, target_file_path) while True: block = sf.read(block_size) sha512_hash.update(block) if not block: break cnt_blocks = cnt_blocks + 1 with open(target_file_path, "a") as tf: tf.write(block) tf.close() if idflag: c4_id_length = 90 b58_hash = b58encode(sha512_hash.digest()) #Pad with '1's if needed padding = '' if len(b58_hash) < (c4_id_length - 2): padding = ('1' * (c4_id_length - 2 - len(b58_hash))) #Combine to form C4 ID string_id = 'c4' + padding + b58_hash print "\n %s" % str(string_id) progress = 100 * cnt_blocks / nb_blocks sys.stdout.flush() draw_progress_bar(progress) sf.close() except IOError: print "Error: cant find or read '%s' file" % (src_filename) if debugFlag: print "Copytime: %s sec" % (time.time() - stime)
def execute(cls, cmd, arguments="", shell=False, cwd=None, traceflag=True, witherror=True): """Run Shell command :param witherror: if set to False the error will not be printed :param traceflag: if set to true the trace is printed in case of an error :param cwd: the current working directory in which the command is supposed to be executed. :param shell: if set to true the subprocess is called as part of a shell :param cmd: command to run :param arguments: we do not know yet :return: """ # print "--------------" result = None terminal = cls.terminal_type() # print cls.command os_command = [cmd] if terminal in ['linux', 'windows']: os_command = [cmd] elif 'cygwin' in terminal: if not cls.command_exists(cmd): print("ERROR: the command could not be found", cmd) return else: os_command = [cls.command[cls.operating_system()][cmd]] if isinstance(arguments, list): os_command = os_command + arguments elif isinstance(arguments, tuple): os_command = os_command + list(arguments) elif isinstance(arguments, str): os_command = os_command + arguments.split() else: print("ERROR: Wrong parameter type", type(arguments)) if cwd is None: cwd = os.getcwd() try: if shell: if platform.lower() == 'win32': import ctypes class disable_file_system_redirection: _disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection _revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection def __enter__(self): self.old_value = ctypes.c_long() self.success = self._disable( ctypes.byref(self.old_value)) def __exit__(self, type, value, traceback): if self.success: self._revert(self.old_value) if len(os_command) == 1: os_command = os_command[0].split(' ') with disable_file_system_redirection(): result = subprocess.check_output(os_command, stderr=subprocess.STDOUT, shell=True, cwd=cwd) else: result = subprocess.check_output( os_command, stderr=subprocess.STDOUT, shell=True, cwd=cwd) else: result = subprocess.check_output( os_command, # shell=True, stderr=subprocess.STDOUT, cwd=cwd) except: if witherror: Console.error("problem executing subprocess", traceflag=traceflag) if result is not None: result = result.strip().decode() return result
#!/usr/bin/env python # Copyright (c) 2019, Michael Boyle # See LICENSE file for details: <https://github.com/moble/spherical_functions/blob/master/LICENSE> from distutils.core import setup from os import getenv # Construct the version number from the date and time this python version was created. from os import environ from sys import platform on_windows = ('win' in platform.lower() and not 'darwin' in platform.lower()) if "package_version" in environ: version = environ["package_version"] print("Setup.py using environment version='{0}'".format(version)) else: print("The variable 'package_version' was not present in the environment") try: # For cases where this is being installed from git. This gives the true version number. from subprocess import check_output if on_windows: version = check_output("""git log -1 --format=%cd --date=format:'%Y.%m.%d.%H.%M.%S'""", shell=False) version = version.decode('ascii').strip().replace('.0', '.').replace("'", "") else: try: from subprocess import DEVNULL as devnull version = check_output("""git log -1 --format=%cd --date=format:'%Y.%-m.%-d.%-H.%-M.%-S'""", shell=True, stderr=devnull) except AttributeError: from os import devnull version = check_output("""git log -1 --format=%cd --date=format:'%Y.%-m.%-d.%-H.%-M.%-S'""", shell=True, stderr=devnull) version = version.decode('ascii').rstrip()
result = speedtest_cli.speedtest(); return (result[1], result[0]) # [0] = up, [1] = down # MAIN if __name__ == "__main__": try: homeDir = os.path.expanduser('~'); outPath = homeDir + "/speedtest.txt"; fileWriter = open(outPath,'a'); logMsg = '' # Running on a mac? if platform.lower() == 'darwin': ssid = getSSID(); isConn = isNetConnected(); if isConn is True: # we're connected, run speed test and get down / up speed in Mbit/s down,up = runSpeedTestAndGetDownloadUpload(); logMsg = str(time.time()) + "," + ssid + "," + "connected," + str(down) + "," + str(up) else: # not connected to the internet... bummer logMsg = str(time.time()) + "," + "not connected" else: # not on a mac logMsg = 'not a mac'
has_cython = False # You will also need NumPy to compile this Cython try: import numpy as np except (ModuleNotFoundError, ImportError): print( 'WARNING: You do not have NumPy installed. Installation preceeding without NumPy.' ) has_cython = False # find all the extension modules in the project, for a Cython build if has_cython: FORCE_FLAGS = ['-f', '--f', '--force'] FORCE_REBUILD = True if any([f in argv for f in FORCE_FLAGS]) else False IS_WINDOWS = True if (os_name.lower() == 'nt' or 'win' in platform.lower()) else False COMP_DIRS = { 'language_level': 3, 'boundscheck': False, 'initializedcheck': False, 'cdivision': True } sep = '\\' if IS_WINDOWS else '/' ext_modules = [ Extension(p[:-4].replace(sep, '.'), [p, p[:-2] + 'y'], include_dirs=[np.get_include(), '.']) for p in glob(sep.join(['mazelib', '*', '*.pxd'])) ] ext_modules_list = cythonize(ext_modules, annotate=False, force=FORCE_REBUILD,
from SettingsUI import SettingsUI # Global vars Entry = 0 Action = "" def escape(x): res = "" for i in x: if i == "\\": # If it equals a single backslash. res += "\\\\" # Add two backslashes else: res += i # Add whatever the character was return res if "windows" in SYS_PLATFORM.lower(): file_delimeter = "\\" else: file_delimeter = "/" class GUI(tk.Frame): def __init__(self, parent): print "" print "GUI thread created" self.fileDict = {} self.displayedEntryList = [] self.displayedAllList = [] self.displayedHeadersList = [] self.pageNum = 0 self.PBPercentage = 0
import os import numpy as np from numpy.testing import * from scikits.statsmodels.discrete.discrete_model import * import scikits.statsmodels.api as sm from sys import platform from nose import SkipTest from results.results_discrete import Spector from scikits.statsmodels.tools.sm_exceptions import PerfectSeparationError DECIMAL_4 = 4 DECIMAL_3 = 3 DECIMAL_2 = 2 DECIMAL_1 = 1 DECIMAL_0 = 0 iswindows = "win" in platform.lower() class CheckModelResults(object): """ res2 should be the test results from RModelWrap or the results as defined in model_results_data """ def test_params(self): assert_almost_equal(self.res1.params, self.res2.params, DECIMAL_4) def test_conf_int(self): assert_almost_equal(self.res1.conf_int(), self.res2.conf_int, DECIMAL_4) def test_zstat(self):