Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
GeoInt_SIDT
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
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mario Chirinos Colunga
GeoInt_SIDT
Commits
bb414682
Commit
bb414682
authored
Sep 11, 2018
by
Renán Sosa Guillen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
L2A products population
parent
5adbe140
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
36 deletions
+51
-36
populate_products_l2a.py
catalog/management/commands/populate_products_l2a.py
+51
-36
No files found.
catalog/management/commands/populate_products_l2a.py
View file @
bb414682
...
@@ -5,52 +5,67 @@
...
@@ -5,52 +5,67 @@
Usage:
Usage:
$ cd GeoInt_SIDT
$ cd GeoInt_SIDT
$ python manage.py populate_products_l2a [path_where_files_are_located]
$ python manage.py populate_products_l2a
Example:
$ cd GeoInt_SIDT
$ python manage.py populate_products_l2a /home/geointdev/sidt-env/sidt-zip/L2A/
"""
"""
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.core.management.base
import
BaseCommand
,
CommandError
from
catalog.models
import
Product_l1c
,
Product_l2a
from
catalog.models
import
Product_l1c
,
Product_l2a
import
os
import
os
,
sys
,
paramiko
SSH_ADDRESS
=
"192.168.1.59"
SSH_USERNAME
=
"geoint"
SSH_COMMAND
=
"cd NAS/sentinelImages/L2A/; pwd"
class
Command
(
BaseCommand
):
ssh
=
paramiko
.
SSHClient
()
ssh
.
set_missing_host_key_policy
(
paramiko
.
AutoAddPolicy
())
def
add_arguments
(
self
,
parser
):
## positional arguments
parser
.
add_argument
(
'file_path'
,
nargs
=
1
,
type
=
str
)
class
Command
(
BaseCommand
):
def
handle
(
self
,
*
args
,
**
options
):
def
handle
(
self
,
*
args
,
**
options
):
path
=
options
[
'file_path'
][
0
]
ssh_stdin
=
ssh_stdout
=
ssh_stderr
=
None
file_list
=
os
.
listdir
(
path
)
file_list
.
sort
()
try
:
ssh
.
connect
(
SSH_ADDRESS
,
username
=
SSH_USERNAME
)
for
file
in
file_list
:
ssh_stdin
,
ssh_stdout
,
ssh_stderr
=
ssh
.
exec_command
(
SSH_COMMAND
)
file_name
=
file
.
replace
(
".zip"
,
''
)
path
=
ssh_stdout
.
read
()
.
replace
(
"
\n
"
,
''
)
try
:
sftp
=
ssh
.
open_sftp
()
## Creates SFTPClient() object
PRODUCT_EXISTS
=
Product_l2a
.
objects
.
filter
(
identifier
=
file_name
)
.
exists
()
sftp
.
chdir
(
path
)
file_list
=
sftp
.
listdir
()
if
not
PRODUCT_EXISTS
:
prod_l1c
=
Product_l1c
.
objects
.
filter
(
identifier
=
file_name
)[
0
]
for
file
in
file_list
:
file_name
=
file
.
replace
(
".zip"
,
''
)
product_l2a
=
Product_l2a
(
prod_l1c
=
prod_l1c
,
try
:
identifier
=
prod_l1c
.
identifier
,
PRODUCT_EXISTS
=
Product_l2a
.
objects
.
filter
(
identifier
=
file_name
)
.
exists
()
file_path
=
path
)
if
not
PRODUCT_EXISTS
:
prod_l1c
=
Product_l1c
.
objects
.
filter
(
identifier
=
file_name
.
replace
(
"L2A"
,
"L1C"
))[
0
]
product_l2a
.
save
()
print
prod_l1c
.
identifier
product_l2a
=
Product_l2a
(
prod_l1c
=
prod_l1c
,
else
:
identifier
=
file_name
,
"Existe"
file_path
=
path
)
product_l2a
.
save
()
print
"NEW product: "
+
file_name
# else:
# print "Product " + file_name + " is ALREADY in DB."
except
:
print
"Error con archivo "
+
file_name
except
Exception
as
e
:
sys
.
stderr
.
write
(
"SSH connection error: {0}"
.
format
(
e
))
if
ssh_stdout
:
sys
.
stdout
.
write
(
ssh_stdout
.
read
())
if
ssh_stderr
:
sys
.
stderr
.
write
(
ssh_stderr
.
read
())
except
:
sftp
.
close
()
print
"Error con archivo "
+
file_name
ssh
.
close
()
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