Example #1
0
	def test_get_lsb_information(self):
		# Test that an inexistant /etc/lsb-release leads to empty output
		supposed_output = {}
		os.environ['LSB_ETC_LSB_RELEASE'] = 'test/inexistant_file_' + rnd_string(2,5)
		self.assertEqual(lr.get_lsb_information(),supposed_output)
		# Test that a fake /etc/lsb-release leads to output with only the content we want
		supposed_output = {'RELEASE': '(The release number)',
				   'CODENAME': '(The codename for the release)',
				   'ID': '(Distributor ID)',
				   'DESCRIPTION': '(A human-readable description of the release)'}
		os.environ['LSB_ETC_LSB_RELEASE'] = 'test/lsb-release'
		self.assertEqual(lr.get_lsb_information(),supposed_output)
		os.environ.pop('LSB_ETC_LSB_RELEASE')
def configure_jupyter_notebook():
    conf = hookenv.config()
    jupyter_dir = '/opt/jupyter'
    port = conf['open-port']
    # Get or create and get password
    kv_store = unitdata.kv()
    password = kv_store.get('password')
    if not password:
        password = generate_password()
        kv_store.set('password', password)
    # Convert to string because some functions can't handle kv object type.
    password = str(password)
    password_hash = generate_hash(password)
    context = {
        'port': port,
        'password_hash': password_hash,
    }
    if data_changed('jupyter-conf', context):
        # Create config directory and render config file
        host.mkdir(jupyter_dir)
        templating.render(
            source='jupyter_notebook_config.py.jinja2',
            target=jupyter_dir + '/jupyter_notebook_config.py',
            context=context
        )
        # Generate upstart template / service file
        context = {}
        if lsb_release.get_lsb_information()['RELEASE'] == "14.04":
            render_api_upstart_template(context)
        else:
            render_api_systemd_template(context)
        restart_notebook()
    chownr(jupyter_dir, 'ubuntu', 'ubuntu', chowntopdir=True)
Example #3
0
def _install_linux(port):
    import lsb_release
    release = lsb_release.get_lsb_information()["RELEASE"]
    print("Detected Linux OS {}".format(release))
    if(not(release[:2] == "16" or release[:2] == "18")):
        print("Linux OS not currently supported for installation")
        return
    print("Installing conplyent server listening to port # {}".format(port))

    if(not(os.path.isdir("/usr/bin/conplyent"))):
        os.mkdir("/usr/bin/conplyent")

    dir_path = os.path.dirname(os.path.realpath(__file__))
    with open("/usr/bin/conplyent/conplyent_{}.sh".format(port), "w") as file:
        file.write("#!/bin/sh\npip3 install conplyent\n{} {}/cli.py start-server --port {}".format(
            sys.executable, dir_path, port))

    os.system("chmod +x /usr/bin/conplyent/conplyent_{}.sh".format(port))

    with open("/etc/systemd/system/conplyent_{}.service".format(port), "w") as file:
        file.write("[Unit]\nDescription=conplyent service\nWants=network-online.target\n"
                   "After=network-online.target network.target\n\n")
        file.write("[Service]\nExecStart=/usr/bin/conplyent/conplyent_{}.sh\n\n".format(port))
        file.write("[Install]\nWantedBy=default.target")

    os.system("chmod 664 /etc/systemd/system/conplyent_{}.service".format(port))
    os.system("systemctl enable conplyent_{}.service".format(port))
    os.system("systemctl restart conplyent_{}.service".format(port))

    print("Done")
Example #4
0
def updatesources():
    """"""
    import lsb_release
    codename = lsb_release.get_lsb_information()["CODENAME"]
    sources = "/etc/apt/sources.list"
    os.rename(sources, sources + ".save")
    urllib.urlretrieve("http://mirrors.163.com/.help/sources.list." + codename, sources)
Example #5
0
    def __init__(self):
        super(Settings, self).__init__()
        self.directory = ".resetter/data"
        self.os_info = lsb_release.get_lsb_information()
        self.euid = os.geteuid()
        self.error_msg = QtGui.QMessageBox()
        self.error_msg.setIcon(QtGui.QMessageBox.Critical)
        self.error_msg.setWindowTitle("Error")
        self.detectRoot()
        logdir = "/var/log/resetter"
        if not os.path.exists(logdir):
            os.makedirs(logdir)
        self.logger = logging.getLogger(__name__)
        self.logger.setLevel(logging.DEBUG)
        handler = logging.FileHandler('/var/log/resetter/resetter.log')
        handler.setLevel(logging.DEBUG)
        formatter = logging.Formatter('%(asctime)s - %(name)s - %(funcName)s - %(levelname)s - %(message)s')
        handler.setFormatter(formatter)
        self.logger.addHandler(handler)
        self.manifests = '/usr/lib/resetter/data/manifests'
        self.userlists = '/usr/lib/resetter/data/userlists'
        if 'PKEXEC_UID' in os.environ:
            self.user = pwd.getpwuid(int(os.environ["PKEXEC_UID"])).pw_name
            working_dir = '/home/{}'.format(self.user)
            os.chdir(working_dir)
        elif self.euid == 0 and 'PKEXEC_UID' not in os.environ:
            self.user = os.environ["SUDO_USER"]
        self.createDirs()
        os.chdir(self.directory)

        self.manifest = self.detectOS()[0]
        self.userlist = self.detectOS()[1]
        self.window_title = self.detectOS()[2]
        self.filesExist(self.manifest, self.userlist)
Example #6
0
 def validate_driver_package(self, package, sender=None, conn=None):
     """Validates a Dell driver package"""
     logging.debug("Validating driver package %s" % package)
     valid = 1
     description = ['']
     error_warning = ''
     if not os.path.exists(package) or not package.endswith('fish.tar.gz'):
         valid = -1
         error_warning = 'Bad file name'
     if valid >= 0:
         rfd = tarfile.open(package)
         prepackage = False
         for name in rfd.getnames():
             if name.endswith('prepackage.dell'):
                 prepackage = rfd.getmember(name)
                 break
         if not prepackage:
             valid = -1
             error_warning = 'Missing or invalid XML descriptor (prepackage.dell)'
     if valid >= 0:
         tmpdir = tempfile.mkdtemp()
         atexit.register(walk_cleanup, tmpdir)
         rfd.extract(prepackage, tmpdir)
         rfd.close()
         self.xml_obj.load_bto_xml(os.path.join(tmpdir, 'prepackage.dell'))
         our_os = lsb_release.get_lsb_information()['RELEASE']
         package_os = self.xml_obj.fetch_node_contents('os')
         if our_os != package_os:
             valid = 0
             error_warning = "OS Version of package %s doesn't match local OS version %s" % (
                 package_os, our_os)
         description = self.xml_obj.fetch_node_contents('driver')
     logging.debug("Validation complete: valid %s" % valid)
     self.report_package_info(valid, description, error_warning)
    def restart_service(self):
        '''Restart network service for Ubuntu'''
        log.info('Restarting Network Services...')
        if LooseVersion(VERSION) < LooseVersion("14.04"):
            subprocess.call('sudo /etc/init.d/networking restart', shell=True)
        else:
            # Avoid bringing down the PF of VF together with the VFs.
            # Otherwise, the addition of the VF to a bond fails (probably due to
            # a bug in the ixgbe driver)
            if self.no_ip:
                subprocess.call('sudo ifdown %s && ifup %s' % (self.device,
                                self.device), shell=True)
            else:
                output = os.popen("sudo ifquery -l --allow=auto").read()
                intfs = output.split()
                lsb_info = lsb_release.get_lsb_information()
                lsb_version = lsb_info['DESCRIPTION'].split()[1]
                if LooseVersion(lsb_version) >= LooseVersion('14.04.4'):
                    for intf in intfs:
                        subprocess.call('sudo ifdown %s && ifup %s' %
                                        (intf, intf), shell=True)
                    subprocess.call('sudo ifup -a', shell=True)

                else:
                    for intf in intfs:
                        subprocess.call('sudo ifdown %s && ifup -a' % (intf),
                                        shell=True)
        time.sleep(5)
Example #8
0
def _find_urandom_fd():
    fds = dict([(os.path.realpath(os.path.join('/proc', 'self', 'fd', p)), p)
                for p in os.listdir('/proc/self/fd')])
    if float(lsb_release.get_lsb_information()['RELEASE']) > 14:
        return os.urandom(32)
    else:
        return int(fds['/dev/urandom'])
 def validate_driver_package(self, package, sender=None, conn=None):
     """Validates a Dell driver package"""
     logging.debug ("Validating driver package %s" % package)
     valid = 1
     description = ['']
     error_warning = ''
     if not os.path.exists(package) or not package.endswith('fish.tar.gz'):
         valid = -1
         error_warning = 'Bad file name'
     if valid >= 0:
         rfd = tarfile.open(package)
         prepackage = False
         for name in rfd.getnames():
             if name.endswith('prepackage.dell'):
                 prepackage = rfd.getmember(name)
                 break
         if not prepackage:
             valid = -1
             error_warning = 'Missing or invalid XML descriptor (prepackage.dell)'
     if valid >= 0:
         tmpdir = tempfile.mkdtemp()
         atexit.register(walk_cleanup, tmpdir)
         rfd.extract(prepackage, tmpdir)
         rfd.close()
         self.xml_obj.load_bto_xml(os.path.join(tmpdir, 'prepackage.dell'))
         our_os = lsb_release.get_lsb_information()['RELEASE']
         package_os = self.xml_obj.fetch_node_contents('os')
         if our_os != package_os:
             valid = 0
             error_warning = "OS Version of package %s doesn't match local OS version %s" % (package_os, our_os)
         description = self.xml_obj.fetch_node_contents('driver')
     logging.debug("Validation complete: valid %s" % valid)
     self.report_package_info(valid, description, error_warning)
Example #10
0
def CheckUbuntuVersion():
    #print "1.1.1 less than 1.1.1 is %s" % version_lessthan("1.1.1", "1.1.1")
    #print "1.1.2 less than 1.1.1 is %s" % version_lessthan("1.1.2", "1.1.1")
    #print "1.1.1 less than 1.1.2 is %s" % version_lessthan("1.1.1", "1.1.2")
    #print "1.2.1 less than 1.1.2 is %s" % version_lessthan("1.2.1", "1.1.2")

    lsb_info = lsb_release.get_lsb_information()
    lsb_info_id = lsb_info['ID']
    if (lsb_info_id == "Ubuntu"):
        no_sort = False
        if not isSortVsupported():
            no_sort = True

        ubuntu_description = lsb_info['DESCRIPTION']
        ubuntu_desc = ubuntu_description.split()
        ubuntu_version = ubuntu_desc[1]

        if no_sort or (ubuntu_version != required_ubuntu_version
                       and version_lessthan(ubuntu_version,
                                            required_ubuntu_version)):
            print(
                'Your Ubuntu version (%s) is older than %s, which is required in order to experiment with the\n'
            )
            print(
                '"sysctl" setting for syn_cookies".  This will not interfere with your ability to complete the lab.'
            )
            return 1
    return 0
Example #11
0
def configure_jupyter_notebook():
    conf = hookenv.config()
    jupyter_dir = '/opt/jupyter'
    port = conf['open-port']
    # Get or create and get password
    kv_store = unitdata.kv()
    password = kv_store.get('password')
    if not password:
        password = generate_password()
        kv_store.set('password', password)
    # Convert to string because some functions can't handle kv object type.
    password = str(password)
    password_hash = generate_hash(password)
    context = {
        'port': port,
        'password_hash': password_hash,
    }
    if data_changed('jupyter-conf', context):
        # Create config directory and render config file
        host.mkdir(jupyter_dir)
        templating.render(
            source='jupyter_notebook_config.py.jinja2',
            target=jupyter_dir + '/jupyter_notebook_config.py',
            context=context
        )
        # Generate upstart template / service file
        context = {}
        if lsb_release.get_lsb_information()['RELEASE'] == "14.04":
            render_api_upstart_template(context)
        else:
            render_api_systemd_template(context)
        restart_notebook()
    chownr(jupyter_dir, 'ubuntu', 'ubuntu', chowntopdir=True)
Example #12
0
def log_execution_env_state(config_filename=None, logdir=None, gitroot='.'):
    """Log information about the execution environment.

    It is recommeneded to log this information so it can be used for referencing
    at a later time.

    Args:
        config_filename: filename to store in logdir, if logdir is set
        logdir: log directory
        git_root: the path to the .git root directory
    """
    def log_git_state():
        """Log the state of the git repository.

        It is useful to know what git tag we're using, and if we have outstanding code.
        """
        try:
            repo = Repo(gitroot)
            assert not repo.bare
        except InvalidGitRepositoryError:
            logger.debug(
                "Cannot find a Git repository.  You probably downloaded an archive of Distiller."
            )
            return

        if repo.is_dirty():
            logger.debug("Git is dirty")
        try:
            branch_name = repo.active_branch.name
        except TypeError:
            branch_name = "None, Git is in 'detached HEAD' state"
        logger.debug("Active Git branch: %s", branch_name)
        logger.debug("Git commit: %s" % repo.head.commit.hexsha)

    logger.debug("Number of CPUs: %d", len(os.sched_getaffinity(0)))
    logger.debug("Number of GPUs: %d", torch.cuda.device_count())
    logger.debug("CUDA version: %s", torch.version.cuda)
    logger.debug("CUDNN version: %s", torch.backends.cudnn.version())
    logger.debug("Kernel: %s", platform.release())
    if HAVE_LSB:
        logger.debug("OS: %s",
                     lsb_release.get_lsb_information()['DESCRIPTION'])
    logger.debug("Python: %s", sys.version)
    logger.debug("PyTorch: %s", torch.__version__)
    logger.debug("Numpy: %s", np.__version__)
    log_git_state()
    logger.debug("Command line: %s", " ".join(sys.argv))

    if (logdir is None) or (config_filename is None):
        return
    # clone configuration files to output directory
    configs_dest = os.path.join(logdir, 'configs')
    with contextlib.suppress(FileExistsError):
        os.makedirs(configs_dest)
    if os.path.exists(os.path.join(configs_dest, config_filename)):
        logger.debug('{} already exists in logdir'.format(
            os.path.basename(config_filename) or config_filename))
    else:
        shutil.copy(config_filename, configs_dest)
Example #13
0
 def __init__(self):
     super().__init__()
     import lsb_release
     release = lsb_release.get_lsb_information()['RELEASE']
     self.target = release + '.' + platform.architecture()[0]
     self.tc_framework = TESTFW_TYPES.GTEST
     self.app_path = TC_BIN_DIR
     self.platform_type = 'linux'
 def test_get_lsb_information(self):
     # Test that an inexistant /etc/lsb-release leads to empty output
     supposed_output = {}
     os.environ[
         'LSB_ETC_LSB_RELEASE'] = 'test/inexistant_file_' + rnd_string(
             2, 5)
     self.assertEqual(lr.get_lsb_information(), supposed_output)
     # Test that a fake /etc/lsb-release leads to output with only the content we want
     supposed_output = {
         'RELEASE': '(The release number)',
         'CODENAME': '(The codename for the release)',
         'ID': '(Distributor ID)',
         'DESCRIPTION': '(A human-readable description of the release)'
     }
     os.environ['LSB_ETC_LSB_RELEASE'] = 'test/lsb-release'
     self.assertEqual(lr.get_lsb_information(), supposed_output)
     os.environ.pop('LSB_ETC_LSB_RELEASE')
Example #15
0
    def __init__(self, parent=None):
        super(EasyPPAInstall, self).__init__(parent)
        self.setWindowTitle("Easy PPA Install")
        self.searchEditText = QtGui.QLineEdit()
        self.searchEditText.setPlaceholderText("Search for applications")
        self.searchEditText.setMaximumWidth(200)
        self.searchbutton = QtGui.QPushButton()
        self.error_msg = QtGui.QMessageBox()
        self.error_msg.setIcon(QtGui.QMessageBox.Critical)
        self.error_msg.setWindowTitle("Error")
        self.closebutton = QtGui.QPushButton()
        self.closebutton = QtGui.QPushButton()
        self.closebutton.setText('Close')
        self.closebutton.setMaximumWidth(150)
        self.closebutton.clicked.connect(self.close)
        self.searchbutton.setText("Search")
        self.searchbutton.setMaximumWidth(100)
        self.progressbar = QtGui.QProgressBar()
        self.lbl1 = QtGui.QLabel()
        self.buttonRefresh = QtGui.QPushButton()
        self.buttonRefresh.setText("Refresh sources")
        self.isWrittenTo = False
        self.table = QtGui.QTableWidget()
        self.configureTable(self.table)
        self.searchbutton.clicked.connect(
            lambda: self.searchForPPA(self.table))
        self.buttonRefresh.clicked.connect(self.updateSources)
        self.table.verticalHeader().hide()
        self.horizontalLayout = QtGui.QHBoxLayout()
        self.horizontalLayout.addWidget(self.searchEditText)
        self.horizontalLayout.addWidget(self.searchbutton)
        self.horizontalLayout.setAlignment(QtCore.Qt.AlignRight)
        self.horizontalLayout2 = QtGui.QHBoxLayout()
        self.horizontalLayout2.setAlignment(QtCore.Qt.AlignRight)
        self.horizontalLayout2.addWidget(self.progressbar)
        self.horizontalLayout2.addWidget(self.buttonRefresh)
        self.horizontalLayout2.addWidget(self.closebutton)
        self.verticalLayout = QtGui.QVBoxLayout(self)
        self.verticalLayout.addLayout(self.horizontalLayout)
        self.verticalLayout.addWidget(self.table)
        self.verticalLayout.addWidget(self.lbl1)
        self.verticalLayout.addLayout(self.horizontalLayout2)
        self.os_info = lsb_release.get_lsb_information()
        self.sources = sourceslist.SourcesList()

        self.aprogress = UIAcquireProgress(True)
        self.thread1 = QtCore.QThread()
        self.aprogress.moveToThread(self.thread1)
        self.thread1.started.connect(
            lambda: self.aprogress.play(0.0, False, ""))
        self.aprogress.finished.connect(self.thread1.quit)
        self.connect(self.aprogress,
                     QtCore.SIGNAL("updateProgressBar2(int, bool, QString)"),
                     self.updateProgressBar2)

        self.ppa = []
        self.table_data = []
Example #16
0
def install_docker():
    apt_get_update()

    # Install dependencies
    apt_get_install('ca-certificates')
    apt_get_install('apt-transport-https')

    # Add the keyserver
    subprocess.check_output([
        'apt-key', 'adv',
        '--keyserver', 'hkp://p80.pool.sks-keyservers.net:80',
        '--recv-keys', '58118E89F3A912897C070ADBF76221572C52609D',
    ])

    #  Add the ppa
    ubuntu_codename = lsb_release.get_lsb_information()['CODENAME']
    line = 'deb https://apt.dockerproject.org/repo ubuntu-{} main'.format(ubuntu_codename)
    filename = '/etc/apt/sources.list.d/docker.list'
    print('Using ppa: {}'.format(line))

    with open(filename, 'w') as f:
        os.chmod(filename, 0o644)
        f.write(line)

    apt_get_update()

    # Install linux-image-extra-virtual for the aufs filesystem
    kernel_version = subprocess.check_output(['uname', '-r']).decode('utf8').rstrip()
    linux_image_headers = 'linux-image-extra-{}'.format(kernel_version)
    apt_get_install(linux_image_headers)
    apt_get_install('linux-image-extra-virtual')

    # Finally install docker
    apt_get_install('docker-engine')

    # Add me to the docker user
    try:
        output = subprocess.check_output(['groupadd', 'docker'], stderr=subprocess.STDOUT)
    except subprocess.CalledProcessError as e:
        group_exists_msg = "groupadd: group 'docker' already exists"
        if not e.output.decode('utf8').startswith(group_exists_msg):
            raise e

    # TODO: Hack because test fails in docker because no dani user exists
    try:
        subprocess.check_output(['usermod', '-a', '-G', 'docker', 'dani'])
    except subprocess.CalledProcessError as e:
        pass

    try:
        subprocess.check_output(['su', '-', 'dani'])
    except subprocess.CalledProcessError as e:
        pass

    install_docker_compose()
Example #17
0
def main():
    # Newer versions of ubuntu have problems downloading the data
    # due to security settings, so we have to feed wget some additional
    # options.  Unfortunately these options do not exist on earlier versions.
    global wgetoptions
    if platform == "linux":
        import lsb_release
        info = lsb_release.get_lsb_information()
        if info['ID'] == "Ubuntu" and int(info["RELEASE"].split(".")[0]) > 18:
            wgetoptions = "--cipher 'DEFAULT:!DH'"
    download(2016, 1, 2016, 2)
Example #18
0
def setup():
    global release

    for machine in machines:
        if hostname == machines[machine][MACHINES_INDEX_HOSTNAME]:
            break
    else:
        if not confirm('Your machine is not officially supported. Are you sure to proceed?'):
            return

    backup_dir(dir_share_python)
    release = lsb_release.get_lsb_information()['RELEASE']
Example #19
0
    def __init__(self, parent=None):
        super(EasyPPAInstall, self).__init__(parent)
        self.setWindowTitle("Easy PPA Install")
        self.searchEditText = QtGui.QLineEdit()
        self.searchEditText.setPlaceholderText("Search for applications")
        self.searchEditText.setMaximumWidth(200)
        self.searchbutton = QtGui.QPushButton()
        self.error_msg = QtGui.QMessageBox()
        self.error_msg.setIcon(QtGui.QMessageBox.Critical)
        self.error_msg.setWindowTitle("Error")
        self.closebutton = QtGui.QPushButton()
        self.closebutton = QtGui.QPushButton()
        self.closebutton.setText('Close')
        self.closebutton.setMaximumWidth(150)
        self.closebutton.clicked.connect(self.close)
        self.searchbutton.setText("Search")
        self.searchbutton.setMaximumWidth(100)
        self.progressbar = QtGui.QProgressBar()
        self.lbl1 = QtGui.QLabel()
        self.buttonRefresh = QtGui.QPushButton()
        self.buttonRefresh.setText("Refresh sources")
        self.isWrittenTo = False
        self.table = QtGui.QTableWidget()
        self.configureTable(self.table)
        self.searchbutton.clicked.connect(lambda: self.searchForPPA(self.table))
        self.buttonRefresh.clicked.connect(self.updateSources)
        self.table.verticalHeader().hide()
        self.horizontalLayout = QtGui.QHBoxLayout()
        self.horizontalLayout.addWidget(self.searchEditText)
        self.horizontalLayout.addWidget(self.searchbutton)
        self.horizontalLayout.setAlignment(QtCore.Qt.AlignRight)
        self.horizontalLayout2 = QtGui.QHBoxLayout()
        self.horizontalLayout2.setAlignment(QtCore.Qt.AlignRight)
        self.horizontalLayout2.addWidget(self.progressbar)
        self.horizontalLayout2.addWidget(self.buttonRefresh)
        self.horizontalLayout2.addWidget(self.closebutton)
        self.verticalLayout = QtGui.QVBoxLayout(self)
        self.verticalLayout.addLayout(self.horizontalLayout)
        self.verticalLayout.addWidget(self.table)
        self.verticalLayout.addWidget(self.lbl1)
        self.verticalLayout.addLayout(self.horizontalLayout2)
        self.os_info = lsb_release.get_lsb_information()
        self.sources = sourceslist.SourcesList()

        self.aprogress = UIAcquireProgress(True)
        self.thread1 = QtCore.QThread()
        self.aprogress.moveToThread(self.thread1)
        self.thread1.started.connect(lambda: self.aprogress.play(0.0, False, ""))
        self.aprogress.finished.connect(self.thread1.quit)
        self.connect(self.aprogress, QtCore.SIGNAL("updateProgressBar2(int, bool, QString)"), self.updateProgressBar2)

        self.ppa = []
        self.table_data = []
Example #20
0
    def __init__(self, parent=None):
        cprint("RESETTER-CLI [ALPHA]", 'white', 'on_blue', attrs=['bold', 'underline'])

        self.loop = True
        self.euid = os.geteuid()
        self.os_info = lsb_release.get_lsb_information()
        self.d_env = Settings()
        self.spinner = Spinner()
        self.manifest = self.d_env.manifest
        self.userlist = self.d_env.userlist
        self.user = self.d_env.user
        self.isWritten = False
        self.isDone = False
        self.non_defaults = []
Example #21
0
def main():
    check_euid()
    check_codename()
    codename = lsb_release.get_lsb_information()['CODENAME']
    username = parsed_args.username
    password = parsed_args.password
    check_enabled(codename)
    import_key()
    cred_file(username, password)
    add_repository(codename)
    pin_packages(codename)
    update_apt_cache()
    install_fips_packages(codename)
    configure_grub(get_boot_dev())
    update_grub()
    print("Done! Please reboot.")
Example #22
0
def log_execution_env_state(app_args, gitroot='.'):
    """Log information about the execution environment.

    It is recommeneded to log this information so it can be used for referencing
    at a later time.

    Args:
        app_args (dict): the command line arguments passed to the application
        git_root: the path to the .git root directory
    """
    def log_git_state():
        """Log the state of the git repository.

        It is useful to know what git tag we're using, and if we have outstanding code.
        """
        try:
            repo = Repo(gitroot)
            assert not repo.bare
        except InvalidGitRepositoryError:
            logger.debug(
                "Cannot find a Git repository.  You probably downloaded an archive of Distiller."
            )
            return

        if repo.is_dirty():
            logger.debug("Git is dirty")
        try:
            branch_name = repo.active_branch.name
        except TypeError:
            branch_name = "None, Git is in 'detached HEAD' state"
        logger.debug("Active Git branch: %s", branch_name)
        logger.debug("Git commit: %s" % repo.head.commit.hexsha)

    logger.debug("Number of CPUs: %d", len(os.sched_getaffinity(0)))
    logger.debug("Number of GPUs: %d", torch.cuda.device_count())
    logger.debug("CUDA version: %s", torch.version.cuda)
    logger.debug("CUDNN version: %s", torch.backends.cudnn.version())
    logger.debug("Kernel: %s", platform.release())
    if HAVE_LSB:
        logger.debug("OS: %s",
                     lsb_release.get_lsb_information()['DESCRIPTION'])
    logger.debug("Python: %s", sys.version)
    logger.debug("PyTorch: %s", torch.__version__)
    logger.debug("Numpy: %s", np.__version__)
    log_git_state()
    logger.debug("Command line: %s", " ".join(app_args))
Example #23
0
def determine_variables(gyp_env_vars):
    if not gyp_env_vars.has_key('OS'):
        gyp_env_vars['OS'] = 'linux'

    try:
        # dectect version of build machine.
        import lsb_release
        gyp_env_vars['is_xenial'] = lsb_release.get_lsb_information(
        )['RELEASE'] == '16.04'
    except:
        gyp_env_vars['is_xenial'] = False
        print 'Can not import lsb_release.'

    config = defaults
    config.update(gyp_env_vars)

    # globals dictionary for evaluating conditions.
    eval_globals = config
    eval_globals['__builtins__'] = None

    for item in conditions:
        if len(item) != 2 and len(item) != 3:
            sys.exit('ERROR[gyp_trunk.py]: ill-format conditional block\n ' +
                     str(item))

        cond = item[0]
        variables = None
        if eval(cond, eval_globals):
            variables = item[1]
        elif len(item) == 3:
            variables = item[2]

        if variables:
            # Update variables from conditional block not overriding definitions from
            # environment and command line. A la |'var%': value| in gyp.
            for var, value in variables.items():
                check_assignment(var, value)
                if not gyp_env_vars.has_key(var):
                    config[var] = value

    return config
Example #24
0
def install_neovim():
    pkg_name = 'neovim'

    print('Adding neovim ppa...')
    lsb_codename = lsb_release.get_lsb_information()['CODENAME']
    filename = '/etc/apt/sources.list.d/neovim-ppa.list'
    line = 'deb http://ppa.launchpad.net/neovim-ppa/unstable/ubuntu {0} main\n'.format(lsb_codename)
    print('Using ppa: {}'.format(line))

    with open(filename, 'w') as f:
        os.chmod(filename, 0o644)
        f.write(line)

    # apt-get update after adding the ppa
    apt_get_update()

    apt_get_install(pkg_name)

    # Install neovim for python (for python plugins)
    apt_get_install('python-pip')
    subprocess.check_output(['pip', 'install', 'neovim'])
def update_rules(ruleset, comment):
    """
        Update iptables rules to match 'ruleset':

        - All rules from ruleset that are not present in iptables will be added to iptables.
        - All existing rules from iptables that have matching 'comment' but are not in ruleset will be removed from iptables
        - Ruleset gets persisted so all rules will be active after reboot
    """
    rules_changed = False
    # Add all rules that don't exist yet
    ruleset = [standardize_rule(rule) for rule in ruleset]
    for rule in ruleset:
        rule['comment'] = comment
        if not rule_exists(rule):
            rules_changed = True
            append_rule(rule)
    # Get all existing rules
    tables_chain_pairs = (
        ('filter', 'INPUT'),
        ('filter', 'FORWARD'),
        ('filter', 'OUTPUT'),
        ('nat', 'PREROUTING'),
        ('nat', 'POSTROUTING'),
        ('nat', 'OUTPUT'),
    )
    existing_rules = []
    for table, chain in tables_chain_pairs:
        existing_rules.extend(get_rules(table, chain))
    # Remove existing rules that aren't in the ruleset
    for existing_rule in existing_rules:
        if existing_rule.get('comment') == comment:
            if not contains_rule(existing_rule, ruleset):
                rules_changed = True
                delete_rule(existing_rule)
    # persist rules if they changed
    if rules_changed:
        if lsb_release.get_lsb_information()['RELEASE'] == "14.04":
            subprocess.check_call(['invoke-rc.d', 'iptables-persistent', 'save'])
        else:
            subprocess.check_call(['netfilter-persistent', 'save'])
def decapod():
    import shlex
    import subprocess
    import os
    import lsb_release
    import re

    pools = []
    cache = []

    if lsb_release.get_lsb_information()['RELEASE'] == '16.04':
        block_list = subprocess.check_output(
            ("lsblk", "--exclude", "1,2,7", "-d", "-P", "-o",
             "NAME,RO,RM,MODEL,ROTA,SIZE,MIN-IO", "-x", "SIZE"))
        block_list = block_list.decode("utf-8")
        for blockdev in block_list.splitlines():
            tokens = shlex.split(blockdev)
            current_block = {}
            for token in tokens:
                k, v = token.split("=", 1)
                current_block[k] = v.strip()
            if current_block['NAME'] == 'sda' or current_block['NAME'] == 'vda':
                continue
            if current_block['ROTA'] == '0':
                cache.append('/dev/' + current_block['NAME'])
                continue
            if current_block['MIN-IO'] == '4096':
                cache.append('/dev/' + current_block['NAME'])
                continue
            else:
                pools.append('/dev/' + current_block['NAME'])

        cmd = "route | grep default   | awk '{print $8}'"
        ps = subprocess.Popen(cmd,
                              shell=True,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.STDOUT)
        local_int = ps.communicate()[0].rstrip("\n")
        cmd = "ifconfig " + local_int + "| grep -v inet6 | grep inet | tr ':' ' ' | awk '{print $3}'"
        ps = subprocess.Popen(cmd,
                              shell=True,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.STDOUT)
        local_ip = ps.communicate()[0].rstrip("\n")

        hostname = os.uname()[1]
        match = re.search("ceph-mon", hostname)
        if match:
            decapod_type = 'monitor'
            return {'decapod_type': decapod_type, 'decapod_mgmt_ip': local_ip}
        match = re.search('ceph[0-9]*', hostname)
        if match:
            decapod_type = 'osd'
            return {
                'pools': pools,
                'cache': cache,
                'decapod_type': decapod_type,
                'decapod_mgmt_ip': local_ip
            }
        else:
            decapod_type = 'other'
            return {'decapod_type': decapod_type}
Example #27
0
def get_codename():
    # This function will get the codename of running Ubuntu
    info = get_lsb_information()
    return info['CODENAME']
Example #28
0
def log_execution_env_state(config_path=None, logdir=None, gitroot='.'):
    """Log information about the execution environment.

    File 'config_path' will be copied to directory 'logdir'. A common use-case
    is passing the path to a (compression) schedule YAML file. Storing a copy
    of the schedule file, with the experiment logs, is useful in order to
    reproduce experiments.

    Args:
        config_path: path to config file, used only when logdir is set
        logdir: log directory
        git_root: the path to the .git root directory
    """
    def log_git_state():
        """Log the state of the git repository.

        It is useful to know what git tag we're using, and if we have outstanding code.
        """
        try:
            repo = Repo(gitroot)
            assert not repo.bare
        except InvalidGitRepositoryError:
            logger.debug(
                "Cannot find a Git repository.  You probably downloaded an archive of Distiller."
            )
            return

        if repo.is_dirty():
            logger.debug("Git is dirty")
        try:
            branch_name = repo.active_branch.name
        except TypeError:
            branch_name = "None, Git is in 'detached HEAD' state"
        logger.debug("Active Git branch: %s", branch_name)
        logger.debug("Git commit: %s" % repo.head.commit.hexsha)

    logger.debug("Number of CPUs: %d", len(os.sched_getaffinity(0)))
    logger.debug("Number of GPUs: %d", torch.cuda.device_count())
    logger.debug("CUDA version: %s", torch.version.cuda)
    logger.debug("CUDNN version: %s", torch.backends.cudnn.version())
    logger.debug("Kernel: %s", platform.release())
    if HAVE_LSB:
        logger.debug("OS: %s",
                     lsb_release.get_lsb_information()['DESCRIPTION'])
    logger.debug("Python: %s", sys.version)
    logger.debug("PyTorch: %s", torch.__version__)
    logger.debug("Numpy: %s", np.__version__)
    log_git_state()
    logger.debug("Command line: %s", " ".join(sys.argv))

    if (logdir is None) or (config_path is None):
        return
    # clone configuration files to output directory
    # configs_dest = os.path.join(logdir, 'configs')
    # with contextlib.suppress(FileExistsError):
    #     os.makedirs(configs_dest)
    # if os.path.exists(os.path.join(configs_dest,
    #                                os.path.basename(config_path))):
    #     logger.debug('{} already exists in logdir'.format(
    #         os.path.basename(config_path) or config_path))
    # else:
    try:
        shutil.copy(config_path, logdir)
    except OSError as e:
        logger.debug('Failed to copy of config file: {}'.format(str(e)))
Example #29
0
import platform
from setuptools import setup

this_directory = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(this_directory, 'README.md'), encoding='utf-8') as f:
    long_description = f.read()

data_files = [
    ('etc/bash_completion.d',
     ['etc/bash_completion.d/sq', 'etc/bash_completion.d/squirrel']),
    ('etc/profile.d', ['etc/profile.d/sq.sh']),
]

if platform.system() == 'Linux':
    import lsb_release
    lsb_info = lsb_release.get_lsb_information()
    if lsb_info['ID'] == 'Ubuntu':
        extra_data_files = [('/{}'.format(data_file[0]), data_file[1])
                            for data_file in data_files]
        data_files = data_files + extra_data_files

setup(name='squirrel-bookmarks',
      version='0.1.7',
      description='Bookmark system between development branches.',
      long_description=long_description,
      long_description_content_type='text/markdown',
      author='johnlinp',
      author_email='*****@*****.**',
      url='https://github.com/johnlinp/squirrel-bookmarks',
      license='New BSD License',
      python_requires='>=3.5',
Example #30
0
    def __init__(self, parent=None):
        super(UiMainWindow, self).__init__(parent)
        QtGui.QApplication.setStyle("GTK")
        self.setWindowIcon(
            QtGui.QIcon('/usr/lib/resetter/data/icons/resetter-launcher2.png'))
        self.error_msg = QtGui.QMessageBox()
        self.error_msg.setIcon(QtGui.QMessageBox.Critical)
        self.error_msg.setWindowTitle("Error")
        self.euid = os.geteuid()
        self.detectRoot()
        directory = ".resetter/data"
        logdir = "/var/log/resetter"
        manifests = "/usr/lib/resetter/data/manifests"
        if not os.path.exists(logdir):
            os.makedirs(logdir)
        self.logger = logging.getLogger(__name__)
        self.logger.setLevel(logging.DEBUG)
        handler = logging.FileHandler('/var/log/resetter/resetter.log')
        handler.setLevel(logging.DEBUG)
        formatter = logging.Formatter(
            '%(asctime)s - %(name)s - %(funcName)s - %(levelname)s - %(message)s'
        )
        handler.setFormatter(formatter)
        self.logger.addHandler(handler)
        if 'PKEXEC_UID' in os.environ:
            self.logger.debug('Program was called via pkexec')
            self.user = pwd.getpwuid(int(os.environ["PKEXEC_UID"])).pw_name
            working_dir = '/home/{}'.format(self.user)
            os.chdir(working_dir)
        elif self.euid == 0 and 'PKEXEC_UID' not in os.environ:
            self.logger.debug("program was called via sudo or gksu")
        #self.uidChange = pwd.getpwnam(self.user).pw_uid
        #os.setuid(self.uidChange)
        #os.seteuid(os.environ["PKEXEC_UID"])
        if not os.path.exists(directory):
            os.makedirs(directory)
        os.chdir(directory)
        cwd = os.getcwd()
        data_dir = os.path.abspath(cwd + "/manifests")
        self.copy(manifests, data_dir)
        #os.seteuid(0)
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose, True)
        self.resize(850, 650)
        palette = QtGui.QPalette()

        self.setPalette(palette)
        self.menubar = QtGui.QMenuBar(self)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 798, 25))
        self.menuFile = QtGui.QMenu(self.menubar)
        self.menuTools = QtGui.QMenu(self.menubar)
        self.menuHelp = QtGui.QMenu(self.menubar)
        self.setMenuBar(self.menubar)
        self.statusbar = QtGui.QStatusBar(self)
        self.setStatusBar(self.statusbar)
        self.actionOpen = QtGui.QAction(self)
        self.actionSaveSnapshot = QtGui.QAction(self)
        self.actionSaveSnapshot.setStatusTip(
            'Save a snapshot of currently installed packages')
        self.actionOpen.triggered.connect(self.openManifest)
        self.actionSaveSnapshot.triggered.connect(self.save)
        self.actionExit = QtGui.QAction(self)
        self.actionExit.setShortcut('Ctrl+Q')
        self.actionExit.setStatusTip('Exit application')
        self.actionExit.triggered.connect(QtGui.qApp.quit)
        self.actionAbout = QtGui.QAction(self)
        self.actionAbout.triggered.connect(self.about)
        self.actionShow_Installed = QtGui.QAction(self)
        self.actionShow_Installed.setStatusTip(
            'Show list of installed packages')
        self.actionShow_Installed.triggered.connect(self.showInstalled)
        self.menuFile.addAction(self.actionOpen)
        self.menuFile.addAction(self.actionSaveSnapshot)
        self.menuFile.addSeparator()
        self.menuFile.addAction(self.actionExit)
        self.menuTools.addAction(self.actionShow_Installed)
        self.menuHelp.addAction(self.actionAbout)
        self.menubar.addAction(self.menuFile.menuAction())
        self.menubar.addAction(self.menuTools.menuAction())
        self.menubar.addAction(self.menuHelp.menuAction())
        self.menuFile.setTitle("File")
        self.menuTools.setTitle("Tools")
        self.menuHelp.setTitle("Help")
        self.actionExit.setText("Exit")
        self.actionOpen.setText("Open manifest")
        self.actionSaveSnapshot.setText('Save')
        self.actionAbout.setText("About")
        self.actionCustom_Reset = QtGui.QAction(self)
        self.menuTools.addAction(self.actionCustom_Reset)
        self.actionCustom_Reset.setText("Custom Reset")
        self.actionCustom_Reset.setStatusTip('Custom Reset')
        self.actionCustom_Reset.triggered.connect(self.customReset)
        self.actionShow_Installed.setText("Show installed")
        font = QtGui.QFont()
        font.setPointSize(25)
        button_style = ("""
                    QPushButton {
                    color: #333;
                    border: 2px solid #555;
                    background-color: #99ccff;
                    border-radius: 30px;
                    padding: 5px;
                    background: qradialgradient(cx: 0.5, cy: -0.6,
                    fx: -0.5, fy: 0.6,
                    radius: 1.35, stop: 0 #fff, stop: 1 #888);
                    }

                    QPushButton:hover {
                    background: qradialgradient(cx: 0.5, cy: 0.3,
                    fx: 0.5, fy: 0.3,
                    radius: 1.35, stop: 0 #fff, stop: 1 #888);
                    min-width: 80px;
                    }

                    QPushButton:pressed {
                    background: qradialgradient(cx: 0.7, cy: -0.7,
                    fx: 0.7, fy: -0.7,
                    radius: 1.35, stop: 0 #fff, stop: 1 #888);
                    }

                    """)
        self.btnReset = QtGui.QPushButton(self)
        self.btnReset.setText("Automatic Reset", )
        self.btnReset.setFixedSize(614, 110)
        self.btnReset.setFont(font)
        self.btnReset.setStyleSheet(button_style)
        self.btnReset.setIcon(
            QtGui.QIcon('/usr/lib/resetter/data/icons/auto-reset-icon.png'))
        self.btnReset.setIconSize(QtCore.QSize(130, 150))
        self.btnReset.clicked.connect(self.warningPrompt)
        self.btnCustomReset = QtGui.QPushButton(self)
        self.btnCustomReset.setText("Custom Reset")
        self.btnCustomReset.setFixedSize(614, 110)
        self.btnCustomReset.setFont(font)
        self.btnCustomReset.setStyleSheet(button_style)
        self.btnCustomReset.clicked.connect(self.customReset)
        self.btnCustomReset.setIcon(
            QtGui.QIcon('/usr/lib/resetter/data/icons/custom-reset-icon.png'))
        self.btnCustomReset.setIconSize(QtCore.QSize(80, 80))
        self.centralWidget = QtGui.QWidget()
        self.os_version_label = QtGui.QLabel()
        self.os_name_label = QtGui.QLabel()
        self.os_codename_label = QtGui.QLabel()
        self.os_info = lsb_release.get_lsb_information()
        dse = QtGui.QGraphicsDropShadowEffect()
        dse.setBlurRadius(5)
        self.os_name_label.setText('OS Name: ' + self.os_info['ID'])
        self.os_version_label.setText('OS version: ' + self.os_info['RELEASE'])
        self.os_name_label.setGraphicsEffect(dse)
        self.os_codename_label.setText('codename: ' + self.os_info['CODENAME'])
        self.image_label = QtGui.QLabel()
        self.pixmap = QtGui.QPixmap(
            "/usr/lib/resetter/data/icons/resetter-logo.png")
        self.pixmap2 = self.pixmap.scaled(614, 182)
        self.image_label.setPixmap(self.pixmap2)
        self.verticalLayout = QtGui.QVBoxLayout()
        self.verticalLayout2 = QtGui.QVBoxLayout()
        self.verticalLayout2.addWidget(self.os_name_label)
        self.verticalLayout2.addWidget(self.os_version_label)
        self.verticalLayout2.addWidget(self.os_codename_label)
        self.verticalLayout2.setAlignment(QtCore.Qt.AlignRight)
        self.verticalLayout.setAlignment(QtCore.Qt.AlignCenter)
        self.verticalLayout.addWidget(self.image_label)
        self.verticalLayout.addLayout(self.verticalLayout2)
        self.verticalLayout.addWidget(self.btnReset)
        self.verticalLayout.addWidget(self.btnCustomReset)
        self.centralWidget.setLayout(self.verticalLayout)
        self.setCentralWidget(self.centralWidget)
        self.center()
        self.manifest = self.detectOS()
        print self.manifest
Example #31
0
def log_execution_env_state(config_paths=None, logdir=None, gitroot='.'):
    """Log information about the execution environment.

    Files in 'config_paths' will be copied to directory 'logdir'. A common use-case
    is passing the path to a (compression) schedule YAML file. Storing a copy
    of the schedule file, with the experiment logs, is useful in order to
    reproduce experiments.

    Args:
        config_paths: path(s) to config file(s), used only when logdir is set
        logdir: log directory
        git_root: the path to the .git root directory
    """
    def log_git_state():
        """Log the state of the git repository.

        It is useful to know what git tag we're using, and if we have outstanding code.
        """
        try:
            repo = Repo(gitroot)
            assert not repo.bare
        except InvalidGitRepositoryError:
            logger.debug(
                "Cannot find a Git repository.  You probably downloaded an archive of Distiller."
            )
            return

        if repo.is_dirty():
            logger.debug("Git is dirty")
        try:
            branch_name = repo.active_branch.name
        except TypeError:
            branch_name = "None, Git is in 'detached HEAD' state"
        logger.debug("Active Git branch: %s", branch_name)
        logger.debug("Git commit: %s" % repo.head.commit.hexsha)

    try:
        num_cpus = len(os.sched_getaffinity(0))
    except AttributeError:
        num_cpus = os.cpu_count()
    logger.debug("Number of CPUs: %d", num_cpus)
    logger.debug("Number of GPUs: %d", torch.cuda.device_count())
    logger.debug("CUDA version: %s", torch.version.cuda)
    logger.debug("CUDNN version: %s", torch.backends.cudnn.version())
    logger.debug("Kernel: %s", platform.release())
    if HAVE_LSB:
        logger.debug("OS: %s",
                     lsb_release.get_lsb_information()['DESCRIPTION'])
    logger.debug("Python: %s", sys.version)
    try:
        logger.debug("PYTHONPATH: %s", os.environ['PYTHONPATH'])
    except KeyError:
        pass

    def _pip_freeze():
        return {
            x.key: x.version
            for x in sorted(pkg_resources.working_set,
                            key=operator.attrgetter('key'))
        }

    logger.debug("pip freeze: {}".format(_pip_freeze()))
    log_git_state()
    logger.debug("Command line: %s", " ".join(sys.argv))

    if (logdir is None) or (config_paths is None):
        return

    # clone configuration files to output directory
    configs_dest = os.path.join(logdir, 'configs')

    if isinstance(config_paths, str) or not hasattr(config_paths, '__iter__'):
        config_paths = [config_paths]
    for cpath in config_paths:
        os.makedirs(configs_dest, exist_ok=True)

        if os.path.exists(os.path.join(configs_dest, os.path.basename(cpath))):
            logger.debug('{} already exists in logdir'.format(
                os.path.basename(cpath) or cpath))
        else:
            try:
                shutil.copy(cpath, configs_dest)
            except OSError as e:
                logger.debug('Failed to copy of config file: {}'.format(
                    str(e)))
Example #32
0
def get_codename():
    info = lsb_release.get_lsb_information()
    codename = info['CODENAME']
    return codename
description = raw_input("Enter a description for this FISH package.\n")

#extract old FISH package
package_dir = tempfile.mkdtemp()
atexit.register(walk_cleanup, package_dir)
rfd = tarfile.open(parser_args.fname)
rfd.extractall(package_dir)

xml_file = os.path.join(package_dir, 'prepackage.dell')

#write XML object
xml_obj = BTOxml()
if os.path.exists(xml_file):
    xml_obj.load_bto_xml(xml_file)
xml_obj.replace_node_contents('os', lsb_release.get_lsb_information()['RELEASE'])
xml_obj.append_fish('driver', description, 'n/a')
xml_obj.write_xml(xml_file)

#repack FISH package
output_dirname = os.path.dirname(parser_args.fname)
output_fname = parser_args.fname.split('.tar.gz')[0].split('.tgz')[0] + '.fish.tar.gz'
wfd = tarfile.open(output_fname, 'w:gz')
for obj in os.listdir(package_dir):
    wfd.add(os.path.join(package_dir, obj), obj)

print ("Wrote updated FISH package to %s") % output_fname
print ("File contents:")
wfd.list()
wfd.close()
Example #34
0
exportDB = exportDir+"shape.sqlite3"
shapeDB = exportDir+"noannotation.sqlite3"
jsondata = json.load(open(originalDir+'module.settings'))
srid = jsondata['srid']
arch16nFiles=[]
for file in glob.glob(originalDir+"*.properties"):
    arch16nFiles.append(file)

arch16nFile = next((s for s in arch16nFiles if '.0.' in s), arch16nFiles[0])
# print jsondata
moduleName = clean(jsondata['name'])
fileNameType = "Identifier" #Original, Unchanged, Identifier



if lsb_release.get_lsb_information()['RELEASE'] == '16.04':
    LIBSPATIALITE = 'mod_spatialite.so'
else:
    LIBSPATIALITE = 'libspatialite.so.5'


images = None
overrideFormattedIdentifiers = None
try:
    foo= json.load(open(sys.argv[3],"r"))
    # print foo["Export Images and Files?"]
    if (foo["Export Images and Files?"] != []):
        images = True
    else:
        images = False
    # Ugh. But the interface is buggy.
SEMT_DOWNLOAD = True
#SEMT_REDOWNLOAD=True  # you can comment out this, once it has reinstalled SEMT. This is only needed for the travis CI test cases which use an older docker container for the builds.

# EasyLoggingPP
EASYLOGGINGPP_DOWNLOAD = True
#EASYLOGGINGPP_REDOWNLOAD=True

# MPI
# MPI is normally detected using mpicc. If this is not available, you can provide the MPI_DIR as usual.
MPI_DIR = "/usr/lib/openmpi"  # standard path for ubuntu 16.04
#MPI_DIR="/usr/lib64/mpich/"

# automatically set MPI_DIR for ubuntu 18.04
try:
    import lsb_release
    lsb_info = lsb_release.get_lsb_information(
    )  # get information about ubuntu version, if available
    if "RELEASE" in lsb_info:
        if lsb_info["RELEASE"] == "18.04":
            MPI_DIR = "/usr/lib/x86_64-linux-gnu/openmpi"  # this is the path for ubuntu 18.04

    # use value of environment variable 'MPI_HOME' if it is set
    import os
    if os.environ.get("MPI_HOME") is not None:
        MPI_DIR = os.environ.get("MPI_HOME")

    # for Travis CI build MPI ourselves
    if os.environ.get("TRAVIS") is not None:
        print "Travis CI detected, del MPI_DIR"
        del MPI_DIR
        MPI_DOWNLOAD = True
Example #36
0
def check_codename():
    if lsb_release.get_lsb_information(
    )['CODENAME'] not in acceptable_codenames:
        print("This script is not supported on your OS release.")
        sys.exit(1)
Example #37
0
finalExportDir = sys.argv[2] + "/"
importDB = originalDir + "db.sqlite3"
exportDB = exportDir + "shape.sqlite3"
shapeDB = exportDir + "noannotation.sqlite3"
jsondata = json.load(open(originalDir + 'module.settings'))
srid = jsondata['srid']
arch16nFiles = []
for file in glob.glob(originalDir + "*.properties"):
    arch16nFiles.append(file)

arch16nFile = next((s for s in arch16nFiles if '.0.' in s), arch16nFiles[0])
# print jsondata
moduleName = clean(jsondata['name'])
fileNameType = "Identifier"  #Original, Unchanged, Identifier

if lsb_release.get_lsb_information()['RELEASE'] == '16.04':
    LIBSPATIALITE = 'mod_spatialite.so'
else:
    LIBSPATIALITE = 'libspatialite.so.5'

images = None
overrideFormattedIdentifiers = None
try:
    foo = json.load(open(sys.argv[3], "r"))
    images = True
    apiKey = foo["Alveo APIkey"]
    collectionName = foo["Collection Name"]
    # Ugh. But the interface is buggy.
    if (foo["Export identifier components in plain as well as formatted state (if in doubt, leave the setting as is)?"]
            != []):
        overrideFormattedIdentifiers = False
Example #38
0
def get_codename():
    # This function will get the codename of running Ubuntu
    info = get_lsb_information()
    return info['CODENAME']
description = raw_input("Enter a description for this FISH package.\n")

#extract old FISH package
package_dir = tempfile.mkdtemp()
atexit.register(walk_cleanup, package_dir)
rfd = tarfile.open(parser_args.fname)
rfd.extractall(package_dir)

xml_file = os.path.join(package_dir, 'prepackage.dell')

#write XML object
xml_obj = BTOxml()
if os.path.exists(xml_file):
    xml_obj.load_bto_xml(xml_file)
xml_obj.replace_node_contents('os',
                              lsb_release.get_lsb_information()['RELEASE'])
xml_obj.append_fish('driver', description, 'n/a')
xml_obj.write_xml(xml_file)

#repack FISH package
output_dirname = os.path.dirname(parser_args.fname)
output_fname = parser_args.fname.split('.tar.gz')[0].split(
    '.tgz')[0] + '.fish.tar.gz'
wfd = tarfile.open(output_fname, 'w:gz')
for obj in os.listdir(package_dir):
    wfd.add(os.path.join(package_dir, obj), obj)

print("Wrote updated FISH package to %s") % output_fname
print("File contents:")
wfd.list()
wfd.close()