Skip to content

Add files via upload #1034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions jdbc_connect.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import java.sql.*;
import java.util.Properties;

public class DatabaseConnection {

Connection conn = null;
Statement stmt = null;
Driver d;

public Connection getConnection(String database_name)
{
try {
d = (Driver) Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
String db_url="jdbc:sqlserver://localhost;database=ThePieChart;integratedSecurity=true;";
conn = d.connect(db_url, new Properties());
System.out.println("Connected to ThePieChart");
return conn;
}
catch(SQLException se){
se.printStackTrace();
return null;
}
catch(Exception e){
e.printStackTrace();
return null;
}
finally{


}

}


}
108 changes: 108 additions & 0 deletions listSource.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import os, re

binary_re = re.compile(br'[\x00-\x08\x0E-\x1F\x7F]')

debug = False

def print_debug(msg):
if debug: print(msg)


def _open(fullpath):
try:
size = os.stat(fullpath).st_size
except OSError as err: # Permission denied - ignore the file
print_debug("%s: permission denied: %s" % (fullpath, err))
return None

if size > 1024*1024: # too big
print_debug("%s: the file is too big: %d bytes" % (fullpath, size))
return None

try:
return open(fullpath, "rb")
except IOError as err: # Access denied, or a special file - ignore it
print_debug("%s: access denied: %s" % (fullpath, err))
return None

def has_python_ext(fullpath):
return fullpath.endswith(".py") or fullpath.endswith(".pyw")

def looks_like_python(fullpath):
infile = _open(fullpath)
if infile is None:
return False

with infile:
line = infile.readline()

if binary_re.search(line):
# file appears to be binary
print_debug("%s: appears to be binary" % fullpath)
return False

if fullpath.endswith(".py") or fullpath.endswith(".pyw"):
return True
elif b"python" in line:
# disguised Python script (e.g. CGI)
return True

return False

def can_be_compiled(fullpath):
infile = _open(fullpath)
if infile is None:
return False

with infile:
code = infile.read()

try:
compile(code, fullpath, "exec")
except Exception as err:
print_debug("%s: cannot compile: %s" % (fullpath, err))
return False

return True


def walk_python_files(paths, is_python=looks_like_python, exclude_dirs=None):
"""\
Recursively yield all Python source files below the given paths.

paths: a list of files and/or directories to be checked.
is_python: a function that takes a file name and checks whether it is a
Python source file
exclude_dirs: a list of directory base names that should be excluded in
the search
"""
if exclude_dirs is None:
exclude_dirs=[]

for path in paths:
print_debug("testing: %s" % path)
if os.path.isfile(path):
if is_python(path):
yield path
elif os.path.isdir(path):
print_debug(" it is a directory")
for dirpath, dirnames, filenames in os.walk(path):
for exclude in exclude_dirs:
if exclude in dirnames:
dirnames.remove(exclude)
for filename in filenames:
fullpath = os.path.join(dirpath, filename)
print_debug("testing: %s" % fullpath)
if is_python(fullpath):
yield fullpath
else:
print_debug(" unknown type")


if __name__ == "__main__":
# Two simple examples/tests
for fullpath in walk_python_files(['.']):
print(fullpath)
print("----------")
for fullpath in walk_python_files(['.'], is_python=can_be_compiled):
print(fullpath)