Example #1
0
def main(args):
    call('/scripts/create_data_links.sh')
    check_upgrade()
    os.chdir(installdir)
    call('service nginx start &')

    admin_pw = {
        'email': get_conf('SEAFILE_ADMIN_EMAIL', '*****@*****.**'),
        'password': get_conf('SEAFILE_ADMIN_PASSWORD', 'asecret'),
    }
    password_file = join(topdir, 'conf', 'admin.txt')
    with open(password_file, 'w+') as fp:
        json.dump(admin_pw, fp)


    try:
        call('{} start'.format(get_script('seafile.sh')))
        call('{} start'.format(get_script('seahub.sh')))
        if args.mode == 'backend':
            call('{} start'.format(get_script('seafile-background-tasks.sh')))
    finally:
        if exists(password_file):
            os.unlink(password_file)

    print 'seafile server is running now.'
    try:
        watch_controller()
    except KeyboardInterrupt:
        print 'Stopping seafile server.'
        sys.exit(0)
Example #2
0
def main():
    if not exists(shared_seafiledir):
        os.mkdir(shared_seafiledir)
    if not exists(generated_dir):
        os.makedirs(generated_dir)

    check_upgrade()
    os.chdir(installdir)

    admin_pw = {
        'email': get_conf('SEAFILE_ADMIN_EMAIL', '*****@*****.**'),
        'password': get_conf('SEAFILE_ADMIN_PASSWORD', 'asecret'),
    }
    password_file = join(topdir, 'conf', 'admin.txt')
    with open(password_file, 'w') as fp:
        json.dump(admin_pw, fp)

    try:
        call('{} start'.format(get_script('seafile.sh')))
        call('{} start'.format(get_script('seahub.sh')))
    finally:
        if exists(password_file):
            os.unlink(password_file)

    print 'seafile server is running now.'
    try:
        watch_controller()
    except KeyboardInterrupt:
        print 'Stopping seafile server.'
        sys.exit(0)
def init_seafile_server():
    version_stamp_file = get_version_stamp_file()
    if exists(join(shared_seafiledir, 'seafile-data')):
        if not exists(version_stamp_file):
            update_version_stamp(os.environ['SEAFILE_VERSION'])
        # sysbol link unlink after docker finish.
        latest_version_dir='/opt/seafile/seafile-server-latest'
        current_version_dir='/opt/seafile/' + get_conf('SEAFILE_SERVER', 'seafile-server') + '-' +  read_version_stamp()
        if not exists(latest_version_dir):
            call('ln -sf ' + current_version_dir + ' ' + latest_version_dir)
        loginfo('Skip running setup-seafile-mysql.py because there is existing seafile-data folder.')
        return

    loginfo('Now running setup-seafile-mysql.py in auto mode.')
    env = {
        'SERVER_NAME': 'seafile',
        'SERVER_IP': get_conf('SEAFILE_SERVER_HOSTNAME', 'seafile.example.com'),
        'MYSQL_USER': '******',
        'MYSQL_USER_PASSWD': str(uuid.uuid4()),
        'MYSQL_USER_HOST': '127.0.0.1',
        # Default MariaDB root user has empty password and can only connect from localhost.
        'MYSQL_ROOT_PASSWD': '',
    }

    # Change the script to allow mysql root password to be empty
    call('''sed -i -e 's/if not mysql_root_passwd/if not mysql_root_passwd and "MYSQL_ROOT_PASSWD" not in os.environ/g' {}'''
         .format(get_script('setup-seafile-mysql.py')))

    setup_script = get_script('setup-seafile-mysql.sh')
    call('{} auto -n seafile'.format(setup_script), env=env)

    domain = get_conf('SEAFILE_SERVER_HOSTNAME', 'seafile.example.com')
    proto = 'https' if is_https() else 'http'
    with open(join(topdir, 'conf', 'seahub_settings.py'), 'a+') as fp:
        fp.write('\n')
        fp.write('FILE_SERVER_ROOT = "{proto}://{domain}/seafhttp"'.format(proto=proto, domain=domain))
        fp.write('\n')

    # By default ccnet-server binds to the unix socket file
    # "/opt/seafile/ccnet/ccnet.sock", but /opt/seafile/ccnet/ is a mounted
    # volume from the docker host, and on windows and some linux environment
    # it's not possible to create unix sockets in an external-mounted
    # directories. So we change the unix socket file path to
    # "/opt/seafile/ccnet.sock" to avoid this problem.
    with open(join(topdir, 'conf', 'ccnet.conf'), 'a+') as fp:
        fp.write('\n')
        fp.write('[Client]\n')
        fp.write('UNIX_SOCKET = /opt/seafile/ccnet.sock\n')
        fp.write('\n')

    files_to_copy = ['conf', 'ccnet', 'seafile-data', 'seahub-data', 'pro-data']
    for fn in files_to_copy:
        src = join(topdir, fn)
        dst = join(shared_seafiledir, fn)
        if not exists(dst) and exists(src):
            shutil.move(src, shared_seafiledir)
            call('ln -sf ' + join(shared_seafiledir, fn) + ' ' + src)

    loginfo('Updating version stamp')
    update_version_stamp(os.environ['SEAFILE_VERSION'])
Example #4
0
def main():
    call('. /etc/init.d/create_data_links.sh')
    os.chdir(installdir)

    call('{} start'.format(get_script('seafile.sh')))
    call('{} start'.format(get_script('seahub.sh')))

    print 'seafile server is running now.'
    sys.exit(0)
Example #5
0
def main():
    logdbg("Starting seafile container ...")
    if not exists(shared_seafiledir):
        os.mkdir(shared_seafiledir)
    if not exists(generated_dir):
        os.makedirs(generated_dir)

    if is_https():
        logdbg("Initializing letsencrypt ...")
        init_letsencrypt()
    
    logdbg("Generating nginx config ...")
    generate_local_nginx_conf()
    logdbg("Reloading nginx ...")
    call('nginx -s reload')


    logdbg("Waiting for mysql server ...")
    wait_for_mysql()
    init_seafile_server()

    check_upgrade()
    os.chdir(installdir)

    admin_pw = {
        'email': get_conf('SEAFILE_ADMIN_EMAIL', '*****@*****.**'),
        'password': get_conf('SEAFILE_ADMIN_PASSWORD', 'asecret'),
    }
    password_file = join(topdir, 'conf', 'admin.txt')
    with open(password_file, 'w') as fp:
        json.dump(admin_pw, fp)


    try:
        call('{} start'.format(get_script('seafile.sh')))
        call('{} start'.format(get_script('seahub.sh')))
    finally:
        if exists(password_file):
            os.unlink(password_file)

    loginfo("Seafile server is running now.")
    try:
        watch_controller()
    except KeyboardInterrupt:
        loginfo("Stopping seafile server.")
        sys.exit(0)
Example #6
0
def main():
    if not exists(shared_seafiledir):
        os.mkdir(shared_seafiledir)
    if not exists(generated_dir):
        os.makedirs(generated_dir)

    if listen_on_https():
        init_letsencrypt()

    utils.nginx.change_nginx_config()

    wait_for_mysql()
    init_seafile_server()

    check_upgrade()

    apply_code_fixes()
    update_settings()
    update_seafdav_config()

    os.chdir(installdir)

    admin_pw = {
        'email': get_conf('SEAFILE_ADMIN_EMAIL', '*****@*****.**'),
        'password': get_conf('SEAFILE_ADMIN_PASSWORD', 'asecret'),
    }
    password_file = join(topdir, 'conf', 'admin.txt')
    with open(password_file, 'w') as fp:
        json.dump(admin_pw, fp)

    try:
        call('{} start'.format(get_script('seafile.sh')))
        call('{} start'.format(get_script('seahub.sh')))
    finally:
        if exists(password_file):
            os.unlink(password_file)

    print 'seafile server is running now.'
    try:
        watch_controller()
    except KeyboardInterrupt:
        print 'Stopping seafile server.'
        sys.exit(0)
Example #7
0
def main():
    admin_pw = {
        'email': get_conf('admin.email'),
        'password': get_conf('admin.password'),
    }
    password_file = join(topdir, 'conf', 'admin.txt')
    with open(password_file, 'w') as fp:
        json.dump(admin_pw, fp)

    wait_for_mysql()

    try:
        call('{} start'.format(get_script('seafile.sh')))
        call('{} start'.format(get_script('seahub.sh')))
    finally:
        if exists(password_file):
            os.unlink(password_file)

    print 'seafile server is running now.'
    try:
        watch_controller()
    except KeyboardInterrupt:
        print 'Stopping seafile server.'
        sys.exit(0)
Example #8
0
    def add_to_library(self, context, objects: typing.List[bpy.types.Object],
                       info: dict):

        id = utils.get_slug(info.get("name", "")).strip('-_')
        if not id:
            id = utils.get_slug(
                utils.get_longest_substring(
                    [object.name for object in objects])).strip('-_')
        if not id:
            id = "untitled_" + utils.get_time_stamp()
        id = self.ensure_unique_id(id)

        asset_folder = os.path.join(self.library, id)

        if not info.get("name"):
            info["name"] = id.replace('_', ' ')

        do_move_images = info.pop('do_move_images')

        asset = Asset.new(asset_folder)
        asset.update_info(info)

        blend_file_path = os.path.join(asset_folder, id + ".blend")
        bpy.data.libraries.write(blend_file_path,
                                 set(objects),
                                 fake_user=True,
                                 path_remap='ABSOLUTE',
                                 compress=True)

        initialize_asset = utils.get_script('initialize_asset.py')
        argv = []
        if do_move_images:
            argv.append('-move_textures')
        bl_utils.run_blender(blend_file_path,
                             initialize_asset,
                             argv,
                             use_atool=True,
                             library_path=self.library)

        self[id] = asset

        threading.Thread(target=self.render_icon, args=(id, context)).start()

        update_search(context.window_manager, context)

        return id, blend_file_path
Example #9
0
def init_seafile_server():
    version_stamp_file = get_version_stamp_file()
    if exists(join(shared_seafiledir, 'seafile-data')):
        if not exists(version_stamp_file):
            update_version_stamp(os.environ['SEAFILE_VERSION'])
        # sysbol link unlink after docker finish.
        latest_version_dir = '/opt/seafile/seafile-server-latest'
        current_version_dir = '/opt/seafile/' + get_conf(
            'SEAFILE_SERVER', 'seafile-server') + '-' + read_version_stamp()
        if not exists(latest_version_dir):
            call('ln -sf ' + current_version_dir + ' ' + latest_version_dir)
        loginfo(
            'Skip running setup-seafile-mysql.py because there is existing seafile-data folder.'
        )
        return

    loginfo('Now running setup-seafile-mysql.py in auto mode.')
    env = {
        'SERVER_NAME': 'seafile',
        'SERVER_IP': get_conf('SEAFILE_SERVER_HOSTNAME',
                              'seafile.example.com'),
        'MYSQL_USER': '******',
        'MYSQL_USER_PASSWD': str(uuid.uuid4()),
        'MYSQL_USER_HOST': '%.%.%.%',
        'MYSQL_HOST': get_conf('DB_HOST', '127.0.0.1'),
        # Default MariaDB root user has empty password and can only connect from localhost.
        'MYSQL_ROOT_PASSWD': get_conf('DB_ROOT_PASSWD', ''),
    }

    # Change the script to allow mysql root password to be empty
    # call('''sed -i -e 's/if not mysql_root_passwd/if not mysql_root_passwd and "MYSQL_ROOT_PASSWD" not in os.environ/g' {}'''
    #     .format(get_script('setup-seafile-mysql.py')))

    # Change the script to disable check MYSQL_USER_HOST
    call(
        '''sed -i -e '/def validate_mysql_user_host(self, host)/a \ \ \ \ \ \ \ \ return host' {}'''
        .format(get_script('setup-seafile-mysql.py')))

    call(
        '''sed -i -e '/def validate_mysql_host(self, host)/a \ \ \ \ \ \ \ \ return host' {}'''
        .format(get_script('setup-seafile-mysql.py')))

    setup_script = get_script('setup-seafile-mysql.sh')
    call('{} auto -n seafile'.format(setup_script), env=env)

    domain = get_conf('SEAFILE_SERVER_HOSTNAME', 'seafile.example.com')
    proto = 'https' if is_https() else 'http'
    with open(join(topdir, 'conf', 'seahub_settings.py'), 'a+') as fp:
        fp.write('\n')
        fp.write("""CACHES = {
    'default': {
        'BACKEND': 'django_pylibmc.memcached.PyLibMCCache',
        'LOCATION': 'memcached:11211',
    },
    'locmem': {
        'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
    },
}
COMPRESS_CACHE_BACKEND = 'locmem'""")
        fp.write('\n')
        fp.write("TIME_ZONE = '{time_zone}'".format(
            time_zone=os.getenv('TIME_ZONE', default='Etc/UTC')))
        fp.write('\n')
        fp.write('FILE_SERVER_ROOT = "{proto}://{domain}/seafhttp"'.format(
            proto=proto, domain=domain))
        fp.write('\n')

    # By default ccnet-server binds to the unix socket file
    # "/opt/seafile/ccnet/ccnet.sock", but /opt/seafile/ccnet/ is a mounted
    # volume from the docker host, and on windows and some linux environment
    # it's not possible to create unix sockets in an external-mounted
    # directories. So we change the unix socket file path to
    # "/opt/seafile/ccnet.sock" to avoid this problem.
    with open(join(topdir, 'conf', 'ccnet.conf'), 'a+') as fp:
        fp.write('\n')
        fp.write('[Client]\n')
        fp.write('UNIX_SOCKET = /opt/seafile/ccnet.sock\n')
        fp.write('\n')

    # Disabled the Elasticsearch process on Seafile-container
    # Connection to the Elasticsearch-container
    if os.path.exists(join(topdir, 'conf', 'seafevents.conf')):
        with open(join(topdir, 'conf', 'seafevents.conf'), 'r') as fp:
            fp_lines = fp.readlines()
            if '[INDEX FILES]\n' in fp_lines:
                insert_index = fp_lines.index('[INDEX FILES]\n') + 1
                insert_lines = [
                    'es_port = 9200\n', 'es_host = elasticsearch\n',
                    'external_es_server = true\n'
                ]
                for line in insert_lines:
                    fp_lines.insert(insert_index, line)

            # office
            if '[OFFICE CONVERTER]\n' in fp_lines:
                insert_index = fp_lines.index('[OFFICE CONVERTER]\n') + 1
                insert_lines = ['host = 127.0.0.1\n', 'port = 6000\n']
                for line in insert_lines:
                    fp_lines.insert(insert_index, line)

        with open(join(topdir, 'conf', 'seafevents.conf'), 'w') as fp:
            fp.writelines(fp_lines)

        # office
        with open(join(topdir, 'conf', 'seahub_settings.py'), 'r') as fp:
            fp_lines = fp.readlines()
            if "OFFICE_CONVERTOR_ROOT = 'http://127.0.0.1:6000/'\n" not in fp_lines:
                fp_lines.append(
                    "OFFICE_CONVERTOR_ROOT = 'http://127.0.0.1:6000/'\n")

        with open(join(topdir, 'conf', 'seahub_settings.py'), 'w') as fp:
            fp.writelines(fp_lines)

    # After the setup script creates all the files inside the
    # container, we need to move them to the shared volume
    #
    # e.g move "/opt/seafile/seafile-data" to "/shared/seafile/seafile-data"
    files_to_copy = [
        'conf', 'ccnet', 'seafile-data', 'seahub-data', 'pro-data'
    ]
    for fn in files_to_copy:
        src = join(topdir, fn)
        dst = join(shared_seafiledir, fn)
        if not exists(dst) and exists(src):
            shutil.move(src, shared_seafiledir)
            call('ln -sf ' + join(shared_seafiledir, fn) + ' ' + src)

    loginfo('Updating version stamp')
    update_version_stamp(os.environ['SEAFILE_VERSION'])
def init_seafile_server():
    version_stamp_file = get_version_stamp_file()
    if exists(join(shared_seafiledir, 'seafile-data')):
        if not exists(version_stamp_file):
            update_version_stamp(os.environ['SEAFILE_VERSION'])
        # sysbol link unlink after docker finish.
        latest_version_dir = '/opt/seafile/seafile-server-latest'
        current_version_dir = '/opt/seafile/' + get_conf(
            'SEAFILE_SERVER', 'seafile-server') + '-' + read_version_stamp()
        if not exists(latest_version_dir):
            call('ln -sf ' + current_version_dir + ' ' + latest_version_dir)
        loginfo(
            'Skip running setup-seafile-mysql.py because there is existing seafile-data folder.'
        )
        return

    loginfo('Now running setup-seafile-mysql.py in auto mode.')
    env = {
        'SERVER_NAME': 'seafile',
        'SERVER_IP': get_conf('SEAFILE_SERVER_HOSTNAME',
                              'seafile.example.com'),
        'MYSQL_USER': '******',
        'MYSQL_USER_PASSWD': str(uuid.uuid4()),
        'MYSQL_USER_HOST': '127.0.0.1',
        # Default MariaDB root user has empty password and can only connect from localhost.
        'MYSQL_ROOT_PASSWD': '',
    }

    # Change the script to allow mysql root password to be empty
    call(
        '''sed -i -e 's/if not mysql_root_passwd/if not mysql_root_passwd and "MYSQL_ROOT_PASSWD" not in os.environ/g' {}'''
        .format(get_script('setup-seafile-mysql.py')))

    setup_script = get_script('setup-seafile-mysql.sh')
    call('{} auto -n seafile'.format(setup_script), env=env)

    domain = get_conf('SEAFILE_SERVER_HOSTNAME', 'seafile.example.com')
    proto = 'https' if is_https() else 'http'
    with open(join(topdir, 'conf', 'seahub_settings.py'), 'a+') as fp:
        fp.write('\n')
        fp.write("""CACHES = {
    'default': {
        'BACKEND': 'django_pylibmc.memcached.PyLibMCCache',
        'LOCATION': '127.0.0.1:11211',
    },
    'locmem': {
        'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
    },
}
COMPRESS_CACHE_BACKEND = 'locmem'

OFFICE_CONVERTOR_ROOT = 'http://127.0.0.1:6000/'\n""")
        fp.write("\nFILE_SERVER_ROOT = '{proto}://{domain}/seafhttp'\n".format(
            proto=proto, domain=domain))
        fp.write("""
TIME_ZONE                           = 'Europe/Berlin'
SITE_BASE                           = 'http://127.0.0.1'
SITE_NAME                           = 'Seafile Server'
SITE_TITLE                          = 'Seafile Server'
SITE_ROOT                           = '/'
ENABLE_SIGNUP                       = False
ACTIVATE_AFTER_REGISTRATION         = False
SEND_EMAIL_ON_ADDING_SYSTEM_MEMBER  = True
SEND_EMAIL_ON_RESETTING_USER_PASSWD = True
CLOUD_MODE                          = False
FILE_PREVIEW_MAX_SIZE               = 30 * 1024 * 1024
SESSION_COOKIE_AGE                  = 60 * 60 * 24 * 7 * 2
SESSION_SAVE_EVERY_REQUEST          = False
SESSION_EXPIRE_AT_BROWSER_CLOSE     = False\n""")

    # By default ccnet-server binds to the unix socket file
    # "/opt/seafile/ccnet/ccnet.sock", but /opt/seafile/ccnet/ is a mounted
    # volume from the docker host, and on windows and some linux environment
    # it's not possible to create unix sockets in an external-mounted
    # directories. So we change the unix socket file path to
    # "/opt/seafile/ccnet.sock" to avoid this problem.
    with open(join(topdir, 'conf', 'ccnet.conf'), 'a+') as fp:
        fp.write('\n')
        fp.write('[Client]\n')
        fp.write('UNIX_SOCKET = /opt/seafile/ccnet.sock\n')
        fp.write('\n')

    # Disabled the Elasticsearch process on Seafile-container
    # Connection to the Elasticsearch-container
    with open(join(topdir, 'conf', 'seafevents.conf'), 'r') as fp:
        seafevents_lines = fp.readlines()
        # es
        es_insert_index = seafevents_lines.index('[INDEX FILES]\n') + 1
        es_insert_lines = [
            'external_es_server = true\n', 'es_host = 127.0.0.1\n',
            'es_port = 9200\n'
        ]
        for line in es_insert_lines:
            seafevents_lines.insert(es_insert_index, line)
        # office
        office_insert_index = seafevents_lines.index(
            '[OFFICE CONVERTER]\n') + 1
        office_insert_lines = ['host = 127.0.0.1\n', 'port = 6000\n']
        for line in office_insert_lines:
            seafevents_lines.insert(office_insert_index, line)

    with open(join(topdir, 'conf', 'seafevents.conf'), 'w') as fp:
        fp.writelines(seafevents_lines)

    files_to_copy = [
        'conf', 'ccnet', 'seafile-data', 'seahub-data', 'pro-data'
    ]
    for fn in files_to_copy:
        src = join(topdir, fn)
        dst = join(shared_seafiledir, fn)
        if not exists(dst) and exists(src):
            shutil.move(src, shared_seafiledir)
            call('ln -sf ' + join(shared_seafiledir, fn) + ' ' + src)

    loginfo('Updating version stamp')
    update_version_stamp(os.environ['SEAFILE_VERSION'])
Example #11
0
def init_database(config):
    """Initialise database with empty tables and indices"""
    conn = sqlite3.connect(config.database)
    conn.executescript(utils.get_script('create_table.sql'))
    conn.commit()
    conn.close()
Example #12
0
def transform_headings(source_path, target_path, platform):
    # print 'Platform:', platform

    with open(source_path) as f:
        soup = BeautifulSoup(f, 'html.parser')

    statbuf = os.stat(source_path)
    last_modified = statbuf.st_mtime
    # print("Modification time: {}".format(statbuf.st_mtime))

    raw = datetime.fromtimestamp(last_modified,
                                 tz=pytz.timezone('Australia/Sydney'))
    formatted = raw.strftime('%d %B %Y, %-I:%M:%S %p %Z')

    new_doc = BeautifulSoup("<!DOCTYPE html>", 'html.parser')

    html = new_doc.new_tag("html", lang="en")
    body = new_doc.new_tag("body")

    header = utils.get_header(platform)

    details = None

    for el in soup.children:
        # print("el:", el)

        el_copy = copy.copy(el)

        if (el.name == "h2"):
            details = new_doc.new_tag("details")
            body.append(details)
            summary = create_summary(new_doc, el.text)
            details.append(summary)
        else:
            if (details is None):
                # the TITLE
                if (el.name == "h1"):
                    # create container
                    container = new_doc.new_tag("div",
                                                **{'class': 'title-container'})

                    # then add (as 1st child) title h1
                    container.append(el_copy)

                    # then add (as 2nd child) the #toggle
                    toggle = new_doc.new_tag("div",
                                             id="toggle",
                                             **{'class': 'collapsed'})
                    container.append(toggle)

                    # add completed container to body
                    body.append(container)

                    # last_modified timestamp
                    date_container = new_doc.new_tag(
                        "div",
                        id="last-modified",
                        **{'class': 'last-modified'})
                    # print("formatted time:", formatted)
                    date_container.string = 'Last modified: ' + str(formatted)
                    body.append(date_container)
                else:
                    body.append(el_copy)

            else:
                details.append(el_copy)

    script = utils.get_script()
    body.append(script)

    html.append(header)
    html.append(body)
    new_doc.append(html)

    # Create "Pills"
    pills = new_doc.find_all("span", class_="pill")
    pill_count = len(pills)

    for index, pill in enumerate(new_doc.find_all("span", class_="pill")):
        pill_text = str(index + 1) + " / " + str(pill_count)
        pill.string = pill_text

    # print("new_doc:", new_doc)

    # Create <a> tags for all urls
    RE_URL = re.compile(
        r'(http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+)'
    )

    for tag in new_doc.find_all(text=True):
        tags = []
        url = False

        for t in RE_URL.split(tag.string):
            if RE_URL.match(t):
                a = new_doc.new_tag("a", href=t, target='_blank')
                a.string = t
                tags.append(a)
                url = True
            else:
                tags.append(t)

        if url:
            for t in tags:
                tag.insert_before(t)
            tag.extract()

    # Write to disk
    f = open(target_path, "w+")
    f.write(str(new_doc))
Example #13
0
def init_seafile_server():
    version_stamp_file = get_version_stamp_file()
    if exists(join(shared_seafiledir, 'seafile-data')):
        if not exists(version_stamp_file):
            update_version_stamp(os.environ['SEAFILE_VERSION'])
        # sysbol link unlink after docker finish.
        latest_version_dir = '/opt/seafile/seafile-server-latest'
        current_version_dir = '/opt/seafile/' + get_conf(
            'SEAFILE_SERVER', 'seafile-server') + '-' + read_version_stamp()
        if not exists(latest_version_dir):
            call('ln -sf ' + current_version_dir + ' ' + latest_version_dir)
        loginfo(
            'Skip running setup-seafile-mysql.py because there is existing seafile-data folder.'
        )

        log_dir = join(shared_seafiledir, 'logs')
        if not exists(log_dir):
            os.mkdir(log_dir)
        files_to_link = [
            'conf', 'ccnet', 'seafile-data', 'seahub-data', 'pro-data', 'logs'
        ]
        for fn in files_to_link:
            src = join(shared_seafiledir, fn)
            dst = join(topdir, fn)
            if not exists(dst) and exists(src):
                call('ln -sf ' + src + ' ' + dst)
        return

    loginfo('Now running setup-seafile-mysql.py in auto mode.')
    env = {
        'SERVER_NAME': 'seafile',
        'SERVER_IP': get_conf('SEAFILE_SERVER_HOSTNAME', '127.0.0.1'),
        'MYSQL_USER': get_conf('MYSQL_USER', 'root'),
        'MYSQL_USER_PASSWD': get_conf('DB_USER_PASSWD', '123'),
        'MYSQL_USER_HOST': get_conf('DB_HOST', '127.0.0.1'),
        'MYSQL_HOST': get_conf('DB_HOST', '127.0.0.1'),
        'MYSQL_ROOT_PASSWD': get_conf('DB_ROOT_PASSWD', ''),
        'USE_EXISTING_DB': get_conf('USE_EXISTING_DB', '0'),
        'CCNET_DB': get_conf('CCNET_DB', 'ccnet_db'),
        'SEAFILE_DB': get_conf('SEAFILE_DB', 'seafile_db'),
        'SEAHUB_DB': get_conf('SEAHUB_DB', 'seahub_db')
    }

    # Change the script to allow mysql root password to be empty
    call(
        '''sed -i -e 's/if not mysql_root_passwd/if not mysql_root_passwd and "MYSQL_ROOT_PASSWD" not in os.environ/g' {}'''
        .format(get_script('setup-seafile-mysql.py')))

    call(
        '''sed -i -e '/def validate_mysql_user_host(self, host)/a \ \ \ \ \ \ \ \ return host' {}'''
        .format(get_script('setup-seafile-mysql.py')))

    call(
        '''sed -i -e '/def validate_mysql_host(self, host)/a \ \ \ \ \ \ \ \ return host' {}'''
        .format(get_script('setup-seafile-mysql.py')))

    setup_script = get_script('setup-seafile-mysql.sh')
    call('{} auto -n seafile'.format(setup_script), env=env)

    domain = get_conf('SEAFILE_SERVER_HOSTNAME', 'seafile.example.com')
    proto = 'https' if is_https() else 'http'
    with open(join(topdir, 'conf', 'seahub_settings.py'), 'a+') as fp:
        fp.write('\n')
        fp.write("""
CACHES = {
    'default': {
        'BACKEND': 'django_pylibmc.memcached.PyLibMCCache',
        'LOCATION': '%s:11211',
    },
    'locmem': {
        'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
    },
}
COMPRESS_CACHE_BACKEND = 'locmem'
FILE_SERVER_ROOT = '%s://%s/seafhttp'
""" % (get_conf('MEMCACHED', 'memcached'), proto, domain))
        fp.write('\n')
        fp.write("TIME_ZONE = '{time_zone}'".format(
            time_zone=os.getenv('TIME_ZONE', default='Etc/UTC')))
        fp.write('\n')

    # By default ccnet-server binds to the unix socket file
    # "/opt/seafile/ccnet/ccnet.sock", but /opt/seafile/ccnet/ is a mounted
    # volume from the docker host, and on windows and some linux environment
    # it's not possible to create unix sockets in an external-mounted
    # directories. So we change the unix socket file path to
    # "/opt/seafile/ccnet.sock" to avoid this problem.
    with open(join(topdir, 'conf', 'ccnet.conf'), 'a+') as fp:
        fp.write('\n')
        fp.write('[Client]\n')
        fp.write('UNIX_SOCKET = /opt/seafile/ccnet.sock\n')
        fp.write('\n')

    # After the setup script creates all the files inside the
    # container, we need to move them to the shared volume
    #
    # e.g move "/opt/seafile/seafile-data" to "/shared/seafile/seafile-data"
    log_dir = join(topdir, 'logs')
    if not exists(log_dir):
        os.mkdir(log_dir)
    files_to_copy = [
        'conf', 'ccnet', 'seafile-data', 'seahub-data', 'pro-data', 'logs'
    ]
    for fn in files_to_copy:
        src = join(topdir, fn)
        dst = join(shared_seafiledir, fn)
        if not exists(dst) and exists(src):
            shutil.move(src, shared_seafiledir)
            call('ln -sf ' + join(shared_seafiledir, fn) + ' ' + src)

    generate_seafevents_conf()

    loginfo('Updating version stamp')
    update_version_stamp(os.environ['SEAFILE_VERSION'])
Example #14
0
def init_seafile_server():
    version_stamp_file = get_version_stamp_file()
    if exists(join(shared_seafiledir, 'seafile-data')):
        if not exists(version_stamp_file):
            update_version_stamp(os.environ['SEAFILE_VERSION'])
        # sysbol link unlink after docker finish.
        latest_version_dir = '/opt/seafile/seafile-server-latest'
        current_version_dir = '/opt/seafile/' + get_conf(
            'SEAFILE_SERVER', 'seafile-server') + '-' + read_version_stamp()
        if not exists(latest_version_dir):
            call('ln -sf ' + current_version_dir + ' ' + latest_version_dir)
        loginfo(
            'Skip running setup-seafile.sh because there is existing seafile-data folder.'
        )
        return False

    loginfo('Now running setup-seafile.sh in auto mode.')
    env = {
        'SERVER_NAME': 'seafile',
        'SERVER_IP': get_conf('SEAFILE_SERVER_HOSTNAME',
                              'seafile.example.com'),
    }

    setup_script = get_script('setup-seafile.sh')
    call('{} auto -n seafile'.format(setup_script), env=env)

    domain = get_conf('SEAFILE_SERVER_HOSTNAME', 'seafile.example.com')
    proto = 'https' if is_https() else 'http'
    with open(join(topdir, 'conf', 'seahub_settings.py'), 'a+') as fp:
        fp.write('\n')
        fp.write("TIME_ZONE = '{time_zone}'".format(
            time_zone=os.getenv('TIME_ZONE', default='Etc/UTC')))
        fp.write('\n')
        fp.write('FILE_SERVER_ROOT = "{proto}://{domain}/seafhttp"'.format(
            proto=proto, domain=domain))
        fp.write('\n')

    # By default ccnet-server binds to the unix socket file
    # "/opt/seafile/ccnet/ccnet.sock", but /opt/seafile/ccnet/ is a mounted
    # volume from the docker host, and on windows and some linux environment
    # it's not possible to create unix sockets in an external-mounted
    # directories. So we change the unix socket file path to
    # "/opt/seafile/ccnet.sock" to avoid this problem.
    with open(join(topdir, 'conf', 'ccnet.conf'), 'a+') as fp:
        fp.write('\n')
        fp.write('[Client]\n')
        fp.write('UNIX_SOCKET = /opt/seafile/ccnet.sock\n')
        fp.write('\n')

    # After the setup script creates all the files inside the
    # container, we need to move them to the shared volume
    #
    # e.g move "/opt/seafile/seafile-data" to "/shared/seafile/seafile-data"
    files_to_copy = [
        'conf', 'ccnet', 'seafile-data', 'seahub-data', 'pro-data',
        'seahub.db', 'logs'
    ]
    for fn in files_to_copy:
        src = join(topdir, fn)
        dst = join(shared_seafiledir, fn)
        if not exists(dst) and exists(src):
            shutil.move(src, shared_seafiledir)
            call('ln -sf ' + join(shared_seafiledir, fn) + ' ' + src)

    call('rsync -axk --delete --exclude "CACHE" ' +
         join(topdir, 'seafile-server-' + seafile_version, 'seahub', 'media') +
         ' ' + nginx)
    call('rsync -ax --delete ' + join(topdir, 'seahub-data', 'avatars') + ' ' +
         join(nginx, 'media'))
    if not exists(join(topdir, 'seahub-data', 'custom')):
        call('mkdir -p ' + join(topdir, 'seahub-data', 'custom'))

    call('rsync -ax --delete ' + join(topdir, 'seahub-data', 'custom') + ' ' +
         join(nginx, 'media'))

    if not exists(join(nginx, 'media', 'CACHE')):
        call('mkdir -p ' + join(nginx, 'media', 'CACHE'))

    if not islink(
            join(topdir, 'seafile-server-' + seafile_version, 'seahub',
                 'media', 'CACHE')):
        call('ln -sf ' + join(nginx, 'media', 'CACHE') + ' ' +
             join(topdir, 'seafile-server-' +
                  seafile_version, 'seahub', 'media', 'CACHE'))

    loginfo('Updating version stamp')
    update_version_stamp(os.environ['SEAFILE_VERSION'])

    return True
Example #15
0
    def render_icon(self, id, context):

        jobs = {}

        asset = self[id]
        result_path = asset.icon

        blends = [
            file.path for file in os.scandir(asset.path)
            if file.path.endswith(".blend")
        ]
        if blends:
            blend = max(blends, key=os.path.getmtime)
            job = {'result_path': result_path, 'filepath': blend}
            jobs['objects'] = [job]
        else:
            images = asset.get_imags()
            if images:

                invert_normal_y = False
                material_settings = asset.get(
                    'material_settings')  # type: dict
                if material_settings:
                    invert_normal_y = bool(
                        material_settings.get("Y- Normal Map"))

                invert_normal_y_dict = {
                    image: invert_normal_y
                    for image in images
                }

                # terrable
                disp_min_max_mult = 1
                for image in images:
                    type = type_definer.get_type(image)
                    if 'displacement' in type:
                        image = image_utils.Image(image)
                        image.type = type
                        file_info = asset.get("file_info")
                        if not file_info:
                            asset["file_info"] = file_info = {}
                        image.process(file_info=file_info)
                        for channel, subtype in image.iter_type():
                            if subtype == 'displacement':
                                min_max = image.min_max.get(channel)
                                disp_min_max_mult = 1 / abs(min_max[1] -
                                                            min_max[0])
                        asset.update_info()

                displacement_scale = 0.1
                dimensions = asset.get('dimensions')
                if dimensions:
                    x = dimensions.get('x', 1)
                    y = dimensions.get('y', 1)
                    z = dimensions.get('z', 0.1)
                    if z:
                        z /= min((x, y))
                        displacement_scale = z
                displacement_scale *= 1.9213  # sphere uv_multiplier
                displacement_scale *= disp_min_max_mult

                job = {
                    'result_path': result_path,
                    'files': images,
                    'invert_normal_y': invert_normal_y_dict,
                    'displacement_scale': displacement_scale
                }
                jobs[
                    'type_definer_config'] = shader_editor_operator.get_definer_config(
                        context)
                jobs['materials'] = [job]

        if not jobs:
            return

        jobs_path = os.path.join(bpy.app.tempdir,
                                 'atool_icon_render_jobs.json')

        with open(jobs_path, 'w', encoding='utf-8') as jobs_file:
            json.dump(jobs, jobs_file, indent=4, ensure_ascii=False)

        initialize_asset = utils.get_script('render_icon.py')
        argv = [
            '-jobs_path', f'"{jobs_path}"' if " " in jobs_path else jobs_path
        ]
        bl_utils.run_blender(script=initialize_asset,
                             argv=argv,
                             use_atool=True,
                             library_path=self.library)

        print(f"An icon for the asset '{asset.id}' has been updated.")
        asset.reload_preview(context)
Example #16
0
def init_seafile_server():
    version_stamp_file = get_version_stamp_file()
    if exists(join(shared_seafiledir, 'seafile-data')):
        if not exists(version_stamp_file):
            update_version_stamp(os.environ['SEAFILE_VERSION'])
        # sysbol link unlink after docker finish.
        latest_version_dir = '/opt/seafile/seafile-server-latest'
        current_version_dir = '/opt/seafile/' + get_conf(
            'SEAFILE_SERVER', 'seafile-server') + '-' + read_version_stamp()
        if not exists(latest_version_dir):
            call('ln -sf ' + current_version_dir + ' ' + latest_version_dir)
        loginfo(
            'Skip running setup-seafile-mysql.py because there is existing seafile-data folder.'
        )
        return

    loginfo('Now running setup-seafile-mysql.py in auto mode.')

    env = utils.settings.from_environment()

    # Change the script to allow mysql root password to be empty
    # call('''sed -i -e 's/if not mysql_root_passwd/if not mysql_root_passwd and "MYSQL_ROOT_PASSWD" not in os.environ/g' {}'''
    #     .format(get_script('setup-seafile-mysql.py')))

    # Change the script to disable check MYSQL_USER_HOST
    call(
        '''sed -i -e '/def validate_mysql_user_host(self, host)/a \ \ \ \ \ \ \ \ return host' {}'''
        .format(get_script('setup-seafile-mysql.py')))

    call(
        '''sed -i -e '/def validate_mysql_host(self, host)/a \ \ \ \ \ \ \ \ return host' {}'''
        .format(get_script('setup-seafile-mysql.py')))

    # Change SQL for seahub db to not fail if tables or records are there. #https://github.com/haiwen/seafile-server/issues/188
    call('''sed -i -Ee 's@(CREATE TABLE\s+)`@\\1 IF NOT EXISTS `@gi' {}'''.
         format(get_script('seahub/sql/mysql.sql')))
    call('''sed -i -Ee 's@INSERT INTO\s+`@INSERT IGNORE `@gi' {}'''.format(
        get_script('seahub/sql/mysql.sql')))

    setup_script = get_script('setup-seafile-mysql.sh')
    #logdbg("  env is: " + str(env))
    call('{} auto -n seafile'.format(setup_script), env=env)

    settings = utils.settings.read_them(
    )  # previous call might have written something already
    utils.settings.update_from_env(settings, env)
    utils.settings.write_them(settings)

    # By default ccnet-server binds to the unix socket file
    # "/opt/seafile/ccnet/ccnet.sock", but /opt/seafile/ccnet/ is a mounted
    # volume from the docker host, and on windows and some linux environment
    # it's not possible to create unix sockets in an external-mounted
    # directories. So we change the unix socket file path to
    # "/opt/seafile/ccnet.sock" to avoid this problem.
    with open(join(topdir, 'conf', 'ccnet.conf'), 'a+') as fp:
        fp.write('\n')
        fp.write('[Client]\n')
        fp.write('UNIX_SOCKET = /opt/seafile/ccnet.sock\n')
        fp.write('\n')

    # Disabled the Elasticsearch process on Seafile-container
    # Connection to the Elasticsearch-container
    if os.path.exists(join(topdir, 'conf', 'seafevents.conf')):
        with open(join(topdir, 'conf', 'seafevents.conf'), 'r') as fp:
            fp_lines = fp.readlines()
            if '[INDEX FILES]\n' in fp_lines:
                insert_index = fp_lines.index('[INDEX FILES]\n') + 1
                insert_lines = [
                    'es_port = 9200\n', 'es_host = elasticsearch\n',
                    'external_es_server = true\n'
                ]
                for line in insert_lines:
                    fp_lines.insert(insert_index, line)

        with open(join(topdir, 'conf', 'seafevents.conf'), 'w') as fp:
            fp.writelines(fp_lines)

    # After the setup script creates all the files inside the
    # container, we need to move them to the shared volume
    #
    # e.g move "/opt/seafile/seafile-data" to "/shared/seafile/seafile-data"
    files_to_copy = [
        'conf', 'ccnet', 'seafile-data', 'seahub-data', 'pro-data'
    ]
    for fn in files_to_copy:
        src = join(topdir, fn)
        dst = join(shared_seafiledir, fn)
        if not exists(dst) and exists(src):
            shutil.move(src, shared_seafiledir)
            call('ln -sf ' + join(shared_seafiledir, fn) + ' ' + src)

    loginfo('Updating version stamp')
    update_version_stamp(os.environ['SEAFILE_VERSION'])
def init_seafile_server():
    version_stamp_file = get_version_stamp_file()
    if exists(join(shared_seafiledir, 'seafile-data')):
        if not exists(version_stamp_file):
            update_version_stamp(os.environ['SEAFILE_VERSION'])
        # sysbol link unlink after docker finish.
        latest_version_dir = '/opt/seafile/seafile-server-latest'
        current_version_dir = '/opt/seafile/' + get_conf(
            'SEAFILE_SERVER', 'seafile-server') + '-' + read_version_stamp()
        if not exists(latest_version_dir):
            call('ln -sf ' + current_version_dir + ' ' + latest_version_dir)
        loginfo(
            'Skip running setup-seafile-mysql.py because there is existing seafile-data folder.'
        )
        return

    loginfo('Now running setup-seafile-mysql.py in auto mode.')
    env = {
        'SERVER_NAME': 'seafile',
        'SERVER_IP': get_conf('SEAFILE_SERVER_HOSTNAME',
                              'seafile.example.com'),
        'MYSQL_USER': '******',
        'MYSQL_USER_PASSWD': str(uuid.uuid4()),
        'MYSQL_USER_HOST': '127.0.0.1',
        # Default MariaDB root user has empty password and can only connect from localhost.
        'MYSQL_ROOT_PASSWD': '',
    }

    # Change the script to allow mysql root password to be empty
    call(
        '''sed -i -e 's/if not mysql_root_passwd/if not mysql_root_passwd and "MYSQL_ROOT_PASSWD" not in os.environ/g' {}'''
        .format(get_script('setup-seafile-mysql.py')))

    setup_script = get_script('setup-seafile-mysql.sh')
    call('{} auto -n seafile'.format(setup_script), env=env)

    domain = get_conf('SEAFILE_SERVER_HOSTNAME', 'seafile.example.com')
    proto = 'https' if is_https() else 'http'
    with open(join(topdir, 'conf', 'seahub_settings.py'), 'a+') as fp:
        fp.write('\n')
        fp.write("""CACHES = {
    'default': {
        'BACKEND': 'django_pylibmc.memcached.PyLibMCCache',
        'LOCATION': '127.0.0.1:11211',
    },
    'locmem': {
        'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
    },
}
COMPRESS_CACHE_BACKEND = 'locmem'""")
        fp.write('\n')
        fp.write('FILE_SERVER_ROOT = "{proto}://{domain}/seafhttp"'.format(
            proto=proto, domain=domain))
        fp.write('\n')

        # set up only office
        fp.write('\n')
        fp.write("""# Enable Only Office
ENABLE_ONLYOFFICE = True
VERIFY_ONLYOFFICE_CERTIFICATE = False
ONLYOFFICE_APIJS_URL = 'http://127.0.0.1/onlyofficeds/web-apps/apps/api/documents/api.js'
ONLYOFFICE_FILE_EXTENSION = ('doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx', 'odt', 'fodt', 'odp', 'fodp', 'ods', 'fods')
ONLYOFFICE_EDIT_FILE_EXTENSION = ('doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx', 'odt', 'fodt', 'odp', 'fodp', 'ods', 'fods')"""
                 )
        fp.write('\n')

    # By default ccnet-server binds to the unix socket file
    # "/opt/seafile/ccnet/ccnet.sock", but /opt/seafile/ccnet/ is a mounted
    # volume from the docker host, and on windows and some linux environment
    # it's not possible to create unix sockets in an external-mounted
    # directories. So we change the unix socket file path to
    # "/opt/seafile/ccnet.sock" to avoid this problem.
    with open(join(topdir, 'conf', 'ccnet.conf'), 'a+') as fp:
        fp.write('\n')
        fp.write('[Client]\n')
        fp.write('UNIX_SOCKET = /opt/seafile/ccnet.sock\n')
        fp.write('\n')

    # After the setup script creates all the files inside the
    # container, we need to move them to the shared volume
    #
    # e.g move "/opt/seafile/seafile-data" to "/shared/seafile/seafile-data"
    files_to_copy = [
        'conf', 'ccnet', 'seafile-data', 'seahub-data', 'pro-data'
    ]
    for fn in files_to_copy:
        src = join(topdir, fn)
        dst = join(shared_seafiledir, fn)
        if not exists(dst) and exists(src):
            shutil.move(src, shared_seafiledir)
            call('ln -sf ' + join(shared_seafiledir, fn) + ' ' + src)

    loginfo('Updating version stamp')
    update_version_stamp(os.environ['SEAFILE_VERSION'])