-
Notifications
You must be signed in to change notification settings - Fork 331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
op-mode: T4038: Python rewrite of image tools #2507
Conversation
Before you approve/merge, I have a very important question to those familiar with |
@erkin Since it's no longer possible to set the user level to operator (we removed that option), I believe it's safe to just set it to admin for all users. |
if os.path.isdir(destination_path): | ||
destination_path = os.path.join(destination_path, os.path.basename(source)) | ||
shutil.copytree(source, destination_path, copy_function=zealous_copy) | ||
else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A missing check here causes problems, in applying 'chown' to the destination directory:
diff --git a/src/op_mode/file.py b/src/op_mode/file.py
index b09631ba2..b675afebf 100755
--- a/src/op_mode/file.py
+++ b/src/op_mode/file.py
@@ -244,6 +244,8 @@ def copy(source_type: str, source_path: str,
destination_path = os.path.join(destination_path, os.path.basename(source))
shutil.copytree(source, destination_path, copy_function=zealous_copy)
else:
+ if os.path.isdir(destination_path):
+ destination_path = os.path.join(destination_path, os.path.basename(source))
zealous_copy(source, destination_path)
else:
print_error(f'Unknown destination type: {source_type}')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the shared check outside the conditional for simplicity.
This one is a simplification using some of the utils from the image-tools revision and, for consideration, dropping the 'disk-install' case --- my impression is that it is antiquated/obsolete, but I may be missing something; we should check with @dmbaturin
|
src/op_mode/file.py
Outdated
|
||
def show(type: str, path: str) -> None: | ||
if type == 'remote': | ||
with tempfile.NamedTemporaryFile(delete=False) as temp: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since using as a context manager here, one does not want delete=False
Comment added here with reference to issue discussed with Erkin; patch is for the companion PR vyos/vyatta-op#84 and cited below. Unless op-mode
... and that's it: 'y'+'enter' or 'enter' is accepted, but prompt is missing.
patch for vyatta-op:
There are two things to note: |
cf. comment in |
A typo in |
Change Summary
Rewrite of
vyatta-image-tools.pl
. Brings with it a minor change to the template schema to add a special case forcomptype
. Please see the corresponding PR onvyatta-op
below.Types of changes
Related Task(s)
Related PR(s)
vyatta-image-tools.pl
vyatta-op#84Component(s) name
op-mode, image tools
Proposed changes
It should be functionally identical with the Perl implementation, except it eschews external programs like
rsync
andcurl
in favour of in-house routines and there are a few user-facing cosmetic changes.It adds the
<imagePath/>
empty tag to the XML schema as an option for<completionType>
. It should theoretically work with others like<list>
and<script>
too, but I haven't tried it yet. (I'll try it withadd system image
later.)A certain
is_interactive()
check for known hosts is replaced withisatty()
since it can be gracefully answered by automated scripts and because it was preventing the SFTP operations ofcopy file
.I tested all routines, except for some cases of
copy file upload
but it would definitely benefit from more eyes if we're going to backport this to 1.4.How to test
Smoketest result
Checklist: