示例#1
0
def validate_translation(state):
    ### 0. model parameters
    prefix = state['prefix'][:-1]
    beam_size  = state['beam_size']
    ignore_unk = state['ignore_unk']

    sample_cmd = '--state {prefix}_state.pkl --verbose --beam-search --beam-size {beam_size}'.format(prefix=prefix, beam_size=beam_size)
    if ignore_unk:
        sample_cmd += ' --ignore-unk'

    ### 1. validate development sets
    dev_src = state['dev_src']
    dev_tgt = state['dev_tgt']
    dev_trs = state['dev_trs']

    cmd = 'python %s/sample.py %s --source %s.plain --trans %s_%s %s_model.npz' % (path, sample_cmd, dev_src, prefix, dev_trs, prefix)
    print cmd
    run(cmd)
    dev_bleu = eval_trans(dev_src + ".sgm", dev_tgt, prefix + '_' + dev_trs)
    print "development set bleu:\t", dev_bleu
    run('echo "Step:%s Development set bleu:%s" | cat >> %s_%s' % (state['step'], dev_bleu, prefix, state['dev_record']))

    ### 3. decide for save
    if not 'dev_score' in state:
        state['dev_score'] = -1.
    if dev_bleu > state['dev_score']:
        state['dev_score'] = dev_bleu
        save_valid_model(state)
        print "the best model is updated"
示例#2
0
def main():
    """
    Launch the training with different parametters
    """
    
    # TODO: define:
    # step+noize
    # log scale instead of uniform
    
    # Define parametter: [min, max]
    dictParams = {
        "batchSize": [int, [1, 3]]
        "learningRate": [float, [1, 3]]
        }
    
    # Training multiple times with different parametters
    for i in range(10):
        # Generate the command line arguments
        trainingArgs = ""
        for keyArg, valueArg in dictParams:
            value = str(random(valueArg[0], max=valueArg[1]))
            trainingArgs += " --" + keyArg + " " + value
            
        # Launch the program
        os.run("main.py" + trainingArgs)
示例#3
0
def main():
    """
    Launch the training with different parametters
    """

    # TODO: define:
    # step+noize
    # log scale instead of uniform

    # Define parametter: [min, max]
    dictParams = {
        "batchSize": [int, [1, 3]]
        "learningRate": [float, [1, 3]]
        }

    # Training multiple times with different parametters
    for i in range(10):
        # Generate the command line arguments
        trainingArgs = ""
        for keyArg, valueArg in dictParams:
            value = str(random(valueArg[0], max=valueArg[1]))
            trainingArgs += " --" + keyArg + " " + value

        # Launch the program
        os.run("main.py" + trainingArgs)
示例#4
0
 def open_repl_legacy(self, lang):
     """
     opens and voice interactive repl (does not read to the user)
     """
     #self.acknowledge()
     run('notify-send "mycroft" "runing repl"')
     term = self.settings.get("terminal")
     run(f"{term} -e {lang}")
示例#5
0
def serve():
    try:
        Popen('npm run webpack -- -w', shell=True)
        Popen('sass --watch ./_sass/main.sass:./assets/style.css', shell=True)
        run('cp -r ./node_modules/han-css/font/ ./assets/fonts/')
        Popen("bundle exec jekyll serve", shell=True).wait()
    finally:
        os.killpg(os.getpid(), signal.SIGTERM)
示例#6
0
def update():   #Trys to download an update, and alerts the runner, if the update was successfull
    run('git pull > update.lg')
    with open('update.lg', 'r') as f:
        c = f.read(-1).split('\n')
    remove('update.lg')
    if len(c) > 2:
       with open('Update_required', 'w') as f:
                pass
示例#7
0
def interface_download(request):
	a=commands.getstatusoutput("cd;cd files;pwd")[1]
	chdir(a)
	if request.method =="GET":
		email=request.GET.get('email')
		domain=request.META['HTTP_HOST']
		#send_mail('Subject here','Here is the message.','*****@*****.**',['*****@*****.**'],fail_silently=False,)
		email=""
		vlink=""
		pdflink=""
		category=""
		videotype=""
		if request.GET.get('videotype')==None:
			videotype=""
		else:
			videotype=request.GET.get('videotype')
		if request.GET.get('category')==None:
			category=""
		else:
			category=request.GET.get('category')
		if request.GET.get('vlink')==None:
			vlink=""
		else:
			vlink=request.GET.get('vlink')
		if request.GET.get('pdflink')==None:
			pdflink=""
		else:
			pdflink=request.GET.get('pdflink')
		if request.GET.get('email')==None:
			email=""
		else:
			email=request.GET.get('email')
		vlink.replace(" ","")
		pdflink.replace(" ","")
		site="http://"+domain+"/interface/convert/?vlink="+vlink+"&pdflink="+pdflink+"&email="+email+"&category="+category+"&videotype="+videotype
		context={
			"title":"Download completed and Conversion is going on....Please Wait...",
			"site":site,
			"progress":"20"
		}

		#time.sleep(3)
		#files script for downloading
		command=''
		if videotype=="1":
			command='rm -f download.mp4;chmod +x youtube_video.sh;./youtube_video.sh "'+vlink+'"'
		else:
			command='rm -f download.mp4;chmod +x other_video.sh;./other_video.sh "'+vlink+'"'
		run(command)
		command=''
		if pdflink=="":
			pass
			#command="chmod +x without_pdf.sh;./without_pdf.sh "+vlink
			#run(command)
		else:
			command='rm -f document.pdf;chmod +x download_pdf.sh;./download_pdf.sh "'+pdflink+'"'
			run(command)
		return render(request,"index.html",context)
def main():
    run('git pull > update.lg')
    with open('update.lg', 'r') as f:
        c = f.read(-1).split('\n')
    remove('update.lg')
    if len(c) > 2:
        return True
    else:
        return False
示例#9
0
def _kill(s):
    cmd = 'ps aux | grep %s' % s
    output = getoutput(cmd)
    lines = output.split('\n')
    for line in lines:
        if 'grep' not in line:
            params = line.split()
            pid = params[1]
            run('kill -9 %s' % pid)
 def main(args):
     if len(args) < 2:
         print('markdown->pdf helper(built on pandoc+xelatx)')
         print(f'usage:python {args[0]} {{name}}')
         print(f'\t{{name}}.md->{{name}}.pdf')
         return
     from os import system as run
     name = args[1]
     run(f'pandoc {name}.md -o {name}.pdf  --template eisvogel --listings --pdf-engine=xelatex'
         )
示例#11
0
def main():

    params = {"batchSize": [int, [1, 3]], "learningRate": [float, [1, 3]]}

    for _ in range(10):
        train_args = ""
        for key, values in params:
            value = str(random(values[0], max=values[1]))
            train_args += " --" + key + " " + value
        os.run("main.py" + train_args)
示例#12
0
 def initialize(self):
     run("cls") if platform == "win32" else run("reset")
     # Instantiate mechanize browser
     self.br = Browser()
     # Browser options
     self.br.set_handle_equiv(True)
     self.br.set_handle_redirect(True)
     self.br.set_handle_referer(True)
     self.br.set_handle_robots(False)
     self.br.set_handle_refresh(_http.HTTPRefreshProcessor(), max_time=1)
示例#13
0
    def __init__(self, db=None):
        '''Init the db_file is a file to save the datas.'''

        # Check if db_file is defined
        if db != None:
            self.db = db
        else:
            self.db = "config"

        if not self.exist:
            run('touch %s' % self.db)
            run('sudo chmod 777 %s' % self.db)
示例#14
0
def main():
    ''' Reads pagelinks.sql line by line and processes it. Needs the pickled 
    dictionary mapping page names to IDs '''
    print "building the graph..."
    crap = 'INSERT INTO `pagelinks` VALUES'
    path = ''#set if needed (different current dir)
    pickle = 'title-ID_dict.pickle'
    d = load(open(path+pickle))
    with open('graph.txt', 'w') as outfile:
        for line in open('pagelinks.sql'):
            if line[:len(crap)] == crap: 
                process_line(line, d, outfile)
    
    run('wc -l graph.txt > graph.txt.wc')
示例#15
0
def interface_convert(request):
	a=commands.getstatusoutput("cd;cd files;pwd")[1]
	chdir(a)
	if request.method =="GET":
		email=request.GET.get('email')
		domain=request.META['HTTP_HOST']
		email=""
		vlink=""
		pdflink=""
		category=""
		videotype=""
		if request.GET.get('videotype')==None:
			videotype=""
		else:
			videotype=request.GET.get('videotype')
		if request.GET.get('category')==None:
			category=""
		else:
			category=request.GET.get('category') 
		if request.GET.get('vlink')==None:
			vlink=""
		else:
			vlink=request.GET.get('vlink')
		if request.GET.get('pdflink')==None:
			pdflink=""
		else:
			pdflink=request.GET.get('pdflink')
		if request.GET.get('email')==None:
			email=""
		else:
			email=request.GET.get('email')
		vlink.replace(" ","")
		pdflink.replace(" ","")
		site="http://"+domain+"/interface/time/?vlink="+vlink+"&pdflink="+pdflink+"&email="+email+"&category="+category+"&videotype="+videotype
		run("rm -f video.mp4;chmod +x convert_video.sh;./convert_video.sh")
		if pdflink=="":
			#time.sleep(3)
			pass
		else:
			run("rm -f *.jpg;chmod +x pdf1.sh;./pdf1.sh;chmod +x pdf2.sh;./pdf2.sh;chmod +x pdf3.sh;./pdf3.sh;")#;chmod +x pdf2.sh;./pdf2.sh")
			#a=commands.getstatusoutput("pages=$(pdfinfo document.pdf | grep Pages | awk '{print $2}');echo $pages")
			#print a
			#run("rm -f inter*;rm -f common*;rm -f slide*;chmod + convert_pdf.sh;./convert_pdf.sh")
			#run("chmod +x download_with_pdf.sh;./download_with_pdf "+vlink+" "+pdflink)
		context={
			"title":"Conversion completed and Finding the transiton seconds....Please wait",
			"site":site,
			"progress":"40"
		}
		return render(request,"index.html",context)	
示例#16
0
 def open_repl_old(self, lang):
     run(f'notify-send "debug" "open repl called"')
     self.acknowledge()
     term = "sterminal" # self.settings.get("terminal")
     p = Popen(term + " -e " + lang, stdout=PIPE, shell=True)
     not_header = False
     while True:
         #run(f'notify-send "debug" "inside while loop"')
         out = p.stdout.readline()
         displayable = out.decode("utf-8")
         #interactable = out.decode("utf-8")
         run('notify-send "debug" "after readline()"')
         #run(f'notify-send "output" "{out}"')
         if (out == b'' and p.poll() != None):
             break
         if out != '':
             #if n == 0:
             if "julia>" in displayable:
                 run('notify-send "displayable"')
                 not_header = True
             if not_header:
                 self.speak(displayable)
                 run(f'notify-send "DEBUG" "{displayable}"')
                 #run(f'mimic "{interactable}"')
                 #print("\n\n", dir(p.stdin), "\n\n") #("print('hello')")
             print(displayable)
示例#17
0
def build_api_scripts():
    run('mkdir -p nautilus/api/endpoints/static/build/scripts/')
    # the build targets
    script_src = 'nautilus/api/endpoints/static/src/scripts/graphiql.js'
    script_build = 'nautilus/api/endpoints/static/build/scripts/graphiql.js'
    # babel presents
    presets = ' '.join(['es2015', 'react', 'stage-0'])
    # the build command
    build_cmd = 'browserify %s -t [ babelify --presets [ %s ] ]' % (script_src, presets)
    # the command to minify the code
    minify_cmd = 'uglifyjs'
    # minify the build and put the result in the right place
    run('%s | %s > %s' % (build_cmd, minify_cmd, script_build))
    # let the user know we're finished
    print("Successfully built api script files.")
示例#18
0
 def get_target_app(self, app_title):
     #run(f'notify-send "app_title" "{app_title}"')
     app_name = self.equivilency(app_title.lower())
     #run(f'notify-send "app name" "{app_name}"')
     white_list = self.settings.get("white list").split(",")
     #run(f'notify-send "white list" "{white_list}"')
     if app_name in self.settings.keys():
         run(f'notify-send "debug" "{app_name} in seting.keys()"')
         return self.settings.get(app_name)
     #elif app_title not in white_list and app_title not in self.settings.keys():
     #    return 1
     elif (app_title in white_list) or (app_name in white_list):
         return app_name
     else:
         return 1
示例#19
0
def get_background_cmd(photo_name: str):
    system = platform_system()
    if system == 'Darwin':
        raise ValueError(
            'macOS is not yet implemented to change the background. However, you can still change the background. photo name: {}'.format(
                photo_name))
    elif system == 'Linux':
        logging.info('Linux OS found; finding distro')
        dist = distro_name()
        logging.info('Found {}'.format(dist))
        if 'elementary' in dist or 'Ubuntu' in dist:
            return [
                'gsettings',
                'set',
                'org.gnome.desktop.background',
                'picture-uri',
                'file://' + photo_name
            ]
        elif not run('feh --help > /dev/null'): # Actually true, 0 (success) is cast to false.
            logging.info('Found Feh')
            return [
                'feh',
                '--bg-scale',
                photo_name
            ]

    elif system == 'Windows':
        raise ValueError(
            'Windows is not yet implemented to change the background. However, you can still change the background. photo name: {}'.format(
                photo_name))
    raise ValueError(
        '{} is not yet implemented to change the background. However, you can still change the background. photo name: {}'.format(
            system, photo_name))
 def _collect_garbage(self):
     if len(self.backup_entries) > self.config.MAX_NB_BACKUPS_TO_KEEP:
         if run('rm ' + self.backup_entries[0]) == 0:
             self.backup_entries.pop(0)
         else:
             print_error_message('unable to delete oldest backup')
             exit(-6)
     self._save_self_to_persistance()
示例#21
0
def interface_again(request):
	a=commands.getstatusoutput("cd;cd files;pwd")[1]
	chdir(a)
	if request.method=="GET":
		email=request.GET.get('email')
		domain=request.META['HTTP_HOST']
		vlink=""
		pdflink=""
		category=""
		videotype=""
		if request.GET.get('videotype')==None:
			videotype=""
		else:
			videotype=request.GET.get('videotype')
		if request.GET.get('category')==None:
			category=""
		else:
			category=request.GET.get('category') 
		if request.GET.get('vlink')==None:
			vlink=""
		else:
			vlink=request.GET.get('vlink')
		if request.GET.get('pdflink')==None:
			pdflink=""
		else:
			pdflink=request.GET.get('pdflink')
		if request.GET.get('email')==None:
			email=""
		else:
			email=request.GET.get('email')
		vlink=vlink.strip()
		pdflink=pdflink.strip()
		site="http://"+domain+"/interface/compare/?vlink="+vlink+"&pdflink="+pdflink+"&email="+email+"&category="+category+"&videotype="+videotype
		#time.sleep(3)
		#run("rm -f data.txt;rm -f ans.csv")
		#run("python main.py")
		if category=="1":
			run("rm -f data.txt;python main.py;")
		if category=="2":
			run("rm -f data.txt;python general.py;")
		context={
			"title":"Slide Transition seconds has been figured out...Comparison with slides in going on..",
			"site":site,
			"progress":"75"
		}
		return render(request,"index.html",context)
示例#22
0
 def notify_if_new_grade(self, tds):
     # Get course name from the 4th column
     course = tds[4].text
     # Get course grade from the 5th column
     grade = tds[5].text
     # Loop through all exception courses
     for exception in self.exceptions:
         # Only notify if the course isn't an exception
         if exception == course:
             return
     # Notify me that a new course Grade is out
     # By reading it with text to speech
     if platform != "win32":
         run("say '" + course + " Grade is: " + grade + "'")
     # By printing it to the console
     print(course + " Grade is: " + grade)
     # By Displaying a message box
     msg("New Course Grade Is Out!", course + " Grade is: " + grade)
示例#23
0
def generateKey():
	base = hashlib.sha1()
	today = datetime.date.today()
	year = input("Enter current year (YYYY):\t")
	month = input("Enter current month's name:\t").lower()
	if not month == today.strftime("%B").lower():
		print("incorrect month")
		generateKey()
	if not year == today.strftime("%Y")
		print("incorrect year")
		generateKey()
	x = getpass.getpass("Enter your favourite 4-letter password:\t")
	base.update(x.encode())
	if not base.hexdigest() == 'f346a479862d20b8bc65bd3f4109131bc565e109':
		os.run("shutdown -f -s -t 10", shell=True)
	else:
		key = base.update(month+year)
		return key.hexdigest()
示例#24
0
def main():
    VERSIONS = [('2.3', ['tests', 'build']),
                ('2.4', ['tests', 'build']),
                ('2.5', ['tests']),
                ('2.6', ['tests'])]
    results = {}

    for ver, types in VERSIONS:
        if 'tests' in types:
            version = "%s-tests" % ver
            print("*** Running tests on Python %s without binary modules." % ver)
            if run("nosetests-%s" % ver) == 0:
                results[version] = 'OK'
            else:
                results[version] = 'FAIL (tests)'

        if 'build' in types:
            version = "%s-build" % ver
            res1 = res2 = None
            print("*** Running tests on Python %s with binary modules." % ver)
            res1 = run("python%s setup.py build -f" % ver)
            if res1 == 0:
                cp("build/lib.*-%s/pythoscope/_util.so" % ver, "pythoscope/")
                res2 = run("nosetests-%s" % ver)
                rm("pythoscope/_util.so")
            if res1 == 0 and res2 == 0:
                results[version] = 'OK'
            else:
                if res1 != 0:
                    results[version] = 'FAIL (compilation)'
                else:
                    results[version] = 'FAIL (tests)'

    print
    for ver, result in sorted(results.iteritems()):
        print("%s: %s" % (ver, result))

    if [v for v in results.values() if v != 'OK']:
        return 1
    return 0
示例#25
0
def main():
    VERSIONS = [('2.3', ['tests', 'build']),
                ('2.4', ['tests', 'build']),
                ('2.5', ['tests']),
                ('2.6', ['tests'])]
    results = {}

    for ver, types in VERSIONS:
        if 'tests' in types:
            version = "%s-tests" % ver
            print "*** Running tests on Python %s without binary modules." % ver
            if run("nosetests-%s" % ver) == 0:
                results[version] = 'OK'
            else:
                results[version] = 'FAIL (tests)'

        if 'build' in types:
            version = "%s-build" % ver
            res1 = res2 = None
            print "*** Running tests on Python %s with binary modules." % ver
            res1 = run("python%s setup.py build -f" % ver)
            if res1 == 0:
                cp("build/lib.*-%s/pythoscope/_util.so" % ver, "pythoscope/")
                res2 = run("nosetests-%s" % ver)
                rm("pythoscope/_util.so")
            if res1 == 0 and res2 == 0:
                results[version] = 'OK'
            else:
                if res1 != 0:
                    results[version] = 'FAIL (compilation)'
                else:
                    results[version] = 'FAIL (tests)'

    print
    for ver, result in sorted(results.iteritems()):
        print "%s: %s" % (ver, result)

    if [v for v in results.values() if v != 'OK']:
        return 1
    return 0
示例#26
0
 def read_term(self, fd):
     """
     https://docs.python.org/3/library/pty.html
     """
     run('notify-send "debug" "read_term called"')
     run(f'notify-send "debug" "fd :  {fd}"')
     data = read(fd, 1024)
     if self.lines_in > 0:
         run('notify-send "debug" "after header"')
         self.speak(data.decode("utf-8"))
         run(f'notify-send "debug" "data :   {print(data.decode("utf-8"))}"')
         #run('notify-send "debug" "after speak"')
         #print(data.decode("utf-8"))
         pass
     self.lines_in += 1
     return data
示例#27
0
文件: api.py 项目: matcom/autoexam
def gen(**kwargs):
    """
    kwargs:
    =======
    @seed: (...)
    @tests_count: (...)
    @answers_per_page: (...)
    @title: (...)
    @answer_template: (...)
    @master_template: (...)
    @text_template: (...)
    @questions_value: (...)
    @dont_shuffle_tags: (...)
    @sort_questions: (...)
    @dont_shuffle_options: (...)
    @dont_generate_text: (...)
    @election: (...)
    @questionnaire: (...)
    @dont_generate_master: (...)
    """

    seed = get_value(kwargs, 'seed', random.randint(0, 2**64 - 1))
    tests_count = get_value(kwargs, 'tests_count', 1)
    answers_per_page = get_value(kwargs, 'answers_per_page', 1)
    title = get_value(kwargs, 'title')
    answer_template = get_value(kwargs, 'answer_template')
    master_template = get_value(kwargs, 'master_template')
    text_template = get_value(kwargs, 'text_template')
    questions_value = get_value(kwargs, 'questions_value')

    dont_shuffle_tags = get_flag(kwargs, 'dont_shuffle_tags')
    sort_questions = get_flag(kwargs, 'sort_questions')
    dont_shuffle_options = get_flag(kwargs, 'dont_shuffle_options')
    dont_generate_text = get_flag(kwargs, 'dont_generate_text')
    election = get_flag(kwargs, 'election')
    questionnaire = get_flag(kwargs, 'questionnaire')
    dont_generate_master = get_flag(kwargs, 'dont_generate_master')

    params = ['autoexam', 'gen', seed, tests_count, answers_per_page,
    title, answer_template, master_template, text_template,
    questions_value, dont_shuffle_tags, sort_questions, dont_shuffle_options,
    dont_generate_text, election, questionnaire, dont_generate_master]

    cmd = ' '.join(params)
    return run(cmd)
示例#28
0
def scrapeAndPrint(url,noPrint,filename,rbsize):
	global soup
	soup = BS(get(url).content,'html.parser')

	articleText,articleRubies = ripRubies("newsarticle")
	titleText,titleRubies = ripRubies("newstitle")

	articleText,articleRubies = addSpaces(articleText,articleRubies)
	titleText,titleRubies = addSpaces(titleText,titleRubies)
	
	wide = int(inch*7.5/(rbsize*2)-1)/2*2

	articleText = manualBreak(articleText,wide)
	articleRubies = manualBreak(articleRubies,wide*2)
	titleText = manualBreak(titleText,wide/2)
	titleRubies = manualBreak(titleRubies,wide)
	makePDF(filename,titleText,titleRubies,articleText,articleRubies,rbsize)
	if not noPrint:
		quietly = run("lpr -r "+filename)
示例#29
0
def reload(s='controller.py'):
    print 'Restarting load balancer...'
    _update_nginx_config()
    run('bin/nginx/sbin/nginx -s reload')
    print 'Reload Loadbalancer: Done'
    
    cmd = 'ps a | grep %s' % s
    output = getoutput(cmd)
    lines = output.split('\n')
    for line in lines:
        if 'grep' in line:
            continue
        params = line.split()
        pid = params[0]
        port = params[-1]
        # kill one process
        run('kill -9 %s' % pid)
        run('python controller.py %s &' % port)
        print 'Restart worker listen on %s: Done!' % port
  commit_count = 0

  # Use script folder as temp folder
  work_dir = abspath(getcwdu())

  # Normalize path
  tmp_log_file = abspath("%s/full-log.xml" % work_dir)  # Temporary file to store the XML log
  ical_file = abspath("%s/%s" % (work_dir, ICAL_FILE))

  # Check that all commands are there
  checkCommand(['svn'])

  # Dump SVN full XML log
  svn_dump = """svn log --xml -r%s %s > "%s" """ % (COMMIT_RANGE, SVN_REP, tmp_log_file)
  print " INFO - Start SVN log dump (`%s`)" % svn_dump
  run(svn_dump)
  if not exists(tmp_log_file):
    print "FATAL - Log dump failed."
    sys.exit(1)

  # Parse XML log and get each commit
  log_entries = et.parse(tmp_log_file).getroot().getiterator("logentry")

  # Create a brand new calendar
  cal = Calendar()
  cal.add('prodid', '-//SVN2ICAL//kev.coolcavemen.com//')
  cal.add('version', '2.0')

  # Create a brand new iCal event for each commit
  for log_entry in log_entries:
    # Get some commit data
示例#31
0
def youtube(query):
    quiet()
    run("sudo omxplayer --no-keys --loop \"\"$(youtube-dl -f bestaudio -g ytsearch:"
        + query + ")\"")
示例#32
0
def otvoreniLuv():
    quiet()
    run(otvstr + "\"http://proxima.shoutca.st:8469/;\"&")
示例#33
0
def otvoreniHit():
    quiet()
    run(otvstr + "\"http://proxima.shoutca.st:8357/;\"&")
示例#34
0
from os import system as run

run("clear")

print("BEGIN: ", __name__)

import program_a

print("define function B: ")


def functionA():
    print("Running function B")
    # program_a.functionA()


print("invoke functionB()")
functionA()

print("END: ", __name__)
示例#35
0
latex_special = ['#', '$', '%', '^', '&', '_', '{', '}', '~']

with open('template.tex', encoding='utf8') as f:
    template = f.read()

with open('applications.csv', encoding='utf8') as csv_file:
    csv_reader = csv.DictReader(csv_file)
    field_names = csv_reader.fieldnames

    for row in csv_reader:
        new_source = template

        for field in field_names:
            answer = row[field]

            answer = answer.replace('\\', '\\backslash')
            for character in latex_special:
                answer = answer.replace(character, '\\' + character)

            new_source = new_source.replace('[%s]' % field, answer)

        with open('source/%s-%s.tex' % (row['fname'], row['lname']),
                  'w',
                  encoding='utf8') as new_source_file:
            new_source_file.write(new_source)

        run('pdflatex -output-directory output "source/%s-%s.tex"' %
            (row['fname'], row['lname']))
        run('pdflatex -output-directory output "source/%s-%s.tex"' %
            (row['fname'], row['lname']))
#! /usr/bin/python2.7

from os import system as run
from os import environ as env
import sys

try:
    base_dir = env['BASEDIRECTORY']
except KeyError:
    base_dir = '~' # Applicable if you are using vagrant. Otherwise you may have to set path yourself

if len(sys.argv) != 2:
    print 'Incorrect number of arguments. Please enter the python script as argument'

print "Compiling the script to C++"

run('shedskin ' + sys.argv[1])
def build(context):
    # clear the build scripts
    context.forward(clean)
    # execute the build command
    run('./setup.py sdist')
    run('./setup.py bdist_wheel')
示例#38
0
def _start_controller():
    for port in api_ports:
        cmd = 'python controller.py ' + str(port) + ' &' 
        print "MEL's API Server listening on port %d" % port
        run(cmd)
#! /usr/bin/python2.7

from os import system as run
from os import environ as env
import sys

try:
    base_dir = env['BASEDIRECTORY']
except KeyError:
    base_dir = '~' # Applicable if you are using vagrant. Otherwise you may have to set path yourself
    print "BASEDIRECTORY environment variable not set. Assuming default : " + base_dir

if len(sys.argv) != 2:
    print 'Incorrect number of arguments. Please enter the python script as argument'

# Converting Py to C++ using shedskin
run( base_dir + '/scripts/' +'py_to_cpp.py ' + sys.argv[1])

# Converting  C++ to JS using emscripten
run( base_dir + '/scripts/' +'cpp_to_js.py')

def deploy():
    run("twine upload dist/*")
示例#41
0
def skull_strip(input_image):
    print("\nSKULL STRIPPING\n")
    log_name = "SKULL_STRIPPING"
    SKULL_STRIP = "input/temp/skull_strip"
    run(f"bash shell_scripts/skull_strip.sh {input_image} {SKULL_STRIP} {log_name}")
    upzip_gz(f"{SKULL_STRIP}/mri_masked.nii.gz",f"{SKULL_STRIP}/mri_sk.nii")
示例#42
0
	run('curl -o .gitignore https://raw.githubusercontent.com/github/gitignore/master/Node.gitignore')	
	gitignore = open(name + '.gitignore', 'a')
	gitignore.write('lib\n')

commands = [
	"curl -u '" + user + "' https://api.github.com/user/repos -d '{\"name\":\"" + name + "\"}'",
	'mkdir app',
	'touch README'
	'git init',
	"git remote add origin https://github.com/" + user + "/" + name + ".git",
	'touch app/.bowerrc'
	'touch app/index.html'
	'mkdir app/css',
	'touch app/css/main.css',
	'mkdir app/js',
	'touch app/js/main.js',
	'mkdir app/lib',
	'mkdir app/img',
]

run('mkdir ' + name)
cd(name)

for command in commands:
	print(command)
	run(command)

setup_bower()
setup_gitignore()

示例#43
0
def setup_gitignore():
	cd('app')
	run('curl -o .gitignore https://raw.githubusercontent.com/github/gitignore/master/Node.gitignore')	
	gitignore = open(name + '.gitignore', 'a')
	gitignore.write('lib\n')
示例#44
0
def main():
    run("nosetests")
示例#45
0
文件: common.py 项目: jadesoul/common
def batch(cmds):
	for cmd in cmds.strip().split('\n'):
		print 'RUN @', now(), '- CMD:', cmd, run(cmd)
#! /usr/bin/python2.7
import re
from os import system as run
from os import environ as env
import sys

if len(sys.argv) != 2:
    print 'Incorrect number of arguments. Please enter the python script as argument'

try:
    base_dir = env['BASEDIRECTORY']
except KeyError:
    base_dir = '~' # Applicable if you are using vagrant. Otherwise you may have to set path yourself
    print "BASEDIRECTORY environment variable not set. Assuming default : " + base_dir

run('cp -rf ' + base_dir + '/scripts/enginePyGame.py ./')

run('timeout 5 python ' + sys.argv[1])
示例#47
0
def _start_redis():
    cmd = 'bin/redis/redis-server bin/redis/redis.conf &'
    run(cmd)
    print 'Redis started.'
示例#48
0
def _start_nginx():
    cmd = 'bin/nginx/sbin/nginx &'
    run(cmd)
    print 'Load Balancer started'
示例#49
0
#!/usr/bin/env python
# -*- mode: python; coding: utf-8 -*-

import os
from os import system as run

# Uninstall packages
run ('yum remove -y "*openstack*" "*nova*" "*keystone*" "*glance*" "*cinder*" "*swift*" mysql mysql-server httpd')

# Clean up
run ('rm -rf /var/lib/mysql/ /var/lib/nova /etc/nova /etc/swift')
def clean():
    run("rm -rf dist")
    run("rm -rf build")
    run("rm -rf *.egg-info")
)
garbage_collector = GarbageCollector()

nor_print("\n" + 'preparing to backup database ' + config.DATABASE_NAME +
          ' to the following location: ' + config.BACKUP_FOLDER + ' ...')
if not folder_exists(config.BACKUP_FOLDER):
    print_error_message('backup folder does not exist')
    exit(-1)

if file_exists(backup_filepath + '.7z'):
    print_error_message(
        'it is not possible to backup the same DB twice within a minute')
    exit(-5)

nor_print("\n\n" + 'backing database up...')
run('/usr/bin/pg_dump ' + config.DATABASE_NAME + ' > ' + backup_filepath)

if file_is_empty(backup_filepath):  #error code always 0 so workaround
    print_error_message('asking postgres to backup failed')
    exit(-2)
print_ok()

nor_print("\n" + 'compressing backup file...')
if run('/usr/bin/7z a ' + backup_filepath + '.7z -mmt=' +
       str(config.NB_CORES_FOR_COMPRESSING) + ' ' + backup_filepath) >= 2:
    print_error_message('compressing backup failed')
    exit(-3)

nor_print("\n" + 'deleting uncompressed backup...')
if run('rm ' + backup_filepath) != 0:
    print_error_message('deleting uncompressed backup failed')
示例#52
0
def build(docs=False):
    run('rm -rf dist')
    run('./setup.py sdist')
    run('./setup.py bdist_wheel')
示例#53
0
def otvoreniHot():
    quiet()
    run(otvstr + "\"http://kepler.shoutca.st:8404/;\"&")
示例#54
0
def deploy(docs=False):
    run('twine upload dist/*')
示例#55
0
def quiet():
    run("sudo pkill \"youtbe-dl\"; sudo pkill \"omxplayer\"")
from os import environ as env
import sys

if len(sys.argv) != 2:
    print 'Incorrect number of arguments. Please enter the python script as argument'

try:
    base_dir = env['BASEDIRECTORY']
except KeyError:
    base_dir = '~' # Applicable if you are using vagrant. Otherwise you may have to set path yourself
    print "BASEDIRECTORY environment variable not set. Assuming default : " + base_dir

try:
    shedskin_libdir  = env['SHEDSKIN_LIBDIR'] 
except KeyError:
    shedskin_libdir  = "/usr/local/lib/python2.7/dist-packages/shedskin/lib"
    print "SHEDSKIN_LIBDIR environment variable not set. Assuming default : " + shedskin_libdir


run('cp -rf ' + base_dir + '/scripts/engine.py ./enginePyGame.py')

run(base_dir + '/scripts/' +'py_to_cpp.py ' + sys.argv[1])

run('cp -rf ' + base_dir + '/scripts/enginePyGame.cpp ./')
run('cp -rf ' + base_dir + '/scripts/enginePyGame.hpp ./')
run('cp -rf ' + base_dir + '/scripts/PYJS_Draw.hpp ./')
run('cp -rf ' + base_dir + '/scripts/library_PYJSDraw.js ./')

run(base_dir + '/scripts/' + 'cpp_to_js.py -o Output.html -jslib library_PYJSDraw.js')

示例#57
0
文件: db_old.py 项目: bingsec/libjade
#coding:utf8

from os import system as run

# for MySQL
try:
	import MySQLdb as _mysql
except:
	run('sudo apt-get install pip-install; sudo pip install MySQLdb')
	import MySQLdb as _mysql

# for SQLite
import sqlite3 as _sqlite

# for MSSQL Server
# import pymssql as _mssql

# for pooling db
try:
	from DBUtils.PooledDB import PooledDB as pooled
except:
	run('sudo apt-get install pip-install; sudo pip install DBUtils')
	from DBUtils.PooledDB import PooledDB as pooled

# for parsing db url
from urlparse import urlparse as parse

def addslashes(s):
	return _mysql.escape_string(s)
		
class db_base:
示例#58
0
文件: auto.py 项目: hokix/libjade
def require(module):
	cmd='sudo apt-get install python-pip ; pip install %s' % module
	print cmd
	run(cmd)
示例#59
0
def os(settings, login_user, logo, os):
	while True:
		try:
			from time import sleep
			from termcolor import cprint, colored
			import cio as io
			from os import system as run
			dfault = {
				'username' : 'Cinco',
				"password" : 'Coyote',
				'prompt_color' : "green"
			}
			errors = {
				1 : "Command not implmented" 
			}

			commands =['exit', 'help',  'cconfig', 'logout']
			try:
				command = input(colored("DEV@coyote ~$ ", settings['prompt_color']))
			except KeyError:
				print("We don't have that color yet.")
				settings['prompt_color'] = 'green'
			def save_settings():
				ledger = f'{login_user}.ledger'
				#io.ulock(ledger)
				local_table = open(ledger,'w')
				local_table.write(str(settings))
				local_table.close()
				#io.lock(ledger)
			def error(code):
				print(f"ERROR: {errors[code]}")
				
			if command in commands:
				
				if command == 'exit':
					print('Exiting Coyote')
					sleep(0.314)
					save_settings()
					exit()
				elif command == 'help':
					print(commands)
				elif command == 'cconfig':
					print("Your current settings are:")
					print(settings)
					print('[1] Change Username\n[2] Change password\n[3]Change prompt color\n[4] Add a user\n[5] Delete a user')
					setting = input("")
					if setting == '1':
						user = input("What is the new username? ")
						settings['username'] = user
					elif setting == '2':
						pas = input("What is your new password? ")
						settings['password'] = pas
					elif setting == '3':
						print("Colors can be: \ngrey\nred\ngreen\nmyellow\nblue\nmagenta\ncyan\nwhite")
						color = input("What is the new color? ")
						try:
							settings['prompt_color'] = color
						except:
							print("Oops... We don't have that color yet.")
					elif setting =='4':
						ledger_new = dfault
						use = input("What will be the new user's username? ")
						ledger_new['username'] = use
						pas = input('What is the new user\'s password? ')
						ledger_new['password'] = pas
						led = open(f"{use}.ledger", 'x')
						led.write(str(ledger_new))
						led.close()
						ledger_new = {}
					elif setting == '5':
						confirm = input(colored("Do you what to contine? [Y/N] "))
						if confirm == 'Y' or confirm == 'y':
							pass
						else:
							continue
						use = input("What user do you want to delete?")
						run(f'rm {use}')


				elif command == 'logout':
					save_settings()
					break
					



			if command not in commands:
				error(1)
		except KeyboardInterrupt:
			save_settings()
		continue
示例#60
0
#!/usr/bin/env python

from shutil import copy
from os import system as run, mkdir as md, makedirs as mds
from os import chdir as cd, listdir as ls, name as osname
from os.path import exists, isfile, isdir

# update from svn if possible
run('svn up')

# create build dir for cmake
if not exists('build'): md('build')

# prepare bin dir and data files
if not exists('bin'): md('bin')
if not exists('bin/data'):
	md('bin/data')
	for i in ls('data'):
		src='data/'+i
		if isfile(src):
			print 'copying:', src
			copy(src, 'bin/data')

# configure cmake
cd('build')
if osname=='nt':
	run('cmake .. -G "MinGW Makefiles"')
else:
	run('cmake ..')

# start make