import_models.py 1.45 KB
Newer Older
nsoler's avatar
nsoler committed
1
2
3
4
5
6
7
8
# Nico 29 Jan 2021 
# data (models to fit sign1 and sign2 are kept here)
# The following function allows a cc instance to copy the model files in a particular signature

import os, shutil


def import_models(sign_object ,version='2020_01'):
9
10
11
12
13
14
15
    """
    Imports the models for predicting sign_objects
    i.e copies the models in the model_path of the reference signature object and
    create symbolics lincs to those model files in the full signature model_path
    """


nsoler's avatar
nsoler committed
16
17
    fileDir= os.path.abspath(os.path.dirname(__file__))

18
19
    signRef= sign_object.get_molset("reference")
    signFull= sign_object.get_molset("full")
nsoler's avatar
nsoler committed
20
21


22
23
24
25
26
27
28
29


    cctype= signRef.cctype
    dataset= signRef.dataset

    destination = signRef.model_path
    destinationLink = signFull.model_path

nsoler's avatar
nsoler committed
30
31

    data= os.path.join(fileDir,version,dataset,cctype)
32

nsoler's avatar
nsoler committed
33
34
35
36
37
    if not os.path.exists(data):
        print("Sorry, no model to import for this signature")
        return None

    for fichero in os.listdir(data):
38
39
40
        if fichero == "fit.ready":
            continue

nsoler's avatar
nsoler committed
41
42
        source= os.path.join(data,fichero)
        target= os.path.join(destination,fichero)
43
44
45
46
47
48
49
50
51
52
53
        symlink= os.path.join(destinationLink,fichero)


        if not os.path.exists(target):
            print("Importing", source, "to", target)
            shutil.copyfile(source, target)

        # Symlincs
        if not os.path.islink(symlink):
            print("Creating symlink", symlink, "from", target)
            os.symlink(target, symlink)
nsoler's avatar
nsoler committed
54