source: ogClient-Git/src/linux/ogOperations.py @ 2e342b5

Last change on this file since 2e342b5 was 2e342b5, checked in by Alvaro Neira Ayuso <alvaroneay@…>, 5 years ago

Modify methods to use less arguments

Now, all the arguments are received from httpparser. Those arguments convert
the function in long lines of codes. Passing directly the httpparser, all the
function will have less arguments and will be more clear the code.

  • Property mode set to 100644
File size: 2.2 KB
Line 
1import os
2import subprocess
3
4OG_PATH = '/opt/opengnsys/'
5
6def poweroff():
7        if os.path.exists('/scripts/oginit'):
8                subprocess.call('source ' + OG_SCRIPT_PATH + 'etc/preinit/loadenviron.sh; ' + OG_SCRIPT_PATH + 'scripts/poweroff', shell=True)
9        else:
10                subprocess.call(['/sbin/poweroff'])
11
12def reboot():
13        if os.path.exists('/scripts/oginit'):
14                subprocess.call('source ' + OG_SCRIPT_PATH + 'etc/preinit/loadenviron.sh; ' + OG_SCRIPT_PATH + 'scripts/reboot', shell=True)
15        else:
16                subprocess.call(['/sbin/reboot'])
17
18def execCMD(httpparser):
19        cmd = httpparser.getCMD()
20        cmds = cmd.split(" ")
21        try:
22                result = subprocess.check_output(cmds)
23        except:
24                raise ValueError('Error: Incorrect command value')
25
26        return result.decode('utf-8')
27
28def procsession(httpparser):
29        disk = httpparser.getDisk()
30        partition = httpparser.getPartition()
31
32        result = subprocess.check_output([OG_PATH + 'interfaceAdm/IniciarSesion', disk, partition], shell=True)
33        return result.decode('utf-8')
34
35def procsoftware(httpparser, path):
36        disk = httpparser.getDisk()
37        partition = httpparser.getPartition()
38
39        result = subprocess.check_output([OG_PATH + 'interfaceAdm/InventarioSoftware', disk, partition, path], shell=True)
40        return result.decode('utf-8')
41
42def prochardware(path):
43        result = subprocess.check_output([OG_PATH + 'interfaceAdm/InventarioHardware', path], shell=True)
44        return result.decode('utf-8')
45
46def procsetup(httpparser):
47        disk = httpparser.getDisk()
48        cache = httpparser.getCache()
49        cachesize = httpparser.getCacheSize()
50        partlist = httpparser.getPartitionSetup()
51
52        for part in partlist:
53                cfg = 'dis=' + disk + '*che=' + cache + '*tch=' + cachesize + '!par=' + part["partition"] + '*cpt='+part["code"] + '*sfi=' + part['filesystem'] + '*tam=' + part['size'] + '*ope=' + part['format'] + '%'
54                subprocess.check_output([OG_PATH + 'interfaceAdm/Configurar', disk, cfg], shell=True)
55
56def procirestore(httpparser):
57        disk = httpparser.getDisk()
58        partition = httpparser.getPartition()
59        name = httpparser.getName()
60        repo = httpparser.getRepo()
61        ctype = httpparser.getType()
62        profile = httpparser.getProfile()
63        cid = httpparser.getId()
64
65        result = subprocess.check_output([OG_PATH + 'interfaceAdm/RestaurarImagen', disk, partition, name, repo, ctype], shell=True)
66        return result.decode('utf-8')
Note: See TracBrowser for help on using the repository browser.