Major updates regarding global variables
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,46 @@
|
|||||||
|
# You are free to use and/or change this code for
|
||||||
|
# your own needs.
|
||||||
|
|
||||||
|
# Original code (c)2018 Jan Lerking
|
||||||
|
# Program to convert C-header (*.h) files to nasm include files (*.inc),
|
||||||
|
# for direct usage in assembly programming using nasm/yasm.
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
def init():
|
||||||
|
home = str(Path.home())
|
||||||
|
global worker
|
||||||
|
worker = []
|
||||||
|
global listener
|
||||||
|
listener = []
|
||||||
|
global thread
|
||||||
|
thread = []
|
||||||
|
global tupline
|
||||||
|
tupline = []
|
||||||
|
global preproc
|
||||||
|
preproc = ()
|
||||||
|
global filelist
|
||||||
|
filelist = []
|
||||||
|
global folderlist
|
||||||
|
folderlist = []
|
||||||
|
global cnt
|
||||||
|
cnt = 0
|
||||||
|
global srcdir
|
||||||
|
srcdir = ''
|
||||||
|
global destdir
|
||||||
|
destdir = ''
|
||||||
|
global fileindex
|
||||||
|
fileindex = 0
|
||||||
|
global filecnt
|
||||||
|
filecnt = 0
|
||||||
|
global incinc
|
||||||
|
incinc = ''
|
||||||
|
global defdir
|
||||||
|
defdir = False
|
||||||
|
global defsrc
|
||||||
|
defsrc = '/usr/include'
|
||||||
|
global defdest
|
||||||
|
defdest = home+'/include'
|
||||||
|
global count
|
||||||
|
count = 0
|
||||||
|
|
||||||
@@ -37,6 +37,7 @@
|
|||||||
</object>
|
</object>
|
||||||
<object class="GtkApplicationWindow" id="window">
|
<object class="GtkApplicationWindow" id="window">
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
|
<property name="title" translatable="yes">h2inc</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkBox" id="box1">
|
<object class="GtkBox" id="box1">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
|
|||||||
@@ -37,6 +37,8 @@
|
|||||||
</object>
|
</object>
|
||||||
<object class="GtkApplicationWindow" id="window">
|
<object class="GtkApplicationWindow" id="window">
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
|
<property name="title" translatable="yes">H2INC</property>
|
||||||
|
<property name="hide_titlebar_when_maximized">True</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkBox" id="box1">
|
<object class="GtkBox" id="box1">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
|
|||||||
+9
-14
@@ -9,27 +9,23 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import io
|
import io
|
||||||
import time
|
import time
|
||||||
from h2inc_globals import destdir, defdest, filelist, folderlist, cnt, srcdir
|
import globvar
|
||||||
|
|
||||||
def sourcedir_filecnt(sourcedir):
|
def sourcedir_filecnt(sourcedir):
|
||||||
### Return the number of files, ending with '.h', in sourcedir - including subdirectories ###
|
### Return the number of files, ending with '.h', in sourcedir - including subdirectories ###
|
||||||
global cnt
|
globvar.srcdir = sourcedir
|
||||||
global filelist
|
|
||||||
global srcdir
|
|
||||||
srcdir = sourcedir
|
|
||||||
for folderName, subfolders, files in os.walk(sourcedir):
|
for folderName, subfolders, files in os.walk(sourcedir):
|
||||||
for file in files:
|
for file in files:
|
||||||
if file.lower().endswith('.h'):
|
if file.lower().endswith('.h'):
|
||||||
cnt += 1
|
globvar.cnt += 1
|
||||||
filelist += [folderName + '/' + file]
|
globvar.filelist += [folderName + '/' + file]
|
||||||
print(folderName + '/' + file)
|
print(folderName + '/' + file)
|
||||||
# print(filelist)
|
# print(filelist)
|
||||||
return cnt
|
return globvar.cnt
|
||||||
|
|
||||||
def sourcedir_foldercnt(sourcedir):
|
def sourcedir_foldercnt(sourcedir):
|
||||||
### Return the number of folders, if it contains '*.h' files, in sourcedir - including subdirectories ###
|
### Return the number of folders, if it contains '*.h' files, in sourcedir - including subdirectories ###
|
||||||
cnt = 0
|
cnt = 0
|
||||||
global folderlist
|
|
||||||
for folderName, subfolders, files in os.walk(sourcedir):
|
for folderName, subfolders, files in os.walk(sourcedir):
|
||||||
if subfolders:
|
if subfolders:
|
||||||
for subfolder in subfolders:
|
for subfolder in subfolders:
|
||||||
@@ -38,13 +34,12 @@ def sourcedir_foldercnt(sourcedir):
|
|||||||
if tempf:
|
if tempf:
|
||||||
cnt = cnt + 1
|
cnt = cnt + 1
|
||||||
# print(folderName)
|
# print(folderName)
|
||||||
folderlist += [folderName]
|
globvar.folderlist += [folderName]
|
||||||
# print(folderlist)
|
# print(folderlist)
|
||||||
# print(len(folderlist))
|
# print(len(folderlist))
|
||||||
return cnt
|
return cnt
|
||||||
|
|
||||||
def process_file(data):
|
def process_file(data):
|
||||||
global count
|
|
||||||
outfile = ''
|
outfile = ''
|
||||||
inputfile = data
|
inputfile = data
|
||||||
encodings = ['utf-8', 'latin-1', 'windows-1250', 'windows-1252', 'ascii',
|
encodings = ['utf-8', 'latin-1', 'windows-1250', 'windows-1252', 'ascii',
|
||||||
@@ -78,9 +73,9 @@ def process_file(data):
|
|||||||
outfile = outfile + lines
|
outfile = outfile + lines
|
||||||
fh.close()
|
fh.close()
|
||||||
outputfile = os.path.splitext(inputfile)[0] + '.inc'
|
outputfile = os.path.splitext(inputfile)[0] + '.inc'
|
||||||
outputfile = str(outputfile).replace(srcdir, destdir)
|
outputfile = str(outputfile).replace(globvar.srcdir, globvar.destdir)
|
||||||
count += 1
|
globvar.count += 1
|
||||||
print(str(count)+'->'+outputfile)
|
print(str(globvar.count)+'->'+outputfile)
|
||||||
if not os.path.exists(os.path.dirname(outputfile)):
|
if not os.path.exists(os.path.dirname(outputfile)):
|
||||||
try:
|
try:
|
||||||
os.makedirs(os.path.dirname(outputfile))
|
os.makedirs(os.path.dirname(outputfile))
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
# You are free to use and/or change this code for
|
|
||||||
# your own needs.
|
|
||||||
|
|
||||||
# Original code (c)2018 Jan Lerking
|
|
||||||
# Program to convert C-header (*.h) files to nasm include files (*.inc),
|
|
||||||
# for direct usage in assembly programming using nasm/yasm.
|
|
||||||
|
|
||||||
worker = []
|
|
||||||
listener = []
|
|
||||||
thread = []
|
|
||||||
tupline = []
|
|
||||||
preproc = ()
|
|
||||||
filelist = []
|
|
||||||
folderlist = []
|
|
||||||
cnt = 0
|
|
||||||
srcdir = ''
|
|
||||||
destdir = ''
|
|
||||||
fileindex = 0
|
|
||||||
filecnt = 0
|
|
||||||
incinc = ''
|
|
||||||
defdir = False
|
|
||||||
defsrc = '/usr/include'
|
|
||||||
defdest = '~/include'
|
|
||||||
count = 0
|
|
||||||
|
|
||||||
+44
-50
@@ -12,14 +12,15 @@ import gi
|
|||||||
gi.require_version('Gtk', '3.0')
|
gi.require_version('Gtk', '3.0')
|
||||||
from gi.repository import Gtk, Gio, GObject as gobject
|
from gi.repository import Gtk, Gio, GObject as gobject
|
||||||
#import time
|
#import time
|
||||||
from h2inc_globals import defsrc, destdir, defdest, filelist, cnt, srcdir
|
import globvar
|
||||||
from h2inc_mp import Worker, start_workers
|
from h2inc_mp import start_workers
|
||||||
from h2inc_fp import sourcedir_filecnt, sourcedir_foldercnt
|
from h2inc_fp import sourcedir_filecnt, sourcedir_foldercnt
|
||||||
|
|
||||||
|
globvar.init()
|
||||||
|
|
||||||
class H2INC:
|
class H2INC:
|
||||||
|
|
||||||
global app
|
global app
|
||||||
global destlabel
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
@@ -40,10 +41,11 @@ class H2INC:
|
|||||||
|
|
||||||
self.obj = builder.get_object
|
self.obj = builder.get_object
|
||||||
self.obj("window").set_application(app)
|
self.obj("window").set_application(app)
|
||||||
self.obj("window").set_wmclass("h2inc_gtk","h2inc_gtk")
|
self.obj("window").set_wmclass("h2inc","h2inc")
|
||||||
|
self.obj("window").set_title("h2inc - v.0.0.1")
|
||||||
self.obj("window").show_all()
|
self.obj("window").show_all()
|
||||||
self.obj("source_entry").set_text(defsrc)
|
self.obj("source_entry").set_text(globvar.defsrc)
|
||||||
self.obj("destination_entry").set_text(defdest)
|
self.obj("destination_entry").set_text(globvar.defdest)
|
||||||
self.obj("default_dir_checkbutton").set_active(False)
|
self.obj("default_dir_checkbutton").set_active(False)
|
||||||
self.obj("include_checkbutton").set_active(True)
|
self.obj("include_checkbutton").set_active(True)
|
||||||
|
|
||||||
@@ -93,38 +95,34 @@ class H2INC:
|
|||||||
self.on_dialog_close(widget)
|
self.on_dialog_close(widget)
|
||||||
|
|
||||||
def on_source_button_clicked(self,widget):
|
def on_source_button_clicked(self,widget):
|
||||||
|
|
||||||
dialog = Gtk.FileChooserDialog("Select source directory!",
|
dialog = Gtk.FileChooserDialog("Select source directory!",
|
||||||
self.obj("window"),
|
self.obj("window"),
|
||||||
Gtk.FileChooserAction.SELECT_FOLDER,
|
Gtk.FileChooserAction.SELECT_FOLDER,
|
||||||
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
|
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
|
||||||
Gtk.STOCK_APPLY, Gtk.ResponseType.OK))
|
Gtk.STOCK_APPLY, Gtk.ResponseType.OK))
|
||||||
dialog.set_default_size(600, 300)
|
dialog.set_default_size(600, 300)
|
||||||
Gtk.FileChooser.set_filename(dialog, srcdir)
|
Gtk.FileChooser.set_filename(dialog, globvar.srcdir)
|
||||||
|
|
||||||
response = dialog.run()
|
response = dialog.run()
|
||||||
if response == Gtk.ResponseType.OK:
|
if response == Gtk.ResponseType.OK:
|
||||||
self.filecnt = sourcedir_filecnt(dialog.get_filename())
|
globvar.filecnt = sourcedir_filecnt(dialog.get_filename())
|
||||||
if self.filecnt >0:
|
if globvar.filecnt >0:
|
||||||
print(self.filecnt)
|
print(globvar.filecnt)
|
||||||
self.obj("source_entry").set_text(dialog.get_filename())
|
self.obj("source_entry").set_text(dialog.get_filename())
|
||||||
self.obj("destination_label").set_sensitive(True)
|
self.obj("destination_label").set_sensitive(True)
|
||||||
self.obj("destination_entry").set_sensitive(True)
|
self.obj("destination_entry").set_sensitive(True)
|
||||||
self.obj("destination_button").set_sensitive(True)
|
self.obj("destination_button").set_sensitive(True)
|
||||||
self.obj("numfiles_label").set_text(str(self.filecnt))
|
self.obj("numfiles_label").set_text(str(self.filecnt))
|
||||||
self.obj("progress_label").set_text("{} of {}".format(self.fileindex, self.filecnt))
|
self.obj("progress_label").set_text("{} of {}".format(globvar.fileindex, globvar.filecnt))
|
||||||
self.foldercnt = sourcedir_foldercnt(dialog.get_filename())
|
globvar.foldercnt = sourcedir_foldercnt(dialog.get_filename())
|
||||||
if self.foldercnt >0:
|
if globvar.foldercnt >0:
|
||||||
self.obj("numfolders_label").set_text(str(self.foldercnt))
|
self.obj("numfolders_label").set_text(str(globvar.foldercnt))
|
||||||
elif response == Gtk.ResponseType.CANCEL:
|
elif response == Gtk.ResponseType.CANCEL:
|
||||||
print("Cancel")
|
print("Cancel")
|
||||||
|
|
||||||
dialog.destroy()
|
dialog.destroy()
|
||||||
|
|
||||||
def on_destination_button_clicked(self,widget):
|
def on_destination_button_clicked(self,widget):
|
||||||
global destdir
|
|
||||||
global incinc
|
|
||||||
|
|
||||||
dialog = Gtk.FileChooserDialog("Select destination directory!",
|
dialog = Gtk.FileChooserDialog("Select destination directory!",
|
||||||
self.obj("window"),
|
self.obj("window"),
|
||||||
Gtk.FileChooserAction.SELECT_FOLDER,
|
Gtk.FileChooserAction.SELECT_FOLDER,
|
||||||
@@ -134,57 +132,53 @@ class H2INC:
|
|||||||
|
|
||||||
response = dialog.run()
|
response = dialog.run()
|
||||||
if response == Gtk.ResponseType.OK:
|
if response == Gtk.ResponseType.OK:
|
||||||
destdir = dialog.get_filename()
|
globvar.destdir = dialog.get_filename()
|
||||||
self.obj("destination_entry").set_text(dialog.get_filename())
|
self.obj("destination_entry").set_text(dialog.get_filename())
|
||||||
self.obj("include_checkbutton").set_sensitive(True)
|
self.obj("include_checkbutton").set_sensitive(True)
|
||||||
self.obj("translation_frame").set_sensitive(True)
|
self.obj("translation_frame").set_sensitive(True)
|
||||||
print(srcdir)
|
print(globvar.srcdir)
|
||||||
if self.obj("include_checkbutton").get_active() == True:
|
if self.obj("include_checkbutton").get_active() == True:
|
||||||
incinc = '/include'
|
globvar.incinc = '/include'
|
||||||
destdir = destdir+incinc
|
globvar.destdir = globvar.destdir+globvar.incinc
|
||||||
print(destdir)
|
print(globvar.destdir)
|
||||||
elif response == Gtk.ResponseType.CANCEL:
|
elif response == Gtk.ResponseType.CANCEL:
|
||||||
print("Cancel")
|
print("Cancel")
|
||||||
|
|
||||||
dialog.destroy()
|
dialog.destroy()
|
||||||
|
|
||||||
def on_include_checkbutton_toggled(self, widget):
|
def on_include_checkbutton_toggled(self, widget):
|
||||||
global destdir
|
|
||||||
global incinc
|
|
||||||
if self.obj("include_checkbutton").get_active() == True:
|
if self.obj("include_checkbutton").get_active() == True:
|
||||||
incinc = '~/include'
|
if globvar.destdir.lower().endswith('/include'):
|
||||||
destdir = destdir+incinc
|
globvar.destdir = globvar.destdir
|
||||||
|
else:
|
||||||
|
globvar.destdir = globvar.destdir+'/include'
|
||||||
if self.obj("include_checkbutton").get_active() == False:
|
if self.obj("include_checkbutton").get_active() == False:
|
||||||
incinc = ''
|
#globvar.incinc = ''
|
||||||
destdir = destdir.replace('~/include', '')
|
globvar.destdir = globvar.destdir.replace('/include', '')
|
||||||
self.obj("destination_entry").set_text(destdir)
|
self.obj("destination_entry").set_text(globvar.destdir)
|
||||||
print(destdir)
|
print(globvar.destdir)
|
||||||
|
|
||||||
def on_default_dir_checkbutton_toggled(self, widget):
|
def on_default_dir_checkbutton_toggled(self, widget):
|
||||||
global defdir
|
globvar.defdir = self.obj("default_dir_checkbutton").get_active()
|
||||||
global srcdir
|
if globvar.defdir == True:
|
||||||
global destdir
|
globvar.srcdir = globvar.defsrc
|
||||||
global incinc
|
self.obj("source_entry").set_text(globvar.srcdir)
|
||||||
defdir = self.obj("default_dir_checkbutton").get_active()
|
globvar.destdir = globvar.defdest
|
||||||
if defdir == True:
|
self.obj("destination_entry").set_text(globvar.destdir)
|
||||||
srcdir = defsrc
|
|
||||||
self.obj("source_entry").set_text(srcdir)
|
|
||||||
destdir = defdest
|
|
||||||
self.obj("destination_entry").set_text(destdir)
|
|
||||||
self.obj("include_checkbutton").set_sensitive(True)
|
self.obj("include_checkbutton").set_sensitive(True)
|
||||||
self.obj("source_label").set_sensitive(False)
|
self.obj("source_label").set_sensitive(False)
|
||||||
self.obj("source_entry").set_sensitive(False)
|
self.obj("source_entry").set_sensitive(False)
|
||||||
self.obj("source_button").set_sensitive(False)
|
self.obj("source_button").set_sensitive(False)
|
||||||
self.obj("translation_frame").set_sensitive(True)
|
self.obj("translation_frame").set_sensitive(True)
|
||||||
self.filecnt = sourcedir_filecnt(srcdir)
|
globvar.filecnt = sourcedir_filecnt(globvar.srcdir)
|
||||||
if self.filecnt >0:
|
if globvar.filecnt >0:
|
||||||
print(self.filecnt)
|
print(globvar.filecnt)
|
||||||
self.obj("numfiles_label").set_text(str(self.filecnt))
|
self.obj("numfiles_label").set_text(str(globvar.filecnt))
|
||||||
self.obj("progress_label").set_text("{} of {}".format(self.fileindex, self.filecnt))
|
self.obj("progress_label").set_text("{} of {}".format(globvar.fileindex, self.filecnt))
|
||||||
self.foldercnt = sourcedir_foldercnt(srcdir)
|
globvar.foldercnt = sourcedir_foldercnt(globvar.srcdir)
|
||||||
if self.foldercnt >0:
|
if globvar.foldercnt >0:
|
||||||
print(self.foldercnt)
|
print(globvar.foldercnt)
|
||||||
self.obj("numfolders_label").set_text(str(self.foldercnt))
|
self.obj("numfolders_label").set_text(str(globvar.foldercnt))
|
||||||
|
|
||||||
def on_translate_button_clicked(self, widget, data=None):
|
def on_translate_button_clicked(self, widget, data=None):
|
||||||
self.obj("sourceframe").set_sensitive(False)
|
self.obj("sourceframe").set_sensitive(False)
|
||||||
|
|||||||
+14
-15
@@ -9,18 +9,15 @@ import multiprocessing
|
|||||||
from queue import Queue
|
from queue import Queue
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
import threading
|
import threading
|
||||||
from h2inc_globals import filelist, cnt
|
import globvar
|
||||||
from h2inc_fp import process_file
|
import h2inc_fp
|
||||||
|
|
||||||
num_cores = multiprocessing.cpu_count()
|
num_cores = multiprocessing.cpu_count()
|
||||||
|
lock = threading.Lock()
|
||||||
|
queue = 0
|
||||||
|
|
||||||
class Worker(Thread):
|
def process_queue():
|
||||||
def __init__(self, queue):
|
print("Worker {} working...".format(threading.current_thread().name))
|
||||||
Thread.__init__(self)
|
|
||||||
self.queue = queue
|
|
||||||
|
|
||||||
def go(self):
|
|
||||||
print("The worker has started doing some work (counting from 0 to 9)")
|
|
||||||
#for i in range(self.filecnt):
|
#for i in range(self.filecnt):
|
||||||
#proportion = (float(i+1))/self.filecnt
|
#proportion = (float(i+1))/self.filecnt
|
||||||
#self.queue.put((proportion, "working...", i))
|
#self.queue.put((proportion, "working...", i))
|
||||||
@@ -28,12 +25,14 @@ class Worker(Thread):
|
|||||||
#process_file(filelist[i])
|
#process_file(filelist[i])
|
||||||
#self.queue.put((1.0, "finished"))
|
#self.queue.put((1.0, "finished"))
|
||||||
#print("The worker has finished.")
|
#print("The worker has finished.")
|
||||||
while True:
|
while True:
|
||||||
cfile = self.queue.get()
|
cfile = queue.get()
|
||||||
process_file(cfile)
|
print(cfile)
|
||||||
self.queue.task_done()
|
h2inc_fp.process_file(cfile)
|
||||||
|
queue.task_done()
|
||||||
|
|
||||||
def start_workers():
|
def start_workers():
|
||||||
|
global queue
|
||||||
print("Creating shared Queue")
|
print("Creating shared Queue")
|
||||||
queue = Queue()
|
queue = Queue()
|
||||||
|
|
||||||
@@ -42,11 +41,11 @@ def start_workers():
|
|||||||
for n in range(num_cores):
|
for n in range(num_cores):
|
||||||
print("Creating Worker", n)
|
print("Creating Worker", n)
|
||||||
|
|
||||||
worker = Worker(queue)
|
worker = threading.Thread(target=process_queue)
|
||||||
worker.deamon = True
|
worker.deamon = True
|
||||||
worker.start()
|
worker.start()
|
||||||
|
|
||||||
for cfile in filelist:
|
for cfile in globvar.filelist:
|
||||||
print("Queueing {}".format(cfile))
|
print("Queueing {}".format(cfile))
|
||||||
queue.put(cfile)
|
queue.put(cfile)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user