-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BFN] Fix exception when fwutil run without sudo
- Loading branch information
Showing
4 changed files
with
42 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/platform_utils.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env python | ||
|
||
try: | ||
import os | ||
import subprocess | ||
|
||
except ImportError as e: | ||
raise ImportError(str(e) + "- required module not found") | ||
|
||
def file_create(path, mode=None): | ||
def run_cmd(cmd): | ||
if os.geteuid() != 0: | ||
cmd.insert(0, 'sudo') | ||
subprocess.check_output(cmd) | ||
|
||
file_path = os.path.dirname(path) | ||
if not os.path.exists(file_path): | ||
run_cmd(['mkdir', '-p', file_path]) | ||
if not os.path.isfile(path): | ||
run_cmd(['touch', path]) | ||
if (mode is not None): | ||
run_cmd(['chmod', mode, path]) |