Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
"""Python Module __init__ file."""
from __future__ import print_function

import os
import subprocess
import sys
import threading
from distutils.spawn import find_executable
from s3fuse import utils as fs
try:
    from configparser import ConfigParser
except:
    from ConfigParser import ConfigParser

config_parser = ConfigParser()
default_conf_path = '/etc/workloadmgr/vault.conf'

def readS3fuseConf(conf_path):
    try:
        # Get the path
        source = os.path.abspath(conf_path)
        # read the conf file
        config_parser.read(source)
        # build a flag containing configuration file info
        # and export it as an environment variable
        flag = '--config-file=' + source
        os.environ['FLAG'] = flag
    except Exception as e:
        print("You should create vault.conf file", file=sys.stderr)
        print("Exception: %s" % str(e), file=sys.stderr)
        sys.exit(1)
    

"""
Build mount points
"""


def mount(conf_path = default_conf_path):
    """Mount s3 fuse mount."""
    readS3fuseConf(conf_path)
    from . import s3vaultfuse
    th = threading.Thread(target=s3vaultfuse.run)
    print('Mounting...')
    th.start()
    print('Mounted....')
    th.join()

"""
when the mount function stops running, it actually performs umount.
This is just to clean the remaining folders and files
"""


def umount(conf_path = default_conf_path):
    readS3fuseConf(conf_path)
    """umount fuse mount."""
    mp = config_parser['DEFAULT']['vault_data_directory']
    cahce = config_parser['DEFAULT']['vault_data_directory_old']
    fs.umount(mp, ['-f','-l'])
    fs.umount(os.path.join(cahce, "tmpfs"), ['-f','-l'])

    sudo_exe = find_executable('sudo')
    rm_mp =  [sudo_exe, 'rm', '-rf', mp] if sudo_exe else ['rm', '-rf', mp]
    rm_cahce = [sudo_exe, 'rm', '-rf', cahce] if sudo_exe else ['rm', '-rf', cahce]
    subprocess.call(rm_mp)
    subprocess.call(rm_cahce)


"""
FIX REQUIRD.
    There is a bug that build one additional mount points.
    For now, this function will remove the files and folders
    from this mountpoint.
"""


def clean():
    """Cleanup directory."""
    subprocess.call('find . -empty -type d -delete'.split())