Esempio n. 1
0
def getContractFile(contract_dir_hint, contract_file_hint):
    ''' Given contract dir and contract file hints, determine the file.

    Contract files are those extended with ``wast``, ``wasm`` and ``abi``.

    First, the ``contract_file_hint`` may be an absolute path.
    Next, it may be relative to the contract directory.

    The contract directory is the container for the project of a contract. This 
    directory is determined with the ``getContractDir`` function, basing on the 
    ``contract_dir_hint``.

    Any contract directory contains directories and files structured according 
    to few schemes:
    flat structure with all the files in this directory as in the ``eos/contracts/*`` contract directories in the EOS repository;
    structure with a directory named ``build`` as resulting from the EOSFactory templates;
    '''
    contract_dir_hint = utils.wslMapWindowsLinux(contract_dir_hint)
    contract_file_hint = utils.wslMapWindowsLinux(contract_file_hint)

    # ? ``contract_file_hint`` may be an absolute path to a file
    trace = contract_file_hint + "\n" 
    if os.path.isabs(contract_file_hint) \
                                    and os.path.isfile(contract_file_hint):
        return contract_file_hint

    # ? it may be relative to the contract directory.
    contract_dir = getContractDir(contract_dir_hint)

    # ? flat structure with all the files in this directory
    contract_file = os.path.join(contract_dir, contract_file_hint)
    trace = trace + contract_file + "\n"
    if os.path.isfile(contract_file):
        return contract_file

    # ? structure with a directory named ``build``
    # and ``contract_file_hint`` is relative file
    contract_file = os.path.join(contract_dir, "build", contract_file_hint)
    trace = trace + contract_file + "\n"
    if os.path.isfile(contract_file):
        return contract_file

    # ? structure with a directory named ``build``
    # and ``contract_file_hint`` is a file extension merely
    build_dir = os.path.join(contract_dir, "build")
    trace = trace + build_dir + "\n"
    files = os.listdir(build_dir)
    for file in files:
        if os.path.splitext(file)[1] == contract_file_hint:
            return os.path.join(build_dir, file)

    raise errors.Error('''
        Cannot determine the contract file basing on hints:
        contract dir hint: {}
        contract file hint: {}
        Tried path list:
        {}
    '''.format(contract_dir_hint, contract_file_hint, trace))  
Esempio n. 2
0
def getContractDir(contract_dir_hint):
    ''' Given a hint, determine the contract directory.
    The contract directory is the container for the project of a contract. The 
    hint is probed to be one of the following pieces of information:
    the absolute path to a contract directory;
    the relative path to a contract directory, relative to the directory set with the EOSIO_CONTRACT_WORKSPACE variable;
    the relative path to a contract directory, relative to the ``contracts`` directory in the repository of EOSFactory;
    the relative path to a contract directory, relative to the ``contracts`` directory in the repository of EOSIO.
    ''' 
    contract_dir_hint = utils.wslMapWindowsLinux(contract_dir_hint)

    # ? the absolute path to a contract directory
    trace = contract_dir_hint + "\n"
    if os.path.isfile(contract_dir_hint):
        contract_dir_hint = os.path.dirname(contract_dir_hint)
    if os.path.isabs(contract_dir_hint):
        return contract_dir_hint

    # ? the relative path to a contract directory, relative to the directory 
    # set with the EOSIO_CONTRACT_WORKSPACE variable
    contract_dir = os.path.join(
        configValue("EOSIO_CONTRACT_WORKSPACE"), contract_dir_hint)
    trace = trace + contract_dir + "\n"
    if os.path.isdir(contract_dir):
        return contract_dir

    # ? the relative path to a contract directory, relative to the 
    # ``contracts`` directory in the repository of EOSFactory
    contract_dir = os.path.join(
            configValue("EOSIO_EOSFACTORY_DIR"), 
            setup.CONTRACTS_DIR, contract_dir_hint)
    trace = trace + contract_dir + "\n"
    if os.path.isdir(contract_dir):
        return contract_dir 

    # ? the relative path to a contract directory, relative to the 
    # ``contracts`` directory in the repository of EOSIO
    contract_dir = os.path.join(
            configValue("EOSIO_SOURCE_DIR"),
            setup.EOSIO_CONTRACT_DIR, contract_dir_hint)
    trace = trace + contract_dir + "\n"
    if os.path.isdir(contract_dir):
        return contract_dir 
    
    raise errors.Error('''
        Cannot determine the contract directory.
        Tried path list:
        {}
    '''.format(trace))
Esempio n. 3
0
def getContractSourceFiles(contract_dir_hint):
    contract_dir = getContractDir(utils.wslMapWindowsLinux(contract_dir_hint))
    trace = contract_dir + "\n"

    srcs = getSourceFiles(contract_dir)
    if srcs:
        return srcs            

    source_path = os.path.join(contract_dir, "src")
    trace = trace + source_path + "\n"
    srcs = getSourceFiles(source_path)
    if srcs:
        return srcs            

    raise errors.Error('''
        Cannot find any contract source directory.
        Tried path list:
        {}
    '''.format(trace))