Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
routersploit
Overview
Overview
Details
Activity
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
czos-dpend
routersploit
Commits
39a69009
Commit
39a69009
authored
May 31, 2016
by
fwkz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Covering case when the file already exist.
parent
bf5a036e
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
7 deletions
+13
-7
utils.py
routersploit/utils.py
+13
-7
No files found.
routersploit/utils.py
View file @
39a69009
...
@@ -448,22 +448,28 @@ def create_resource(name, content=(), python_package=False):
...
@@ -448,22 +448,28 @@ def create_resource(name, content=(), python_package=False):
if
python_package
:
if
python_package
:
open
(
os
.
path
.
join
(
root_path
,
"__init__.py"
),
"a"
)
.
close
()
open
(
os
.
path
.
join
(
root_path
,
"__init__.py"
),
"a"
)
.
close
()
print_success
(
"__init__.py successfully created."
)
for
name
,
template_path
,
context
in
content
:
for
name
,
template_path
,
context
in
content
:
if
os
.
path
.
splitext
(
name
)[
-
1
]
==
""
:
# Checking if resource has extension if not it's directory
if
os
.
path
.
splitext
(
name
)[
-
1
]
==
""
:
# Checking if resource has extension if not it's directory
os
.
mkdir
(
os
.
path
.
join
(
root_path
,
name
))
mkdir_p
(
os
.
path
.
join
(
root_path
,
name
))
print_success
(
"Sub-directory /{name} successfully created."
.
format
(
name
=
name
))
else
:
else
:
try
:
try
:
with
open
(
template_path
,
"rb"
)
as
template_file
:
with
open
(
template_path
,
"rb"
)
as
template_file
:
template
=
string
.
Template
(
template_file
.
read
())
template
=
string
.
Template
(
template_file
.
read
())
except
(
IOError
,
TypeError
):
except
(
IOError
,
TypeError
):
template
=
string
.
Template
(
""
)
template
=
string
.
Template
(
""
)
finally
:
with
open
(
os
.
path
.
join
(
root_path
,
name
),
"wb"
)
as
target_file
:
try
:
file_handle
=
os
.
open
(
os
.
path
.
join
(
root_path
,
name
),
os
.
O_CREAT
|
os
.
O_EXCL
|
os
.
O_WRONLY
)
except
OSError
as
e
:
if
e
.
errno
==
errno
.
EEXIST
:
print_status
(
"{} already exist."
.
format
(
name
))
else
:
raise
else
:
with
os
.
fdopen
(
file_handle
,
'w'
)
as
target_file
:
target_file
.
write
(
template
.
substitute
(
**
context
))
target_file
.
write
(
template
.
substitute
(
**
context
))
print_success
(
"{
file} successfully created."
.
format
(
file
=
name
))
print_success
(
"{
} successfully created."
.
format
(
name
))
def
mkdir_p
(
path
):
def
mkdir_p
(
path
):
...
@@ -474,7 +480,7 @@ def mkdir_p(path):
...
@@ -474,7 +480,7 @@ def mkdir_p(path):
"""
"""
try
:
try
:
os
.
makedirs
(
path
)
os
.
makedirs
(
path
)
print_success
(
"Directory {path} sucessfully created."
.
format
(
path
=
path
))
print_success
(
"Directory {path} suc
c
essfully created."
.
format
(
path
=
path
))
except
OSError
as
exc
:
except
OSError
as
exc
:
if
exc
.
errno
==
errno
.
EEXIST
and
os
.
path
.
isdir
(
path
):
if
exc
.
errno
==
errno
.
EEXIST
and
os
.
path
.
isdir
(
path
):
print_success
(
"Directory {path}"
.
format
(
path
=
path
))
print_success
(
"Directory {path}"
.
format
(
path
=
path
))
...
...
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