Skip to content

Commit

Permalink
Merge branch 'master' into rekognition-image-python-examples
Browse files Browse the repository at this point in the history
  • Loading branch information
AWSChris authored Jan 15, 2019
2 parents cd2aed9 + ef7481a commit 044dfb6
Show file tree
Hide file tree
Showing 341 changed files with 22,847 additions and 701 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
language: python
python:
- "3.6"
script: python check_metadata.py
script: python check_metadata.py -q
184 changes: 104 additions & 80 deletions check_metadata.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,60 @@
import os, fnmatch, sys

def checkFile(directory, filePattern):
filecount = 0;
for path, dirs, files in os.walk(os.path.abspath(directory)):
for filename in fnmatch.filter(files, filePattern):
filecount += 1
filepath = os.path.join(path, filename)
print("\nChecking File: " + filename + " in " + filepath)
with open(filepath) as f:
s = f.read()
words = s.split()
snippetStartCheck(words)
snippets = s.split('snippet-')
snippetAuthorCheck(snippets)
snippetServiceCheck(snippets)
snippetDescriptionCheck(snippets)
snippetTypeCheck(snippets)
snippetDateCheck(snippets)
snippetKeywordCheck(snippets)
print(str(filecount) + " files scanned in " + directory)
print("")

def checkFileStrings(directory, filePattern):
def checkFile(directory, filePattern, warn, quiet):
filecount = 0;
for path, dirs, files in os.walk(os.path.abspath(directory)):
for filename in fnmatch.filter(files, filePattern):
# Ignore this file
if filename == sys.argv[0]:
continue
wordcount = 0;
filecount += 1
errors = []
filepath = os.path.join(path, filename)
if quiet == False:
print("\nChecking File: " + filepath)
with open(filepath) as f:
s = f.read()
words = s.split()
snippetStartCheck(words)
for word in words:
checkStringLength(word, filename)
checkStringLength(word, warn)
wordcount +=1;
f.close();
print("File: " + filename + " has been scanned. " + str(wordcount) + " words found.")
print("")

# Check for mismatched Snippet start and end.
snippets = s.split('snippet-')

# Check Metadata for optional metadata
errors.append(snippetStartCheck(words, filepath))
errors.append(snippetAuthorCheck(snippets, warn))
errors.append(snippetServiceCheck(snippets, warn))
errors.append(snippetDescriptionCheck(snippets, warn))
errors.append(snippetTypeCheck(snippets, warn))
errors.append(snippetDateCheck(snippets, warn))
errors.append(snippetKeywordCheck(snippets, warn))
f.close()
if quiet == False:
print(str(wordcount) + " words found.")
if warn == True:
# Filter to only warning messages
errors = list(filter(None, errors))
# print out file name, if warnings found
if len(errors) > 0 and quiet == True:
print("\nChecking File: " + filepath)
for error in errors:
if error:
print(error)
print(str(filecount) + " files scanned in " + directory)
print("")
def checkStringLength (word, filename):


def checkStringLength (word, warn):
length = len(word)
if length == 40 or length == 20:
sys.exit ("WARNING -- String found in " + filename + " \n" + word + " is " + str(length) + " characters long")
if warn == True:
return "WARNING -- " + word + " is " + str(length) + " characters long"


def snippetStartCheck(words):
def snippetStartCheck(words, filelocation):
#print (words)
snippetStart = 'snippet-start:['
snippetEnd = 'snippet-end:['
Expand All @@ -68,33 +74,36 @@ def snippetStartCheck(words):
for end in snippettags:
if string.endswith(end):
match = True
#print("True: "+ string + " has matching end tag." )
#return "True: "+ string + " has matching end tag." )
if match == False:
print("ERROR -- Found in " + filelocation)
sys.exit("ERROR -- " + string + "'s matching end tag not found.")
else:
#print("WARNING -- Snippet Start not detected")
else:
#return "WARNING -- Snippet Start not detected"
return False

def snippetAuthorCheck(words):
def snippetAuthorCheck(words, warn):
author = 'sourceauthor:['
matching = [s for s in words if author in s]
if matching == []:
print("WARNING -- Missing snippet-sourceauthor:[Your Name]")
if warn == True:
return "WARNING -- Missing snippet-sourceauthor:[Your Name]"

def snippetServiceCheck(words):
def snippetServiceCheck(words, warn):
service = 'service:['
matching = [s for s in words if service in s]
if matching == []:
print("WARNING -- Missing snippet-service:[AWS service name]")
print("Find a list of AWS service names under AWS Service Namespaces in the General Reference Guide: https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html")
if warn == True:
return "WARNING -- Missing snippet-service:[AWS service name] \nFind a list of AWS service names under AWS Service Namespaces in the General Reference Guide: https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html"

def snippetDescriptionCheck(words):
def snippetDescriptionCheck(words, warn):
desc = 'sourcedescription:['
matching = [s for s in words if desc in s]
if matching == []:
print("WARNING -- Missing snippet-sourcedescription:[Filename demonstrates how to ... ]")
if warn == True:
return "WARNING -- Missing snippet-sourcedescription:[Filename demonstrates how to ... ]"

def snippetTypeCheck(words):
def snippetTypeCheck(words, warn):
author = 'sourcetype:['
matching = [s for s in words if author in s]
containsType = False
Expand All @@ -108,27 +117,30 @@ def snippetTypeCheck(words):
containsType = True
break
if not containsType:
print("WARNING -- Missing snippet-sourcetype:[full-example] or snippet-sourcetype:[snippet]")
if warn == True:
return "WARNING -- Missing snippet-sourcetype:[full-example] or snippet-sourcetype:[snippet]"


def snippetDateCheck(words):
def snippetDateCheck(words, warn):
datetag = 'sourcedate:['
matching = [s for s in words if datetag in s]
if matching == []:
print("WARNING -- Missing snippet-sourcedate:[YYYY-MM-DD]")
if warn == True:
return "WARNING -- Missing snippet-sourcedate:[YYYY-MM-DD]"

def snippetKeywordCheck(words):
def snippetKeywordCheck(words, warn):
snippetkeyword = 'keyword:['
matching = [s for s in words if snippetkeyword in s]
# print(matching)
codeSample = [s for s in words if 'keyword:[Code Sample]\n' in s]
if not codeSample:
print("WARNING -- Missing snippet-keyword:[Code Sample]")
keywordServiceName(matching)
keywordLanguageCheck(matching)
keywordSDKCheck(matching)
if warn == True:
return "WARNING -- Missing snippet-keyword:[Code Sample]"
keywordServiceName(matching, warn)
keywordLanguageCheck(matching, warn)
keywordSDKCheck(matching, warn)

def keywordServiceName(words):
def keywordServiceName(words, warn):
containsServiceTag = False;
AWS = 'keyword:[AWS'
matching = [s for s in words if AWS in s]
Expand All @@ -139,9 +151,10 @@ def keywordServiceName(words):
if matching:
containsServiceTag = True;
if not containsServiceTag:
print("WARNING -- Missing snippet-keyword:[FULL SERVICE NAME]")
if warn == True:
return "WARNING -- Missing snippet-keyword:[FULL SERVICE NAME]"

def keywordLanguageCheck(words):
def keywordLanguageCheck(words, warn):
languages = ['C++', 'C', '.NET', 'Go', 'Java', 'JavaScript', 'PHP', 'Python', 'Ruby','TypeScript' ]
containsLanguageTag = False;
for language in languages:
Expand All @@ -150,11 +163,11 @@ def keywordLanguageCheck(words):
containsLanguageTag = True;
break
if containsLanguageTag == False:
print("WARNING -- Missing snippet-keyword:[Language]")
print("Options include:")
print(languages)
if warn == True:
return "WARNING -- Missing snippet-keyword:[Language] \nOptions include:" + ', '.join(languages)

def keywordSDKCheck(words):
def keywordSDKCheck(words, warn):
sdkVersions = ['AWS SDK for PHP v3', 'AWS SDK for Python (Boto3)', 'CDK V0.14.1' ]
containsSDKTag = False;
for sdk in sdkVersions:
Expand All @@ -163,29 +176,40 @@ def keywordSDKCheck(words):
containsSDKTag = True;
break
if containsSDKTag == False:
print("WARNING -- Missing snippet-keyword:[SDK Version used]")
print("Options include:")
print(sdkVersions)
if warn == True:
return "WARNING -- Missing snippet-keyword:[SDK Version used] \nOptions include:" + ', '.join(sdkVersions)

# We allow two args:
# -w to suppress warnings
# -q to suppress name of file we are parsing (quiet mode)
warn = True;
quiet = False;

print ('----------\n\nRun Tests\n')
print ('----------\n\nAWS SDK for C++\n')
checkFile( './', '*.cpp')
print ('----------\n\nAWS SDK for .NET\n')
checkFile( './', '*.cs')
print ('----------\n\nAWS SDK for Go\n')
checkFile( './', '*.go')
print ('----------\n\nAWS SDK for Java\n')
checkFile( './', '*.java')
print ('----------\n\nAWS SDK for JavaScript\n')
checkFile( './', '*.js')
print ('----------\n\nAWS SDK for PHP\n')
checkFile( './', '*.php')
print ('----------\n\nAWS SDK for Python\n')
checkFile( './', '*.py')
print ('----------\n\nAWS SDK for Ruby\n')
checkFile( './', '*.rb')
print ('----------\n\nAWS SDK for TypeScript\n')
checkFile( './', '*.ts')
i = 0;

while i < len(sys.argv):
if sys.argv[i] == "-w":
warn = False
elif sys.argv[i] == "-q":
quiet = True
i += 1

print ('----------\n\nRun Tests\n')
print ('----------\n\nC++ Code Examples(*.cpp)\n')
checkFile( './', '*.cpp', warn, quiet)
print ('----------\n\nC# Code Examples (*.cs)\n')
checkFile( './', '*.cs', warn, quiet)
print ('----------\n\nGo Code Examples (*.go)\n')
checkFile( './', '*.go', warn, quiet)
print ('----------\n\nJava Code Examples (*.java)\n')
checkFile( './', '*.java', warn, quiet)
print ('----------\n\nJavaScript Code Examples (*.js)\n')
checkFile( './', '*.js', warn, quiet)
print ('----------\n\nPHP Code Examples (*.php)\n')
checkFile( './', '*.php', warn, quiet)
print ('----------\n\nPython Code Examples (*.py)\n')
checkFile( './', '*.py', warn, quiet)
print ('----------\n\nRuby Code Examples (*.rb)\n')
checkFile( './', '*.rb', warn, quiet)
print ('----------\n\nTypeScript Code Examples (*.ts)\n')
checkFile( './', '*.ts', warn, quiet)
2 changes: 1 addition & 1 deletion cpp/example_code/cloudtrail/create_trail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//snippet-keyword:[C++]
//snippet-keyword:[Code Sample]
//snippet-keyword:[AWS CloudTrail]
//snippet-service[cloudtrail]
//snippet-service:[cloudtrail]
//snippet-sourcetype:[full-example]
//snippet-sourcedate:[]
//snippet-sourceauthor:[tapasweni-pathak]
Expand Down
4 changes: 2 additions & 2 deletions cpp/example_code/cloudwatch/delete_subscription_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ int main(int argc, char** argv)

auto outcome = cwl.DeleteSubscriptionFilter(request);
if (!outcome.IsSuccess()) {
std::cout << "Failed to delete cloudwatch log subscription filter "
std::cout << "Failed to delete CloudWatch log subscription filter "
<< filter_name << ": " << outcome.GetError().GetMessage() <<
std::endl;
} else {
std::cout << "Successfully deleted cloudwatch logs subscription " <<
std::cout << "Successfully deleted CloudWatch logs subscription " <<
"filter " << filter_name << std::endl;
}
}
Expand Down
3 changes: 1 addition & 2 deletions cpp/example_code/cloudwatch/describe_alarms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <aws/monitoring/model/DescribeAlarmsResult.h>
#include <iomanip>
#include <iostream>
#include <iomanip>
//snippet-end:[cw.cpp.describe_alarms.inc]

static const char* SIMPLE_DATE_FORMAT_STR = "%Y-%m-%d";
Expand All @@ -54,7 +53,7 @@ int main(int argc, char** argv)
auto outcome = cw.DescribeAlarms(request);
if (!outcome.IsSuccess())
{
std::cout << "Failed to describe cloudwatch alarms:" <<
std::cout << "Failed to describe CloudWatch alarms:" <<
outcome.GetError().GetMessage() << std::endl;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ int main(int argc, char** argv)
auto outcome = cwl.DescribeSubscriptionFilters(
request);
if (!outcome.IsSuccess()) {
std::cout << "Failed to describe cloudwatch subscription filters "
std::cout << "Failed to describe CloudWatch subscription filters "
<< "for log group " << log_group << ": " <<
outcome.GetError().GetMessage() << std::endl;
break;
Expand Down
2 changes: 1 addition & 1 deletion cpp/example_code/cloudwatch/enable_alarm_actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void CreateAlarmAndEnableActions(
auto outcome = cw.PutMetricAlarm(request);
if (!outcome.IsSuccess())
{
std::cout << "Failed to create cloudwatch alarm:" <<
std::cout << "Failed to create CloudWatch alarm:" <<
outcome.GetError().GetMessage() << std::endl;
return;
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/example_code/cloudwatch/list_metrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ int main(int argc, char** argv)
auto outcome = cw.ListMetrics(request);
if (!outcome.IsSuccess())
{
std::cout << "Failed to list cloudwatch metrics:" <<
std::cout << "Failed to list CloudWatch metrics:" <<
outcome.GetError().GetMessage() << std::endl;
break;
}
Expand Down
4 changes: 2 additions & 2 deletions cpp/example_code/cloudwatch/put_events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ int main(int argc, char** argv)
auto outcome = cwe.PutEvents(request);
if (!outcome.IsSuccess())
{
std::cout << "Failed to post cloudwatch event: " <<
std::cout << "Failed to post CloudWatch event: " <<
outcome.GetError().GetMessage() << std::endl;
}
else
{
std::cout << "Successfully posted cloudwatch event" << std::endl;
std::cout << "Successfully posted CloudWatch event" << std::endl;
}
// snippet-end:[cw.cpp.put_events.code]
}
Expand Down
4 changes: 2 additions & 2 deletions cpp/example_code/cloudwatch/put_metric_alarm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ int main(int argc, char** argv)
auto outcome = cw.PutMetricAlarm(request);
if (!outcome.IsSuccess())
{
std::cout << "Failed to create cloudwatch alarm:" <<
std::cout << "Failed to create CloudWatch alarm:" <<
outcome.GetError().GetMessage() << std::endl;
}
else
{
std::cout << "Successfully created cloudwatch alarm " << alarm_name
std::cout << "Successfully created CloudWatch alarm " << alarm_name
<< std::endl;
}
// snippet-end:[cw.cpp.put_metric_alarm.code]
Expand Down
4 changes: 2 additions & 2 deletions cpp/example_code/cloudwatch/put_rule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ int main(int argc, char** argv)
auto outcome = cwe.PutRule(request);
if (!outcome.IsSuccess())
{
std::cout << "Failed to create cloudwatch events rule " <<
std::cout << "Failed to create CloudWatch events rule " <<
rule_name << ": " << outcome.GetError().GetMessage() <<
std::endl;
}
else
{
std::cout << "Successfully created cloudwatch events rule " <<
std::cout << "Successfully created CloudWatch events rule " <<
rule_name << " with resulting Arn " <<
outcome.GetResult().GetRuleArn() << std::endl;
}
Expand Down
Loading

0 comments on commit 044dfb6

Please sign in to comment.