Skip to content

Commit c7c90f5

Browse files
author
mas
committed
cleaning up the repos
1 parent 863d985 commit c7c90f5

42 files changed

Lines changed: 1298 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Server-py3.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#sample code to run a server using python 3
2+
#https://docs.python.org/3/library/http.server.html
3+
#python files are served from /cgi-bin
4+
#required heading for python files
5+
'''
6+
print('Content-type: text/html\n')
7+
print('<title>Hello World</title>')
8+
'''
9+
10+
11+
from http.server import CGIHTTPRequestHandler, HTTPServer
12+
13+
handler = CGIHTTPRequestHandler
14+
handler.cgi_directories = ['/cgi-bin', '/htbin'] # this is the default
15+
server = HTTPServer(('localhost', 8123), handler)
16+
server.serve_forever()
17+

background.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
### check for running process
2+
3+
# -*- coding: utf-8 -*-
4+
"""
5+
Created on Wed Nov 30 00:07:07 2016
6+
@author: mas
7+
"""
8+
9+
#!/usr/bin/env python3
10+
11+
import re
12+
import subprocess
13+
14+
check="./run.sh"
15+
16+
def is_running(process):
17+
18+
s = subprocess.Popen(["ps", "axw"],stdout=subprocess.PIPE)
19+
for x in s.stdout:
20+
if process in x:
21+
print("Processing is running")
22+
# print(x)
23+
#else:
24+
# print("no")
25+
print("check complete")
26+
is_running(b"run.sh")
27+
28+
##############
29+
30+
31+
32+
sample run command
33+
34+
#!/usr/bin/bash
35+
36+
mas=0
37+
run='/usr/bin/date'
38+
39+
rm -rf check
40+
while [ $mas -lt 10 ] ; do
41+
$run >> check
42+
sleep 5
43+
done
44+
45+
###
46+
python
47+
48+
### run a backgroup process and send the stout to a file. Use the file for a status update and delete
49+
### http://stackoverflow.com/questions/1996518/retrieving-the-output-of-subprocess-call
50+
51+
#!/usr/bin/env python3
52+
53+
import subprocess, os , sys
54+
55+
mas = "hmm"
56+
process = "run.sh"
57+
58+
#os.unlink("check")
59+
60+
## run background process
61+
62+
code= subprocess.call(["./run.sh & "],shell=True)
63+
64+
65+
## check if process is running
66+
#code= subprocess.call(["tail -f check "],shell=True)
67+
68+
print(mas)
69+
70+
71+
72+
##### list log files and output
73+
### To do run a process and grab the standout when running the apiscripter we will need the log number ###
74+
##then use this log number to locate the log files and output the contents ###
75+
76+
# -*- coding: utf-8 -*-
77+
"""
78+
Created on Wed Dec 7 04:36:15 2016
79+
80+
@author: mas
81+
"""
82+
83+
import os
84+
85+
86+
p = os.listdir('/var/log/')
87+
88+
89+
for i in p:
90+
if 'Xorg' in i:
91+
print(i)

class_function.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env python3
2+
3+
4+
##testing out a class
5+
6+
7+
8+
class Homeboy:
9+
10+
face = "Welcome to my world"
11+
12+
def __init__(self, name):
13+
self.name = name
14+
15+
16+
17+
def displaycon(self):
18+
math = 2 * 12
19+
print("Hello " + self.name + " your math calculation is 2*12={} ".format(math))

count-exercise.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
class Twit:
2+
def count3(self,check):
3+
self.check = check
4+
self.taz1 = self.check % 3
5+
self.taz2 = self.check % 5
6+
return self.taz1,self.taz2
7+
8+
def count5(self):
9+
if self.taz1 == 0:
10+
print(str(self.check) + "- foo")
11+
if self.taz2 == 0:
12+
print(str(self.check) + "- Bar")
13+
if self.taz1 == 0 and self.taz2 == 0:
14+
print(str(self.check) + "- Foobar")
15+
16+
## once the function is done. You will just need to run the below code and change the
17+
## variable value of top as needed
18+
top = 100
19+
f = Twit()
20+
21+
for num in range(top):
22+
f.count3(num)
23+
f.count5()
24+
25+
26+
27+
28+
29+
#==============
30+
#original code
31+
#max = 100
32+
33+
#for num in range(max):
34+
# if num % 3 == 0:
35+
# print "Foo"
36+
# if num % 5 == 0:
37+
# print "Bar"
38+
# if num % 3 == 0 and num % 5 == 0:
39+
# print "FooBar"

csa_tool/check

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Thu Dec 8 04:13:15 EST 2016
2+
Thu Dec 8 04:13:20 EST 2016
3+
Thu Dec 8 04:13:25 EST 2016
4+
Thu Dec 8 04:13:30 EST 2016
5+
Thu Dec 8 04:13:35 EST 2016

csa_tool/check_background.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env python3
2+
3+
import re
4+
import subprocess
5+
6+
check="./run.sh"
7+
8+
def is_running(process):
9+
10+
s = subprocess.Popen(["ps", "axw"],stdout=subprocess.PIPE)
11+
for x in s.stdout:
12+
if process in x:
13+
print("Processing is running")
14+
# print(x)
15+
#else:
16+
# print("no")
17+
# print("check complete")
18+
#is_running(b"run.sh")

csa_tool/check_log.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
##### list log files and output
3+
### To do run a process and grab the standout when running the apiscripter we will need the log number ###
4+
##then use this log number to locate the log files and output the contents ###
5+
6+
# -*- coding: utf-8 -*-
7+
"""
8+
Created on Wed Dec 7 04:36:15 2016
9+
10+
@author: mas
11+
"""
12+
13+
import os
14+
15+
16+
p = os.listdir('/var/log/')
17+
18+
19+
for i in p:
20+
if 'Xorg' in i:
21+
print(i)

csa_tool/readfile.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Thu Dec 8 03:52:35 2016
4+
5+
@author: mas
6+
"""
7+
8+
file = open('check')
9+
10+
content= file.read()
11+
if "Nov" in content:
12+
print(content)
13+
else:
14+
print("not found")
15+
16+
file.close()

csa_tool/readme.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
CSA modules
2+
3+
## python script to run a background process, verify if the background process is running
4+
## output the log data if any
5+
6+
1. need to combine them into functions
7+
2. I hate UI, but this tool requires a UI . Jquery/html5/bootstrap?
8+
9+
##components
10+
run.sh - sample process to run
11+
run_background.py - script to execute run.sh
12+
check_background.py - script to check if the process is still running
13+
readfile.py - read the output of the log after the process as completed
14+
15+
16+
## process file
17+
18+
run process > check if running > read log file

csa_tool/run.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/bash
2+
3+
mas=0
4+
run='/usr/bin/date'
5+
6+
rm -rf check
7+
echo /var/log/mas.5858585.log
8+
echo masekela
9+
while [ $mas -lt 10 ] ; do
10+
$run >> check
11+
sleep 5
12+
done

0 commit comments

Comments
 (0)