Skip to content

Commit

Permalink
Added function for import remote modules
Browse files Browse the repository at this point in the history
  • Loading branch information
RedToor committed Aug 4, 2016
1 parent 12f116a commit 260d839
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
4 changes: 4 additions & 0 deletions LINETIME
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* 04/08/16
Added New Option to ktf.ktf class: import remote modules
Create New Repository : rmfktf, for remote modules and tools

* 01/08/16
New Class : ktf.ktf, for functions of framework (import, export, setting, etc)
Change of banner for ktf.tool, ktf.run, ktf.linker
Expand Down
36 changes: 29 additions & 7 deletions ktf.ktf
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,27 @@
#HEAD#########################################################
#
# Katana Framework | ktf.ktf
# Last Modified: 01/08/2016
# Last Modified: 04/08/2016
#
#########################################################HEAD#

from core.Function import GetRootModules,status_cmd
from core.Design import *
import importlib,argparse,sys,os
import importlib,argparse,sys,os,urllib2,json

VAR=0
Namektf=False
Import=False
isRemote=False
CLASS_BANNER=DESIGN()
CLASS_BANNER.ktfktf()

try:
for eachArg in sys.argv:
if eachArg=="--i-module":
if eachArg=="--i-module" :Import=sys.argv[VAR+1]
if eachArg=="--i-module-remote":
Import=sys.argv[VAR+1]
isRemote=True
VAR+=1

except:printAlert(1,"Check your Arguments")
Expand All @@ -31,7 +34,7 @@ class ktf:
Loadingfile(FilenameModule)
try:
printAlert(0,"Information Module")
os.system("cp "+FilenameModule+".py tmp/")
os.system("cp "+FilenameModule+".py tmp/ >/dev/null 2>&1")
os.system("echo > tmp/__init__.py")
FilenameModule=os.path.basename(FilenameModule)
ModuleToStart = importlib.import_module("tmp."+FilenameModule)
Expand All @@ -49,7 +52,7 @@ class ktf:
root=GetRootModules()
for modules in root.findall('module'):
if modules.get('name') == init.CodeName:
printAlert(1,"the CodeName is already being used by another module. ")
printAlert(1,"the CodeName is already being used by another module.\n")
exit()
if os.path.isdir("modules/"+New[0]+"/") == False:
printAlert(0,status_cmd("mkdir modules/"+New[0]+"/")+" Crating a new category")
Expand Down Expand Up @@ -84,6 +87,25 @@ class ktf:
os.system("rm tmp/*.pyc")
except Exception as e:printAlert(1,str(e)+"\n")

def RemoteImport(self):
u = urllib2.urlopen("https://raw.githubusercontent.com/PowerScript/rmfktf/master/modules.js")
data_string = json.loads(u.read())
for module in data_string['Modules']:
if module['CodeName'] == Import:
printAlert(0,"Downloading Module : "+Import)
d = urllib2.urlopen("https://raw.githubusercontent.com/PowerScript/rmfktf/master/"+module['Filename'])
outFile = open(module['Filename'], 'w')
outFile.writelines(d.read())
outFile.close
return module['Filename'][:-3]
printAlert(1,"Module not found or server is down\n")
exit()

ktf=ktf()
if Import:ktf.ImportModule()
else:printAlert(1,"Check your Arguments\n |Use '--i-module' for import modules\n |Use '--i-tool' for import tools\n")
if Import and isRemote:
Import=ktf.RemoteImport()
ktf.ImportModule()

elif Import :ktf.ImportModule()
else:
printAlert(1,"Check your Arguments\n |Use '--i-module' for import modules\n |Use '--i-module-remote' for import remote modules\n |Use '--i-tool' for import tools\n")

0 comments on commit 260d839

Please sign in to comment.