Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
elphel-apps-camogm
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Elphel
elphel-apps-camogm
Commits
8a3d9375
Commit
8a3d9375
authored
Jan 17, 2017
by
Mikhail Karpenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Show partitioned disk in table
parent
f30b7676
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
8 deletions
+36
-8
format_disk.php
src/format_disk/format_disk.php
+18
-2
format_disk.py
src/format_disk/format_disk.py
+18
-6
No files found.
src/format_disk/format_disk.php
View file @
8a3d9375
...
@@ -47,6 +47,8 @@ function table_row_err($msg)
...
@@ -47,6 +47,8 @@ function table_row_err($msg)
function
table_body
(
$disks
)
function
table_body
(
$disks
)
{
{
global
$parted_script
;
$ret_val
=
$disks
[
"ret_val"
];
$ret_val
=
$disks
[
"ret_val"
];
$num
=
count
(
$disks
[
"disks"
]);
$num
=
count
(
$disks
[
"disks"
]);
if
(
$ret_val
==
0
&&
$num
>
0
)
{
if
(
$ret_val
==
0
&&
$num
>
0
)
{
...
@@ -55,8 +57,22 @@ function table_body($disks)
...
@@ -55,8 +57,22 @@ function table_body($disks)
table_row
(
$i
,
$data
[
0
],
$data
[
1
],
$data
[
2
]);
table_row
(
$i
,
$data
[
0
],
$data
[
1
],
$data
[
2
]);
}
}
}
else
if
(
$ret_val
==
0
&&
$num
==
0
)
{
}
else
if
(
$ret_val
==
0
&&
$num
==
0
)
{
exec
(
$parted_script
.
" --partitions"
,
$output
,
$ret
);
if
(
$ret
==
0
)
{
$msg
=
"Disk is already partitioned: "
;
foreach
(
$output
as
$line
)
{
$plist
=
explode
(
':'
,
$line
);
foreach
(
$plist
as
$p
)
{
$msg
=
$msg
.
$p
.
" "
;
}
}
$partition
=
substr
(
$plist
[
0
],
0
,
strpos
(
$plist
[
0
],
'('
)
-
1
);
$disk
=
substr
(
$partition
,
0
,
-
1
);
table_row
(
0
,
$disk
,
""
,
""
,
$msg
);
}
else
{
$msg
=
"No disks suitable for partitioning"
;
$msg
=
"No disks suitable for partitioning"
;
table_row_err
(
$msg
);
table_row_err
(
$msg
);
}
}
else
{
}
else
{
table_row_err
(
$disks
[
"disks"
][
0
]);
table_row_err
(
$disks
[
"disks"
][
0
]);
}
}
...
...
src/format_disk/format_disk.py
View file @
8a3d9375
...
@@ -106,9 +106,11 @@ def check_prerequisites():
...
@@ -106,9 +106,11 @@ def check_prerequisites():
ret_str
=
tool
[
0
]
ret_str
=
tool
[
0
]
return
ret_str
return
ret_str
def
find_disks
():
def
find_disks
(
partitioned
=
False
):
"""
"""
Find all attached and unpartitioned SCSI disks.
Find all attached and, by default, unpartitioned SCSI disks. If a key is specified
then a list of all attached disks is is returned.
@param partitioned: include partitioned disks
Return: a list containing paths to disks
Return: a list containing paths to disks
"""
"""
dlist
=
[]
dlist
=
[]
...
@@ -119,9 +121,12 @@ def find_disks():
...
@@ -119,9 +121,12 @@ def find_disks():
dev
=
re
.
search
(
' +(sd[a-z]$)'
,
partition
)
dev
=
re
.
search
(
' +(sd[a-z]$)'
,
partition
)
if
dev
:
if
dev
:
dev_path
=
'/dev/{0}'
.
format
(
dev
.
group
(
1
))
dev_path
=
'/dev/{0}'
.
format
(
dev
.
group
(
1
))
if
not
partitioned
:
plist
=
find_partitions
(
dev_path
)
plist
=
find_partitions
(
dev_path
)
if
not
plist
:
if
not
plist
:
dlist
.
append
(
dev_path
)
dlist
.
append
(
dev_path
)
else
:
dlist
.
append
(
dev_path
)
except
:
except
:
# something went wrong, clear list to prevent accidental data loss
# something went wrong, clear list to prevent accidental data loss
del
dlist
[:]
del
dlist
[:]
...
@@ -136,12 +141,12 @@ def find_partitions(dev_path):
...
@@ -136,12 +141,12 @@ def find_partitions(dev_path):
plist
=
[]
plist
=
[]
try
:
try
:
partitions
=
subprocess
.
check_output
([
'cat'
,
'/proc/partitions'
])
partitions
=
subprocess
.
check_output
([
'cat'
,
'/proc/partitions'
])
search_str
=
' +({0}[0-9]+$)'
.
format
(
dev_path
.
rpartition
(
'/'
)[
-
1
])
search_str
=
'
([0-9]+)
+({0}[0-9]+$)'
.
format
(
dev_path
.
rpartition
(
'/'
)[
-
1
])
# the first two elemets of the list are table header and empty line delimiter, skip them
# the first two elemets of the list are table header and empty line delimiter, skip them
for
partition
in
partitions
.
splitlines
()[
2
:]:
for
partition
in
partitions
.
splitlines
()[
2
:]:
dev
=
re
.
search
(
search_str
,
partition
)
dev
=
re
.
search
(
search_str
,
partition
)
if
dev
:
if
dev
:
plist
.
append
(
'/dev/{0}
'
.
format
(
dev
.
group
(
1
)
))
plist
.
append
(
'/dev/{0}
({1:.1f} GB)'
.
format
(
dev
.
group
(
2
),
int
(
dev
.
group
(
1
))
/
1000000
))
except
:
except
:
# something went wrong, clear list to prevent accidental data loss
# something went wrong, clear list to prevent accidental data loss
del
plist
[:]
del
plist
[:]
...
@@ -236,6 +241,7 @@ if __name__ == "__main__":
...
@@ -236,6 +241,7 @@ if __name__ == "__main__":
parser
.
add_argument
(
'-e'
,
'--errno'
,
nargs
=
1
,
type
=
int
,
help
=
"convert error number returned by the script to error message"
)
parser
.
add_argument
(
'-e'
,
'--errno'
,
nargs
=
1
,
type
=
int
,
help
=
"convert error number returned by the script to error message"
)
parser
.
add_argument
(
'-d'
,
'--dry_run'
,
action
=
'store_true'
,
help
=
"execute the script but do not actually create partitions"
)
parser
.
add_argument
(
'-d'
,
'--dry_run'
,
action
=
'store_true'
,
help
=
"execute the script but do not actually create partitions"
)
parser
.
add_argument
(
'-f'
,
'--force'
,
action
=
'store_true'
,
help
=
"force 'mkfs' to create a file system"
)
parser
.
add_argument
(
'-f'
,
'--force'
,
action
=
'store_true'
,
help
=
"force 'mkfs' to create a file system"
)
parser
.
add_argument
(
'-p'
,
'--partitions'
,
action
=
'store_true'
,
help
=
"list partitions and their sizes separated by colon"
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
if
args
.
list
:
if
args
.
list
:
...
@@ -247,6 +253,12 @@ if __name__ == "__main__":
...
@@ -247,6 +253,12 @@ if __name__ == "__main__":
else
:
else
:
sys_size
=
0
sys_size
=
0
print
(
'{0}:{1} GB:{2} GB'
.
format
(
disk
,
total_size
,
sys_size
))
print
(
'{0}:{1} GB:{2} GB'
.
format
(
disk
,
total_size
,
sys_size
))
elif
args
.
partitions
:
all_partitions
=
[]
dlist
=
find_disks
(
partitioned
=
True
)
for
disk
in
dlist
:
all_partitions
+=
find_partitions
(
disk
)
print
(
':'
.
join
(
all_partitions
))
elif
args
.
errno
:
elif
args
.
errno
:
ret
=
ErrCodes
(
args
.
errno
[
0
])
ret
=
ErrCodes
(
args
.
errno
[
0
])
print
(
ret
.
err2str
())
print
(
ret
.
err2str
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment