-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #210 from BillHallahan/scripts_update
Updating the nebula scripts by including the scripts to Download Hack…
- Loading branch information
Showing
6 changed files
with
188 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Revision history for DownloadHackage | ||
|
||
## 0.1.0.0 -- YYYY-mm-dd | ||
|
||
* First version. Released on an unsuspecting world. |
34 changes: 34 additions & 0 deletions
34
nebula_scripts/ScriptsForDownloadHackage/DownloadHackage.cabal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
cabal-version: 2.4 | ||
name: DownloadHackage | ||
version: 0.1.0.0 | ||
|
||
-- A short (one-line) description of the package. | ||
-- synopsis: | ||
|
||
-- A longer description of the package. | ||
-- description: | ||
|
||
-- A URL where users can report bugs. | ||
-- bug-reports: | ||
|
||
-- The license under which the package is released. | ||
-- license: | ||
author: QHWU1228 | ||
maintainer: [email protected] | ||
|
||
-- A copyright notice. | ||
-- copyright: | ||
-- category: | ||
extra-source-files: CHANGELOG.md | ||
|
||
executable DownloadHackage | ||
main-is: Main.hs | ||
|
||
-- Modules included in this executable, other than Main. | ||
-- other-modules: | ||
|
||
-- LANGUAGE extensions used by modules in this package. | ||
-- other-extensions: | ||
build-depends: base ^>=4.16.4.0, extra | ||
hs-source-dirs: app | ||
default-language: Haskell2010 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Main where | ||
|
||
import Data.List.Extra ( groupOn, word1 ) | ||
import System.Process.Extra ( systemOutput_, system_ ) | ||
|
||
main :: IO () | ||
main = do | ||
let toUrl (name, ver) = "http://hackage.haskell.org/package/" ++ name ++ "/" ++ name ++ "-" ++ ver ++ ".tar.gz" | ||
urls <- map (toUrl . last) . groupOn fst . map word1 . lines <$> systemOutput_ "cabal list --simple" | ||
writeFile "_urls.txt" $ unlines urls | ||
system_ "wget --input-file=_urls.txt" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Run g2_output script before running this script | ||
# This script analyze the file from g2_result folder | ||
# This script aim to create a corresponding file for each file in g2_results' folder | ||
# This scripts will do the following: | ||
# # of verified rules | ||
# # of counterexamples | ||
# # of "limit hits" (don't know what the regular expression gonna be ) | ||
# # of errors from Nebula. (don't know what regular expression to used currently ) | ||
# total # of rules | ||
import re | ||
import sys | ||
import os | ||
counter_example = r"Counterexample\s*found" # of counterexamples | ||
verified = r'verified' # of verified rules | ||
checking = r'checking'# total # of rules | ||
|
||
def starter(directory): | ||
actual_directory = os.getcwd() + '/' + directory | ||
os.chdir(actual_directory) | ||
for root, directories, files in os.walk(actual_directory): | ||
for file in files: | ||
file_path = os.path.join(root,file) | ||
file_name_analysis = os.path.basename(file_path) | ||
# get the parent directory | ||
# so we can create a separate folder outside from the current directory to store files | ||
parent_dir = os.path.dirname(os.getcwd()) | ||
print("The parent directory is " + parent_dir +'\n') | ||
file_path_analysis = parent_dir + '/g2_analysis/' + file_name_analysis | ||
if not os.path.exists(file_path_analysis): | ||
total_counter_example = 0 | ||
total_verified = 0 | ||
total_rule = 0 | ||
with open(file_path,"r") as file: | ||
# recording all the info per file | ||
for line in file: | ||
search_for_counter_example = re.search(counter_example,line,re.IGNORECASE) | ||
search_verified = re.search(verified,line,re.IGNORECASE) | ||
search_rule = re.search(checking,line,re.IGNORECASE) | ||
if search_for_counter_example: total_counter_example += 1 | ||
if search_verified: total_verified += 1 | ||
if search_rule: total_rule += 1 | ||
# checking to the upper directory and create a directory | ||
os.chdir('..') | ||
print("We are currently in the home directory call " + os.getcwd() + "\n") | ||
# store all those info in a file now | ||
analysis_dir = './g2_analysis' | ||
os.makedirs(analysis_dir,exist_ok=True) | ||
os.chdir(analysis_dir) | ||
print("After changing directory, we are in directory " + os.getcwd() + "\ns") | ||
with open(file_name_analysis,"a") as file: | ||
file.write("Total counter example found in this file: " + str(total_counter_example) + "\n") | ||
file.write("Total verified rules found in this file " + str(total_verified) + "\n") | ||
file.write("Total rules in this file is " + str(total_rule) + "\n") | ||
# now I am changing back to the root directory so we can continue reading | ||
os.chdir(actual_directory) | ||
|
||
|
||
# main: | ||
args = sys.argv | ||
if len(args) != 2: | ||
raise Exception("Invalid number of commands provided. The first argument is the script name. The second argument is the directory contain all the file that stored the output and error after running with cabal build.") | ||
directory = sys.argv[1] | ||
starter(directory) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# remember to use Build_cabal_and_project.py | ||
# on the package so the package will have a dependency on g2 before this script | ||
# so we can run G2 using subprocess | ||
# This script just record the content of the resulting output after using g2 on package | ||
import subprocess | ||
import sys | ||
import os | ||
import shutil | ||
|
||
def using_subprocess(file_path): | ||
# chaging the working directory from home to the nested directory | ||
|
||
os.chdir(file_path) | ||
current_dir = os.path.abspath(file_path) | ||
# write the result to the file | ||
file = os.path.split(current_dir) | ||
file_name = file[1] +'.txt' | ||
source_path = os.getcwd() + '/' + file_name | ||
|
||
print("creating a file called in " + file_name + " in current directory " + os.getcwd()) | ||
with open(file_name,'a') as file: | ||
# merging the standard out and standard error and redirecting them to the file | ||
subprocess.run(['cabal','clean']) | ||
subprocess.run(['cabal','build'],text=True,stdout=file,stderr=subprocess.STDOUT) | ||
|
||
# changing back the home directory | ||
os.chdir('..') | ||
print('The source path is ' + source_path + '\n') | ||
# making a folder called g2_output | ||
dest_dir = './g2_output' | ||
os.makedirs(dest_dir,exist_ok=True) | ||
os.chdir(dest_dir) | ||
dest_path = os.getcwd() | ||
file_name_in_g2 = file_name | ||
|
||
# making a same file we just make in g2_output so we could replace it | ||
with open(file_name_in_g2, 'w') as file: | ||
file.write('there is something') | ||
dest_path = dest_path + '/' + file_name_in_g2 | ||
print('The dest_path is ' + dest_path + '\n') | ||
# now I am moving the file from the file_path to the g2's output folder | ||
print("Destination path: ", dest_path + '\n') | ||
print("Source path is :" + source_path + '\n') | ||
shutil.move(source_path,dest_path) | ||
#changing back to the home directory | ||
os.chdir("../..") | ||
print("We are in the home directory " + os.getcwd()) | ||
|
||
|
||
|
||
def starter(home_directory): | ||
for filename in os.listdir(home_directory): | ||
file_path = os.path.join(home_directory,filename) | ||
if os.path.exists(file_path): | ||
if os.path.isdir(file_path) and not file_path.endswith('g2_output'): | ||
print("going into a directory " + file_path) | ||
file_path_in_G2 = home_directory+"/g2_output/" +filename + '.txt' | ||
if not os.path.exists(file_path_in_G2): | ||
using_subprocess(file_path) | ||
|
||
|
||
|
||
|
||
|
||
# main: | ||
args = sys.argv | ||
if len(args) != 2: | ||
raise Exception("Invalid number of commands provided. The first argument is the script name. The second argument is the directory contain all the package that have rules.") | ||
directory = sys.argv[1] | ||
starter(directory) |