Skip to content

Commit

Permalink
Added more comments as suggested in code review (HTCONDOR-728)
Browse files Browse the repository at this point in the history
  • Loading branch information
markcoatsworth committed Sep 16, 2021
1 parent 5de190e commit bc57bc5
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/condor_examples/filetransfer_example_plugin.py
@@ -1,5 +1,13 @@
#!/usr/bin/env python3

"""
This is an example template for a custom HTCondor file transfer plugin.
In this example, it transfers files described by an example://path/to/file URL
by copying them from the path indicated to a job's working directory.
To make this a functional plugin, change everything in this file that comes
after a #CHANGE ME HERE comment.
"""

import classad
import json
import os
Expand All @@ -10,10 +18,10 @@
import sys
import time

from urllib.parse import urlparse # Python 3
from urllib.parse import urlparse

DEFAULT_TIMEOUT = 30
EXAMPLE_PLUGIN_VERSION = '1.0.0'
PLUGIN_VERSION = '1.0.0'

def print_help(stream = sys.stderr):
help_msg = '''Usage: {0} -infile <input-filename> -outfile <output-filename>
Expand All @@ -33,8 +41,11 @@ def print_capabilities():
capabilities = {
'MultipleFileSupport': True,
'PluginType': 'FileTransfer',
# SupportedMethods indicates which URL methods/types this plugin supports
#CHANGE ME HERE
'SupportedMethods': 'example',
'Version': EXAMPLE_PLUGIN_VERSION,
#END CHANGE
'Version': PLUGIN_VERSION,
}
sys.stdout.write(classad.ClassAd(capabilities).printOld())

Expand Down Expand Up @@ -97,7 +108,9 @@ def get_error_dict(error, url = ''):

return error_dict

#CHANGE ME HERE
class ExamplePlugin:
#END CHANGE

# Extract whatever information we want from the url provided.
# In this example, convert the example://path/to/file url to a
Expand All @@ -113,9 +126,11 @@ def download_file(self, url, local_file_path):
# Download transfer logic goes here
# In this example, we simply copy the file from a path indicated in the
# URL string to the current working directory.
#CHANGE ME HERE
example_file_path = self.parse_url(url)
shutil.copy(example_file_path, local_file_path)
file_size = os.stat(local_file_path).st_size
#END CHANGE

end_time = time.time()

Expand All @@ -142,9 +157,11 @@ def upload_file(self, url, local_file_path):
# Upload transfer logic goes here
# In this example, we simply copy the file to a path indicated in the
# URL string from the current working directory.
#CHANGE ME HERE
example_file_path = self.parse_url(url)
shutil.copy(local_file_path, example_file_path)
file_size = os.stat(local_file_path).st_size
#END CHANGE

end_time = time.time()

Expand Down Expand Up @@ -173,7 +190,9 @@ def upload_file(self, url, local_file_path):
except Exception:
sys.exit(1)

#CHANGE ME HERE
example_plugin = ExamplePlugin()
#END CHANGE

# Parse in the classads stored in the input file.
# Each ad represents a single file to be transferred.
Expand All @@ -194,9 +213,13 @@ def upload_file(self, url, local_file_path):
for ad in infile_ads:
try:
if not args['upload']:
#CHANGE ME HERE
outfile_dict = example_plugin.download_file(ad['Url'], ad['LocalFileName'])
#END CHANGE
else:
#CHANGE ME HERE
outfile_dict = example_plugin.upload_file(ad['Url'], ad['LocalFileName'])
#END CHANGE

outfile.write(str(classad.ClassAd(outfile_dict)))

Expand Down

0 comments on commit bc57bc5

Please sign in to comment.