Skip to content

Commit

Permalink
Finished beta
Browse files Browse the repository at this point in the history
  • Loading branch information
vYZ committed Jan 26, 2017
1 parent cbcdbd3 commit 4a0bf3c
Show file tree
Hide file tree
Showing 18 changed files with 51 additions and 57 deletions.
1 change: 0 additions & 1 deletion src/init/Notes/ANSI-C-Notes-PL-
Submodule ANSI-C-Notes-PL- deleted from a4fad2
1 change: 0 additions & 1 deletion src/init/Notes/Academy
Submodule Academy deleted from fe474e
1 change: 0 additions & 1 deletion src/init/Notes/C-Primer-Plus-6th-Edition-Notes-PL-
Submodule C-Primer-Plus-6th-Edition-Notes-PL- deleted from 851310
1 change: 0 additions & 1 deletion src/init/Notes/Effective-Modern-CPP-2014-Notes-PL-
Submodule Effective-Modern-CPP-2014-Notes-PL- deleted from 93acdc
1 change: 0 additions & 1 deletion src/init/Notes/Getting-Started-with-SQL-Notes-PL-
Submodule Getting-Started-with-SQL-Notes-PL- deleted from 41eb40
1 change: 0 additions & 1 deletion src/init/Notes/Introduction-To-Algorithms-CLRS-Notes-PL
Submodule Introduction-To-Algorithms-CLRS-Notes-PL deleted from b3a956
Submodule Java-Complete-Reference-9th-Edition-Notes-PL- deleted from e6f99e
1 change: 0 additions & 1 deletion src/init/Notes/Machine-Learning-Notes-PL
Submodule Machine-Learning-Notes-PL deleted from 59ad31
1 change: 0 additions & 1 deletion src/init/Notes/MySQL-Dev-Library-4th-Notes-PL
Submodule MySQL-Dev-Library-4th-Notes-PL deleted from 1791ca
1 change: 0 additions & 1 deletion src/init/Notes/Pro-Git-Second-Edition-Notes-PL-
Submodule Pro-Git-Second-Edition-Notes-PL- deleted from 9dafa3
1 change: 0 additions & 1 deletion src/init/Notes/Python-Essential-Reference-Notes-PL-
Submodule Python-Essential-Reference-Notes-PL- deleted from 2cffc2
1 change: 0 additions & 1 deletion src/init/Notes/Sedgewick-Notes-PL
Submodule Sedgewick-Notes-PL deleted from 7b68d1
Submodule The-CPP-Programming-Language-4th-Edition-Notes-PL- deleted from 5ad786
1 change: 0 additions & 1 deletion src/init/content.xml

This file was deleted.

56 changes: 29 additions & 27 deletions src/init/init.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,30 @@
#DODAC COMMITE'Y
from argparse import ArgumentParser
from zipfile import ZipFile
import xml.etree.ElementTree as xmlET
import os
import mysql.connector
from getpass import getpass
import sys
import pexpect

from argparse import ArgumentParser
from zipfile import ZipFile
from time import sleep
from subprocess import run

from getpass import getpass
from os import walk

from setup_database import setup_database
sys.path.append('../procedures')
from setup_procedures import setup_procedures

#TO FIX
id=1
#RECURSIVE READ OF MIND MAPS

def recursive_read(root, cursor, database):
global id
global MAP_ID
if root.text is not None:
cursor.callproc('add_node', (id, root.text))
print('Adding branch: ' + str(id), end='\r')
id += 1
cursor.callproc('add_node', (MAP_ID, root.text))[0]
print('Added branch: ' + str(MAP_ID) , end='\r')
MAP_ID += 1
for elem in root.getchildren():
recursive_read(elem, cursor, database)

#id = 1
#def recursive_read(root, cursor, database):
# global id
# if root.text is not None:
# cursor.callproc('add_node', (id, root.text))
# database.commit()
# print('[GATHERING DATA] Working on branch: ' + str(id), end='\r')
# id += 1
# for elem in root.getchildren():
# recursive_read(elem, cursor, database)

#ARGUMENT PARSING AND MAIN PROGRAM LOGIC

parser = ArgumentParser(
description='''
Expand Down Expand Up @@ -76,6 +64,13 @@ def recursive_read(root, cursor, database):
help='''Engine used for database creation [DEFAULT: InnoDB]''',
default='InnoDB')

parser.add_argument('--no_store_password', '-n', required=False, action='store_true',
help='''Do not store password in secured file in the database\n
WARNING! if this argument is specified, xms searcher will ask you\n
to provide MySQL password each time!
''',
default=True)

parser.add_argument('--experimental', required=False, action='store_true',
help='''Turns on experimental functions [Mind Maps XSD validation]\n
IMPORTANT: Slows down the program significantly\n''',
Expand Down Expand Up @@ -110,27 +105,34 @@ def recursive_read(root, cursor, database):
process.sendline('source ../procedures/setup_procedures.sql')
#BUDUJEMY NAPIECIE
sleep(1)
#process.interact()
#ZBUDOWANO NAPIECIE
process.close()
print("Procedures loaded correctly\n")

#SET UP ROOT
cursor.execute('''INSERT INTO tree (content, lft, rgt) VALUES ('root', 1, 2) ''')

for subdir, dirs, files in os.walk(args.path):
for subdir, dirs, files in walk(args.path):
for i, file in enumerate(files):
if file.endswith('.xmind'):
archive = ZipFile(subdir + r'/' + file, 'r')

#EXPERIMENTAL
if args.experimental:
print('Validating file ' + file)
run(['xmllint', '--noout', '--schema', '../validations/mind_map.xsd', archive.extract('content.xml')])
run(['rm', 'content.xml'])

#SCANNING MIND MAPS
with archive.open('content.xml', 'r') as content:
id = 1
MAP_ID = 1
print('Adding branches from file ' + file + ' to database')
tree = xmlET.parse(content)
recursive_read(tree.getroot(), cursor, database)
print('Branches from file ' + file + ' added successfully\n')
except Error as e:

except Exception as e:
print(e)
finally:
cursor.close()
Expand Down
2 changes: 1 addition & 1 deletion src/init/setup_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def setup_database(database, args):
content TEXT NOT NULL,
lft BIGINT NOT NULL,
rgt BIGINT NOT NULL,
FULLTEXT (content)
FULLTEXT(content)
)ENGINE=''' + args.engine
)
return cursor;
11 changes: 7 additions & 4 deletions src/procedures/setup_procedures.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ proc: BEGIN

START TRANSACTION;

UPDATE tree SET lft = CASE WHEN lft > parent_rgt THEN lft + 2 ELSE lft END
,rgt = CASE WHEN rgt >= parent_rgt THEN rgt + 2 ELSE rgt END
UPDATE tree SET lft = CASE WHEN lft > parent_rgt THEN lft + 2 ELSE lft END,
rgt = CASE WHEN rgt >= parent_rgt THEN rgt + 2 ELSE rgt END
WHERE rgt >= parent_rgt;

INSERT INTO tree (content, lft, rgt)
Expand All @@ -39,15 +39,18 @@ DROP PROCEDURE IF EXISTS find_node;
//

CREATE DEFINER = CURRENT_USER PROCEDURE find_node (
IN searched TEXT
IN searched TEXT,
IN off BIGINT
)

proc: BEGIN

SELECT parent.content
FROM tree AS node,
tree AS parent
WHERE node.lft BETWEEN parent.lft AND parent.rgt AND MATCH(node.content) AGAINST(searched IN BOOLEAN MODE)
WHERE node.lft BETWEEN parent.lft AND parent.rgt
AND node.content =
(SELECT content FROM tree WHERE match(content) AGAINST(searched IN BOOLEAN MODE) LIMIT 1 OFFSET off)
ORDER BY parent.lft;

END //
Expand Down
25 changes: 14 additions & 11 deletions src/xms.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
)

parser.add_argument('--database', '-d', required=False,
help='''Name of the database [DEFAULT: mind_maps]''',
help='''Name of the database [DEFAULT: xmindmaps]''',
default='xmindmaps')


Expand All @@ -39,13 +39,16 @@
)

cursor = database.cursor()
cursor.callproc('find_node', (args.keyword,))

for result in cursor.stored_results():
limit = 0
for branch in result.fetchall():
if limit % 5 == 0:
print('%s' % branch)
else:
print('%s' % branch, end='->')
limit += 1

id = 0
while True:
print()
cursor.callproc('find_node', [args.keyword, id])

for result in cursor.stored_results():
for indent, branch in enumerate(result.fetchall()[1:]):
print(' '*indent + '%s' %branch)
decision = input('\nShow next result?\n [Y] yes [OTHER] no ')
if decision.lower() != 'y':
break
id += 1

0 comments on commit 4a0bf3c

Please sign in to comment.