Exemple #1
0
def main():
    if not os.path.exists(os.path.expanduser('~/.bpkg')):
        os.mkdir(os.path.expanduser('~/.bpkg'))

    if len(sys.argv) == 1:
        print('Error: No arguments present.')
        os.system('python bpkg.py -h')
        exit()

    # Change this each time version changes
    if sys.argv[1] == '-v':
        print('bpkg application packaging utility version 1.0.0')
        exit()

    if sys.argv[1] == '-h':
        print('''
bpkg syntax - bpkg [-h|-v|start|bundle|extract|cleanup] foldername

bpkg is a tool used to bundle applications.

    cleanup - Cleans up the bpkg cache
    start - This command is used to start the application.
    bundle - This command is used to bundle an application hence the name.
    extract - This command is used to extract the contents of an application from its bundle.
            ''')
        exit()

    if not sys.argv[1] == 'cleanup':
        if sys.argv[2] == None:
            print(
                'The directory of the project you want to package should be the second argument'
            )

    if sys.argv[1] == 'start':
        start_app(sys.argv[2])
    elif sys.argv[1] == 'cleanup':
        for root, dirs, files in os.walk(os.path.expanduser('~/.bpkg')):
            for f in files:
                os.unlink(os.path.join(root, f))
            for d in dirs:
                shutil.rmtree(os.path.join(root, d))
    elif sys.argv[1] == 'bundle':
        bundle(sys.argv[2])
    elif sys.argv[1] == 'extract':
        extract(sys.argv[2])
    else:
        print(
            'bundle, start, cleanup or extract should be present as the second argument'
        )
        exit()
Exemple #2
0
def upload_files(ingest_server='',
                 bundle_name='',
                 file_list=None,
                 bundle_size=0,
                 meta_list=None,
                 auth={},
                 verify=True,
                 tartar=False):
    """
    task created on a separate Celery process to bundle and upload in the background
    status and errors are pushed by celery to the main server through RabbitMQ
    """
    # one big-ass exception handler for upload.
    try:

        target_dir = os.path.dirname(bundle_name)
        if not os.path.isdir(target_dir):
            task_error('Bundle directory does not exist')
            return

        TaskComm.set_state("PROGRESS", "Cleaning previous uploads")

        # initial state pushed through celery
        TaskComm.set_state("PROGRESS", "Starting Bundle/Upload Process")

        bundle(bundle_name=bundle_name,
               file_list=file_list,
               meta_list=meta_list,
               bundle_size=bundle_size)

        TaskComm.set_state("PROGRESS", "Completed Bundling")

        if tartar:
            # create the file tuple list of 1 file
            fname = os.path.basename(bundle_name)

            file_tuples = []
            file_tuples.append((bundle_name, fname))

            bundle_size = os.path.getsize(bundle_name)

            # dual extension indicates tartar
            bundle_name += '.tar'

            bundle(bundle_name=bundle_name,
                   file_list=file_tuples,
                   meta_list=meta_list,
                   bundle_size=bundle_size)

        TaskComm.set_state(
            "PROGRESS", "Starting Uploady: " + str(bundle_name) + ": " +
            ingest_server + ": " + str(auth))

        uploader = Uploader(bundle_name, ingest_server, auth, verify)

        TaskComm.set_state("PROGRESS", "Uploader Initialized")

        result = uploader.upload_bundle()

        TaskComm.set_state("PROGRESS", "Finished Upload")

        try:
            status = json.loads(result)
        except Exception, e:
            print 'Upload Error'
            print result
            raise Exception('Upload error:  ' + result)
            print 'End Upload Error'

        # check for a valid job id.  Ingest error should return -99
        job_id = status['job_id']
        if job_id < 0:
            task_error(err)
            raise Exception('Upload error:  ' + bundle_name)

        TaskComm.set_state("PROGRESS", "Rename Tar File")

        try:
            rename_tar_file(target_dir, bundle_name, job_id)
        except Exception, ex:
            raise Exception(ex.message + ':  ' + bundle_name + ':  ' +
                            str(job_id))
def modify(request):
    print "modify " + request.get_full_path()

    global selectedList
    global user
    global password
    global directoryHistory

    if request.POST:
        if request.POST.get("Clear"):
            selectedList = []

        if request.POST.get("upDir"):
            dir = os.path.dirname(rootDir)
            if os.path.exists(dir):
                rootDir = dir

        if request.POST.get("Select All"):
            contents = os.listdir(rootDir)
            for path in contents:
                fullPath = os.path.join(rootDir, path)
                if not os.path.isdir(fullPath):
                    if fullPath not in selectedList:
                        selectedList.append(fullPath)

        if request.POST.get("Upload"):

            # create a list of tuples to meet the call format
            tupleList = []
            for path in selectedList:
                tupleList.append((path, None))

            current_time = datetime.datetime.now().time().strftime("%m.%d.%Y.%H.%M.%S")
            # current_date = datetime.datetime.now().date().strftime("%H.%M.%S")

            targetPath = Filepath.objects.get(name="target")
            if targetPath is not None:
                targetDir = targetPath.fullpath
            else:
                targetDir = rootDir

            bundleName = os.path.join(targetDir, current_time + ".tar")

            print bundleName

            serverPath = Filepath.objects.get(name="server")
            if serverPath is not None:
                sPath = serverPath.fullpath
            else:
                sPath = "dev1.my.emsl.pnl.gov"

            # return HttpResponseRedirect(reverse('home.views.list'))

            bundle(
                bundle_name=bundleName,
                instrument_name="insty",
                tarfile=True,
                proposal="45796",
                file_list=tupleList,
                recursive=False,
                verbose=True,
                groups=None,
            )

            """
            sesh = OpenSession(protocol="https",
                   server=sPath,
                   user="******",
                   insecure=True,
                   password="******",
                   negotiate = False,
                   verbose=True
                   )
            
            boolVal = TestAuth(protocol="https",
                   server=sPath,
                   user="******",
                   insecure=True,
                   password="******",
                   negotiate = False,
                   verbose=True
                   )
            
            res = UploadBundle( bundle_name=bundleName, session=sesh)
            """

            print user

            res = upload(
                bundle_name=bundleName,
                protocol="https",
                server=sPath,
                user=user,
                insecure=True,
                password=password,
                negotiate=False,
                verbose=True,
            )

            if "http" in res:
                return HttpResponseRedirect(res)

    else:
        o = urlparse(request.get_full_path())
        params = o.query.split("=")
        modType = params[0]
        path = params[1]

        # spaces
        path = path.replace("%20", " ")
        # backslash
        path = path.replace("%5C", "\\")

        full = os.path.join(rootDir, path)

        if modType == "enterDir":
            rootDir = os.path.join(rootDir, path)
            directoryHistory.append(path)
            print "rootDir = " + rootDir

        elif modType == "toggleFile":
            if full not in selectedFiles:
                selectedFiles.append(full)
            else:
                selectedFiles.remove(full)

        elif modType == "toggleDir":
            if full not in selectedDirs:
                selectedDirs.append(full)
            else:
                selectedDirs.remove(full)

    return HttpResponseRedirect(reverse("home.views.list"))
Exemple #4
0
def upload_files(ingest_server = '',
                 bundle_name='',
                 file_list=None,
                 bundle_size=0,
                 meta_list=None,
                 tartar = False):
    """
    task created on a separate Celery process to bundle and upload in the background
    status and errors are pushed by celery to the main server through RabbitMQ
    """

    target_dir = os.path.dirname(bundle_name)
    if not os.path.isdir(target_dir):
        current_task.update_state(state='ERROR', meta={'Status': 'Bundle directory does not exist'})

        task_state("PROGRESS", "Cleaning previous uploads")

    ##clean tar directory
    #if CLEAN_TAR:
    #    err_str = clean_target_directory(target_dir)
    #    if err_str:
    #        task_state('PROGRESS', err_str)

    # initial state pushed through celery
    task_state("PROGRESS", "Starting Bundle/Upload Process")

    bundle(bundle_name=bundle_name,
           file_list=file_list,
           meta_list= meta_list,
           bundle_size=bundle_size)

    task_state("PROGRESS", "Completed Bundling")

    if tartar:
        # create the file tuple list of 1 file
        dir = os.path.dirname(bundle_name)
        fname = os.path.basename(bundle_name)

        file_tuples=[]
        file_tuples.append((bundle_name, fname))

        bundle_size = os.path.getsize(bundle_name)

                    # dual extension indicates tartar
        bundle_name += '.tar'

        bundle(bundle_name=bundle_name,
               file_list=file_tuples,
               meta_list= meta_list,
               bundle_size=bundle_size)

    task_state("PROGRESS", "Starting Upload")

    result = upload(bundle_name=bundle_name, ingest_server = ingest_server)

    if not result:
        task_state('FAILURE',  "Uploader dieded. We don't know why it did")

    try:
        status = json.loads(result)
    except Exception, e:
        task_state('FAILURE', e.message)
        return 'Upload Failed'