Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
rabbitmq_agents
Manage
Activity
Members
Labels
Plan
Issues
16
Issue boards
Milestones
Wiki
Code
Merge requests
9
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
rc
rabbitmq_agents
Merge requests
!16
Adding create directory agent
Code
Review changes
Check out branch
Download
Patches
Plain diff
Closed
Adding create directory agent
github/fork/chirag06/feat-create-dir
into
develop
Overview
1
Commits
2
Pipelines
0
Changes
1
Closed
Ravi Tripathi
requested to merge
github/fork/chirag06/feat-create-dir
into
develop
5 years ago
Overview
1
Commits
2
Pipelines
0
Changes
1
Expand
Created by: chirag06
👍
0
👎
0
Merge request reports
Compare
develop
develop (base)
and
latest version
latest version
b5333f62
2 commits,
1 year ago
1 file
+
57
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
ohpc_dir_create.py
0 → 100644
+
57
−
0
Options
#!/usr/bin/env python
import
shutil
import
json
import
sys
import
os
from
rc_rmq
import
RCRMQ
task
=
'
ohpc_homedir
'
# Instantiate rabbitmq object
confirm_rmq
=
RCRMQ
({
'
exchange
'
:
'
Confirm
'
})
fanout_rmq
=
RCRMQ
({
'
exchange
'
:
'
Create
'
,
'
exchange_type
'
:
'
fanout
'
})
def
dir_walk
(
path
):
'''
Get All Directories & Files
'''
yield
path
for
dir_path
,
dir_names
,
file_names
in
os
.
walk
(
path
):
# Directories
for
dir_name
in
dir_names
:
yield
os
.
path
.
join
(
dir_path
,
dir_name
)
# Files
for
file_name
in
file_names
:
yield
os
.
path
.
join
(
dir_path
,
file_name
)
def
ohpc_dir_create
(
ch
,
method
,
properties
,
body
):
msg
=
json
.
loads
(
body
)
print
(
"
Message received {}
"
.
format
(
msg
))
username
=
msg
[
'
username
'
]
success
=
False
try
:
exist
=
os
.
path
.
isdir
(
msg
[
'
destination
'
])
if
not
exist
:
if
(
'
template
'
in
msg
):
shutil
.
copytree
(
msg
[
'
template
'
],
msg
[
'
destination
'
])
else
:
os
.
mkdir
(
msg
[
'
destination
'
])
#os.chown(msg['destination'], msg['uid'], msg['gid'])
for
recursive_path
in
dir_walk
(
msg
[
'
destination
'
]):
os
.
chown
(
recursive_path
,
msg
[
'
uid
'
],
msg
[
'
gid
'
])
else
:
print
(
"
Home directory already exists, skip
"
)
success
=
True
except
:
e
=
sys
.
exc_info
()[
0
]
print
(
"
Error: {}
"
.
format
(
e
))
ch
.
basic_ack
(
delivery_tag
=
method
.
delivery_tag
)
confirm_rmq
.
publish_msg
({
'
routing_key
'
:
username
,
'
msg
'
:
{
'
task
'
:
task
,
'
success
'
:
success
}})
print
(
"
Start listening to queue
'
{}
'
in exchange
'
Create
'
.
"
.
format
(
task
))
fanout_rmq
.
start_consume
({
'
queue
'
:
task
,
'
cb
'
:
ohpc_dir_create
})
Loading