示例#1
0
文件: run.py 项目: baxter13/flask
def library_author(author_pid):
    
    if Authors.query.get(author_pid) == None:
        return redirect(url_for('library_authors_all'))
    
    form = Addbook_from(request.form)    
    if request.method == 'POST':
        elem_id = None
    
    #UNLINK BOOK FROM AUTHOR    
        try:
            elem_id = request.form['edit_hidden_input']
        except:
            pass
                    
        if elem_id:
            book = Books.query.get(elem_id)
            shelf = Shelfs.query.filter(Shelfs.book_id == book.id, Shelfs.author_id == author_pid).first()
            db_session.delete(shelf)
            db_session.commit()
            
            zombie_book()
            
    #ADD&LINK NEW BOOK TO AUTHOR
        try:
            book_name = form.book_name.data
        except:
            pass
        
        if book_name:
            if validator() and not Books.query.filter(Books.name == book_name).first():
                db_session.add(Books(book_name))
                db_session.commit()
            
            if validator():
                db_session.add(Shelfs(author_pid, Books.query.filter(Books.name == book_name).first().id))
                db_session.commit()
    
    author = Authors.query.filter(Authors.id == author_pid).first()
    books_ids = Shelfs.query.filter(Shelfs.author_id == author_pid)
    books_list = []
    
    for ids in books_ids:
        books_list.append(Books.query.get(ids.book_id))

    variables = {'author' : author,
                'books_list' : books_list,
                'form' : form,
                'MESSAGE' : settings('MESSAGE'),
                'USER' : settings('USER'),
                'STATIC_URL' : settings('STATIC_URL'),
                 }
    return render_template('author.html', **variables)
示例#2
0
文件: run.py 项目: baxter13/flask
def library_main():
    
    #SETTINGS
    search = None
    
    #GET ALL ITEMS
    persons = Persons.query.all()
    books_list = Books.query.order_by(Books.id.desc())
    authors_list = Authors.query.all()[:10]
    random.shuffle(authors_list)

    #GET BOOKS&AUTHORS RELATIONS
    books_main = []
    url_authors = []
    for book in books_list[:10]:
        book_authors_ids = Shelfs.query.filter(Shelfs.book_id == book.id)
        for ids in book_authors_ids:
            url_authors.append('<a href=\"'+str(ids.author_id)+'\">'+str(Authors.query.get(ids.author_id))+'</a>')
        books_main.append((book, url_authors))
        url_authors = []

    #SEARCH MODULE
    search_result = []
    search_is = False
    if request.method == 'POST':
        search_is = True
        search = request.form['text_box']
        if search:
            try:
                search_result += ['Author: <a href=\"'+str(author.id)+'\">'+str(author)+'</a>' for author in Authors.query.filter(Authors.name.like('%'+search+'%'))]
                search_result += ['Book: '+str(book) for book in Books.query.filter(Books.name.like('%'+search+'%'))]
            except:
                pass
        else:
            search_is = False

                            
    variables = {'authors_list' : authors_list,
                 'books_list' : books_list[:10],
                 'search_result' : search_result,
                 'MESSAGE' : settings('MESSAGE'),
                 'USER' : settings('USER'),
                 'persons' : persons,
                 'STATIC_URL' : settings('STATIC_URL'),
                 'books_main' : books_main,
                 'search_is' : search_is,
                 'search_query' : search,
                 }
    return render_template('main.html', **variables)
示例#3
0
 def specific_init(self): 
   self.settings=settings() #replace with xmlsettings
   self.new_settings=settings()
   print ("Connecting...")
   self.get_widgets()
   self.socket=whale_connect(self.settings.getSetting('host'),int(self.settings.getSetting('port')))
   print ("Logging...")
   whale_log_user(self.socket,"maciek","xxx")
   print ("Getting dir...")
   self.get_dir("/home/maciek/mp3/")
   #print ("Getting playlist...");
   #self.get_playlist();
   #print ("Getting now playing...");
   #self.get_now_playing()
   gtk.main()
def add_prompt_to_user(home='/root', user='******'):  # {{{
    """
    Add an awesomely cool shell prompt for a user 

    Our setup comes with a cool prompt but that comes from the
    skeleton directory for new users. If we are already a user, e.g.
    if we're root or the default system user then we've already got
    a home directory and some config files, so we'll need to
    gracefully add our setup with as little invasiveness as possible.

    The ``home`` and ``user`` parameters are used if you are making
    this copy as another user, for example as root. In that case,
    after you are done copying these files, you'll want to hand
    ownership over to the user in question, also you'll want
    the files to be uploaded to the proper home directory.
    """
    env.host_string = root_host

    put(local_config_dir + '/skel/.colors_prompts', home)
    put(local_config_dir + '/skel/.bash_prompt', home)
    put(local_config_dir + '/skel/.gemrc', home)
    with settings(hide('warnings'), warn_only=True):
        if run('[ ! -e ' + home + '/.bashrc.bak ]').succeeded:
            run('cp ' + home + '/.bashrc ' + home + '/.bashrc.bak')
            run('echo >> ' + home + '/.bashrc')
            run("echo 'if [ -f " + home + "/.colors_prompts ]; then . " +
                home + "/.colors_prompts; fi' >> " + home + "/.bashrc")
            run("echo 'if [ -f " + home + "/.bash_prompt ]; then . " + home +
                "/.bash_prompt; fi' >> " + home + "/.bashrc")

    # in other words if this was done as root
    if home != '~' and len(user) > 0:
        run('chown -R ' + user + '.' + user + ' ' + home)
def add_prompt_to_user(home='/root', user='******'): 
    """
    Add an awesomely cool shell prompt for a user 

    Our setup comes with a cool prompt but that comes from the
    skeleton directory for new users. If we are already a user, e.g.
    if we're root or the default system user then we've already got
    a home directory and some config files, so we'll need to
    gracefully add our setup with as little invasiveness as possible.

    The ``home`` and ``user`` parameters are used if you are making
    this copy as another user, for example as root. In that case,
    after you are done copying these files, you'll want to hand
    ownership over to the user in question, also you'll want
    the files to be uploaded to the proper home directory.
    """
    env.host_string = root_host

    put(local_config_dir+'/skel/.colors_prompts', home)
    put(local_config_dir+'/skel/.bash_prompt', home)
    put(local_config_dir+'/skel/.gemrc', home)
    with settings(hide('warnings'), warn_only=True):
        if run('[ ! -e '+home+'/.bashrc.bak ]').succeeded:
            run('cp '+home+'/.bashrc '+home+'/.bashrc.bak')
            run('echo >> '+home+'/.bashrc')
            run("echo 'if [ -f "+home+"/.colors_prompts ]; then . "+home+"/.colors_prompts; fi' >> "+home+"/.bashrc")
            run("echo 'if [ -f "+home+"/.bash_prompt ]; then . "+home+"/.bash_prompt; fi' >> "+home+"/.bashrc")

    # in other words if this was done as root
    if home != '~' and len(user) > 0:
        run('chown -R '+user+'.'+user+' '+home)
示例#6
0
def main(paramC):
    if paramC == [1, 1, 1] :
        while True:
            mainMeasure()
    elif paramC == [1, 1, 0] :
        while True:
            writeLog(temp_measure(), hum_measure())
    elif paramC == [1, 0, 1] :
        while True:
            lcd_view()
    elif paramC == [0, 1, 1] :
        while True:
            lcd_view()
            writeLog(cleansreen_measureT(), cleansreen_measureH())
    elif paramC == [0, 0, 1] :
        while True:
            temp_measure()
    elif paramC == [0, 0, 0] :
        while True:
            print("ERROR! CHECK SETTINGS")
            main()
    else:
        print("Хотя бы один параметр должен быть включен: \n")
        paramC = settings(paramA)
    return paramC

    userChoise = str(input("choise: "))
def backup_apache_config(): 
    """
    Backs up the apache config to the backup directory
    """
    env.host_string = root_host
    with settings(hide('warnings'), warn_only=True):
        if run('[ ! -e '+remote_backup_dir+'/apache2.tar.gz ]').succeeded:
            with cd('/etc'):
                run('tar -czf '+remote_backup_dir+'/apache2.tar.gz apache2')
示例#8
0
文件: setup.py 项目: topochan/ts
def start_glusterd():
    # Start gluster daemon on all the servers
    with settings(warn_only = True):
        if run("pgrep glusterd").failed:
            if run("%s/sbin/glusterd"%installbase).failed:
                print "Unable to start glusterd, exiting..."
                sys.exit(1)
        else:
            print "glusterd is already running"
示例#9
0
 def __init__(self, args):
     QtGui.QApplication.__init__(self, args)
     # application details for settings
     QtCore.QCoreApplication.setOrganizationName("Ollie Terrance")
     QtCore.QCoreApplication.setOrganizationDomain("terrance.uk.to")
     QtCore.QCoreApplication.setApplicationName("DoX Tray")
     self.settings = settings()
     # start tray icon
     self.tray = tray(dox(), self.settings)
示例#10
0
def menu(surface):
    """Оперирует окном главного меню.

    Примает поверхность вывода.

    """
    finished = False

    vert_control_tick = 0
    demo_fig = []

    while not finished:
        surface.fill(sett.WHITE)

        printer(surface, 'Тетрис', 50, (340, 330))

        play_butt = Buttons.Button()
        settings_butt = Buttons.Button()
        stat_butt = Buttons.Button()

        play_butt.create_button(surface, sett.WHITE, 350, 420, 200, 80, 3,
                                "Играть", sett.BLACK)
        settings_butt.create_button(surface, sett.WHITE, 350, 520, 200, 80, 3,
                                    "Настройки", sett.BLACK)
        stat_butt.create_button(surface, sett.WHITE, 350, 620, 200, 80, 3,
                                "Статистика", sett.BLACK)

        vert_control_tick, demo_fig = animation(surface, vert_control_tick,
                                                demo_fig)

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
            elif event.type == MOUSEBUTTONDOWN:
                if play_butt.pressed(pygame.mouse.get_pos()):
                    new_game = Game(surface)
                    new_game.driver()
                elif settings_butt.pressed(pygame.mouse.get_pos()):
                    settings(surface)
                elif stat_butt.pressed(pygame.mouse.get_pos()):
                    stat(surface)

        pygame.display.flip()
示例#11
0
 def delete(cls, connection=None, **params):
     local_resource = cls.resource_name
     setting = settings()
     cls.resource_name = str(setting.delete(cls.resource_name))
     response = cls._make_request('delete',
                                  cls.resource_name,
                                  connection,
                                  params=params)
     cls.resource_name = local_resource
     return response
示例#12
0
def create_database():
    """Creates user and database from Django settings"""
    db_user = django_settings.DATABASES['default']['USER']
    db_pass = django_settings.DATABASES['default']['PASSWORD']
    db_name = django_settings.DATABASES['default']['NAME']
    with settings(warn_only=True):
        run('sudo -u postgres psql -c "CREATE USER %s WITH NOCREATEDB NOCREATEUSER \
               ENCRYPTED PASSWORD E\'%s\'"' % (db_user, db_pass))
        run('sudo -u postgres psql -c "CREATE DATABASE %s WITH OWNER %s"' %
                ( db_name, db_user))
def backup_apache_config():  # {{{
    """
    Backs up the apache config to the backup directory
    """
    env.host_string = root_host
    with settings(hide('warnings'), warn_only=True):
        if run('[ ! -e ' + remote_backup_dir + '/apache2.tar.gz ]').succeeded:
            with cd('/etc'):
                run('tar -czf ' + remote_backup_dir +
                    '/apache2.tar.gz apache2')
示例#14
0
文件: run.py 项目: baxter13/flask
def library_add_user():
    ER_MESSAGE = ''    
    form = Adduser_from(request.form)
    
    if request.method == 'POST':
        inputs = {'user_name':form.user_name.data, 'user_email':form.user_email.data, 'user_password':form.user_password.data} 
        if validator(**inputs):
            db_session.add(Persons(form.user_name.data, form.user_email.data, password_encode(form.user_password.data)))
            db_session.commit()
            return redirect(url_for('library_main'))
        else:
            ER_MESSAGE = 'En error while adding user! Syntax error or maybe he is already exists in database!'
            
    variables = {'form' : form,
                 'MESSAGE' : settings('MESSAGE'),
                 'USER' : settings('USER'),
                 'STATIC_URL' : settings('STATIC_URL'),
                 'ER_MESSAGE' : ER_MESSAGE
                 }
    return render_template('admin_add_user.html', **variables)
示例#15
0
文件: run.py 项目: baxter13/flask
def library_add_author():
    ER_MESSAGE = ''    
    form = Addauthor_from(request.form)
    if request.method == 'POST':
        inputs = {'user_name':form.author_name.data}
        if validator(**inputs) and not Authors.query.filter(Authors.name == form.author_name.data).first():
            db_session.add(Authors(form.author_name.data))
            db_session.commit()
            return redirect(url_for('library_authors_all'))
        else:
            ER_MESSAGE = 'En error while adding author! Syntax error or maybe he is already exists in database!'
    
    message = 'Add author interface'
    variables = {'form' : form,
                 'MESSAGE' : settings('MESSAGE'),
                 'USER' : settings('USER'),
                 'STATIC_URL' : settings('STATIC_URL'),
                 'ER_MESSAGE' : ER_MESSAGE
                 }
    return render_template('admin_add_author.html', **variables)
示例#16
0
def monitor_zerorpc(peers):
    for p in peers:
        print p['host_string'][p['host_string'].index('@')+1:], p['port'],
        c = Client('tcp://{hostname}:{port}'.format(hostname=p['host_string'][p['host_string'].index('@')+1:],
                                                    port=p['port']), timeout=60, heartbeat=None)
        try:
            c.test('test')
        except RemoteError:
            print 'passed'
        except TimeoutExpired:
            with settings(host_string=p['host_string'], warn_only=True):
                run('kill $(sudo lsof -t -i:{0})'.format(p['port']))
def install_rubygems():  # {{{
    """
    Download and install the latest rubygems system wide
    """
    env.host_string = root_host

    with settings(hide('warnings'), warn_only=True):
        if run('wget ' + rubygems_url + '/' + rubygems_tarball).succeeded:
            run('tar -zxf ' + rubygems_tarball)
            with cd(rubygems_vers):
                run('ruby setup.rb')
                run('ln -s /usr/bin/gem1.8 /usr/bin/gem')
示例#18
0
文件: setup.py 项目: topochan/ts
def deploy():
    """Download, build and deploy GlusterFS."""
    with settings(warn_only = True):
        if run("test -d %s" % src).failed:
            run("mkdir -p %s" %src)
        with cd(src):
            if run("test -f %s"% tarball).failed:
                run("wget -c %s"% durl)
            else:
                print "Source exists. Not downloading, continuing with \
installation..."
    __install()
def install_rubygems(): # {{{
    """
    Download and install the latest rubygems system wide
    """
    env.host_string = root_host

    with settings(hide('warnings'), warn_only=True):
        if run('wget '+rubygems_url+'/'+rubygems_tarball).succeeded:
            run('tar -zxf '+rubygems_tarball)
            with cd(rubygems_vers):
                run('ruby setup.rb')
                run('ln -s /usr/bin/gem1.8 /usr/bin/gem')
示例#20
0
def reload():
    """Restart services"""
    with hide('warnings'):
        with settings(warn_only=True):
            if USES_CELERY:
                sudo('service celeryd stop')
            if USES_DJANGO:
                sudo('service %s stop' % GUNICORN_SERVICE_NAME)
                sudo('service %s start' % GUNICORN_SERVICE_NAME)
            sudo('service nginx start')
            sudo('service nginx reload')
            if USES_CELERY:
                sudo('service celeryd start')
def backup_webroot():  # {{{
    """
    Backs up the webroot if it exists.

    Title should be self explanatory, this backs up the main server
    webroot directory if it exists.
    """
    env.host_string = root_host

    with settings(hide('warnings'), warn_only=True):
        if len(webroot_dir) and run('[ -e ' + webroot_dir + ' ]').succeeded:
            with cd(webroot_dir):
                run('tar -czf ' + remote_backup_dir + '/webroot.tar.gz ./')
示例#22
0
def backup_webroot(): 
    """
    Backs up the webroot if it exists.

    Title should be self explanatory, this backs up the main server
    webroot directory if it exists.
    """
    env.host_string = root_host

    with settings(hide('warnings'), warn_only=True):
        if len(webroot_dir) and run('[ -e '+webroot_dir+' ]').succeeded:
            with cd(webroot_dir):
                run('tar -czf '+remote_backup_dir+'/webroot.tar.gz ./')
示例#23
0
def clean_master_users(): 
    """
    Remove the deploy and main user accounts
    """
    env.host_string = root_host

    with settings(hide('warnings'), warn_only=True):
        run('deluser '+deploy_username)
        run('rm -rf /home/'+deploy_username)

        if not single_user_mode:
            run('deluser '+main_username)
            run('rm -rf /home/'+main_username)
示例#24
0
 def __init__(self):
     super(self.__class__, self).__init__()
     self.setupUi(self)
     self.settingsDialog = settings()
     self.baudrate = 115200
     self.databits = 8
     self.name = ""
     self.stopbits = 0
     self.parity = 0
     self.flowcontrol = 0
     self.serialport = QSerialPort()
     self.currentTime = ""
     self.initUI()
示例#25
0
文件: mount.py 项目: topochan/ts
def umount(mountpt=None):
    with settings(warn_only = True):
        if mountpt is not None or mountpt == "":
            if run("umount -l %s; :"%(mountpt)).failed:
                print "umount failed on %s"%host
        else:
            for client in clients:
                mounts = client['mnts']
                host = client['host']
                for mount in mounts:
                    if env.host == host:
                        if run("umount -l %s; :"%(mount)).failed:
                            print "umount failed on %s"%host
def clean_master_users():  # {{{
    """
    Remove the deploy and main user accounts
    """
    env.host_string = root_host

    with settings(hide('warnings'), warn_only=True):
        run('deluser ' + deploy_username)
        run('rm -rf /home/' + deploy_username)

        if not single_user_mode:
            run('deluser ' + main_username)
            run('rm -rf /home/' + main_username)
示例#27
0
def setup_celery():
    """Set up log files and RabbitMQ for Celery"""
    sudo('mkdir -p /var/log/celery')
    sudo('chown www-data:adm /var/log/celery')
    sudo('mkdir -p /var/run/celery')
    sudo('chown www-data:adm /var/run/celery')
    with hide('stdout'):
        sudo('aptitude install -y rabbitmq-server')
    with settings(warn_only=True):
        sudo('rabbitmqctl add_user %s %s' % (django_settings.BROKER_USER,
            django_settings.BROKER_PASSWORD))
        sudo('rabbitmqctl add_vhost %s' % django_settings.BROKER_VHOST)
        sudo('rabbitmqctl set_permissions -p %s %s ".*" ".*" ".*"' %
                (django_settings.BROKER_VHOST, django_settings.BROKER_USER))
示例#28
0
def restore_webroot(): 
    """
    Restore original webroot from backup if the backup exists
    """
    env.host_string = root_host

    with settings(hide('warnings'), warn_only=True):
        if run('[ -e '+remote_backup_dir+'/webroot.tar.gz ]').succeeded:
            run('rm -rf '+webroot_dir)
            run('mkdir -p '+webroot_dir)
            run('mv '+remote_backup_dir+'/webroot.tar.gz '+webroot_dir)
            with cd(webroot_dir):
                run('tar -zxf webroot.tar.gz')
                run('rm -rf webroot.tar.gz')
def restore_nginx_config():  # {{{
    """
    Restore original nginx config from backup if the backup exists
    """
    env.host_string = root_host

    with settings(hide('warnings'), warn_only=True):
        if run('[ -e ' + remote_backup_dir + '/nginx.tar.gz ]').succeeded:
            # remove custom apache config
            run('rm -rf /etc/nginx')
            run('mv ' + remote_backup_dir + '/nginx.tar.gz /etc')
            with cd('/etc'):
                run('tar -zxf nginx.tar.gz')
                run('rm -rf nginx.tar.gz')
示例#30
0
def restore_nginx_config(): 
    """
    Restore original nginx config from backup if the backup exists
    """
    env.host_string = root_host

    with settings(hide('warnings'), warn_only=True):
        if run('[ -e '+remote_backup_dir+'/nginx.tar.gz ]').succeeded:
            # remove custom apache config
            run('rm -rf /etc/nginx')
            run('mv '+remote_backup_dir+'/nginx.tar.gz /etc')
            with cd('/etc'):
                run('tar -zxf nginx.tar.gz')
                run('rm -rf nginx.tar.gz')
def restore_webroot():  # {{{
    """
    Restore original webroot from backup if the backup exists
    """
    env.host_string = root_host

    with settings(hide('warnings'), warn_only=True):
        if run('[ -e ' + remote_backup_dir + '/webroot.tar.gz ]').succeeded:
            run('rm -rf ' + webroot_dir)
            run('mkdir -p ' + webroot_dir)
            run('mv ' + remote_backup_dir + '/webroot.tar.gz ' + webroot_dir)
            with cd(webroot_dir):
                run('tar -zxf webroot.tar.gz')
                run('rm -rf webroot.tar.gz')
示例#32
0
def git_push_from_local():
    """Push local repo to remote machine"""
    if not exists(REPO_DIR):
        # Set up bare Git repo to push to
        run('mkdir -p %s' % REPO_DIR)
        with cd(REPO_DIR):
            run('git init --bare')

    local('ssh-add %(key_filename)s' % env)
    local('git remote add ec2push ssh://ubuntu@%(host_string)s:22%(repo_dir)s' % env)
    with settings(warn_only=True):
        result = local('git push ec2push %(gitbranch)s' % env)
    local('git remote rm ec2push')
    if result.failed:
        abort("Git push failed.")
示例#33
0
def clean_team_users(): 
    """
    Remove any team user accounts
    """
    env.host_string = root_host

    with settings(hide('warnings'), warn_only=True):
        run('deluser '+deploy_username)
        run('deluser '+main_username)
        run('rm -rf /home/'+deploy_username)
        run('rm -rf /home/'+main_username)

        for name in team_users:
            run('deluser '+name)
            run('rm -rf /home/'+name)
示例#34
0
def backup_user_home(user): 
    """
    Backup a users home dir to the backup dir

    If no backup yet exists for the given user's home directory
    then create a backup for that user in remote_backup_dir/home_user.tar.gz
    """
    env.host_string = root_host

    bak_file = remote_backup_dir+'/home_'+user+'.tar.gz'
    with settings(hide('warnings'), warn_only=True):
        if run('[ ! -e '+bak_file+' ]').succeeded:
            if run('[ -e /home/'+user+' ]').succeeded:
                with cd('/home'):
                    run('tar -czf '+bak_file+' '+user)
示例#35
0
def monitor_fd():
    from sh import lsof, wc, ls, pkill, service
    try:
        mongodb_pid = lsof('-t', '-i:27017', '-sTCP:LISTEN').split('\n')[0]
        num_fd = int(wc(lsof('-p', '{0}'.format(mongodb_pid)), '-l').strip())
        print 'num_fd:',  num_fd
        if num_fd >= 4096:
            #service('mongodb', 'restart')
            pkill('-f', 'run.py')
            for p in chain(CRAWLER_PEERS, POWER_PEERS, TEXT_PEERS):
                with settings(host_string=p['host_string'], warn_only=True):
                    run('kill $(sudo lsof -t -i:{0})'.format(p['port']))
    except Exception:
        import traceback
        traceback.print_exc()
def backup_user_home(user):  # {{{
    """
    Backup a users home dir to the backup dir

    If no backup yet exists for the given user's home directory
    then create a backup for that user in remote_backup_dir/home_user.tar.gz
    """
    env.host_string = root_host

    bak_file = remote_backup_dir + '/home_' + user + '.tar.gz'
    with settings(hide('warnings'), warn_only=True):
        if run('[ ! -e ' + bak_file + ' ]').succeeded:
            if run('[ -e /home/' + user + ' ]').succeeded:
                with cd('/home'):
                    run('tar -czf ' + bak_file + ' ' + user)
def clean_team_users():  # {{{
    """
    Remove any team user accounts
    """
    env.host_string = root_host

    with settings(hide('warnings'), warn_only=True):
        run('deluser ' + deploy_username)
        run('deluser ' + main_username)
        run('rm -rf /home/' + deploy_username)
        run('rm -rf /home/' + main_username)

        for name in team_users:
            run('deluser ' + name)
            run('rm -rf /home/' + name)
示例#38
0
def restore_user_home(user): 
    """
    Restore a user's original home directory from the backup dir

    If a backup exists for the user's home directory, delete the
    current home directory and restore from the backup.
    """
    env.host_string = root_host

    bak_file = remote_backup_dir+'/home_'+user+'.tar.gz'
    with settings(hide('warnings'), warn_only=True):
        if run('[ -e '+bak_file+' ]').succeeded:
            if run('[ -e /home/'+user+' ]').succeeded:
                with cd('/home'):
                    run('rm -rf '+user)
                    run('tar -xzf '+bak_file)
def restore_user_home(user):  # {{{
    """
    Restore a user's original home directory from the backup dir

    If a backup exists for the user's home directory, delete the
    current home directory and restore from the backup.
    """
    env.host_string = root_host

    bak_file = remote_backup_dir + '/home_' + user + '.tar.gz'
    with settings(hide('warnings'), warn_only=True):
        if run('[ -e ' + bak_file + ' ]').succeeded:
            if run('[ -e /home/' + user + ' ]').succeeded:
                with cd('/home'):
                    run('rm -rf ' + user)
                    run('tar -xzf ' + bak_file)
def install_python_pip():  # {{{
    """
    Download and install a recent version of the pip utility
    """
    env.host_string = root_host
    the_file = pip_vers + '.tar.gz'
    run('wget ' + pip_url)

    with settings(warn_only=True):
        md5_compute = run('md5sum ' + the_file)
        md5_string = pip_md5 + '  ' + the_file
        result = run('[ "' + md5_compute + '" = "' + md5_string + '" ]')
    if result.failed and not confirm("Bad pip tarball. Continue anyway?"):
        abort("Aborting at user request.")

    run('tar -zxf ' + the_file)
    with cd(pip_vers):
        run('python setup.py install')
示例#41
0
def install_python_pip(): 
    """
    Download and install a recent version of the pip utility
    """
    env.host_string = root_host
    the_file = pip_vers + '.tar.gz'
    run('wget ' + pip_url)

    with settings(warn_only=True):
        md5_compute = run('md5sum '+the_file)
        md5_string  = pip_md5+'  '+the_file
        result      = run('[ "'+md5_compute+'" = "'+md5_string+'" ]')
    if result.failed and not confirm("Bad pip tarball. `Continue anyway?"):
        abort("Aborting at user request.")

    run('tar -zxf ' + the_file)
    with cd(pip_vers):
        run('python setup.py install')
示例#42
0
def init_system():
    """
    Initialialize the bare necessities, i.e. root user etc

    Configures your admin user. Uploads the custom
    home directory skeleton for new users. Creates backup
    and config directories.
    """
    env.host_string = root_host

    regen_tarballs()

    init_root_user()

    with settings(hide('warnings'), warn_only=True):
        local('mkdir -p ' + local_backup_dir)
        local('mkdir -p ' + local_tar_dir)
        run('mkdir -p ' + remote_backup_dir)
        run('mkdir -p ' + remote_config_dir)
示例#43
0
def init_system(): 
    """
    Initialialize the bare necessities, i.e. root user etc

    Configures your admin user. Uploads the custom
    home directory skeleton for new users. Creates backup
    and config directories.
    """
    env.host_string = root_host

    regen_tarballs()

    init_root_user();

    with settings(hide('warnings'), warn_only=True):
        local('mkdir -p '+local_backup_dir)
        local('mkdir -p '+local_tar_dir)
        run('mkdir -p '+remote_backup_dir)
        run('mkdir -p '+remote_config_dir)
	def __init__(self, driveService, sheetService, discountID, rosterID, row):
		self.config = settings()

		self.emailSender = sender()

		self.log = warnings(printOutput = True)

		self.driveService = driveService
		self.sheetService = sheetService
		self.discountID = discountID
		self.rosterID = rosterID

		print("rosterID is " + self.rosterID)

		self.roster = self.config.getStrList('temp','pastHandlers')

		# row[0] is timestamp
		self.name = str(row[1])
		self.email = str(row[2])
		# row[3] is faculty
		# row[4] is phone number
		self.support = self.parseSupport(str(row[5]))
		# row[6] is support details
		self.resolution = self.parseResolution(str(row[7]))
		# row[8] is purpose
		self.material = self.parseMaterial(str(row[9]))
		self.infill = self.parseInfill(str(row[10]))
		self.color = self.parseColor(str(row[11]))
		self.stlFiles = self.parseFileNames(str(row[12]))
		self.couponCode = str(row[13])
		# row[14] is how did you hear abt us

		self.sane = self.sanityCheck()

		self.platerConf = ""
		self.receipt = ""

		if not self.sane:
			# TODO: add email support
			print("Print job is not valid, skipping...")
			return

		self.process()
示例#45
0
文件: setup.py 项目: topochan/ts
def __install():
    # Extract, configure and install
    with settings(warn_only = True):
        if run("test -d %s"% tmp).failed:
            run("mkdir -p %s"% tmp)
        with cd(src):
            if run("tar zxvf %s -C %s"% (tarball, tmp)).failed:
                print "Unable to untar, exiting..."
                sys.exit(1)
        builddir = "%s/glusterfs-%s"% (tmp, cluster['version'])
        with cd(builddir):
            if run("./configure --prefix=%s/%s"% \
                       (installbase, cluster['version'])).failed:
                print "Configuring GlusterFS installation failed, exiting..."
                sys.exit(1)
            if run("make install clean").failed:
                print "Compilation and installation of GlusterFS failed, \
exiting..."
    # Clean up the build directory
    __cleanup()
示例#46
0
def setup_project():
    """Initial setup of project on server"""
    run('mkdir -p %s' % PROJECT_DIR)

    # Set up log files for Gunicorn
    if USES_DJANGO:
        sudo('mkdir -p /var/log/gunicorn')
        sudo('touch /var/log/gunicorn/%s.log' % GUNICORN_SERVICE_NAME)
        sudo('chown www-data:adm /var/log/gunicorn')
        sudo('chown www-data:adm /var/log/gunicorn/%s.log' % GUNICORN_SERVICE_NAME)

    # Install and set up PIP and Virtualenv
    with hide('stdout'):
        sudo('aptitude install -y python-setuptools')
        sudo('easy_install pip')
        sudo('pip install virtualenv')
    if not exists(ENV_DIR):
        run('virtualenv %(env_dir)s' % env)
        run('echo "export DJANGO_SETTINGS=production" >> %(env_dir)s/bin/activate' % env)
        run('echo "export TOKOTOKO_FABFILE_PROJECT=%(webapp_dir)s" >> %(env_dir)s/bin/activate' % env)

    # Set up Celery
    if USES_CELERY:
        setup_celery()

    # Set up database
    if USES_DJANGO:
        create_database()

    # Push local repo and update
    deploy()

    # Set up cron job for daily backups
    sudo('mkdir -p %s' % BACKUP_DIR)
    sudo('chmod a+rwx %s' % BACKUP_DIR)
    with hide('warnings'):
        with settings(warn_only=True):
            run('crontab -l > /tmp/crondump')
    cronjob = '00 19 * * * %(webapp_dir)s/cron.sh %(env_dir)s > %(backup_dir)s/cron.log' % env
    run('echo "%s" >> /tmp/crondump' % cronjob)
    run('crontab /tmp/crondump')
示例#47
0
def mennu():
    surface = pygame.display.set_mode((WIN_WIDTH, WIN_HEIGHT))
    surface.fill((51, 51, 51))
    menu = Menu()  #necessary
    menu.init(['Start', 'Options', 'Quit'], surface)  #necessary
    menu.draw()  #necessary
    pygame.key.set_repeat(199, 69)  #(delay,interval)
    pygame.display.update()
    menus = True
    server = False
    while menus:
        for event in pygame.event.get():
            if event.type == KEYDOWN:
                if event.key == K_UP:
                    menu.draw(-1)  #here is the Menu class function
                if event.key == K_DOWN:
                    menu.draw(1)  #here is the Menu class function
                if event.key == K_RETURN:
                    if menu.get_position() == 0:
                        return server
                    if menu.get_position(
                    ) == 2:  #here is the Menu class function
                        pygame.display.quit()
                        sys.exit()
                    if menu.get_position(
                    ) == 1:  #here is the Menu class function
                        server = settings()
                        menu = Menu()  #necessary
                        menu.init(['Start', 'Options', 'Quit'],
                                  surface)  #necessary
                        surface.fill((51, 51, 51))
                        menu.draw()

                if event.key == K_ESCAPE:
                    pygame.display.quit()
                    sys.exit()
                pygame.display.update()
            elif event.type == QUIT:
                pygame.display.quit()
                sys.exit()
        pygame.time.wait(8)
def regen_tarball(srcdir, source):  # {{{
    """
    Generate a tarball of a config dir

    This is a helper function for regenerating all the config tarballs for upload

    Files end up in

    * ``conf/tarballs``
    """

    target_dir = os.path.join(local_tar_dir, srcdir)
    target = os.path.join(target_dir, source + '.tar.gz')
    srcdir = os.path.join(local_config_dir, srcdir)

    local('if [ -e ' + target + ' ]; then mv ' + target + ' ' + target +
          '.tar.gz.bak.' + get_cur_timestamp + '; fi')
    local('mkdir -p ' + target_dir)

    with settings(hide('warnings'), warn_only=True):
        if local('[ -e "' + srcdir + '" ]').succeeded:
            with lcd(srcdir):
                local('tar -czf ' + target + ' ' + source + '')
def install_vim_config():  # {{{
    """
    Install custom vim configuration

    Try to install our custom vim configuration in the main system 
    for all users.
    """
    env.host_string = root_host

    if len(vim_config_tarball_url):
        # get nice vim configuration
        with settings(hide('warnings'), warn_only=True):
            if run('wget ' + vim_config_tarball_url).succeeded:
                filename = os.path.basename(vim_config_tarball_url)
                run('tar -zxf ' + filename)

                run('rm -rf /usr/share/vim/vimfiles')

                # install the vim configuration system wide
                run('mv .vimrc /etc/vim/vimrc.local')
                run('mv .vim /usr/share/vim/vimfiles')

                # cleanup
                run('rm -rf ' + filename)
示例#50
0
文件: menu.py 项目: Ludokir/proect
    stop = True
    if stop:
        label = pg.image.load('textures/settings.png')
        label_rect = label.get_rect(center=((1920 // 2), 200))
        screen.blit(label, label_rect)
        bt_st('BACK', 50, (screen_height - label_rect[3] - 50), menu)


run = True
while run:
    for e in pg.event.get():
        if e.type == pg.QUIT:
            sys.exit(0)
        elif e.type == pg.KEYDOWN:
            if e.key == pg.K_ESCAPE:
                sys.exit(0)

    screen.fill(BG)

    if not stop:
        bt_st('START', 1350, 650, starter)
        bt_st('SETTINGS', 1350, 750, settings)
        bt_st('QUIT', 1350, 850, quit)
    if stop:
        settings()
    if begin:
        run = False
    name()

    pg.display.update()
def install_gitolite_config():  # {{{
    """
    Initializes and sets up the gitolite server

    Installs and a basic git server adds your repos and gives
    your developers access to those repos. There's no backup
    fab task because there are never any repos to begin with,
    you may however wish to run the ``clean_gitolite`` task
    which deletes any and all files that the gitolite setup
    adds to its home directory.
    """
    env.host_string = deploy_host

    # create key pair for deploy user for doing checkouts
    with settings(hide('warnings'), warn_only=True):
        run('no | ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa')
    deploy_ssh_rsa = run('cat ~/.ssh/id_rsa.pub')
    local_ssh_rsa = local('cat ~/.ssh/id_rsa.pub', capture=True)

    # setup gitolite user and repositories
    env.host_string = root_host

    # gitolite is very adamant in its desires to run as its own independent
    # user which is added when gitolite is installed. thusly we must first
    # enable shell access so we can log in as the gitolite user
    clone_root_pubkey('gitolite', '/var/lib/gitolite')

    # set git user config on the server itself for the user we'll be working as
    env.host_string = gitolite_host
    run('git config --global user.name "' + gitolite_admin_name + '"')
    run('git config --global user.email ' + gitolite_admin_email)

    # because gitolite makes some assumptions about how we'll be using ssh
    # it does not like it if there is already a .ssh folder so we must
    # delete the .ssh dir before running gl-setup to install
    # the gitolite configuration.
    #
    # Deleting the .ssh folder, obviously will lock us out, but the gitolite
    # setup script by default requires a public key and will load this
    # key so users can do repository checkouts. Gitolite does not, however
    # grant shell access to its user account, so we must do that explicitly.
    #
    # We must do all these things at once to prevent being locked out between
    # commands because fabric retrieves a new connection for each command
    run("echo '" + local_ssh_rsa + "' > ~/" + gitolite_admin_user + ".pub")
    run('rm -rf .ssh && gl-setup ~/' + gitolite_admin_user +
        '.pub && yes "" | /usr/share/gitolite/gl-tool shell-add ~/' +
        gitolite_admin_user + '.pub')

    # save original config information
    git_local_name = local('git config --global --get user.name', capture=True)
    git_local_email = local('git config --global --get user.email',
                            capture=True)

    local('# SAVED CONFIG: ' + git_local_name + ' ' + git_local_email)

    local('git config --global user.name "' + gitolite_admin_name + '"')
    local('git config --global user.email ' + gitolite_admin_email)

    # make a local dir for checking out the gitolite admin settings
    local('mkdir -p ' + gitolite_admin_local)
    local('rm -rf ' + gitolite_admin_local + '/gitolite-admin')

    with lcd(gitolite_admin_local):
        local('git clone ' + gitolite_host + ':gitolite-admin')

    with lcd(gitolite_admin_local + '/gitolite-admin'):
        # and add keys for users
        local("echo '" + deploy_ssh_rsa + "' > keydir/" + deploy_username +
              ".pub")

    local('rm -rf ' + gitolite_admin_local +
          '/gitolite-admin/conf/gitolite.conf')
    local('cp ' + local_config_dir + '/gitolite.conf ' + gitolite_admin_local +
          '/gitolite-admin/conf')
    local('cp ' + local_config_dir + '/gitolite_repos.conf ' +
          gitolite_admin_local + '/gitolite-admin/conf')

    for name in git_repo_devteam:
        with settings(hide('warnings'), warn_only=True):
            if local('[ ! -e ' + local_config_dir + '/keys/gitolite/' + name +
                     '.pub ]').succeeded:
                local('ssh-keygen -t rsa -N "" -f ' + local_config_dir +
                      '/keys/gitolite/' + name)

            local('cp ' + local_config_dir + '/keys/gitolite/' + name +
                  '.pub ' + gitolite_admin_local + '/gitolite-admin/keydir')

    with lcd(gitolite_admin_local + '/gitolite-admin'):
        local('git add .')
        local('git commit -a -m "Added users"')
        local('git push origin master')

    # restore original config information
    local('git config --global user.name "' + git_local_name + '"')
    local('git config --global user.email ' + git_local_email)
示例#52
0
 def getConsoleStr(self):
     return settings().get('py').get('consoleStr', "{title}, {variable}")
示例#53
0
 def getConsoleSingleQuotes(self):
     return settings().get('py').get('single_quotes', False)
示例#54
0
 def getPreTag(self):
     return settings().get('php').get('preTag', True)
示例#55
0
def settings(**d):
    return o(name="Differention Evolution",
             what="DE tuner. Tune the predictor parameters parameters",
             author="Rahul Krishna",
             adaptation=
             "https://github.com/ai-se/Rahul/blob/master/DEADANT/deadant.py",
             copyleft="(c) 2014, MIT license, http://goo.gl/3UYBp",
             seed=1,
             np=10,
             k=100,
             tiny=0.01,
             de=o(np=5, iter=5, epsilon=1.01, N=20, f=0.3, cf=0.4,
                  lives=100)).update(**d)


The = settings()


class diffEvol(object):
    """
  Differential Evolution
  """
    def __init__(self, model, data):
        self.frontier = []
        self.model = model(data)

    def new(self):
        # Creates a new random instance
        return [randi(d[0], d[1]) for d in self.model.indep()]

    def initFront(self, N):
示例#56
0
 def getConsoleFunc(self):
     return settings().get('php').get('consoleFunc', ['print_r'])
示例#57
0
 def getDieAfterLog(self):
     return settings().get('php').get('dieAfterLog', False)
示例#58
0
__language__ = __addon__.getLocalizedString
# settings method
BASE_CACHE_PATH = os.path.join(
    xbmc.translatePath("special://profile").decode('utf-8'), "Thumbnails",
    "Video")
BASE_CURRENT_SOURCE_PATH = os.path.join(
    xbmc.translatePath("special://profile/addon_data/").decode('utf-8'),
    os.path.basename(__addon__.getAddonInfo('path')))
BASE_RESOURCE_PATH = xbmc.translatePath(
    os.path.join(__addon__.getAddonInfo('path').decode('utf-8'), 'resources'))
home_automation_folder = os.path.join(BASE_CURRENT_SOURCE_PATH, "ha_scripts")
home_automation_module = os.path.join(home_automation_folder,
                                      "home_automation.py")
sys.path.append(os.path.join(BASE_RESOURCE_PATH, "lib"))
from settings import *
settings = settings()

trivia_settings = settings.trivia_settings
trailer_settings = settings.trailer_settings
ha_settings = settings.ha_settings
video_settings = settings.video_settings
extra_settings = settings.extra_settings
audio_formats = settings.audio_formats
_3d_settings = settings._3d_settings
triggers = settings.triggers

playback = ""
header = "Cinema Experience"
time_delay = 200
image = xbmc.translatePath(
    os.path.join(__addon__.getAddonInfo("path"), "icon.png")).decode('utf-8')
示例#59
0
    flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
except ImportError:
    flags = None

# If modifying these scopes, delete your previously saved credentials
# at ~/.credentials/drive-python-quickstart.json
SCOPES = [
    'https://www.googleapis.com/auth/drive.readonly',
    'https://www.googleapis.com/auth/spreadsheets.readonly',
    'https://www.googleapis.com/auth/gmail.compose'
]
CLIENT_SECRET_FILE = 'client_secret.json'
APPLICATION_NAME = 'Drive API Python Quickstart'

#initialize settings
config = settings()

# ID of sheet to monitor
sheetID = None
discountID = None
rosterID = None

# Store the last submission timestamp
lastSubDate = None

waitForSheet = None

# Create a dictionary for fileNames and fileIds
fileDict = {}

示例#60
0
def downloadDukasData(cross):
    """Download Dukas Data and store it in file"""

    BASEFILE = 'dukas_{0}.csv'.format(cross.lower())
    BASEDIR = os.path.abspath(os.path.dirname(__file__))
    file_path = os.path.join(BASEDIR + '/../', 'data/', BASEFILE)

    date_output = settings('dukascopy.cfg', 'date_output')
    datetime_format = settings('dukascopy.cfg', 'datetime_format')
    delimiter = settings('dukascopy.cfg', 'delimiter')
    interval = settings('dukascopy.cfg', 'interval')
    symbol = settings('dukascopy.cfg', 'symbol', cross)
    system = settings('dukascopy.cfg', 'system')

    utc_now = roundTime(datetime.datetime.utcnow()).replace(tzinfo=pytz.utc)
    # cet_now = utc_now.astimezone(pytz.timezone('CET'))
    # start_date = utc_now.date().strftime(settings('dukascopy.cfg', 'date_input_format'))
    start_date = settings('dukascopy.cfg', 'start_date')

    # if cet_now.isoweekday() >= 5 and cet_now.hour >= 22 and cet_now.minute > 0:
    #     cet_now.replace(hour=22, minute=0)
    #     utc_now = cet_now.astimezone(pytz.timezone('UTC'))
    utc_now = utc_now.replace(tzinfo=None)

    stored_candles = 0
    candles_to_store = settings('dukascopy.cfg', 'min_candles')

    if os.path.exists(file_path):
        with open(file_path, mode='r') as f:
            quote = list(csv.reader(f, delimiter=';'))[::-1]
            stored_candles = len(quote) - 1
            last_saved_time = roundTime(datetime.datetime.strptime(quote[1][0], datetime_format))
            start_date = last_saved_time.strftime(settings('dukascopy.cfg', 'date_input_format'))
            day_shift = datetime.timedelta(1)
    else:
        with open(file_path, mode='w') as f:
            csv_writer = csv.writer(f, delimiter=';')
            csv_writer.writerow(['datetime', 'open', 'high', 'low', 'close', 'volume'])
            last_saved_time = datetime.datetime(1970, 1, 1)

    if last_saved_time < utc_now:
        print('Last stored candle is older than actual time')
    else:
        return

    while last_saved_time < utc_now or stored_candles < candles_to_store:
        chunk_size = max([min([settings('dukascopy.cfg', 'chunk_size'), (utc_now - last_saved_time).total_seconds() // 60]), 200])
        print('Downloading', chunk_size, 'starting from', start_date, 'last saved time', last_saved_time)
        url = 'http://www.dukascopy.com/freeApplets/exp/exp.php?fromD={0}&np={1}&interval={2}&DF={3}&Stock={4}&endSym={5}&split={6}'.format(start_date, chunk_size, interval, date_output, symbol, system, delimiter)

        succesfull_downloaded = False
        while not succesfull_downloaded:
            try:
                url_handle = urllib.request.urlopen(url)
            except urllib.error.URLError:
                print('connection error')
                return
            else:
                head_line = next(url_handle).decode('UTF-8').strip()
                if head_line.split(';')[0] != 'DATE':
                    print(head_line, head_line.split(';'))
                else:
                    succesfull_downloaded = True

        for line in url_handle:
            quote = line.decode('UTF-8').strip().split(';')
            try:
                date = roundTime(datetime.datetime.strptime(' '.join([quote[0], quote[1]]), datetime_format))
                date_str = datetime.datetime.strftime(date, datetime_format)
            except:
                raise
            finally:
                if date > last_saved_time:
                    day_shift = datetime.timedelta(1)
                    with open(file_path, mode='a') as f:
                        csv_writer = csv.writer(f, delimiter=';')
                        csv_writer.writerow([date_str, quote[3], quote[6], quote[5], quote[4], quote[2]])
                        last_saved_time = date
                        start_date = last_saved_time.strftime(settings('dukascopy.cfg', 'date_input_format'))
                elif date == last_saved_time:
                    start_date = (last_saved_time + day_shift).strftime(settings('dukascopy.cfg', 'date_input_format'))
                    day_shift += datetime.timedelta(1)