-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutility.py
More file actions
45 lines (33 loc) · 1.16 KB
/
utility.py
File metadata and controls
45 lines (33 loc) · 1.16 KB
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
#! /usr/bin/python
import os, sys, commands
def get_folders(root_dir):
folders = [ name for name in os.listdir(root_dir) if os.path.isdir(os.path.join(root_dir, name)) ]
return folders
def get_files(root_dir):
files = [ name for name in os.listdir(root_dir) if os.path.isfile(os.path.join(root_dir, name)) ]
return files
def get_home():
return os.path.abspath(os.getenv('HOME'))
def get_pwd():
return os.path.abspath(os.getenv('PWD'))
def is_valid_dir( path ):
return os.path.isdir( path )
def is_valid_file( path ):
return os.path.isfile( path )
def run_command( cmd ):
rc, cmd_info = commands.getstatusoutput(cmd)
if rc != 0:
print 'error processing command ['+cmd+']'
print 'msg: '
print cmd_info
return rc, cmd_info
def get_mount_point( disk_name ):
rc, cmd_info = commands.getstatusoutput( 'mount | grep -w '+disk_name )
if len(cmd_info) == 0:
return ''
else:
rc, mount_dir = commands.getstatusoutput('echo \''+cmd_info+'\' | awk \'{print $3}\'')
if rc != 0:
print 'error processing command!'
print mount_dir
return mount_dir