summaryrefslogtreecommitdiffstats
path: root/lib/sunhpc/commands/soft/autodock/__init__.py
blob: 61ad54b06160586b52084541bee8735765c2357c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#
#coding:utf-8
#
#Author  : QCSun
#Email   : qcsun@sunhpc.com
#Times   : 2023-04-14 05:21:02
#WebSite : https://www.sunhpc.com

import os
import re
import sys
import sunhpc
import shutil

class command(sunhpc.commands.soft.command):
    pass

class Command(command):
    """
    Compilation and installation of the parallel computing software.

    <arg type="string" name="version">
    Specifies the software version. e.g,, version=x.x.x
    </arg>

    <param type="path" name="source">
    Specifies the software source path. Default: /mnt/usb
    </param>

    <param type="path" name="prefix">
    Specifies the software install path. Default: /share/apps/soft
    </param>

    <param type="path" name="envs">
    Specifies the environment variable storage path. Default: /share/apps/envs
    </param>

    <example cmd='soft mpi prefix=/share/apps/soft/xxx version=x.x.x'>
    Build the command line and associated parameters for this software.
    </example>
    """
    def run(self, params, args):

        (prefix, source, envs, version) = self.fillParams([
            ('prefix', '/share/apps/soft'),
            ('source', '/mnt/usb'),
            ('envs', '/share/apps/envs'),
            ('version', None),
            ])

        softname = 'autodock'
        suffname = 'tar.gz'
        dirsname = os.path.join(source, 'hpcsoft', 'AutoDock')
        try:
            verslist = self.getVersions(key=softname, suffix=suffname, dirs=dirsname)
        except FileNotFoundError as e:
            self.msg(str(e), 'a')

        if len(args):
            version = args[0]

        if not version:
            self.msg('must supply an "Version Number", e.g,, version=%s' % '/'.join(verslist), 'a')

        self.create_dirs(prefix, source, envs, version, softname, suffname, dirsname)

        self.build(prefix)
        self.clean()

    def build(self, prefix):
        """Start build the software."""
        self.cwd = os.getcwd()

        names = os.listdir(self.tmpdirs)
        if self.basename not in names:
            self.msg('Unpack the file from the %s to the %s directory.' % (self.filename, prefix))
            os.system('tar -xf %s -C %s' % (self.source, prefix))


        with open(self.envfile, 'w') as f:
            f.write('#!/bin/sh\n')
            f.write('#\n# %s env config\n#\n\n' % self.basename)
            f.write('export PATH=%s:$PATH\n' % (self.prefix))

        # create shared user and group.
        self.msg('')
        self.msg('--------------------------------------------------------')
        self.msg('Create a shared group to run the %s software.' % self.basename)
        self.msg('  1, groupadd -g 888    public ')
        self.msg('  2, usermod  -G public dell   ')
        self.msg('  3, chown    -R root:public %s' % self.prefix)
        self.msg('--------------------------------------------------------')
        self.msg('')
        self.msg('  source %s' % self.envfile)
        self.msg('--------------------------------------------------------')
        

    def create_dirs(self, prefix, source, envs, version, softname, suffname, dirsname):
        """Create base build directory."""

        self.basename = '%s-%s' % (softname, version)
        self.filename = '%s.%s' % (self.basename, suffname)

        self.prefix = os.path.join(prefix, softname, version)
        if not os.path.exists(self.prefix):
            os.makedirs(self.prefix)

        self.source = os.path.join(dirsname, self.filename)
        if not os.path.exists(self.source):
            self.msg('The %s does not exist,please check it.' % self.source, 'a')

        if not os.path.exists(envs):
            os.makedirs(envs)
        self.envfile = os.path.join(envs, '%s-%s' % (softname, version))

        self.tmpdirs = os.path.join(prefix, 'tmpdirs', softname)
        if not os.path.exists(self.tmpdirs):
            os.makedirs(self.tmpdirs)

    def clean(self):
        """Clean the install tmp directory."""
        if os.path.exists(self.tmpdirs):
            shutil.rmtree(self.tmpdirs)