diff --git a/Python-Paramiko/nested-paramiko.py b/Python-Paramiko/nested-paramiko.py new file mode 100644 index 0000000..0bc71f8 --- /dev/null +++ b/Python-Paramiko/nested-paramiko.py @@ -0,0 +1,29 @@ +import paramiko +import sys +import subprocess +# +# we instantiate a new object referencing paramiko's SSHClient class +# +jumphost = "192.168.1.10" +server = "192.168.1.11" + +vm = paramiko.SSHClient() +vm.set_missing_host_key_policy(paramiko.AutoAddPolicy()) +vm.connect(jumphost, username='root', password='a') + +# +vmtransport = vm.get_transport() +server_addr = (server, 22) #edited# +jump_host = (jumphost, 22) #edited# + +jhost = paramiko.SSHClient() +jhost.set_missing_host_key_policy(paramiko.AutoAddPolicy()) +#jhost.load_host_keys('/home/osmanl/.ssh/known_hosts') #disabled# +jhost.connect(server, username='root', password='a', sock=vmchannel) + +stdin, stdout, stderr = jhost.exec_command("cat /home/server") +# +print stdout.read() #edited# +# +jhost.close() +vm.close() diff --git a/Python-Paramiko/subprocess-example.py b/Python-Paramiko/subprocess-example.py new file mode 100644 index 0000000..e4fcbb5 --- /dev/null +++ b/Python-Paramiko/subprocess-example.py @@ -0,0 +1,12 @@ +import subprocess + +logile="subprocess.log" +def subprocess_cmd(command): + print (command) + process = subprocess.Popen(command,stdout=subprocess.PIPE, shell=True) + proc_stdout = process.communicate()[0].strip() + with open(logile,'w') as f: + f.writelines(proc_stdout.split(' ')) + return logile + +subprocess_cmd("uname") diff --git a/Python-with-class/Class_with_attribute.py b/Python-with-class/Class_with_attribute.py new file mode 100644 index 0000000..fa961bf --- /dev/null +++ b/Python-with-class/Class_with_attribute.py @@ -0,0 +1,23 @@ + +################################################# +# Python Class with Attribute Example +################################################# + +class class_with_Attribute: +#class attribute Declaration + type="Normal" + +t1 = class_with_Attribute() +t2 = class_with_Attribute() + +#Getting Output of Class Attribute +print (t1.type,t2.type) +#Output would be +# Normal Normal + +#updating class Attribute value +testing.type="Advance" + +print (t1.type,t2.type) +#Output would be +# Advance Advance diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..034e848 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,21 @@ +# Security Policy + +## Supported Versions + +Use this section to tell people about which versions of your project are +currently being supported with security updates. + +| Version | Supported | +| ------- | ------------------ | +| 5.1.x | :white_check_mark: | +| 5.0.x | :x: | +| 4.0.x | :white_check_mark: | +| < 4.0 | :x: | + +## Reporting a Vulnerability + +Use this section to tell people how to report a vulnerability. + +Tell them where to go, how often they can expect to get an update on a +reported vulnerability, what to expect if the vulnerability is accepted or +declined, etc. diff --git a/fibonacci.py b/fibonacci.py new file mode 100644 index 0000000..c8224a2 --- /dev/null +++ b/fibonacci.py @@ -0,0 +1,11 @@ +a, b = 0, 1 +count = 0 +input_count=10 + +print("Fibonacci sequence:") +while count < input_count: + print(a) + new = a + b + a = b + b = new + count += 1 diff --git a/lambda/example1.py b/lambda/example1.py new file mode 100644 index 0000000..7c51499 --- /dev/null +++ b/lambda/example1.py @@ -0,0 +1,25 @@ +## FIND THE SQUARE OF A NUMBER USING LEMBDA FUNCTION + +square= lambda num: num**2 +print(square(8)) + +## REVERSE A STRING USING LAMBDA FUNCTION + +str = 'hello guys' +# lambda returns a function object +rev_upper = lambda string: string.upper()[::-1] +print(rev_upper(str)) + +## MAP OUT THE EVEN NUMBER FROM THE LIST USING LEMBDA FUNCTION + +mynums=[1,2,3,4,5] +print(list(map(lambda num: num%2==0,mynums))) + +## FILTER OUT THE EVEN NUMBER FROM THE LIST USING LEMBDA FUNCTION +mynums=[1,2,3,4,5] +print(list(filter(lambda num: num%2==0,mynums))) + +# FIND MAXIMUM NUMBER BETWEEN TWO NUMBERS USING LEMBDA FUNCTION +Max = lambda a, b : a if(a > b) else b +print(Max(8, 4)) + diff --git a/lambda/example2.py b/lambda/example2.py new file mode 100644 index 0000000..1f98602 --- /dev/null +++ b/lambda/example2.py @@ -0,0 +1,25 @@ +# Add 10 to argument a, and return the result: +x = lambda a : a + 10 +print(x(5)) + +# square of number +squ = lambda num: num**2 +print(squ(5)) + +# Summarize argument a, b, and c and return the result: +x = lambda a, b, c : a + b + c +print(x(5, 6, 2)) + + +# reverse a string with the help of list, map, lamda +fun=["pthon","is","fun"] +ans=(list(map(lambda x:x[::-1],fun))) +print(ans) + +# first latter of word of list +name=["python","with","s3cloudehub"] +(print(list(map(lambda n:n[0],name)))) + +# print even number +mynum=[1,2,3,4,5,6] +print(list(filter(lambda num:num%2==0,mynum))) diff --git a/lambda/example_lambda_filter.py b/lambda/example_lambda_filter.py new file mode 100644 index 0000000..8c6c459 --- /dev/null +++ b/lambda/example_lambda_filter.py @@ -0,0 +1,28 @@ +## RETURN THE NUMBER IF IT IS EVEN + +# CHECK_EVEN FUNCTION DEFINE +def check_even(num): + +# RETURN THE NUMBER IF THE CONDITION IS TRUE + return num%2==0 + +# GIVING INPUTS TO THE NUMS +nums = [1,2,3,4,5,6] + +# HERE WE PRINT WITH THE FILTER AND IN LIST FORMAT +print(list(filter(check_even,nums))) + +# PRINT USING FOR LOOP +for i in filter(check_even,nums): + print(i) + +## SIMPLE OUTPUT +# HOW TO RUN +# PYTHON: example_lambda_filter.py +# [2, 4, 6] + +## OUTPUT AFTER USING THE FOR LOOP +# PYTHON: example_lambda_filter.py +# 2 +# 4 +# 6 \ No newline at end of file diff --git a/lambda/example_lambda_map.py b/lambda/example_lambda_map.py new file mode 100644 index 0000000..4ad2766 --- /dev/null +++ b/lambda/example_lambda_map.py @@ -0,0 +1,19 @@ +## RETURN THE 'EVEN' IF STRING IS EVEN OTHERWISE RETURN FIRST LETTER OF A STRING + +# SLICER FUNCTION DEFINE +def slicer(mystring): +# FIND THE LENGTH OF MYSTRING VARIABLE + if len(mystring)%2 == 0: +# IF THE LENGTH OF MYSTRING IS EVEN IT RETURNS EVEN + return 'even' + else: +# OTHERWISE RETURNS THE FIRST LETTER OF THE STRING + return mystring[0] +names = ['adam','eve','sla','rock','rio'] +# HERE WE PRINT WITH THE MAP AND IN LIST FORMAT +print(list(map(slicer,names))) + +## HOW TO RUN + +# python: example_lambda_map.py +# ['even', 'e', 's', 'even', 'r'] diff --git a/nested_stetment_and_scop/example.py b/nested_stetment_and_scop/example.py new file mode 100644 index 0000000..87fe844 --- /dev/null +++ b/nested_stetment_and_scop/example.py @@ -0,0 +1,56 @@ +x=25 #globel +def p(): + x=50 # local + print(x) + +print(x) + +p() + + +x = 100 #global + +def p(): + global x + x=50 # local + return x + + +print(x) + +p() + +x=50 +def fun(): + global x + print(f"x is {x}") + + #Local Reassigment! + x=200 + print(f"just localy change x to {x}") + +fun() + +x=50 +def fun(): + print(f"x is {x}") + + #Local Reassigment! + x=200 + print(f"just localy change x to {x}") + +fun() + +name = "this is " + +def new(): + #ENclossing + name="summy" + print(name) + + def new1(): + name="gimmy" + print(name) + + + diff --git a/nested_stetment_and_scop/local_example.py b/nested_stetment_and_scop/local_example.py new file mode 100644 index 0000000..a4d408e --- /dev/null +++ b/nested_stetment_and_scop/local_example.py @@ -0,0 +1,17 @@ +# Local Reassigment! +x=200 +print(f"just localy change x to {x}") + +# How To Run +# local_ocal_example.py" +# output just localy change x to 200 + +def myfunc(): + x = 300 #local veriabal + print(x) + +myfunc() + +# How To Run +# local_ocal_example.py" +# output 300 \ No newline at end of file diff --git a/pylint/demo.py b/pylint/demo.py new file mode 100644 index 0000000..5b8c703 --- /dev/null +++ b/pylint/demo.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python +import string + +shift = 3 +choice = "encode" +word = "Hello" +letters = string.ascii_letters + string.punctuation + string.digits +encoded = '' +if choice == "encode": + for letter in word: + if letter == ' ': + encoded = encoded + ' ' + else: + x = letters.index(letter) + shift + encoded=encoded + letters[x] +print encoded diff --git a/python_input/python_input.py b/python_input/python_input.py new file mode 100644 index 0000000..7141ed0 --- /dev/null +++ b/python_input/python_input.py @@ -0,0 +1,70 @@ +user = input("enter a any key : >>>") #input from user + +if (type(user)) == int: # chack type + print("it is a number") +else: + print("it is not a number") + +# ///////output///////// + # enter a any key : >>>q + # it is not a number + + +user = input("enter a number:>>>>") #input from user +try: + val = int(user) # pass if number +except ValueError: + print("that is not a number") # if not message print + +# ///////output///////// +# enter a number:>>>>q +# that is not a input + + +user = input("enter a number:>>") #input from user +if user.isdigit(): + print("it is a digit") +else: + print("it is not a digit:") + +# ///////output///////// +# enter a number:>>1 +# it is a digit + +# enter a number:>>a +# it is not a digit: + + +def user(): + choice ="worng" + while choice.isdigit() == False: + choice = input("plese enter a number:") + return int(choice) +user() + +# output 1 +# plese enter a number:12 + +# output 2 +# enter a number:>>q +# it is not a digit: + + +def user(): + choice = "worng" + acceptable_rang = range(0,10) + with_rang = False + + while choice.isdigit() == False or with_rang==False: + choice = input("enter a number (0,10):") + + if choice.isdigit() == False: + print("sorry this is not a digit") + + if choice.isdigit() == True: + if int(choice) in acceptable_rang: + with_rang = True + else: + with_rang = False + + return int(choice) \ No newline at end of file diff --git a/sample.py b/sample.py new file mode 100644 index 0000000..95e592c --- /dev/null +++ b/sample.py @@ -0,0 +1,9 @@ +################ +# Sample Python program +################### + +print ("THIS IS SAMPLE PYTHON PROGRAM") + +print ("\n") + +print ("THIS IS JENKINS Integration") diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000..b4ec736 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,15 @@ +sonar.projectKey=project:sonarqube-sample +sonar.projectName=sonarqube-sample1 +sonar.projectVersion=1.0 +sonar.sources= +sonar.language=py +sonar.sourceEncoding=UTF-8 +# Test Results +sonar.python.xunit.reportPath=nosetests.xml +# Coverage +sonar.python.coverage.reportPath=coverage.xml +# Linter (https://docs.sonarqube.org/display/PLUG/Pylint+Report) +#sonar.python.pylint=/usr/local/bin/pylint +#sonar.python.pylint_config=.pylintrc +#sonar.python.pylint.reportPath=pylint-report.txt +sonar.host.url=http://10.29.41.148:9000