Exemple #1
0
def keosd_start():
    if not config.keosd_wallet_dir(raise_error=False):
        utils.spawn([config.keosd_exe()])

        while True:
            time.sleep(1)
            if config.keosd_wallet_dir(raise_error=False):
                break
Exemple #2
0
def wsl_root():
    '''The root directory of the Windows WSL, or empty string if not Windows.
    
    The root directory of the Ubuntu file system, owned by the installation,
    if any, of the Windows Subsystem Linux (WSL).

    It may be changed with 
    *WSL_ROOT* entry in the *config.json* file, 
    see :func:`.current_config`.
    '''
    if not utils.is_windows_ubuntu():
        return ""

    wsl_root_sh = "wsl_root.sh"
    wsl_root_sh = os.path.join(eosfactory_data(), wsl_root_sh)

    if wsl_root_[1][0] is None:
        path = ""
        path, error = utils.spawn([wsl_root_sh, path], raise_exception=False)
        if error:
            while True:
                if not os.path.exists(wsl_root_sh):
                    path = ""
                    logger.ERROR('''
Cannot find the bash command:
'{}'
The intelisense feature of Visual Studio Code will be disabled. 
                    '''.format(wsl_root_sh),
                                 translate=False)
                    break

                path = input(
                    logger.error('''
Error message is
{}

Cannot find the root of the WSL file system which was tried to be
'{}'
Please, find the path in your computer and enter it. Enter nothing, if you do
not care about having efficient the intelisense of Visual Studio Code.
                '''.format(error, path),
                                 translate=False) + "\n<<< ")
                if not path:
                    break

                path, error = utils.spawn([wsl_root_sh, path],
                                          raise_exception=False)
                if not error:
                    break

        path = path.replace("\\", "/")
        path = path.replace(path[0:2], path[0:2].lower())

        wsl_root_[1][0] = path

    return wsl_root_[1][0]
Exemple #3
0
def eosio_cpp_dir():
    '''The path to the *eosio-cpp* installation directory.
    
    The setting may be changed with 
    *EOSIO_CPP* entry in the *config.json* file, 
    see :func:`.current_config`.
    '''
    eosio_cpp_version = utils.spawn(
        [eosio_cpp(), "-version"],
        "Cannot determine the version of the installed 'eosio.cpp' pckage."
    ).replace("eosio-cpp version ", "")

    version_pattern = re.compile(".+/eosio\.cdt/(\d\.\d\.\d)/$")
    dir = eosio_cpp_dir_[1][0]
    if not version_pattern.match(dir):
        raise errors.Error('''
The assumed pattern
{}
does not match the directory template 'core.config.EOSIO_CPP_DIR'
{}
            '''.format(version_pattern, EOSIO_CPP_DIR),
                           translate=False)
    dir = dir.replace(re.findall(version_pattern, dir)[0], eosio_cpp_version)

    return dir
Exemple #4
0
def read_map(file_name, text_editor="nano"):
    '''Return json account map

Attempt to open the account map file named ``setup.account_map``, located 
in the wallet directory ``config.keosd_wallet_dir()``, to return its json 
contents. If the file does not exist, return an empty json.

If the file is corrupted, offer editing the file with the ``nano`` linux 
editor. Return ``None`` if the the offer is rejected.
    '''
    wallet_dir_ = config.keosd_wallet_dir()
    path = os.path.join(wallet_dir_, file_name)
    while True:
        try:  # whether the setup map file exists:
            with open(path, "r") as input_file:
                return json.load(input_file)

        except Exception as e:
            if isinstance(e, FileNotFoundError):
                return {}
            else:
                raise errors.Error('''
            The json file 
            {}
            is misformed. The error message is:
            {}
            
            Do you want to edit the file?
            '''.format(str(path), str(e)),
                                   translate=False)

                answer = input("y/n <<< ")
                if answer == "y":
                    utils.spawn([text_editor, path])
                    continue
                else:
                    raise errors.Error('''
                    Use the function 'manager.edit_account_map(text_editor="nano")' to edit the file.
                    ''',
                                       translate=False)
                    return None
Exemple #5
0
def edit_map(file_name, text_editor="nano"):
    utils.spawn(
        [text_editor,
         os.path.join(config.keosd_wallet_dir(), file_name)])
    read_map(file_name, text_editor)
Exemple #6
0
    def __init__(self, is_html=False, error_codes=""):
        self.is_html = is_html
        self.html_text = ""
        self.is_error = False
        self.is_warning = False
        self.IS_WINDOWS = utils.is_windows_ubuntu()
        self.os_version = utils.os_version()

        self.print_msg("EOSFactory version {}".format(config.VERSION))

        ################################################################################
        # psutil
        ################################################################################
        try:
            if "psutil" in error_codes:
                import psutil1
            else:
                import psutil
        except ImportError:
            command = "pip3 install --user psutil"
            button = '''
<button 
    style="text-align:left;"
    class="btn ${{BASH_COMMAND}}";
    class="btn"; 
    id="Install psutil"; 
    title="Install psutil. Click the button then ENTER in a newly created bash terminal window, to go."
>
    {}
</button>            
'''.format(command)

            self.error_msg('''
Module 'psutil' is not installed. Install it: {}
'''.format(button))
            self.print_error('''Module 'psutil' is not installed.
Install it: ''')
            self.print_code("`{}`\n".format(command))

################################################################################
# termcolor
################################################################################
        try:
            if "termcolor" in error_codes:
                import termcolor1
            else:
                import termcolor
        except ImportError:
            command = "pip3 install --user termcolor"
            button = '''
<button 
    style="text-align:left;"
    class="btn ${{BASH_COMMAND}}";
    class="btn"; 
    id="Install termcolor"; 
    title="Install termcolor. Click the button then ENTER in a newly created bash terminal window, to go."
>
    {}
</button>            
'''.format(command)

            self.error_msg('''
Module 'termcolor' is not installed. Install it: {}
'''.format(button))

            self.print_error('''Module 'termcolor' is not installed.
Install it: ''')
            self.print_code("`{}`\n".format(command))

        if self.IS_WINDOWS:

            ################################################################################
            # Ubuntu version
            ################################################################################
            lsb_release, error = utils.spawn(["lsb_release", "-r", "-s"],
                                             raise_exception=False)
            if error:
                self.error_msg(error)
            else:
                if "ubuntuversion" in error_codes:
                    lsb_release = "16.4.1"

                ubuntu_version = int(lsb_release.split(".")[0])
                if ubuntu_version < config.UBUNTU_VERSION_MIN:
                    msg = \
'''
WSL Ubuntu version is {}.
EOSIO nodeos can fail with Windows WSL Ubuntu below version 16.
                        '''.format(lsb_release)

                    self.status_msg(self.warning(msg))
                    self.print_warning(msg)

################################################################################
# WSL root
################################################################################
            root = config.wsl_root()
            if not root or "wslroot" in error_codes:
                self.error_msg(
                    '''Cannot determine the root of the WSL. Set it: 
<button 
    class="btn ${FIND_WSL}"; 
    id=""; 
    title="Click the button to open file dialog. Navigate to a directory containing the Ubuntu file system."
>
    Indicate WSL root
</button>
''')
                self.print_error(
                    '''Cannot determine the root of the WSL. To indicate it, use the command:'''
                )
                self.print_code("`python3 -m eosfactory.config --wsl_root`\n")

################################################################################
# eosio
################################################################################
        eosio_version = config.eosio_version()
        if "eosio" in error_codes:
            eosio_version = ["", "1.8.0"]
        # eosio_version = ["1.3.3", "1.8.0"]

        if eosio_version[0]:
            self.status_msg("Found eosio version {}".format(eosio_version[0]))
            self.print_status("Found eosio version {}".format(
                eosio_version[0]))

        if not eosio_version[0] or len(eosio_version) > 1\
                and not self.equal(eosio_version[0], eosio_version[1]):
            command = ""

            if self.os_version == utils.UBUNTU:
                ubuntu_version = utils.spawn(
                    ["lsb_release", "-r", "-s"],
                    raise_exception=False)[0].split(".")[0]

                if ubuntu_version and ubuntu_version == 16:
                    command = \
'''sudo apt remove eosio &&\\
wget https://github.com/eosio/eos/releases/download/v1.8.0/eosio_1.8.0-1-ubuntu-16.04_amd64.deb &&\\
sudo apt install ./eosio_1.8.0-1-ubuntu-16.04_amd64.deb                
'''
                else:
                    command = \
'''sudo apt remove eosio &&\\
wget https://github.com/eosio/eos/releases/download/v1.8.0/eosio_1.8.0-1-ubuntu-18.04_amd64.deb &&\\
apt install ./eosio_1.8.0-1-ubuntu-18.04_amd64.deb
'''
            elif self.os_version == utils.DARWIN:
                command = \
'''brew remove eosio &&\\
brew tap eosio/eosio &&\\
brew install eosio
'''

            button = '''
<button 
    style="text-align:left;"
    class="btn ${{BASH_COMMAND}}";
    class="btn"; 
    id="Install eosio v{0}"; 
    title="Install eosio v{0}. Click the button then ENTER in a newly created bash terminal window, to go."
>
    {1}
</button>            
'''.format(eosio_version[1], command)

            instructions = '<a href="https://github.com/EOSIO/eos">EOSIO installation instructions</a>'

            if eosio_version[0] and len(eosio_version) > 1:
                self.warning_msg('''
NOTE: EOSFactory was tested with version {0} while installed is {1}. Install eosio v{0}:<br>
{2}
'''.format(eosio_version[1], eosio_version[0],
                button if command else instructions))

                self.print_warning(
                    '''NOTE: EOSFactory was tested with version {0} while installed is {1}. Install eosio v{0}:
'''.format(eosio_version[1], eosio_version[0]))
                self.print_code('''```
{}
```
'''.format(command if command else instructions))

            else:
                if not "ignoreeoside" in error_codes:
                    self.warning_msg('''
Cannot determine that eosio is installed as nodeos does not response.<br>
It hangs up sometimes.<br>
EOSFactory expects eosio version {}. Install eosio, if not installed:<br>
{}<br>
'''.format(eosio_version[1], button if command else instructions))

                    self.print_warning(
                        '''Cannot determine that eosio is installed as nodeos does not response.
It hangs up sometimes.
EOSFactory expects eosio version {}. Install eosio, if not installed:
'''.format(eosio_version[1]))

                    self.print_code('''```
{}
```
'''.format(command if command else instructions))

################################################################################
# eosio_cdt
################################################################################
        eosio_cdt_version = config.eosio_cdt_version()
        if "eosio_cdt" in error_codes:
            eosio_cdt_version = ["", "1.6.0"]
        # eosio_cdt_version = ["1.6.1", "1.6.0"]

        if eosio_cdt_version[0]:
            self.status_msg("Found eosio.cdt version {}.".format(
                eosio_cdt_version[0]))
            self.print_status("Found eosio.cdt version {}.".format(
                eosio_cdt_version[0]))

        if not eosio_cdt_version[0] or len(eosio_cdt_version) > 1\
                and not self.equal(eosio_cdt_version[0], eosio_cdt_version[1]):
            command = ""

            if self.os_version == utils.UBUNTU:
                command = \
'''sudo apt remove eosio.cdt &&\\
wget https://github.com/eosio/eosio.cdt/releases/download/v1.6.1/eosio.cdt_1.6.1-1_amd64.deb &&\\
sudo apt install ./eosio.cdt_1.6.1-1_amd64.deb
'''
            elif self.os_version == utils.DARWIN:
                command = \
'''brew remove eosio.cdt &&\\
brew tap eosio/eosio.cdt && \\
brew install eosio.cdt
'''
            button = '''
<button 
    style="text-align:left;"
    class="btn ${{BASH_COMMAND}}";
    class="btn"; 
    id="Install eosio.cdt v{0}"; 
    title="Install eosio.cdt v{0}. Click the button then ENTER in a newly created bash terminal window, to go."
>
    {1}
</button>
'''.format(eosio_cdt_version[1], command)

            instructions = '<a href="https://github.com/EOSIO/eosio.cdt">EOSIO.cdt installation instructions</a>'

            if eosio_cdt_version[0] and len(eosio_cdt_version) > 1 \
                    and not eosio_cdt_version[0] == eosio_cdt_version[1]:
                self.warning_msg('''
NOTE: EOSFactory was tested with version {0} while installed is {1}. Install eosio.cdt v{0}:<br>
{2}
'''.format(eosio_cdt_version[1], eosio_cdt_version[0],
                button if command else instructions))

                self.print_warning(
                    '''NOTE: EOSFactory was tested with version {0} while installed is {1}. Install eosio v{0}:
'''.format(eosio_cdt_version[1], eosio_cdt_version[0]))

                self.print_code('''```
{}
```
'''.format(command if command else instructions))

            else:
                self.error_msg('''
    Cannot determine that eosio.cdt is installed as eosio-cpp does not response.<br>
    EOSFactory expects eosio.cdt version {}. Install it, if not installed.
    {}<br>
'''.format(eosio_cdt_version[1], button if command else instructions))

                self.print_error(
                    '''Cannot determine that eosio.cdt is installed as eosio-cpp does not response.
EOSFactory expects eosio.cdt version {}. Install it, if not installed.
'''.format(eosio_cdt_version[1]))

                self.print_code('''```
{}
```
'''.format(command if command else instructions))

################################################################################
# Default workspace
################################################################################
        try:
            contract_workspace_dir = config.contract_workspace_dir()
        except:
            contract_workspace_dir = None

        button = '''
<button 
    class="btn ${CHANGE_WORKSPACE}";
    id="${CHANGE_WORKSPACE}"; 
    title="Set workspace"
>
    Set workspace.
</button>            
'''
        if not contract_workspace_dir or "workspace" in error_codes:
            self.error_msg('''
Default workspace is not set, or it does not exist.{}
'''.format(button))

        else:
            self.status_msg('''Default workspace is {}.{}
'''.format(contract_workspace_dir, button))