INSTRUCTION stringlengths 1 8.43k | RESPONSE stringlengths 75 104k |
|---|---|
Retrieves connection to Cloud Speech. | def get_conn(self):
"""
Retrieves connection to Cloud Speech.
:return: Google Cloud Speech client object.
:rtype: google.cloud.speech_v1.SpeechClient
"""
if not self._client:
self._client = SpeechClient(credentials=self._get_credentials())
return self... |
Recognizes audio input | def recognize_speech(self, config, audio, retry=None, timeout=None):
"""
Recognizes audio input
:param config: information to the recognizer that specifies how to process the request.
https://googleapis.github.io/google-cloud-python/latest/speech/gapic/v1/types.html#google.cloud.spe... |
Call the SparkSqlHook to run the provided sql query | def execute(self, context):
"""
Call the SparkSqlHook to run the provided sql query
"""
self._hook = SparkSqlHook(sql=self._sql,
conf=self._conf,
conn_id=self._conn_id,
total_executor_co... |
Provide task_instance context to airflow task handler.: param ti: task instance object | def set_context(self, ti):
"""
Provide task_instance context to airflow task handler.
:param ti: task instance object
"""
local_loc = self._init_file(ti)
self.handler = logging.FileHandler(local_loc)
self.handler.setFormatter(self.formatter)
self.handler.s... |
Template method that contains custom logic of reading logs given the try_number.: param ti: task instance record: param try_number: current try_number to read log from: param metadata: log metadata can be used for steaming log reading and auto - tailing.: return: log message as a string and metadata. | def _read(self, ti, try_number, metadata=None):
"""
Template method that contains custom logic of reading
logs given the try_number.
:param ti: task instance record
:param try_number: current try_number to read log from
:param metadata: log metadata,
... |
Read logs of given task instance from local machine.: param task_instance: task instance object: param try_number: task instance try_number to read logs from. If None it returns all logs separated by try_number: param metadata: log metadata can be used for steaming log reading and auto - tailing.: return: a list of log... | def read(self, task_instance, try_number=None, metadata=None):
"""
Read logs of given task instance from local machine.
:param task_instance: task instance object
:param try_number: task instance try_number to read logs from. If None
it returns all logs separat... |
Create log directory and give it correct permissions.: param ti: task instance object: return: relative log path of the given task instance | def _init_file(self, ti):
"""
Create log directory and give it correct permissions.
:param ti: task instance object
:return: relative log path of the given task instance
"""
# To handle log writing when tasks are impersonated, the log files need to
# be writable b... |
Load AirflowPlugin subclasses from the entrypoints provided. The entry_point group should be airflow. plugins. | def load_entrypoint_plugins(entry_points, airflow_plugins):
"""
Load AirflowPlugin subclasses from the entrypoints
provided. The entry_point group should be 'airflow.plugins'.
:param entry_points: A collection of entrypoints to search for plugins
:type entry_points: Generator[setuptools.EntryPoint,... |
Check whether a potential object is a subclass of the AirflowPlugin class. | def is_valid_plugin(plugin_obj, existing_plugins):
"""
Check whether a potential object is a subclass of
the AirflowPlugin class.
:param plugin_obj: potential subclass of AirflowPlugin
:param existing_plugins: Existing list of AirflowPlugin subclasses
:return: Whether or not the obj is a valid ... |
Sets tasks instances to skipped from the same dag run. | def skip(self, dag_run, execution_date, tasks, session=None):
"""
Sets tasks instances to skipped from the same dag run.
:param dag_run: the DagRun for which to set the tasks to skipped
:param execution_date: execution_date
:param tasks: tasks to skip (not task_ids)
:par... |
Return a AzureDLFileSystem object. | def get_conn(self):
"""Return a AzureDLFileSystem object."""
conn = self.get_connection(self.conn_id)
service_options = conn.extra_dejson
self.account_name = service_options.get('account_name')
adlCreds = lib.auth(tenant_id=service_options.get('tenant'),
... |
Check if a file exists on Azure Data Lake. | def check_for_file(self, file_path):
"""
Check if a file exists on Azure Data Lake.
:param file_path: Path and name of the file.
:type file_path: str
:return: True if the file exists, False otherwise.
:rtype: bool
"""
try:
files = self.connect... |
Upload a file to Azure Data Lake. | def upload_file(self, local_path, remote_path, nthreads=64, overwrite=True,
buffersize=4194304, blocksize=4194304):
"""
Upload a file to Azure Data Lake.
:param local_path: local path. Can be single file, directory (in which case,
upload recursively) or glob patt... |
Download a file from Azure Blob Storage. | def download_file(self, local_path, remote_path, nthreads=64, overwrite=True,
buffersize=4194304, blocksize=4194304):
"""
Download a file from Azure Blob Storage.
:param local_path: local path. If downloading a single file, will write to this
specific file, unl... |
List files in Azure Data Lake Storage | def list(self, path):
"""
List files in Azure Data Lake Storage
:param path: full path/globstring to use to list files in ADLS
:type path: str
"""
if "*" in path:
return self.connection.glob(path)
else:
return self.connection.walk(path) |
Run Presto Query on Athena | def execute(self, context):
"""
Run Presto Query on Athena
"""
self.hook = self.get_hook()
self.hook.get_conn()
self.query_execution_context['Database'] = self.database
self.result_configuration['OutputLocation'] = self.output_location
self.query_executio... |
Cancel the submitted athena query | def on_kill(self):
"""
Cancel the submitted athena query
"""
if self.query_execution_id:
self.log.info('⚰️⚰️⚰️ Received a kill Signal. Time to Die')
self.log.info(
'Stopping Query with executionId - %s', self.query_execution_id
)
... |
Uncompress gz and bz2 files | def uncompress_file(input_file_name, file_extension, dest_dir):
"""
Uncompress gz and bz2 files
"""
if file_extension.lower() not in ('.gz', '.bz2'):
raise NotImplementedError("Received {} format. Only gz and bz2 "
"files can currently be uncompressed."
... |
Queries MSSQL and returns a cursor of results. | def _query_mssql(self):
"""
Queries MSSQL and returns a cursor of results.
:return: mssql cursor
"""
mssql = MsSqlHook(mssql_conn_id=self.mssql_conn_id)
conn = mssql.get_conn()
cursor = conn.cursor()
cursor.execute(self.sql)
return cursor |
Takes a cursor and writes results to a local file. | def _write_local_data_files(self, cursor):
"""
Takes a cursor, and writes results to a local file.
:return: A dictionary where keys are filenames to be used as object
names in GCS, and values are file handles to local files that
contain the data for the GCS objects.
... |
Upload all of the file splits ( and optionally the schema. json file ) to Google cloud storage. | def _upload_to_gcs(self, files_to_upload):
"""
Upload all of the file splits (and optionally the schema .json file) to
Google cloud storage.
"""
hook = GoogleCloudStorageHook(
google_cloud_storage_conn_id=self.google_cloud_storage_conn_id,
delegate_to=self... |
Takes a value from MSSQL and converts it to a value that s safe for JSON/ Google Cloud Storage/ BigQuery. | def convert_types(cls, value):
"""
Takes a value from MSSQL, and converts it to a value that's safe for
JSON/Google Cloud Storage/BigQuery.
"""
if isinstance(value, decimal.Decimal):
return float(value)
else:
return value |
Decorates function to execute function at the same time submitting action_logging but in CLI context. It will call action logger callbacks twice one for pre - execution and the other one for post - execution. | def action_logging(f):
"""
Decorates function to execute function at the same time submitting action_logging
but in CLI context. It will call action logger callbacks twice,
one for pre-execution and the other one for post-execution.
Action logger will be called with below keyword parameters:
... |
Builds metrics dict from function args It assumes that function arguments is from airflow. bin. cli module s function and has Namespace instance where it optionally contains dag_id task_id and execution_date. | def _build_metrics(func_name, namespace):
"""
Builds metrics dict from function args
It assumes that function arguments is from airflow.bin.cli module's function
and has Namespace instance where it optionally contains "dag_id", "task_id",
and "execution_date".
:param func_name: name of function... |
Yields a dependency status that indicate whether the given task instance s trigger rule was met. | def _evaluate_trigger_rule(
self,
ti,
successes,
skipped,
failed,
upstream_failed,
done,
flag_upstream_failed,
session):
"""
Yields a dependency status that indicate whether the given task instanc... |
Create the specified cgroup. | def _create_cgroup(self, path):
"""
Create the specified cgroup.
:param path: The path of the cgroup to create.
E.g. cpu/mygroup/mysubgroup
:return: the Node associated with the created cgroup.
:rtype: cgroupspy.nodes.Node
"""
node = trees.Tree().root
... |
Delete the specified cgroup. | def _delete_cgroup(self, path):
"""
Delete the specified cgroup.
:param path: The path of the cgroup to delete.
E.g. cpu/mygroup/mysubgroup
"""
node = trees.Tree().root
path_split = path.split("/")
for path_element in path_split:
name_to_node ... |
: return: a mapping between the subsystem name to the cgroup name: rtype: dict [ str str ] | def _get_cgroup_names():
"""
:return: a mapping between the subsystem name to the cgroup name
:rtype: dict[str, str]
"""
with open("/proc/self/cgroup") as f:
lines = f.readlines()
d = {}
for line in lines:
line_split = line.rstr... |
The purpose of this function is to be robust to improper connections settings provided by users specifically in the host field. | def _parse_host(host):
"""
The purpose of this function is to be robust to improper connections
settings provided by users, specifically in the host field.
For example -- when users supply ``https://xx.cloud.databricks.com`` as the
host, we must strip out the protocol to get the... |
Utility function to perform an API call with retries | def _do_api_call(self, endpoint_info, json):
"""
Utility function to perform an API call with retries
:param endpoint_info: Tuple of method and endpoint
:type endpoint_info: tuple[string, string]
:param json: Parameters for this API call.
:type json: dict
:return... |
Sign into Salesforce only if we are not already signed in. | def get_conn(self):
"""
Sign into Salesforce, only if we are not already signed in.
"""
if not self.conn:
connection = self.get_connection(self.conn_id)
extras = connection.extra_dejson
self.conn = Salesforce(
username=connection.login,... |
Make a query to Salesforce. | def make_query(self, query):
"""
Make a query to Salesforce.
:param query: The query to make to Salesforce.
:type query: str
:return: The query result.
:rtype: dict
"""
conn = self.get_conn()
self.log.info("Querying for all objects")
quer... |
Get the description of an object from Salesforce. This description is the object s schema and some extra metadata that Salesforce stores for each object. | def describe_object(self, obj):
"""
Get the description of an object from Salesforce.
This description is the object's schema and
some extra metadata that Salesforce stores for each object.
:param obj: The name of the Salesforce object that we are getting a description of.
... |
Get a list of all available fields for an object. | def get_available_fields(self, obj):
"""
Get a list of all available fields for an object.
:param obj: The name of the Salesforce object that we are getting a description of.
:type obj: str
:return: the names of the fields.
:rtype: list of str
"""
self.ge... |
Get all instances of the object from Salesforce. For each model only get the fields specified in fields. | def get_object_from_salesforce(self, obj, fields):
"""
Get all instances of the `object` from Salesforce.
For each model, only get the fields specified in fields.
All we really do underneath the hood is run:
SELECT <fields> FROM <obj>;
:param obj: The object name to... |
Convert a column of a dataframe to UNIX timestamps if applicable | def _to_timestamp(cls, column):
"""
Convert a column of a dataframe to UNIX timestamps if applicable
:param column: A Series object representing a column of a dataframe.
:type column: pd.Series
:return: a new series that maintains the same index as the original
:rtype: p... |
Write query results to file. | def write_object_to_file(self,
query_results,
filename,
fmt="csv",
coerce_to_timestamp=False,
record_time_added=False):
"""
Write query results to file.
... |
Read logs of given task instance and try_number from GCS. If failed read the log from task instance host machine.: param ti: task instance object: param try_number: task instance try_number to read logs from: param metadata: log metadata can be used for steaming log reading and auto - tailing. | def _read(self, ti, try_number, metadata=None):
"""
Read logs of given task instance and try_number from GCS.
If failed, read the log from task instance host machine.
:param ti: task instance object
:param try_number: task instance try_number to read logs from
:param meta... |
Returns the log found at the remote_log_location.: param remote_log_location: the log s location in remote storage: type remote_log_location: str ( path ) | def gcs_read(self, remote_log_location):
"""
Returns the log found at the remote_log_location.
:param remote_log_location: the log's location in remote storage
:type remote_log_location: str (path)
"""
bkt, blob = self.parse_gcs_url(remote_log_location)
return sel... |
Writes the log to the remote_log_location. Fails silently if no hook was created.: param log: the log to write to the remote_log_location: type log: str: param remote_log_location: the log s location in remote storage: type remote_log_location: str ( path ): param append: if False any existing log file is overwritten. ... | def gcs_write(self, log, remote_log_location, append=True):
"""
Writes the log to the remote_log_location. Fails silently if no hook
was created.
:param log: the log to write to the remote_log_location
:type log: str
:param remote_log_location: the log's location in remot... |
Given a Google Cloud Storage URL ( gs:// <bucket >/ <blob > ) returns a tuple containing the corresponding bucket and blob. | def parse_gcs_url(gsurl):
"""
Given a Google Cloud Storage URL (gs://<bucket>/<blob>), returns a
tuple containing the corresponding bucket and blob.
"""
parsed_url = urlparse(gsurl)
if not parsed_url.netloc:
raise AirflowException('Please provide a bucket name... |
Fetches PyMongo Client | def get_conn(self):
"""
Fetches PyMongo Client
"""
if self.client is not None:
return self.client
# Mongo Connection Options dict that is unpacked when passed to MongoClient
options = self.extras
# If we are using SSL disable requiring certs from spe... |
Fetches a mongo collection object for querying. | def get_collection(self, mongo_collection, mongo_db=None):
"""
Fetches a mongo collection object for querying.
Uses connection schema as DB unless specified.
"""
mongo_db = mongo_db if mongo_db is not None else self.connection.schema
mongo_conn = self.get_conn()
... |
Runs an aggregation pipeline and returns the results https:// api. mongodb. com/ python/ current/ api/ pymongo/ collection. html#pymongo. collection. Collection. aggregate https:// api. mongodb. com/ python/ current/ examples/ aggregation. html | def aggregate(self, mongo_collection, aggregate_query, mongo_db=None, **kwargs):
"""
Runs an aggregation pipeline and returns the results
https://api.mongodb.com/python/current/api/pymongo/collection.html#pymongo.collection.Collection.aggregate
https://api.mongodb.com/python/current/exam... |
Runs a mongo find query and returns the results https:// api. mongodb. com/ python/ current/ api/ pymongo/ collection. html#pymongo. collection. Collection. find | def find(self, mongo_collection, query, find_one=False, mongo_db=None, **kwargs):
"""
Runs a mongo find query and returns the results
https://api.mongodb.com/python/current/api/pymongo/collection.html#pymongo.collection.Collection.find
"""
collection = self.get_collection(mongo_c... |
Inserts a single document into a mongo collection https:// api. mongodb. com/ python/ current/ api/ pymongo/ collection. html#pymongo. collection. Collection. insert_one | def insert_one(self, mongo_collection, doc, mongo_db=None, **kwargs):
"""
Inserts a single document into a mongo collection
https://api.mongodb.com/python/current/api/pymongo/collection.html#pymongo.collection.Collection.insert_one
"""
collection = self.get_collection(mongo_colle... |
Inserts many docs into a mongo collection. https:// api. mongodb. com/ python/ current/ api/ pymongo/ collection. html#pymongo. collection. Collection. insert_many | def insert_many(self, mongo_collection, docs, mongo_db=None, **kwargs):
"""
Inserts many docs into a mongo collection.
https://api.mongodb.com/python/current/api/pymongo/collection.html#pymongo.collection.Collection.insert_many
"""
collection = self.get_collection(mongo_collectio... |
Updates a single document in a mongo collection. https:// api. mongodb. com/ python/ current/ api/ pymongo/ collection. html#pymongo. collection. Collection. update_one | def update_one(self, mongo_collection, filter_doc, update_doc,
mongo_db=None, **kwargs):
"""
Updates a single document in a mongo collection.
https://api.mongodb.com/python/current/api/pymongo/collection.html#pymongo.collection.Collection.update_one
:param mongo_colle... |
Replaces a single document in a mongo collection. https:// api. mongodb. com/ python/ current/ api/ pymongo/ collection. html#pymongo. collection. Collection. replace_one | def replace_one(self, mongo_collection, doc, filter_doc=None,
mongo_db=None, **kwargs):
"""
Replaces a single document in a mongo collection.
https://api.mongodb.com/python/current/api/pymongo/collection.html#pymongo.collection.Collection.replace_one
.. note::
... |
Replaces many documents in a mongo collection. | def replace_many(self, mongo_collection, docs,
filter_docs=None, mongo_db=None, upsert=False, collation=None,
**kwargs):
"""
Replaces many documents in a mongo collection.
Uses bulk_write with multiple ReplaceOne operations
https://api.mongodb.c... |
Deletes a single document in a mongo collection. https:// api. mongodb. com/ python/ current/ api/ pymongo/ collection. html#pymongo. collection. Collection. delete_one | def delete_one(self, mongo_collection, filter_doc, mongo_db=None, **kwargs):
"""
Deletes a single document in a mongo collection.
https://api.mongodb.com/python/current/api/pymongo/collection.html#pymongo.collection.Collection.delete_one
:param mongo_collection: The name of the collecti... |
Deletes one or more documents in a mongo collection. https:// api. mongodb. com/ python/ current/ api/ pymongo/ collection. html#pymongo. collection. Collection. delete_many | def delete_many(self, mongo_collection, filter_doc, mongo_db=None, **kwargs):
"""
Deletes one or more documents in a mongo collection.
https://api.mongodb.com/python/current/api/pymongo/collection.html#pymongo.collection.Collection.delete_many
:param mongo_collection: The name of the co... |
Checks the mail folder for mails containing attachments with the given name. | def has_mail_attachment(self, name, mail_folder='INBOX', check_regex=False):
"""
Checks the mail folder for mails containing attachments with the given name.
:param name: The name of the attachment that will be searched for.
:type name: str
:param mail_folder: The mail folder wh... |
Retrieves mail s attachments in the mail folder by its name. | def retrieve_mail_attachments(self,
name,
mail_folder='INBOX',
check_regex=False,
latest_only=False,
not_found_mode='raise'):
"""
Retr... |
Downloads mail s attachments in the mail folder by its name to the local directory. | def download_mail_attachments(self,
name,
local_output_directory,
mail_folder='INBOX',
check_regex=False,
latest_only=False,
... |
Gets all attachments by name for the mail. | def get_attachments_by_name(self, name, check_regex, find_first=False):
"""
Gets all attachments by name for the mail.
:param name: The name of the attachment to look for.
:type name: str
:param check_regex: Checks the name for a regular expression.
:type check_regex: bo... |
Gets the file including name and payload. | def get_file(self):
"""
Gets the file including name and payload.
:returns: the part's name and payload.
:rtype: tuple
"""
return self.part.get_filename(), self.part.get_payload(decode=True) |
Write batch records to Kinesis Firehose | def put_records(self, records):
"""
Write batch records to Kinesis Firehose
"""
firehose_conn = self.get_conn()
response = firehose_conn.put_record_batch(
DeliveryStreamName=self.delivery_stream,
Records=records
)
return response |
Determines whether a task is ready to be rescheduled. Only tasks in NONE state with at least one row in task_reschedule table are handled by this dependency class otherwise this dependency is considered as passed. This dependency fails if the latest reschedule request s reschedule date is still in future. | def _get_dep_statuses(self, ti, session, dep_context):
"""
Determines whether a task is ready to be rescheduled. Only tasks in
NONE state with at least one row in task_reschedule table are
handled by this dependency class, otherwise this dependency is
considered as passed. This d... |
Send email using backend specified in EMAIL_BACKEND. | def send_email(to, subject, html_content,
files=None, dryrun=False, cc=None, bcc=None,
mime_subtype='mixed', mime_charset='utf-8', **kwargs):
"""
Send email using backend specified in EMAIL_BACKEND.
"""
path, attr = configuration.conf.get('email', 'EMAIL_BACKEND').rsplit('.... |
Send an email with html content | def send_email_smtp(to, subject, html_content, files=None,
dryrun=False, cc=None, bcc=None,
mime_subtype='mixed', mime_charset='utf-8',
**kwargs):
"""
Send an email with html content
>>> send_email('test@example.com', 'foo', '<b>Foo</b> bar', ['/d... |
Processes DateTimes from the DB making sure it is always returning UTC. Not using timezone. convert_to_utc as that converts to configured TIMEZONE while the DB might be running with some other setting. We assume UTC datetimes in the database. | def process_result_value(self, value, dialect):
"""
Processes DateTimes from the DB making sure it is always
returning UTC. Not using timezone.convert_to_utc as that
converts to configured TIMEZONE while the DB might be
running with some other setting. We assume UTC datetimes
... |
Check if a blob exists on Azure Blob Storage. | def check_for_blob(self, container_name, blob_name, **kwargs):
"""
Check if a blob exists on Azure Blob Storage.
:param container_name: Name of the container.
:type container_name: str
:param blob_name: Name of the blob.
:type blob_name: str
:param kwargs: Option... |
Check if a prefix exists on Azure Blob storage. | def check_for_prefix(self, container_name, prefix, **kwargs):
"""
Check if a prefix exists on Azure Blob storage.
:param container_name: Name of the container.
:type container_name: str
:param prefix: Prefix of the blob.
:type prefix: str
:param kwargs: Optional ... |
Upload a file to Azure Blob Storage. | def load_file(self, file_path, container_name, blob_name, **kwargs):
"""
Upload a file to Azure Blob Storage.
:param file_path: Path to the file to load.
:type file_path: str
:param container_name: Name of the container.
:type container_name: str
:param blob_name... |
Upload a string to Azure Blob Storage. | def load_string(self, string_data, container_name, blob_name, **kwargs):
"""
Upload a string to Azure Blob Storage.
:param string_data: String to load.
:type string_data: str
:param container_name: Name of the container.
:type container_name: str
:param blob_name... |
Download a file from Azure Blob Storage. | def get_file(self, file_path, container_name, blob_name, **kwargs):
"""
Download a file from Azure Blob Storage.
:param file_path: Path to the file to download.
:type file_path: str
:param container_name: Name of the container.
:type container_name: str
:param bl... |
Read a file from Azure Blob Storage and return as a string. | def read_file(self, container_name, blob_name, **kwargs):
"""
Read a file from Azure Blob Storage and return as a string.
:param container_name: Name of the container.
:type container_name: str
:param blob_name: Name of the blob.
:type blob_name: str
:param kwarg... |
Delete a file from Azure Blob Storage. | def delete_file(self, container_name, blob_name, is_prefix=False,
ignore_if_missing=False, **kwargs):
"""
Delete a file from Azure Blob Storage.
:param container_name: Name of the container.
:type container_name: str
:param blob_name: Name of the blob.
... |
BACKPORT FROM PYTHON3 FTPLIB. | def mlsd(conn, path="", facts=None):
"""
BACKPORT FROM PYTHON3 FTPLIB.
List a directory in a standardized format by using MLSD
command (RFC-3659). If path is omitted the current directory
is assumed. "facts" is a list of strings representing the type
of information desired (e.g. ["type", "size"... |
Returns a FTP connection object | def get_conn(self):
"""
Returns a FTP connection object
"""
if self.conn is None:
params = self.get_connection(self.ftp_conn_id)
pasv = params.extra_dejson.get("passive", True)
self.conn = ftplib.FTP(params.host, params.login, params.password)
... |
Returns a dictionary of { filename: { attributes }} for all files on the remote system ( where the MLSD command is supported ). | def describe_directory(self, path):
"""
Returns a dictionary of {filename: {attributes}} for all files
on the remote system (where the MLSD command is supported).
:param path: full path to the remote directory
:type path: str
"""
conn = self.get_conn()
co... |
Returns a list of files on the remote system. | def list_directory(self, path, nlst=False):
"""
Returns a list of files on the remote system.
:param path: full path to the remote directory to list
:type path: str
"""
conn = self.get_conn()
conn.cwd(path)
files = conn.nlst()
return files |
Transfers the remote file to a local location. | def retrieve_file(
self,
remote_full_path,
local_full_path_or_buffer,
callback=None):
"""
Transfers the remote file to a local location.
If local_full_path_or_buffer is a string path, the file will be put
at that location; if it is a file-... |
Transfers a local file to the remote location. | def store_file(self, remote_full_path, local_full_path_or_buffer):
"""
Transfers a local file to the remote location.
If local_full_path_or_buffer is a string path, the file will be read
from that location; if it is a file-like buffer, the file will
be read from the buffer but n... |
Rename a file. | def rename(self, from_name, to_name):
"""
Rename a file.
:param from_name: rename file from name
:param to_name: rename file to name
"""
conn = self.get_conn()
return conn.rename(from_name, to_name) |
Returns a datetime object representing the last time the file was modified | def get_mod_time(self, path):
"""
Returns a datetime object representing the last time the file was modified
:param path: remote file path
:type path: string
"""
conn = self.get_conn()
ftp_mdtm = conn.sendcmd('MDTM ' + path)
time_val = ftp_mdtm[4:]
... |
Infers from the dates which dag runs need to be created and does so.: param dag: the dag to create dag runs for: param execution_dates: list of execution dates to evaluate: param state: the state to set the dag run to: param run_id_template: the template for run id to be with the execution date: return: newly created a... | def _create_dagruns(dag, execution_dates, state, run_id_template):
"""
Infers from the dates which dag runs need to be created and does so.
:param dag: the dag to create dag runs for
:param execution_dates: list of execution dates to evaluate
:param state: the state to set the dag run to
:param ... |
Set the state of a task instance and if needed its relatives. Can set state for future tasks ( calculated from execution_date ) and retroactively for past tasks. Will verify integrity of past dag runs in order to create tasks that did not exist. It will not create dag runs that are missing on the schedule ( but it will... | def set_state(task, execution_date, upstream=False, downstream=False,
future=False, past=False, state=State.SUCCESS, commit=False, session=None):
"""
Set the state of a task instance and if needed its relatives. Can set state
for future tasks (calculated from execution_date) and retroactively
... |
Helper method that set dag run state in the DB.: param dag_id: dag_id of target dag run: param execution_date: the execution date from which to start looking: param state: target state: param session: database session | def _set_dag_run_state(dag_id, execution_date, state, session=None):
"""
Helper method that set dag run state in the DB.
:param dag_id: dag_id of target dag run
:param execution_date: the execution date from which to start looking
:param state: target state
:param session: database session
"... |
Set the dag run for a specific execution date and its task instances to success.: param dag: the DAG of which to alter state: param execution_date: the execution date from which to start looking: param commit: commit DAG and tasks to be altered to the database: param session: database session: return: If commit is true... | def set_dag_run_state_to_success(dag, execution_date, commit=False, session=None):
"""
Set the dag run for a specific execution date and its task instances
to success.
:param dag: the DAG of which to alter state
:param execution_date: the execution date from which to start looking
:param commit:... |
Set the dag run for a specific execution date and its running task instances to failed.: param dag: the DAG of which to alter state: param execution_date: the execution date from which to start looking: param commit: commit DAG and tasks to be altered to the database: param session: database session: return: If commit ... | def set_dag_run_state_to_failed(dag, execution_date, commit=False, session=None):
"""
Set the dag run for a specific execution date and its running task instances
to failed.
:param dag: the DAG of which to alter state
:param execution_date: the execution date from which to start looking
:param c... |
Set the dag run for a specific execution date to running.: param dag: the DAG of which to alter state: param execution_date: the execution date from which to start looking: param commit: commit DAG and tasks to be altered to the database: param session: database session: return: If commit is true list of tasks that hav... | def set_dag_run_state_to_running(dag, execution_date, commit=False, session=None):
"""
Set the dag run for a specific execution date to running.
:param dag: the DAG of which to alter state
:param execution_date: the execution date from which to start looking
:param commit: commit DAG and tasks to be... |
Return a version to identify the state of the underlying git repo. The version will indicate whether the head of the current git - backed working directory is tied to a release tag or not: it will indicate the former with a release: { version } prefix and the latter with a dev0 prefix. Following the prefix will be a sh... | def git_version(version):
"""
Return a version to identify the state of the underlying git repo. The version will
indicate whether the head of the current git-backed working directory is tied to a
release tag or not : it will indicate the former with a 'release:{version}' prefix
and the latter with ... |
Call the DiscordWebhookHook to post message | def execute(self, context):
"""
Call the DiscordWebhookHook to post message
"""
self.hook = DiscordWebhookHook(
self.http_conn_id,
self.webhook_endpoint,
self.message,
self.username,
self.avatar_url,
self.tts,
... |
Validates if field is OK. | def _validate_field(self, validation_spec, dictionary_to_validate, parent=None,
force_optional=False):
"""
Validates if field is OK.
:param validation_spec: specification of the field
:type validation_spec: dict
:param dictionary_to_validate: dictionary w... |
Validates if the body ( dictionary ) follows specification that the validator was instantiated with. Raises ValidationSpecificationException or ValidationFieldException in case of problems with specification or the body not conforming to the specification respectively. | def validate(self, body_to_validate):
"""
Validates if the body (dictionary) follows specification that the validator was
instantiated with. Raises ValidationSpecificationException or
ValidationFieldException in case of problems with specification or the
body not conforming to th... |
Return the FileService object. | def get_conn(self):
"""Return the FileService object."""
conn = self.get_connection(self.conn_id)
service_options = conn.extra_dejson
return FileService(account_name=conn.login,
account_key=conn.password, **service_options) |
Check if a directory exists on Azure File Share. | def check_for_directory(self, share_name, directory_name, **kwargs):
"""
Check if a directory exists on Azure File Share.
:param share_name: Name of the share.
:type share_name: str
:param directory_name: Name of the directory.
:type directory_name: str
:param kw... |
Check if a file exists on Azure File Share. | def check_for_file(self, share_name, directory_name, file_name, **kwargs):
"""
Check if a file exists on Azure File Share.
:param share_name: Name of the share.
:type share_name: str
:param directory_name: Name of the directory.
:type directory_name: str
:param f... |
Return the list of directories and files stored on a Azure File Share. | def list_directories_and_files(self, share_name, directory_name=None, **kwargs):
"""
Return the list of directories and files stored on a Azure File Share.
:param share_name: Name of the share.
:type share_name: str
:param directory_name: Name of the directory.
:type dir... |
Create a new directory on a Azure File Share. | def create_directory(self, share_name, directory_name, **kwargs):
"""
Create a new directory on a Azure File Share.
:param share_name: Name of the share.
:type share_name: str
:param directory_name: Name of the directory.
:type directory_name: str
:param kwargs: ... |
Download a file from Azure File Share. | def get_file(self, file_path, share_name, directory_name, file_name, **kwargs):
"""
Download a file from Azure File Share.
:param file_path: Where to store the file.
:type file_path: str
:param share_name: Name of the share.
:type share_name: str
:param directory... |
Download a file from Azure File Share. | def get_file_to_stream(self, stream, share_name, directory_name, file_name, **kwargs):
"""
Download a file from Azure File Share.
:param stream: A filehandle to store the file to.
:type stream: file-like object
:param share_name: Name of the share.
:type share_name: str
... |
Upload a file to Azure File Share. | def load_file(self, file_path, share_name, directory_name, file_name, **kwargs):
"""
Upload a file to Azure File Share.
:param file_path: Path to the file to load.
:type file_path: str
:param share_name: Name of the share.
:type share_name: str
:param directory_n... |
Upload a string to Azure File Share. | def load_string(self, string_data, share_name, directory_name, file_name, **kwargs):
"""
Upload a string to Azure File Share.
:param string_data: String to load.
:type string_data: str
:param share_name: Name of the share.
:type share_name: str
:param directory_n... |
Upload a stream to Azure File Share. | def load_stream(self, stream, share_name, directory_name, file_name, count, **kwargs):
"""
Upload a stream to Azure File Share.
:param stream: Opened file/stream to upload as the file content.
:type stream: file-like
:param share_name: Name of the share.
:type share_name... |
Provide filename context to airflow task handler.: param filename: filename in which the dag is located | def set_context(self, filename):
"""
Provide filename context to airflow task handler.
:param filename: filename in which the dag is located
"""
local_loc = self._init_file(filename)
self.handler = logging.FileHandler(local_loc)
self.handler.setFormatter(self.form... |
Create log file and directory if required.: param filename: task instance object: return: relative log path of the given task instance | def _init_file(self, filename):
"""
Create log file and directory if required.
:param filename: task instance object
:return: relative log path of the given task instance
"""
relative_path = self._render_filename(filename)
full_path = os.path.join(self._get_log_di... |
Given a Google Cloud Storage URL ( gs:// <bucket >/ <blob > ) returns a tuple containing the corresponding bucket and blob. | def _parse_gcs_url(gsurl):
"""
Given a Google Cloud Storage URL (gs://<bucket>/<blob>), returns a
tuple containing the corresponding bucket and blob.
"""
parsed_url = urlparse(gsurl)
if not parsed_url.netloc:
raise AirflowException('Please provide a bucket name')
else:
bucke... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.