Beispiel #1
0
def connect(config = None, nodb = False):
    """Connect if not already connected, using config values."""
    if get_dbconnection():
        return 0
    config = config or configxml.default_config().config
    if nodb:
        db = ''
    else:
        db = config.db_name

    host=config.__dict__.get('db_host','')
    port=""
    if ':' in host:
        host,port=config.__dict__.get('db_host','').split(":")

    if port == '':
        port = 3306
    else:
        port = int(port)
    do_connect(db=db,
               host=host,
               port=port,
               user=config.__dict__.get('db_user',''),
               passwd=config.__dict__.get('db_passwd', ''))
    return 1
Beispiel #2
0
def connect(config = None, nodb = False):
    """Connect if not already connected, using config values."""
    if get_dbconnection():
        return 0
    config = config or configxml.default_config().config
    if nodb:
        db = ''
    else:
        db = config.db_name
    
    host=config.__dict__.get('db_host','')
    port=""
    if ':' in host:
        host,port=config.__dict__.get('db_host','').split(":")

    if port == '':
        port = 3306
    else:
        port = int(port)
    do_connect(db=db,
               host=host,
               port=port,
               user=config.__dict__.get('db_user',''),
               passwd=config.__dict__.get('db_passwd', ''))
    return 1
def get_output_file_path(filename):
    """ Return the filename's path in the upload directory
        Use this if you're developing a validator/assimilator in Python
    """
    config = configxml.default_config()
    fanout = long(config.config.uldl_dir_fanout)
    s = md5.new(filename).hexdigest()[1:8]
    x = long(s, 16)
    return "%s/%x/%s" % (config.config.upload_dir, x % fanout, filename)
Beispiel #4
0
def get_output_file_path(filename):
    """ Return the filename's path in the upload directory
        Use this if you're developing a validator/assimilator in Python
    """
    config = configxml.default_config()
    fanout = long(config.config.uldl_dir_fanout)
    s = md5.new(filename).hexdigest()[1:8]
    x = long(s, 16)
    return "%s/%x/%s" % (config.config.upload_dir, x % fanout, filename)
def create_database(srcdir, config = None, drop_first = False):
    ''' creates a new database. '''
    import boinc_path_config
    config = config or configxml.default_config().config
    connect(config, nodb=True)
    cursor = get_dbconnection().cursor()
    if drop_first:
        cursor.execute("drop database if exists %s"%config.db_name)
    cursor.execute("create database %s"%config.db_name)
    cursor.execute("use %s"%config.db_name)
    for file in ['schema.sql', 'constraints.sql']:
        _execute_sql_script(cursor, os.path.join(srcdir, 'db', file))
    cursor.close()
Beispiel #6
0
def create_database(srcdir, config=None, drop_first=False):
    ''' creates a new database. '''
    import boinc_path_config
    config = config or configxml.default_config().config
    connect(config, nodb=True)
    cursor = get_dbconnection().cursor()
    if drop_first:
        cursor.execute("drop database if exists %s" % config.db_name)
    cursor.execute("create database %s" % config.db_name)
    cursor.execute("use %s" % config.db_name)
    for file in ['schema.sql', 'constraints.sql']:
        _execute_sql_script(cursor, os.path.join(srcdir, 'db', file))
    cursor.close()
def connect(config = None, nodb = False):
    """Connect if not already connected, using config values."""
    if get_dbconnection():
        return 0
    config = config or configxml.default_config().config
    if nodb:
        db = ''
    else:
        db = config.db_name
    
    host=config.__dict__.get('db_host','')
    do_connect(db=db,
               host=host,
               user=config.__dict__.get('db_user',''),
               passwd=config.__dict__.get('db_passwd', ''))
    return 1
Beispiel #8
0
def connect(config=None, nodb=False):
    """Connect if not already connected, using config values."""
    if get_dbconnection():
        return 0
    config = config or configxml.default_config().config
    if nodb:
        db = ''
    else:
        db = config.db_name

    host = config.__dict__.get('db_host', '')
    do_connect(db=db,
               host=host,
               user=config.__dict__.get('db_user', ''),
               passwd=config.__dict__.get('db_passwd', ''))
    return 1
def process_app_file(file, signature_text=None, quiet=False, executable=True):
    """Handle a new executable (or non-executable) file to be added to the
    database.

    0. target filename is url_filename as described in process_app_version
    1. Copy file to download_dir if necessary.
    2. Return <file_info> XML.
        - if signature_text specified, use it
        - if no signature_text specified, generate md5sum.
    """

    config = configxml.default_config()

    source_dir, source_file_base = os.path.split(file)
    target_file_base = get_kludge_url_filename(source_file_base)
    target_path = os.path.join(config.config.download_dir, target_file_base)
    target_url = os.path.join(config.config.download_url, target_file_base)
    if file != target_path:
        if not quiet:
            print "Copying %s to %s" % (source_file_base, target_path)
        shutil.copy(file, target_path)

    xml = """<file_info>
    <name>%s</name>
    <url>%s</url>
""" % (
        target_file_base,
        target_url,
    )
    if executable:
        xml += "    <executable/>\n"
    if signature_text:
        if signature_text.find("<signatures>") >= 0:
            xml += signature_text
        else:
            xml += "    <file_signature>\n%s    </file_signature>\n" % signature_text
    else:
        xml += "    <md5_cksum>%s</md5_cksum>\n" % md5_file(target_path)

    xml += "    <nbytes>%f</nbytes>\n</file_info>\n" % file_size(target_path)
    return xml
Beispiel #10
0
def sign_executable(executable_path, quiet=False):
    """Returns signed text for executable"""
    config = configxml.default_config()
    if not quiet:
        query_sign_executable(executable_path)
        print "Signing", executable_path
    code_sign_key = os.path.join(config.config.key_dir, "code_sign_private")

    # sign_executable could be in bin/ or ../tool/, depending on
    # whether this is a test or an upgrade

    sign_executable_path = "bin/sign_executable"
    if not os.path.exists(sign_executable_path):
        sign_executable_path = "../tools/sign_executable"
        if not os.path.exists(sign_executable_path):
            print os.getcwd()
            raise SystemExit("sign_executable not found! did you `make' it?")
    signature_text = os.popen("%s %s %s" % (sign_executable_path, executable_path, code_sign_key)).read()
    if not signature_text:
        raise SystemExit("Couldn't sign executable %s" % executable_path)
    return signature_text
Beispiel #11
0
def sign_executable(executable_path, quiet=False):
    '''Returns signed text for executable'''
    config = configxml.default_config()
    if not quiet:
        query_sign_executable(executable_path)
        print 'Signing', executable_path
    code_sign_key = os.path.join(config.config.key_dir, 'code_sign_private')

    # sign_executable could be in bin/ or ../tool/, depending on
    # whether this is a test or an upgrade

    sign_executable_path = 'bin/sign_executable'
    if not os.path.exists(sign_executable_path):
        sign_executable_path = '../tools/sign_executable'
        if not os.path.exists(sign_executable_path):
            print os.getcwd()
            raise SystemExit("sign_executable not found! did you `make' it?")
    signature_text = os.popen('%s %s %s'%(sign_executable_path,
        executable_path,code_sign_key)).read()
    if not signature_text:
        raise SystemExit("Couldn't sign executable %s"%executable_path)
    return signature_text
def process_app_file(file, signature_text=None, quiet=False, executable=True):
    '''Handle a new executable (or non-executable) file to be added to the
    database.

    0. target filename is url_filename as described in process_app_version
    1. Copy file to download_dir if necessary.
    2. Return <file_info> XML.
        - if signature_text specified, use it
        - if no signature_text specified, generate md5sum.
    '''

    config = configxml.default_config()

    source_dir, source_file_base = os.path.split(file)
    target_file_base = get_kludge_url_filename(source_file_base)
    target_path = os.path.join(config.config.download_dir, target_file_base)
    target_url = os.path.join(config.config.download_url, target_file_base)
    if file != target_path:
        if not quiet:
            print "Copying %s to %s" % (source_file_base, target_path)
        shutil.copy(file, target_path)

    xml = '''<file_info>
    <name>%s</name>
    <url>%s</url>
''' % (target_file_base, target_url)
    if executable:
        xml += '    <executable/>\n'
    if signature_text:
        if signature_text.find('<signatures>') >= 0:
            xml += signature_text
        else:
            xml += '    <file_signature>\n%s    </file_signature>\n' % signature_text
    else:
        xml += '    <md5_cksum>%s</md5_cksum>\n' % md5_file(target_path)

    xml += '    <nbytes>%f</nbytes>\n</file_info>\n' % file_size(target_path)
    return xml
def process_app_file(file, signature_text=None, quiet=False, executable=True):
    '''Handle a new file to be added to the app version.

    0. target filename is url_filename as described in process_app_version
    1. Copy file to download_dir if necessary.
    2. Return <file_info> XML.
        - if signature_text specified, use it
        - if no signature_text specified, generate md5sum.
    '''

    config = configxml.default_config()

    source_dir, source_file_base = os.path.split(file)
    target_file_base = get_kludge_url_filename(source_file_base)
    target_path = os.path.join(config.config.download_dir, target_file_base)
    target_url = os.path.join(config.config.download_url, target_file_base)
    if not quiet:
        print "Copying %s to %s"%(source_file_base, target_path)
    check_immutable(file, target_path)
    shutil.copy(file, target_path)

    xml = '''<file_info>
    <name>%s</name>
    <url>%s</url>
''' %(target_file_base,target_url)
    if executable:
        xml += '    <executable/>\n'
    if signature_text:
        if signature_text.find('<signatures>') >= 0:
            xml += signature_text
        else:
            xml += '    <file_signature>\n%s    </file_signature>\n'%signature_text
    else:
        xml += '    <md5_cksum>%s</md5_cksum>\n' % md5_file(target_path)

    xml += '    <nbytes>%f</nbytes>\n</file_info>\n' % file_size(target_path)
    return xml