Example #1
1
    def _reboot_buildout(self):
        # rerun bootstrap to recreate bin/buildout with
        # the virtualenf python as the interpreter
        buildout_dir = self.buildout["buildout"]["directory"]
        bootstrap_path = buildout_dir + "/bootstrap.py"
        cmd_list = [self.python_cmd]
        if os.path.exists(bootstrap_path):
            cmd_list.append(bootstrap_path)
            # cmd_list.extend(self.buildout_args)
        else:
            cmd_list.append(self.buildout_path)
            cmd_list.extend(self.buildout_args)
            cmd_list.append("bootstrap")
        subprocess.call(cmd_list)

        # rerun buildout if it isn't running under the
        # virtualenv interpreter
        self.logger.info(sys.executable)
        if sys.executable != self.python_cmd:
            cmd_list = [self.buildout_path]
            cmd_list.extend(self.buildout_args)
            self.logger.info("Rebooting buildout")
            subprocess.call(cmd_list)

            sys.exit()

        pass
Example #2
0
 def stress(self, stress_options):
     stress = common.get_stress_bin(self.get_cassandra_dir())
     args = [ stress ] + stress_options
     try:
         subprocess.call(args)
     except KeyboardInterrupt:
         pass
Example #3
0
def dispatch_to_slurm(commands):
    scripts = {}

    for job_name, command in commands.iteritems():
        script = submit(command, job_name=job_name, time="0",
                        memory="{}G".format(maxmem), backend="slurm",
                        shell_script="#!/usr/bin/env bash")
        script += " --partition={}".format(partition)
        script += " --ntasks=1"
        script += " --cpus-per-task={}".format(maxcpu)
        script += " --mail-type=END,FAIL"
        script += " --mail-user={}".format(email)
        scripts[job_name] = script

    scheduled_jobs = set(queued_or_running_jobs())

    for job_name, script in scripts.iteritems():
        if job_name not in scheduled_jobs:
            if verbose:
                print("{}".format(script), file=sys.stdout)

            if not dry_run:
                subprocess.call(script, shell=True)
        else:
            print("{} already running, skipping".format(job_name),
                  file=sys.stderr)
Example #4
0
    def OnButton1Click(self):
        self.labelVariable.set( self.entryVariable.get()+" pocket" )
        #execfile("pocket_V1.py")
	#pocket_V1.main() # do whatever is in test1.py
        subprocess.call("./pocket_V1.py", shell=True)
        self.entry.focus_set()
        self.entry.selection_range(0, Tkinter.END)
Example #5
0
    def configure_linter(self, language):
        """Fill out the template and move the linter into Packages."""

        try:
            if language is None:
                return

            if not self.fill_template(self.temp_dir, self.name, self.fullname, language):
                return

            git = util.which('git')

            if git:
                subprocess.call((git, 'init', self.temp_dest))

            shutil.move(self.temp_dest, self.dest)

            util.open_directory(self.dest)
            self.wait_for_open(self.dest)

        except Exception as ex:
            sublime.error_message('An error occurred while configuring the plugin: {}'.format(str(ex)))

        finally:
            if self.temp_dir and os.path.exists(self.temp_dir):
                shutil.rmtree(self.temp_dir)
Example #6
0
def setup():
  import subprocess

  line_break()
  print("Installing python2.7...")
  subprocess.call(['brew', 'install', 'python'])

  line_break()
  print("Installing pip...")
  subprocess.call(['easy_install-2.7', 'pip'])
  # if you got permissions issues and bad install, use this
  # subprocess.call(['sudo', 'easy_install-2.7', 'pip'])

  line_break()
  print("Installing Fabric...")
  subprocess.call(['pip', 'install', 'fabric'])

  line_break()
  print("Installing YAML...")
  subprocess.call(['pip', 'install', 'PyYAML'])

  line_break()
  print("Installing terminal-notifier...")
  subprocess.call(['gem', 'install', 'terminal-notifier'])

  line_break()
  print("DONE!  You're good to go!")
Example #7
0
def share(filename):
    # TODO: Move this connection handling into a function in Kano Utils
    import subprocess

    if not is_internet():
        subprocess.call(['sudo', 'kano-settings', '4'])

    if not is_internet():
        return 'You have no internet'

    success, _ = login_using_token()
    if not success:
        os.system('kano-login 3')
        success, _ = login_using_token()
        if not success:
            return 'Cannot login'

    data = json.loads(request.data)
    filename, filepath = _save(data)
    success, msg = upload_share(filepath, filename, APP_NAME)

    if not success:
        return msg

    increment_app_state_variable_with_dialog(APP_NAME, 'shared', 1)

    return ''
Example #8
0
 def push(self, ssh_options, file):
   master = self._get_master()
   if not master:
     sys.exit(1)
   subprocess.call('scp %s -r %s ubuntu@%s:' % (xstr(ssh_options),
                                              file, master.public_ip),
                                              shell=True)
Example #9
0
def generate_image(now):
    """
    Generate the GEMPAK file!
    """
    cmd = "csh mwplot.csh %s" % (
                                        now.strftime("%Y %m %d %H %M"),)
    subprocess.call(cmd, shell=True)
def help_boot_avd():
    try:
        emulator = get_identifier()

        # Wait for the adb to answer
        args = [settings.ADB_BINARY,
                "-s",
                emulator,
                "wait-for-device"]
        logger.info("help_boot_avd: wait-for-device")
        subprocess.call(args)

        # Make sure adb running as root
        logger.info("help_boot_avd: root")
        adb_command(['root'])

        # Make sure adb running as root
        logger.info("help_boot_avd: remount")
        adb_command(['remount'])

        # Make sure the system verity feature is disabled (Obviously, modified the system partition)
        logger.info("help_boot_avd: disable-verity")
        adb_command(['disable-verity'])

        # Make SELinux permissive - in case SuperSu/Xposed didn't patch things right
        logger.info("help_boot_avd: setenforce")
        adb_command(['setenforce', '0'], shell=True)

        logger.info("help_boot_avd: finished!")
        return True
    except:
        PrintException("help_boot_avd")
        return False
Example #11
0
def open_file(fname):
    if sys.platform.startswith('darwin'):
        subprocess.call(('open', fname))
    elif os.name == 'nt':
        os.startfile(fname)
    elif os.name == 'posix':
        subprocess.call(('xdg-open', fname))
Example #12
0
def cloneFromGit():
    global clone_dir,git_path
    try:
        subprocess.call('/usr/bin/git clone '+git_path+' '+clone_dir,shell=True)
    except Exception as e:
        print e
        sys.exit(1)
Example #13
0
    def test_s_option(self):
        usersite = site.USER_SITE
        self.assertIn(usersite, sys.path)

        rc = subprocess.call([sys.executable, '-c',
            'import sys; sys.exit(%r in sys.path)' % usersite])
        self.assertEqual(rc, 1)

        rc = subprocess.call([sys.executable, '-s', '-c',
            'import sys; sys.exit(%r in sys.path)' % usersite])
        self.assertEqual(rc, 0)

        env = os.environ.copy()
        env["PYTHONNOUSERSITE"] = "1"
        rc = subprocess.call([sys.executable, '-c',
            'import sys; sys.exit(%r in sys.path)' % usersite],
            env=env)
        self.assertEqual(rc, 0)

        env = os.environ.copy()
        env["PYTHONUSERBASE"] = "/tmp"
        rc = subprocess.call([sys.executable, '-c',
            'import sys, site; sys.exit(site.USER_BASE.startswith("/tmp"))'],
            env=env)
        self.assertEqual(rc, 1)
Example #14
0
def get_task(task_id, src_id):
    print task_id
    print src_id
    task = filter(lambda t: t['dst'][:5] == task_id[:5], tasks)
    new_task = filter(lambda t: t['src'][:5] == src_id[:5], task)
    if len(new_task) == 0:
	print "cannot find the ip " + task_id + " from the database"
        print "calling king service from server"
	print subprocess.call(["../king/bin/king", src_id, task_id], stdout=open('log.txt','a'))
	re_tasks = []
	with open('out.txt') as ff:
    		lines = ff.readlines()
    		for line in lines:
    			words = line.split(' ')
			re_task = {'src': words[1],
				'dst': words[4],
				'rtt': words[7],
				'bandwidth': words[11]}
			re_tasks.append(re_task)
	print re_tasks
	_task = filter(lambda t: t['dst'][:5] == task_id[:5], re_tasks)
    	inject_task = filter(lambda t: t['src'][:5] == src_id[:5], _task)
	print inject_task
	if len(inject_task) == 0:
		abort(404)
	print inject_task
	new_task = inject_task
    print new_task
    return jsonify( { 'task': make_public_task(new_task[0]) } )
Example #15
0
	def __init__(self):
		#try loading the config file
		# if it doesn't exist, create one
		try:
			self.configFile = expanduser("~") + "/.puut/puut.conf"
			#load configuration
			self.config = {}
			exec(open(self.configFile).read(),self.config)
		except IOError:
			self.setupPuut()
			call(["notify-send", "Puut: Setup config", "Setup your user data at '~/.puut/puut.conf'"])
			sys.exit(1)

		#testing if server & credentials are correct
		r = requests.get(self.config["serverAddress"] + "/info", auth=(self.config["user"],self.config["password"]))
		if not (r.text=="PUUT"):
			call(["notify-send", "Puut: Server error", "Contacting the server was unsuccessful, are credentials and server correct?\nResponse was: "+ r.text])
			sys.exit(1)		
		
		#setting up keyhooks
		for self.idx, self.val in enumerate(self.config["keys"]):
			keybinder.bind(self.val, self.hotkeyFired, self.idx) 

		#setup GTK Status icon
		self.statusicon = gtk.StatusIcon()
		self.statusicon.set_from_file("icon.png") 
		self.statusicon.connect("popup-menu", self.right_click_event)
		self.statusicon.set_tooltip("StatusIcon Example")
Example #16
0
    def do_lrun(self, argv):
        """Execute client-side shell command

        SYNOPSIS:
            lrun command [arg1 [arg2 [...] ] ]

        DESCRIPTION:
                Execute a shell command in your own operating system.
                This command works like the `exec` command in unix
                shells.
             
                NOTE: This core command shouldn't be confused with the
                `run` plugin, which does the same thing in the
                remotely exploited system.
             
        EXAMPLES:
            > lrun ls -la /
            > lrun htop
        """
        if len(argv) == 1:
            return self.interpret("help lrun")

        cmd = " ".join(argv[1:])

        if argv[1] != "exit":
            tmpfile = Path()
            postcmd = " ; pwd >'%s' 2>&1" % tmpfile
            subprocess.call(cmd + postcmd, shell=True)
            try:
                os.chdir(tmpfile.read())
            finally:
                del tmpfile
Example #17
0
 def login(self, ssh_options):
   master = self._get_master()
   if not master:
     sys.exit(1)
   subprocess.call('ssh %s ubuntu@%s' % \
                   (xstr(ssh_options), master.public_ip),
                   shell=True)
def dump_a_session(dbobj, str_session_id):
    """
    Using mongodump to export images in a session from hardcoded database 
    on slideatlas
    """
    sessionid = ObjectId("4ed62213114d971078000000")

    # Create a meta collection connecting to temp db

    conn = dbobj.connection
    db = conn["bev1"]
    sessionobj = db["sessions"].find_one({"_id" : ObjectId(str_session_id)})

#    for aviewid in sessionobj["views"]:
#        viewobj = db["views"].find_one({"_id" : aviewid["ref"]})
#        imgobj = db["images"].find_one({"_id" : viewobj["img"]})
#        print "Processing ", imgobj["filename"]
#        db["claw"].insert(imgobj)
#        params = [ "mongodump", "-h", "slide-atlas.org", "-u", "claw", "-p", "claw123", "-d", "bev1", "-c", str(imgobj["_id"]) ]
#        print params
#        call(params)
    params = [ "mongodump", "-h", "slide-atlas.org", "-u", "claw", "-p", "claw123", "-d", "bev1", "-c", "claw"]
    call(params)

    print "done"
Example #19
0
 def execute(self, ssh_options, args):
   master = self._get_master()
   if not master:
     sys.exit(1)
   subprocess.call("ssh %s root@%s '%s'" % (xstr(ssh_options),
                                            master.public_ip,
                                            " ".join(args)), shell=True)
Example #20
0
def render(filtered, args):
    print("> Regenerating haproxy configuration...")
    with file_or_stdout(args['--output']) as outf:
        outf.write(_generate_conf(filtered, args['<jinja2_template>']))

    if args['--run-cmd']:
        subprocess.call(args['--run-cmd'], shell=True)
Example #21
0
def StartTCPServer():
	userAddress = ""
	firstConn = 1
	TCP_IP = '0.0.0.0'
	TCP_PORT = 1337
	while(1):
		print("Starting TCP Server on {0}:{1}".format(TCP_IP,TCP_PORT))
		print("Configuring connection")
		s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
		s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
		s.bind((TCP_IP,TCP_PORT))
		print("Waiting for connection")
		try:
			s.listen(1)
			conn,addr = s.accept()
			if firstConn == 1:
				userAddress = str(addr[0])
				firstConn = 0
			print("Connected to: " + str(addr[0]) +":"+ str(addr[1]))
			while 1:
				if userAddress == str(addr[0]):
					data = conn.recv(BUFFER_SIZE)
					if not data: break
					data = data.decode()
					print("Data received: "+data)
					if data[:3] == Client.INIT_HEY:
						print("Initiallizing connection")
						conn.send((Server.INIT_OK+"\n").encode())
						print("Connection initiallized")
					elif data[:3] == Client.KTHXBYE:
						conn.send(Server.CLOSE.encode())
						clean()
					elif data[:3] == Client.CUSTOM_MOVE:
						data = str(data)
						formattedData = data.split(",")
						direction = formattedData[1]
						left = formattedData[2]
						right = formattedData[3]
						response = "URRAY"
						response = customSpeed(direction,left,right)
						print(direction+","+left+","+right)
						conn.send((str(response)+"\n").encode())
					elif data[:3] == Client.SHUTDOWN:
						conn.send("Shutdown Received")
						call(["shutdown", "now"])
					elif data[:3] == Client.REBOOT:
						conn.send("Rebbot received")
						call(["reboot"])
					else:
						print("Command not understood: "+data)
				else:
					print("Somebody else was trying to connect!!")
			conn.send(Server.CLOSE.encode())
		except KeyboardInterrupt:
			print("Rage Quit")
		except:
			print("Error happened:",sys.exc_info())
		finally:
			s.close()
			clean()
Example #22
0
def main():
    f1 = TFile("/afs/cern.ch/user/m/muell149/workb/HLTONLINE/CMSSW_7_0_0_pre1/src/DQMOffline/Trigger/test/700pre1DQM.root")
    f2 = TFile("/afs/cern.ch/user/m/muell149/workb/HLTONLINE/CMSSW_7_0_0_pre1/src/DQMOffline/Trigger/test/700pre2DQM.root")
    r1="700pre1"
    r2="700pre2"
    savePlotDir="DQM_plots/"+r1+"_"+r2+"/"
    cmd = "mkdir "+savePlotDir
    subprocess.call(cmd,shell=True)
    
    path1="DQMData/Run 1/HLT/Run summary/GeneralHLTOffline"
    f1.cd(path1)
    dir = f1.Get(path1)
    nextkey = dir.GetListOfKeys()
      
    for key in nextkey:
        h1 = key.ReadObj()
        #print "h1 before=",type(h1)
        if isinstance(h1,TH1F):
            print h1.GetName()
            if h1 is not None:
                hist_name = h1.GetName()
                path = "DQMData/Run 1/HLT/Run summary/GeneralHLTOffline/"+hist_name
                h2 = f2.Get(path)
                if h2 is not None:
                    #print "h2=",h2.GetName()
                    #print type(h1), type(h2)
                    #break
                    plot(h1,h2,r1,r2,savePlotDir)
def gen_moc():
  workDir = os.getcwd() + "/Gui"
  print workDir
  dirList = os.listdir(workDir)

  for files in 	dirList:
    if files.endswith(".h"):
      print files
      outp = "moc_" + files[:-2] + ".cpp"
      print outp
      affected = "./Gui/" + files
      call(["moc", affected, "-o", outp])
      #os.rename(outp, "./Gui/" + outp)
      l = -1
      f = open(outp)
      lines = f.readlines()
      f.close()
      for line in lines:
        if line[0] == '#':
            break;
        l = l + 1

      if l >= 0:
        f = open(outp, 'w');
        lines[l] = '\n#include "EdPrec.h"\n'
        f.writelines(lines)
        f.close()
      
      shutil.move(outp, "./Gui/" + outp)
Example #24
0
def main():
    active = []

    for streamer in streamers:
        x = twitch.searchStreams(streamer)
        if x:
            for stream in x:
                if stream['channel']['name'] == streamer:
                    active.append(stream)

    count = 0
    for result in active:
        print("{0} -{1}: {2}".format(count,
                                     result['channel']['name'],
                                     result['channel']['url']))
        count = count + 1

    choice = -99
    if count > 0:
        choice = input("Please select a stream (-99 to exit): ")

    if int(choice) != -99:
        url = active[int(choice)]['channel']['url']
        command = "livestreamer --player mpv {0} high".format(url)
        subprocess.call(shlex.split(command))
    else:
        print("No active streams.\n")
def bootstrap_file(task, semaphore):
    ct = threading.current_thread()
    semaphore.acquire()
    print("Running \"%s\"" % " ".join(task["command"]))
    with open(task["output"], "w") as log_fp:
        subp.call(task["command"], stdout=log_fp, stderr=subp.STDOUT)
    semaphore.release()
Example #26
0
def hype(jobguid):
  workdir = 'workdirs/{}'.format(jobguid)


  spin0 = os.path.abspath('hype_static/fake_spin0.yoda'.format(workdir))
  spin2 = os.path.abspath('{}/inputs/fake_spin2.yoda'.format(workdir))
  
  env = jinja2.Environment(undefined=jinja2.StrictUndefined)

  hypetmplt = 'hype_static/Higgs_spin0_vs_2_diphoton_hepdata.tmplt'
 

  log.info("trying to render template")
  with open(hypetmplt) as hypeRunTemplate:
    basename = os.path.basename(hypetmplt)
    filledtemplate = '{}/{}'.format(workdir,basename.rsplit('.',1)[0]+'.hype')

    template = env.from_string(hypeRunTemplate.read())

    with open(filledtemplate,'w+') as output:
        log.info("writing template to {}".format(filledtemplate))
        output.write(template.render({'SPIN_0_YODA':spin0,'SPIN_2_YODA':spin2}))


  logfile = '{}/hype.logfile'.format(workdir)
  log.info("trying to run hype and print to logfile {}".format(logfile))
  with open(logfile,'w') as logfile:
    subprocess.call(['hype/bin/hype',os.path.abspath(filledtemplate)], stdout = logfile)

  log.info('hype done')

  return jobguid
Example #27
0
def make_directories():
    input_base = os.path.dirname(input_root)
    command = ("find {} -type d | sed -n 's|{}||p' | "
               "parallel --gnu -j 4 mkdir -p {}/{{}}").format(input_root,
                                                              input_base,
                                                              output_root)
    subprocess.call(command, shell=True)
Example #28
0
 def create_profile_F(self):
     """Function to create the SSHTunnel Firefox profile
     All firefox instances must be closed
     (or they can be left open, but the function will killall firefox)        
     """
    
     
     subprocess.call(["killall", "firefox"]) #all firefox instance must be killed
     subprocess.check_call(["firefox","-CreateProfile","SSHTunnel"]) #Create a new Profile named SSHTunnel
   
     
     #Navigate to the profile folder:
     os.chdir('/home/'+ str(LOGNAME) +'/.mozilla/firefox/')
     list_of_items = os.listdir(os.getcwd())
     for folder in list_of_items:
         if 'SSHTunnel' in folder:
             os.chdir(folder)
             break
     else:
         raise Exception("Create new profile for firefox failed")
                     
     
     write_prefs_js()       
     
     self.launch_firefox_instance()
Example #29
0
def loop():
	time.sleep(1)
	
	print 'Check if server has stuff, and if so send to Arduino.'
	# When the Server **sends** data:
	# Write to the Arduino's Serial port.
	# Currently, timeout = 1
	data = get_from_server()
	if len(data) > 0:
		print "Got data: %s" % data
		try:
			print 'sending to arduino light?'
			shelf_num = int(data)
			light_shelf(shelf_num)
			time.sleep(5)
			print 'done sleeping'
		except:
			print 'oops not a number!'

	# When the Arduino **sends** data:
	# POST to the Server.
	print 'listening to arduino'
	tags_data = get_tags_from_arduino()
	print tags_data
	# Parse tags
	if tags_data is not None:
		tag_scan_pairs = []
		print tags_data
		for tag in tags_data.split('|'):
			if len(tag) == 0:
				continue
			tmp = tag.split(':')
			print tmp
			call(['afplay','beep-2.wav'])
			tag_to_server(int(tmp[0]), int(tmp[1]))
Example #30
0
    def update_map(self):
        """Update map images (Tilemill)
        """
        print "\n- Aggiorna cartine Tilemill"

        projectFileName = os.path.join(self.TILEMILLDIR, "project.mml")
        inFile = open(projectFileName)
        data = json.load(inFile)
        inFile.close()
        #print_layers_statuses(data)

        #create map img background
        imgFile = os.path.join("html", "img", "tilemill", "sfondo_errori.png")
        self.export_tilemill_img("sfondo_errori", imgFile)

        #create map img with all errors
        print "Total"
        self.enable_all_layers(data)
        self.save_tilemill_project(projectFileName, data)
        self.export_tilemill_img("tags_sbagliati", imgFile)
        #add a label over tilemill img
        call("convert %s -quality 100 -fill white -undercolor '#00000080' -gravity NorthWest -pointsize 24 -annotate +0+3 ' Tutti ' %s" % (imgFile, imgFile), shell=True)

        #create map img of each check
        for check in self.checks.values():
            if check.type != "tags":
                continue
            print check.name
            self.toggle_layers(check.name, data)
            self.save_tilemill_project(projectFileName, data)
            imgFile = os.path.join("html", "img", "tilemill", "%s.png" % check.name)
            self.export_tilemill_img("tags_sbagliati", imgFile)
            #add a label with the check name over tilemill image
            call("convert %s -quality 100 -fill white -undercolor '#00000080' -gravity NorthWest -pointsize 24 -annotate +0+3 ' %s ' %s" % (imgFile, check.title, imgFile), shell=True)