예제 #1
0
파일: proxy.py 프로젝트: kamijawa/kmgdgis3D
def run_kmgdgis3D():
    time.sleep(3)
    exe = os.path.join(module_path().replace('\\script', '\\bin'), 'kmgdgis3D.exe')
    if hasattr(sys, "frozen"):
        exe = os.path.join(module_path(), 'kmgdgis3D.exe')
    log('launching [%s]...' % exe)
    p = Popen(exe)
예제 #2
0
파일: proxy.py 프로젝트: kamijawa/kmgdgis3D
def modify_config_js():
    path = os.path.join(module_path(), '..', 'data', 'www', 'js', 'config.js')
    l = []
    with open(path) as f:
        for i in f.readlines():
            if len(i.strip())>14 and i.strip()[:14] == 'var g_app_root':
                root = os.path.join(module_path(), '..','data', 'www')
                root = root.replace('\\','/')
                g_app_root = 'var g_app_root = "file:///' + root + '";\r\n'
                l.append(g_app_root)
            elif len(i.strip())>20 and i.strip()[:20] == 'var g_local_tile_url':
                g_local_tile_path = 'var g_local_tile_url = "%s";\r\n' % gConfig['map_local_tiles_url']
                l.append(g_local_tile_path)
            elif "var g_default_basemap" in i:
                if len(gConfig['map_local_tiles_url'])>0:
                    l.append("var g_default_basemap = 'basemap_esrilocal';\r\n")
                else:
                    l.append("var g_default_basemap = 'basemap_googlesat';\r\n")
            elif "'basemap_esrilocal':'本地地图'," in i:
                if len(gConfig['map_local_tiles_url'])>0:
                    l.append("\t'basemap_esrilocal':'本地地图',\r\n")
                else:
                    l.append("\t//'basemap_esrilocal':'本地地图',\r\n")
            else:
                l.append(i)
                
    s = ''
    for i in l:
        s += dec(i) 
    #print(s)
    with open(path, 'w') as f:
        f.write(enc(s))
예제 #3
0
    def Activated(self):
        # So we can open the "Open File" dialog
        mw = FreeCADGui.getMainWindow()

        # Try to keep track of the previous path used to open as a convenience to the user
        if self.previousPath is None:
            # Start off defaulting to the Examples directory
            module_base_path = module_locator.module_path()
            exs_dir_path = os.path.join(module_base_path, 'Examples')

            self.previousPath = exs_dir_path

        filename = QtGui.QFileDialog.getOpenFileName(
            mw, mw.tr("Open CadQuery Script"), self.previousPath,
            mw.tr("CadQuery Files (*.py)"))

        # Make sure the user didn't click cancel
        if filename[0]:
            self.previousPath = filename[0]

            # Append this script's directory to sys.path
            sys.path.append(os.path.dirname(filename[0]))

            # We've created a library that FreeCAD can use as well to open CQ files
            ImportCQ.open(filename[0])
예제 #4
0
    def Activated(self):
        import os
        try:
            from . import module_locator
        except:
            import module_locator
        try:
            from CadQuery.CQGui import ImportCQ
        except:
            from CQGui import ImportCQ

        module_base_path = module_locator.module_path()

        import cadquery
        from PySide import QtGui, QtCore

        msg = QtGui.QApplication.translate(
            "cqCodeWidget",
            "CadQuery " + cadquery.__version__ + "\r\n"
            "CadQuery is a parametric scripting API "
            "for creating and traversing CAD models\r\n"
            "Author: David Cowden\r\n"
            "License: Apache-2.0\r\n"
            "Website: https://github.com/dcowden/cadquery\r\n",
            None)
        FreeCAD.Console.PrintMessage(msg)

        #Getting the main window will allow us to start setting things up the way we want
        mw = FreeCADGui.getMainWindow()

        dockWidgets = mw.findChildren(QtGui.QDockWidget)

        for widget in dockWidgets:
            if widget.objectName() == "Report view":
                widget.setVisible(True)
예제 #5
0
    def __init__(self, gall_url, id):
        self.gall_list = {}
        self.kGALLERY_URL = gall_url
        self.kLOCATION = id


        self.start_urls = [
            "http://gall.dcinside.com/board/view/?id=game_classic&no=6329821&page=1"
        ]

        self.app_urls = {}

        # find out current module(exeuctable) path and set to temporary download dir
        # where we'll watch
        collector_current_path = module_locator.module_path()
        temp_download_dir = os.path.join(collector_current_path, 'dn_' + id)
        if not os.path.exists(temp_download_dir):
            logging.info("make a download dir : %s", temp_download_dir)
            os.makedirs(temp_download_dir)

        self.browser_options = {}
        self.browser_options['download_folder'] = os.path.abspath(temp_download_dir)

        # option --browser firefox
        # option -c -f -???
        # on linux, firefox causes an error when clicking links with delays.
        self.web_driver = self.init_selenium_driver("chrome", self.browser_options)
예제 #6
0
    def Activated(self):
        FreeCAD.Console.PrintMessage(self.exFile + "\r\n")

        #So we can open the "Open File" dialog
        mw = FreeCADGui.getMainWindow()

        #Start off defaulting to the Examples directory
        module_base_path = module_locator.module_path()
        exs_dir_path = os.path.join(module_base_path, 'Examples')

        #We need to close any file that's already open in the editor window
        CadQueryCloseScript().Activated()

        #Append this script's directory to sys.path
        sys.path.append(os.path.dirname(exs_dir_path))

        #We've created a library that FreeCAD can use as well to open CQ files
        ImportCQ.open(os.path.join(exs_dir_path, self.exFile))

        docname = os.path.splitext(os.path.basename(self.exFile))[0]
        FreeCAD.newDocument(docname)

        #Execute the script
        CadQueryExecuteScript().Activated()

        #Get a nice view of our model
        FreeCADGui.activeDocument().activeView().viewAxometric()
        FreeCADGui.SendMsgToActiveView("ViewFit")
예제 #7
0
파일: jgui.py 프로젝트: fmcphail/jaide
 def show_help(self):
     """ Purpose: This is called when the user selects the 'Help Text' menubar option. It opens the README.html file
                  in their default browser. If the file doesn't exist it opens the github readme page instead.
     """
     # Grab the directory where the script is running.
     readme = module_path()
     # Determine our OS, attach the README.html file to the path, and open that file.
     if sys.platform.startswith('darwin'):
         readme += "/README.html"
         if os.path.isfile(readme):
             subprocess.call(('open', readme))
         else:
             try:
                 webbrowser.open('https://github.com/nprintz/jaide')
             except webbrowser.Error:
                 pass
     elif os.name == 'nt':
         readme += "\\README.html"
         if os.path.isfile(readme):
             os.startfile(readme)  # this works on windows, not sure why pylint shows an error. 
         else: 
             try:
                 webbrowser.open('https://github.com/nprintz/jaide')
             except webbrowser.Error:
                 pass
     elif os.name == 'posix':
         readme += "/README.html"
         if os.path.isfile(readme):
             subprocess.call(('xdg-open', readme))
         else: 
             try:
                 webbrowser.open('https://github.com/nprintz/jaide')
             except webbrowser.Error:
                 pass
예제 #8
0
    def __init__(self, gall_url, id):
        self.gall_list = {}
        self.kGALLERY_URL = gall_url
        self.gallery_id = id

        self.list_url = gall_url + id
        self.view_url = self.list_url

        self.app_urls = {}

        # find out current module(exeuctable) path and set to temporary download dir
        # where we'll watch
        collector_current_path = module_locator.module_path()
        temp_download_dir = os.path.join(collector_current_path, 'dn_' + id)
        if not os.path.exists(temp_download_dir):
            logging.info("make a download dir : %s", temp_download_dir)
            os.makedirs(temp_download_dir)

        self.browser_options = {}
        self.browser_options['download_folder'] = os.path.abspath(
            temp_download_dir)

        # option --browser firefox
        # option -c -f -???
        # on linux, firefox causes an error when clicking links with delays.
        self.web_driver = self.init_selenium_driver("chrome",
                                                    self.browser_options)
예제 #9
0
파일: jgui.py 프로젝트: fmcphail/jaide
 def show_examples(self):
     """ Purpose: This method opens the example folder for the user, or open the github page for the example folder. 
     """
     # Grab the directory that the script is running from. 
     examples = module_path()
     # Determin our OS, attach the README.html file to the path, and open that file.
     if sys.platform.startswith('darwin'):
         examples += "/examples/"
         if os.path.isdir(examples):
             subprocess.call(('open', examples))
         else:
             try:
                 webbrowser.open('https://github.com/nprintz/jaide/examples')
             except webbrowser.Error:
                 pass
     elif os.name == 'nt':
         examples += "\\examples\\"
         if os.path.isdir(examples):
             os.startfile(examples)  # this works on windows, not sure why pylint shows an error. 
         else: 
             try:
                 webbrowser.open('https://github.com/nprintz/jaide/examples')
             except webbrowser.Error:
                 pass
     elif os.name == 'posix':
         examples += "/examples/"
         if os.path.isdir(examples):
             subprocess.call(('xdg-open', examples))
         else: 
             try:
                 webbrowser.open('https://github.com/nprintz/jaide/examples')
             except webbrowser.Error:
                 pass
    def Activated(self):
        FreeCAD.Console.PrintMessage(self.exFile + "\r\n")

        #So we can open the "Open File" dialog
        mw = FreeCADGui.getMainWindow()

        #Start off defaulting to the Examples directory
        module_base_path = module_locator.module_path()
        exs_dir_path = os.path.join(module_base_path, 'Examples')

        #We need to close any file that's already open in the editor window
        CadQueryCloseScript().Activated()

        #Append this script's directory to sys.path
        sys.path.append(os.path.dirname(exs_dir_path))

        #We've created a library that FreeCAD can use as well to open CQ files
        ImportCQ.open(os.path.join(exs_dir_path, self.exFile))

        docname = os.path.splitext(os.path.basename(self.exFile))[0]
        FreeCAD.newDocument(docname)

        #Execute the script
        CadQueryExecuteScript().Activated()

        #Get a nice view of our model
        FreeCADGui.activeDocument().activeView().viewAxometric()
        FreeCADGui.SendMsgToActiveView("ViewFit")
예제 #11
0
    def Activated(self):
        import os
        try:
            from . import module_locator
        except:
            import module_locator
        try:
            from CadQuery.CQGui import ImportCQ
        except:
            from CQGui import ImportCQ

        module_base_path = module_locator.module_path()

        import cadquery
        from PySide import QtGui, QtCore

        msg = QtGui.QApplication.translate(
            "cqCodeWidget",
            "CadQuery " + cadquery.__version__ + "\r\n"
            "CadQuery is a parametric scripting API "
            "for creating and traversing CAD models\r\n"
            "Author: David Cowden\r\n"
            "License: Apache-2.0\r\n"
            "Website: https://github.com/dcowden/cadquery\r\n",
            None)
        FreeCAD.Console.PrintMessage(msg)

        #Getting the main window will allow us to start setting things up the way we want
        mw = FreeCADGui.getMainWindow()

        dockWidgets = mw.findChildren(QtGui.QDockWidget)

        for widget in dockWidgets:
            if widget.objectName() == "Report view":
                widget.setVisible(True)
예제 #12
0
def Arc2GeoJsonTunnel(name):
    path = os.path.join(module_path(), JSON_DIR, 'arcjson_tunnel_%s.json' % name)
    arcjson = None
    if os.path.exists(path):
        with open(path) as f:
            arcjson = json.loads(f.read())
    if arcjson:
        offsetx, offsety = CalcOffset(name)
        obj = {}
        obj['type'] = 'FeatureCollection'
        obj['features'] = []
        for feature in arcjson['features']:
            for path in feature['geometry']['paths']:
                o = {}
                o['type'] = 'Feature'
                o['properties'] = {}
                o['geometry'] = {}
                o['geometry']['type'] = 'LineString'
                o['geometry']['coordinates'] = []
                for point in path:
                    lng, lat = ToGeographic(point[0] + offsetx, point[1] + offsety)
                    o['geometry']['coordinates'].append([lng, lat])
                obj['features'].append(o)
        
        path = '%s/geojson_tunnel_%s.json' % (JSON_DIR, name)
        with open(path, 'w') as f:
            f.write(json.dumps(obj, ensure_ascii=True, indent=4) + '\n')
예제 #13
0
    def Activated(self):
        module_base_path = module_locator.module_path()
        templ_dir_path = os.path.join(module_base_path, 'Templates')

        # Use the library that FreeCAD can use as well to open CQ files
        ImportCQ.open(os.path.join(templ_dir_path, 'script_template.py'))

        FreeCAD.Console.PrintMessage("Please save this template file as another name before creating any others.\r\n")
예제 #14
0
    def Activated(self):
        module_base_path = module_locator.module_path()
        templ_dir_path = os.path.join(module_base_path, 'Templates')

        # Use the library that FreeCAD can use as well to open CQ files
        ImportCQ.open(os.path.join(templ_dir_path, 'script_template.py'))

        FreeCAD.Console.PrintMessage("Please save this template file as another name before creating any others.\r\n")
예제 #15
0
def get_backlinks(onion_url):
    """ Call backlink tester and return the number of backlinks. """
    my_path = module_locator.module_path()
    backlink_tool = my_path + "/backlinkers.py"
    args = ["python", backlink_tool, "-c", onion_url]
    proc = subprocess.Popen(args, stdout=subprocess.PIPE)
    count = int(proc.communicate()[0])
    return count
예제 #16
0
def GetDeviceList():
    ret = []
    path = os.path.join(module_path(), JSON_DIR)
    for i in os.listdir(path):
        p = os.path.join(path, i)
        if os.path.isfile(p) and 'arcjson_device_' in i:
            ret.append(i.replace('arcjson_device_', '').replace('.json', ''))
    return ret
예제 #17
0
def get_backlinks(onion_url):
    """ Call backlink tester and return the number of backlinks. """
    my_path = module_locator.module_path()
    backlink_tool = my_path + "/backlinkers.py"
    args = ["python", backlink_tool, "-c", onion_url]  # TODO: use the new backlinker spider instead?
    proc = subprocess.Popen(args, stdout=subprocess.PIPE)
    count = int(proc.communicate()[0])
    return count
def save_popularity_data(data, onion_id):
    """ Save the popularity data to """
    my_path = module_locator.module_path()
    document_dir = my_path.replace("/tools", "/popularity_stats/")
    document_dir = document_dir + datetime.datetime.now().strftime("%y-%m-%d")
    if not os.path.exists(document_dir):
        os.makedirs(document_dir)
    pretty_data = valid_pretty_json(data)
    text2file(pretty_data, document_dir + "/" + onion_id + ".json")
예제 #19
0
def main():
    """Main function."""
    my_path = module_locator.module_path()
    json_data_dir = my_path.replace("/tools", "/tor2web_stats/")
    onions_data = {}
    for filename in os.listdir(json_data_dir):
        if filename.endswith(".json"):
            json_file = json_data_dir + filename
            json_data = open(json_file)
            day_data = json.load(json_data)
            json_data.close()
            time_stamp = day_data["date"].encode("ascii", "ignore")
            for onion_data in day_data["hidden_services"]:
                onion = onion_data["id"].lower()
                access_count = int(onion_data["access_count"])
                try:
                    found = False
                    last_time_stamp = onions_data[onion]#[-1].keys()[0]
                    for o in onions_data[onion]:
                        if o.keys()[0] == time_stamp:
                            o[time_stamp] = o[time_stamp] + access_count
                            found = True
                            break
                    if not found:
                        onions_data[onion].append({time_stamp: access_count})
                except:
                    onions_data[onion] = []
                    onions_data[onion].append({time_stamp: access_count})
    static_log = my_path.replace("/tools", "/ahmia/static/log/onion_site_history/")
    onions = []

    # Filter banned domains, get the list first
    r = requests.get('https://127.0.0.1/banneddomains.txt', verify=False)
    text = r.text.encode('ascii')
    text = text.replace("http://", "")
    text = text.replace("https://", "")
    text = text.replace(".onion/", "")
    ban_list = text.split("\n")

    # Print to files
    for onion in onions_data.keys():
        data = onions_data[onion]
        # Only show those onions that have over 100 active days
        # Filter out banned domains
        if len(data) > 100 and not onion in ban_list:
            onions.append(onion)
        if not onion in ban_list:
            data = sorted(data, key=getKey)
            pretty = json.dumps(data, indent=4, ensure_ascii=False)
            file = open(static_log + onion + ".json", "w")
            file.write(pretty+"\n")
            file.close()
    onions.sort()
    pretty = json.dumps(onions, indent=4, sort_keys=True, ensure_ascii=False)
    file = open(static_log + "onions.json", "w")
    file.write(pretty+"\n")
    file.close()
    def Activated(self):
        #We need to close any file that's already open in the editor window
        CadQueryCloseScript().Activated()

        module_base_path = module_locator.module_path()
        templ_dir_path = os.path.join(module_base_path, 'Templates')

        #Use the library that FreeCAD can use as well to open CQ files
        ImportCQ.open(os.path.join(templ_dir_path, 'script_template.py'))
예제 #21
0
    def Activated(self):
        #We need to close any file that's already open in the editor window
        CadQueryCloseScript().Activated()

        module_base_path = module_locator.module_path()
        templ_dir_path = os.path.join(module_base_path, 'Templates')

        #Use the library that FreeCAD can use as well to open CQ files
        ImportCQ.open(os.path.join(templ_dir_path, 'script_template.py'))
예제 #22
0
def save_popularity_data(data, onion_id):
    """ Save the popularity data to """
    my_path = module_locator.module_path()
    document_dir = my_path.replace("/tools", "/popularity_stats/")
    document_dir = document_dir + datetime.datetime.now().strftime("%y-%m-%d")
    if not os.path.exists(document_dir):
        os.makedirs(document_dir)
    pretty_data = valid_pretty_json(data)
    text2file(pretty_data, document_dir + "/" + onion_id + ".json")
예제 #23
0
def loader(tor2web_nodes):
    """Load visited domains information from tor2web nodes."""
    my_path = module_locator.module_path()
    filename = my_path.replace("/tools", "/ahmia/static/log/")
    for node in tor2web_nodes:
        print "\n Trying download from the %s \n" % node
        md5list = get_md5list("abcd." + node)
        if md5list:
            filename = filename + node + "_md5filterlist.txt"
            text2file(md5list, filename)
예제 #24
0
def loader(tor2web_nodes):
    """Load visited domains information from tor2web nodes."""
    my_path = module_locator.module_path()
    filename = my_path.replace("/tools", "/ahmia/static/log/")
    for node in tor2web_nodes:
        print "\n Trying download from the %s \n" % node
        md5list = get_md5list("abcd." + node)
        if md5list:
            filename = filename + node + "_md5filterlist.txt"
            text2file(md5list, filename)
예제 #25
0
파일: proxy.py 프로젝트: kamijawa/kmgdgis3D
def init_tunnel_name_file():
    ret = {}
    d =  os.path.join(module_path(), DATA_DOCS_DIR)
    path = os.path.join(d, gConfig['xls_tunnel_main'])
    book = xlrd.open_workbook(path)
    sheet = book.sheet_by_name(u'隧道文件对应')
    row, col = find_boundary(sheet)
    for i in range(row+1):
        ret[sheet.cell_value(i,0)] = sheet.cell_value(i,1)
    return ret
예제 #26
0
def CalcOffset(name):
    offsetx, offsety = 0, 0
    path = os.path.join(module_path(), JSON_DIR, 'tunnel_boundry_%s.json' % name)
    boundry = None
    if os.path.exists(path):
        with open(path) as f:
            boundry = json.loads(f.read())
    if boundry:
        mercstartx, mercstarty = ToWebMercator(boundry['lnglat']['startx'], boundry['lnglat']['starty'])
        offsetx, offsety = mercstartx - boundry['dwg_mercator']['startx'], mercstarty - boundry['dwg_mercator']['starty']
    return offsetx, offsety    
예제 #27
0
def Cad2Geodatabase(dwgfile, reference_scale=2000):
    #import arcpy
    #from arcpy import env
    PRJWGS1984 = arcpy.SpatialReference("WGS 1984")
    PRJWEBMERCATOR = arcpy.SpatialReference("WGS 1984 Web Mercator (Auxiliary Sphere)")
    CreateTunnelGDB()
    ws = os.path.join(module_path(), WORKSPACE)
    if not os.path.exists(ws):
        os.mkdir(ws)
    env.workspace = ws
    
    input_cad_dataset = os.path.join(module_path(), DWG_DIR, dwgfile)
    out_tmp_gdb_path = os.path.join(ws, "tmp.gdb") 
    if not os.path.exists(out_tmp_gdb_path):
        arcpy.CreateFileGDB_management(ws, u"tmp.gdb")
    out_tmp_dataset_name = dwgfile.replace('.dwg', '')
    rs = str(reference_scale)
    #ws = '%s/tmp.gdb' % WORKSPACE
    DeleteExist(out_tmp_gdb_path, out_tmp_dataset_name)
    arcpy.CADToGeodatabase_conversion(input_cad_dataset, out_tmp_gdb_path, out_tmp_dataset_name, rs, PRJWEBMERCATOR)
예제 #28
0
def GetADBExecutablePath():
    arr = []
    if '/' in gConfig['android']['sdk_root']:
        arr = gConfig['android']['sdk_root'].split('/')
    elif '\\' in gConfig['android']['sdk_root']:
        arr = gConfig['android']['sdk_root'].split('\\')
    adb = module_path()
    if len(arr)>0:
        adb = os.path.join(adb, *arr)
    adb = os.path.join(adb, 'platform-tools', 'adb.exe')
    return adb
예제 #29
0
def main():
    """Main function."""
    my_path = module_locator.module_path()
    access_file_path = my_path.replace("/tools", "/error/access.log")
    json_pretty = analyser(access_file_path)
    filename = my_path.replace("/tools", "/ahmia/static/log/access.json")
    text2file(json_pretty, filename)
    access_file_path = my_path.replace("/tools", "/error/hs_access.log")
    json_pretty = analyser(access_file_path)
    filename = my_path.replace("/tools", "/ahmia/static/log/hs_access.json")
    text2file(json_pretty, filename)
예제 #30
0
def main():
    """Main function."""
    my_path = module_locator.module_path()
    access_file_path = my_path.replace("/tools", "/error/access.log")
    json_pretty = analyser(access_file_path)
    filename = my_path.replace("/tools", "/ahmia/static/log/access.json")
    text2file(json_pretty, filename)
    access_file_path = my_path.replace("/tools", "/error/hs_access.log")
    json_pretty = analyser(access_file_path)
    filename = my_path.replace("/tools", "/ahmia/static/log/hs_access.json")
    text2file(json_pretty, filename)
예제 #31
0
def main():
    """Main function."""
    my_path = module_locator.module_path()
    document_dir = my_path.replace("/tools", "/tor2web_stats/")
    timestamp = datetime.datetime.now().strftime("%y-%m-%d")
    timestamp = "_" + timestamp + "-"
    # Use Tor2web stats
    for filename in os.listdir(document_dir):
        if not filename.endswith(".json"):
            continue
        if timestamp in filename:
            analyser(document_dir + filename)
예제 #32
0
def main():
    """Main function."""
    my_path = module_locator.module_path()
    document_dir = my_path.replace("/tools", "/tor2web_stats/")
    timestamp = datetime.datetime.now().strftime("%y-%m-%d")
    timestamp = "_" + timestamp + "-"
    # Use Tor2web stats
    for filename in os.listdir(document_dir):
        if not filename.endswith(".json"):
            continue
        if timestamp in filename:
            analyser(document_dir+filename)
예제 #33
0
def open(filename):
    #All of the CQGui.* calls in the Python console break after opening if we don't do this
    FreeCADGui.doCommand("import FreeCADGui as CQGui")

    # Make sure that we enforce a specific version (2.7) of the Python interpreter
    ver = hex(sys.hexversion)
    interpreter = "python%s.%s" % (ver[2], ver[4])  # => 'python2.7'

    # The extra version numbers won't work on Windows
    if sys.platform.startswith('win'):
        interpreter = 'python'

    # Set up so that we can import from our embedded packages
    module_base_path = module_locator.module_path()
    libs_dir_path = os.path.join(module_base_path, 'Libs')

    # Make sure we get the right libs under the FreeCAD installation
    fc_base_path = os.path.dirname(os.path.dirname(module_base_path))
    fc_lib_path = os.path.join(fc_base_path, 'lib')

    #Getting the main window will allow us to find the children we need to work with
    mw = FreeCADGui.getMainWindow()

    # Grab just the file name from the path/file that's being executed
    docname = os.path.basename(filename)

    # Pull the font size from the FreeCAD-stored settings
    fontSize = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/cadquery-freecad-module").GetInt("fontSize")

    # Set up the code editor
    codePane = CodeEditor()
    codePane.setFont(QtGui.QFont('SansSerif', fontSize))
    codePane.setObjectName("cqCodePane_" + os.path.splitext(os.path.basename(filename))[0])

    mdi = mw.findChild(QtGui.QMdiArea)
    # add a code editor widget to the mdi area
    sub = mdi.addSubWindow(codePane)
    sub.setWindowTitle(docname)
    sub.setWindowIcon(QtGui.QIcon(':/icons/applications-python.svg'))
    sub.show()
    mw.update()

    #Pull the text of the CQ script file into our code pane
    codePane.open(filename)

    msg = QtGui.QApplication.translate(
            "cqCodeWidget",
            "Opened ",
            None)
    FreeCAD.Console.PrintMessage(msg + filename + "\r\n")

    return
예제 #34
0
    def __init__(self, output_dir, tmp_dir, resources_dir, argv):
        self.output_dir = output_dir
        self.tmp_dir = tmp_dir
        self.resources_dir = resources_dir

        program_settings = Settings()
        program_path = module_locator.module_path()
        program_settings.load_settings(
            "%s/%s/%s" % (program_path, "Resources", "settings.ini"))

        self.application_name = program_settings.read_setting(
            "application_name")
        self.php_version = program_settings.read_setting("php_version")
예제 #35
0
    def ListExamples():
        import os
        import module_locator

        dirs = []

        # List all of the example files in an order that makes sense
        module_base_path = module_locator.module_path()
        exs_dir_path = os.path.join(module_base_path, 'Examples')
        dirs = os.listdir(exs_dir_path)
        dirs.sort()

        return dirs
예제 #36
0
def Arc2GeoJsonDevice(name):
    path = os.path.join(module_path(), JSON_DIR, 'arcjson_device_%s.json' % name)
    arcjson = None
    if os.path.exists(path):
        with open(path) as f:
            arcjson = json.loads(f.read())
    if arcjson:
        offsetx, offsety = CalcOffset(name)
        obj = {}
        for feature in arcjson['features']:
            typ = feature['attributes']['type']
            if not obj.has_key(typ):
                obj[typ] = {}
                obj[typ]['type'] = 'FeatureCollection'
                obj[typ]['features'] = []
                
            o = {}
            o['type'] = 'Feature'
            NAME = feature['attributes']['type']
            if NAME is None:
                NAME = ''
            id = feature['attributes']['id']
            if id is None:
                id = ''
            o['properties'] = {'NAME': NAME + id}
            o['geometry'] = {}
            o['geometry']['type'] = 'Point'
            lng, lat = ToGeographic(feature['geometry']['x'] + offsetx, feature['geometry']['y'] + offsety)
            o['geometry']['coordinates'] = [lng, lat]
            obj[typ]['features'].append(o)
        
        for k in obj.keys():
            code = GetDeviceCode(k)
            if code:
                path = os.path.join(module_path(), JSON_DIR, 'geojson_%s_%s.json' % (code, name))
                print(enc1(os.path.basename(path)))
                with open(path, 'w') as f:
                    f.write(json.dumps(obj[k], ensure_ascii=True, indent=4) + '\n')
예제 #37
0
def HandleDevicesReinstall(devices, pipe):
    s = ''
    for i in devices:
        VirtualDeviceWarning(i, pipe)
        s += '[%s]' % i
    if pipe:pipe.send({'type':'notify','title':u'检测到有设备连接到本机', 'message':u'检测到以下[%d]个设备:%s' % (len(devices), s), 'show':3, })
    adb = GetADBExecutablePath()
    adb = '"%s"' % adb
    apkpath = os.path.join(module_path(), 'kmgdgis_mobile_android-release.apk')
    for i in devices:
        cmd = '%s -s "%s" shell pm uninstall com.kmgdgis.mobile' % (adb, i)
        RunCmd(pipe, cmd)
        cmd = '%s -s "%s" install -l "%s"' % (adb, i, apkpath)
        RunCmd(pipe, cmd)
예제 #38
0
    def Activated(self):
        FreeCAD.Console.PrintMessage(self.exFile + "\r\n")

        # So we can open the "Open File" dialog
        mw = FreeCADGui.getMainWindow()

        # Start off defaulting to the Examples directory
        module_base_path = module_locator.module_path()
        exs_dir_path = os.path.join(module_base_path, 'Libs/cadquery/examples/FreeCAD')

        # Append this script's directory to sys.path
        sys.path.append(os.path.dirname(exs_dir_path))

        # We've created a library that FreeCAD can use as well to open CQ files
        ImportCQ.open(os.path.join(exs_dir_path, self.exFile))
예제 #39
0
    def Activated(self):
        FreeCAD.Console.PrintMessage(self.exFile + "\r\n")

        # So we can open the "Open File" dialog
        mw = FreeCADGui.getMainWindow()

        # Start off defaulting to the Examples directory
        module_base_path = module_locator.module_path()
        exs_dir_path = os.path.join(module_base_path, 'Libs/cadquery/examples/FreeCAD')

        # Append this script's directory to sys.path
        sys.path.append(os.path.dirname(exs_dir_path))

        # We've created a library that FreeCAD can use as well to open CQ files
        ImportCQ.open(os.path.join(exs_dir_path, self.exFile))
예제 #40
0
def get_epub_info(fname, _filename):

    try:
        ns = {
            'n':'urn:oasis:names:tc:opendocument:xmlns:container',
            'pkg':'http://www.idpf.org/2007/opf',
            'dc':'http://purl.org/dc/elements/1.1/'
        }

        # prepare to read from the .epub file
        zip = zipfile.ZipFile(fname)

        # find the contents metafile
        txt = zip.read('META-INF/container.xml')
        tree = etree.fromstring(txt)
        cfname = tree.xpath('n:rootfiles/n:rootfile/@full-path',namespaces=ns)[0]


        # grab the metadata block from the contents metafile
        cf = zip.read(cfname)
        tree = etree.fromstring(cf)
        p = tree.xpath('/pkg:package/pkg:metadata',namespaces=ns)[0]

        # repackage the data
        res = {}
        for s in ['title','language','creator','date','identifier']:
            res[s] = p.xpath('dc:%s/text()'%(s),namespaces=ns)[0]


        # Save cover in tmp folder
        for member in zip.namelist():
            filename = os.path.basename(member)
            # skip directories
            if not filename:
                continue

            res['cover-path'] = cover_source_path = os.path.abspath(os.path.join(module_path(), os.pardir)) + os.sep + "tmp" + os.sep + _filename + "_cover"

            if filename.lower() == "cover.png":
                # copy file (taken from zipfile's extract)
                source = zip.open(member)
                target = file(cover_source_path, "wb")
                with source, target:
                    shutil.copyfileobj(source, target)
    except Exception as ex:
        return None

    return res
예제 #41
0
    def ListExamples():
        import os
        try:
            from . import module_locator
        except:
            import module_locator

        dirs = []

        # List all of the example files in an order that makes sense
        module_base_path = module_locator.module_path()
        exs_dir_path = os.path.join(module_base_path, 'Libs/cadquery/examples/FreeCAD')
        dirs = os.listdir(exs_dir_path)
        dirs.sort()

        return dirs
예제 #42
0
    def ListExamples():
        import os
        try:
            from . import module_locator
        except:
            import module_locator

        dirs = []

        # List all of the example files in an order that makes sense
        module_base_path = module_locator.module_path()
        exs_dir_path = os.path.join(module_base_path, 'Libs/cadquery/examples/FreeCAD')
        dirs = os.listdir(exs_dir_path)
        dirs.sort()

        return dirs
예제 #43
0
파일: ankiAdd.py 프로젝트: Blargian/ankiAdd
def clearSpace():

    json_pattern = "word_data.json"
    main_script_path = module_locator.module_path()
    file_pattern = os.path.join(main_script_path, json_pattern)
    audio_directory = os.path.join(os.path.dirname(file_pattern),
                                   'audio\\').strip()
    image_directory = os.path.join(os.path.dirname(file_pattern),
                                   'images\\').strip()
    print(image_directory)
    print(os.path.exists(image_directory))
    if os.path.exists(image_directory):
        shutil.rmtree(image_directory, ignore_errors=True)
        print('initialised')
    if os.path.exists(audio_directory):
        shutil.rmtree(audio_directory, ignore_errors=True)
        print('initialised')
예제 #44
0
def main(argv):
    profitfile = ''
    offerfile = ''
    directory = module_locator.module_path()
    try:
        opts, args = getopt.getopt(argv, "hp:o:", ["pfile=", "ofile="])
    except getopt.GetoptError:
        print 'offers_evolution.py -p <profitfile> -o <offerfile>'
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print 'offers_evolution.py -p <profitfile> -o <offerfile>'
            sys.exit()
        elif opt in ("-p", "--pfile"):
            profitfile = arg
        elif opt in ("-o", "--ofile"):
            offerfile = arg
    if ((isBlank(profitfile) == False) and (isBlank(offerfile) == False)):
        generate_figure(directory, profitfile, offerfile)
    print 'Profit file is "', profitfile
    print 'Offer file is "', offerfile
예제 #45
0
def main(argv):
    inputfile = ''
    outputfile = ''
    directory = module_locator.module_path()
    try:
        opts, args = getopt.getopt(argv, "hi:o:", ["ifile=", "ofile="])
    except getopt.GetoptError:
        print 'offers_evolution.py -i <inputfile> -o <outputfile>'
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print 'offers_evolution.py -i <inputfile> -o <outputfile>'
            sys.exit()
        elif opt in ("-i", "--ifile"):
            inputfile = arg
        elif opt in ("-o", "--ofile"):
            outputfile = arg
    if ((isBlank(inputfile) == False) and (isBlank(outputfile) == False)):
        generate_figure(directory, inputfile, outputfile)
    print 'Input file is "', inputfile
    print 'Output file is "', outputfile
def main(argv):
    inputfile = ''
    outputfile = ''
    directory = module_locator.module_path()
    try:
        opts, args = getopt.getopt(argv,"hi:o:",["ifile=","ofile="])
    except getopt.GetoptError:
        print 'offers_evolution.py -i <inputfile> -o <outputfile>'
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print 'offers_evolution.py -i <inputfile> -o <outputfile>'
            sys.exit()
        elif opt in ("-i", "--ifile"):
            inputfile = arg
        elif opt in ("-o", "--ofile"):
            outputfile = arg
    if ((isBlank(inputfile) == False) 
            and (isBlank(outputfile) == False)):
        generate_figure(directory, inputfile, outputfile)
    print 'Input file is "', inputfile
    print 'Output file is "', outputfile
def main(argv):
    profitfile = ''
    offerfile = ''
    directory = module_locator.module_path()
    try:
        opts, args = getopt.getopt(argv,"hp:o:",["pfile=","ofile="])
    except getopt.GetoptError:
        print 'offers_evolution.py -p <profitfile> -o <offerfile>'
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print 'offers_evolution.py -p <profitfile> -o <offerfile>'
            sys.exit()
        elif opt in ("-p", "--pfile"):
            profitfile = arg
        elif opt in ("-o", "--ofile"):
            offerfile = arg
    if ((isBlank(profitfile) == False) 
            and (isBlank(offerfile) == False)):
        generate_figure(directory, profitfile, offerfile)
    print 'Profit file is "', profitfile
    print 'Offer file is "', offerfile
예제 #48
0
    def Activated(self):
        #So we can open the "Open File" dialog
        mw = FreeCADGui.getMainWindow()

        #Try to keep track of the previous path used to open as a convenience to the user
        if self.previousPath is None:
            #Start off defaulting to the Examples directory
            module_base_path = module_locator.module_path()
            exs_dir_path = os.path.join(module_base_path, 'Examples')

            self.previousPath = exs_dir_path

        filename = QtGui.QFileDialog.getOpenFileName(
            mw, mw.tr("Open CadQuery Script"), self.previousPath,
            mw.tr("CadQuery Files (*.py)"))

        #Make sure the user didn't click cancel
        if filename[0]:
            #We need to close any file that's already open in the editor window
            CadQueryCloseScript().Activated()

            self.previousPath = filename[0]

            #Append this script's directory to sys.path
            sys.path.append(os.path.dirname(filename[0]))

            #We've created a library that FreeCAD can use as well to open CQ files
            ImportCQ.open(filename[0])

            docname = os.path.splitext(os.path.basename(filename[0]))[0]
            FreeCAD.newDocument(docname)

            #Execute the script
            CadQueryExecuteScript().Activated()

            #Get a nice view of our model
            FreeCADGui.activeDocument().activeView().viewAxometric()
            FreeCADGui.SendMsgToActiveView("ViewFit")
예제 #49
0
    def Activated(self):
        # So we can open the "Open File" dialog
        mw = FreeCADGui.getMainWindow()

        # Try to keep track of the previous path used to open as a convenience to the user
        if self.previousPath is None:
            # Start off defaulting to the Examples directory
            module_base_path = module_locator.module_path()
            exs_dir_path = os.path.join(module_base_path, "Examples")

            self.previousPath = exs_dir_path

        filename = QtGui.QFileDialog.getOpenFileName(
            mw, mw.tr("Open CadQuery Script"), self.previousPath, mw.tr("CadQuery Files (*.py)")
        )

        # Make sure the user didn't click cancel
        if filename[0]:
            # We need to close any file that's already open in the editor window
            CadQueryCloseScript().Activated()

            self.previousPath = filename[0]

            # Append this script's directory to sys.path
            sys.path.append(os.path.dirname(filename[0]))

            # We've created a library that FreeCAD can use as well to open CQ files
            ImportCQ.open(filename[0])

            docname = os.path.splitext(os.path.basename(filename[0]))[0]
            FreeCAD.newDocument(docname)

            # Execute the script
            CadQueryExecuteScript().Activated()

            # Get a nice view of our model
            FreeCADGui.activeDocument().activeView().viewAxometric()
            FreeCADGui.SendMsgToActiveView("ViewFit")
예제 #50
0
"""FreeCAD init script of the CadQuery module"""
# (c) 2014-2016 Jeremy Wright Apache 2.0 License

#TODO: The FreeCAD devs like to put as much init code as possible in here so that the module can be used without the
#TODO: GUI if desired

import os
import sys
import module_locator

# Set up so that we can import from our embedded packages
module_base_path = module_locator.module_path()
libs_dir_path = os.path.join(module_base_path, 'Libs')
sys.path.insert(0, libs_dir_path)

# Tack on our CadQuery library git subtree
cq_lib_path = os.path.join(libs_dir_path, 'cadquery-lib')
sys.path.insert(1, cq_lib_path)

# Make sure we get the right libs under the FreeCAD installation
fc_base_path = os.path.dirname(os.path.dirname(module_base_path))
fc_lib_path = os.path.join(fc_base_path, 'lib')
fc_bin_path = os.path.join(fc_base_path, 'bin')

# Make sure that the directories exist before we add them to sys.path
# This could cause problems or solve them by overriding what CQ is setting for the paths
if os.path.exists(fc_lib_path):
    sys.path.insert(1, fc_lib_path)
if os.path.exists(fc_bin_path):
    sys.path.insert(1, fc_bin_path)
예제 #51
0
    def Activated(self):
        import os, sys
        import module_locator
        from Gui import Command, ImportCQ
        import Settings

        #Set up so that we can import from our embedded packages
        module_base_path = module_locator.module_path()
        libs_dir_path = os.path.join(module_base_path, 'Libs')
        sys.path.insert(0, libs_dir_path)

        #Make sure we get the right libs under the FreeCAD installation
        fc_base_path = os.path.dirname(os.path.dirname(module_base_path))
        fc_lib_path = os.path.join(fc_base_path, 'lib')
        fc_bin_path = os.path.join(fc_base_path, 'bin')

        #Make sure that the directories exist before we add them to sys.path
        #This could cause problems or solve them by overriding what CQ is setting for the paths
        if os.path.exists(fc_lib_path):
            sys.path.insert(1, fc_lib_path)
        if os.path.exists(fc_bin_path):
            sys.path.insert(1, fc_bin_path)

        import cadquery
        from pyqode.core.modes import FileWatcherMode
        from pyqode.python.widgets import PyCodeEdit
        from PySide import QtGui, QtCore

        msg = QtGui.QApplication.translate(
            "cqCodeWidget",
            "CadQuery " + cadquery.__version__ + "\r\n"
            "CadQuery is a parametric scripting language "
            "for creating and traversing CAD models\r\n"
            "Author: David Cowden\r\n"
            "License: LGPL\r\n"
            "Website: https://github.com/dcowden/cadquery\r\n",
            None,
            QtGui.QApplication.UnicodeUTF8)
        FreeCAD.Console.PrintMessage(msg)

        #Make sure that we enforce a specific version (2.7) of the Python interpreter
        ver = hex(sys.hexversion)
        interpreter = "python%s.%s" % (ver[2], ver[4])  # => 'python2.7'

        #If the user doesn't have Python 2.7, warn them
        if interpreter != 'python2.7':
            msg = QtGui.QApplication.translate(
                "cqCodeWidget",
                "Please install Python 2.7",
                None,
                QtGui.QApplication.UnicodeUTF8)
            FreeCAD.Console.PrintError("\r\n" + msg)

        #The extra version numbers won't work on Windows
        if sys.platform.startswith('win'):
            interpreter = 'python'

        #Getting the main window will allow us to start setting things up the way we want
        mw = FreeCADGui.getMainWindow()

        # TODO: Fix the extra newline foolishness with the output in the report view

        dockWidgets = mw.findChildren(QtGui.QDockWidget)

        for widget in dockWidgets:
            if widget.objectName() == "Report view":
                widget.setVisible(True)

        #Add a new widget here that's a simple text area to begin with. It will become the CQ coding area
        cqCodeWidget = QtGui.QDockWidget("CadQuery Code View")
        cqCodeWidget.setObjectName("cqCodeView")
        mw.addDockWidget(QtCore.Qt.LeftDockWidgetArea, cqCodeWidget)

        #Set up the text area for our CQ code
        server_path = os.path.join(module_base_path, 'cq_server.py')

        #Windows needs some extra help with paths
        if sys.platform.startswith('win'):
            codePane = PyCodeEdit(server_script=server_path, interpreter=interpreter
                                  , args=['-s', fc_lib_path, libs_dir_path])
        else:
            codePane = PyCodeEdit(server_script=server_path, interpreter=interpreter
                                  , args=['-s', libs_dir_path])

        # Allow easy use of an external editor
        if Settings.use_external_editor:
            codePane.modes.append(FileWatcherMode())
            codePane.modes.get(FileWatcherMode).file_reloaded.connect(self.AutoExecute)
            codePane.modes.get(FileWatcherMode).auto_reload = True

        codePane.setObjectName("cqCodePane")

        #Add the text area to our dock widget
        cqCodeWidget.setWidget(codePane)

        #Set up the paths to allow us to open and execute our introduction example
        example_path = os.path.join(module_base_path, 'Examples')
        example_path = os.path.join(example_path, 'Ex000_Introduction.py')

        # TODO: Enable this for FreeCAD 0.16 or greater
        # Make sure we get the correct MdiArea object
        # for child in mw.children():
        #     if child.__class__ == QtGui.QMdiArea:
        #         mdiArea = child
        #
        # # Set up the editor in a new subwindow
        # #sub_window = QtGui.QMdiSubWindow(mw.centralWidget())
        # sub_window = QtGui.QMdiSubWindow(mdiArea)
        # #sub_window.setWidget(codePane)
        # sub_window.setWidget(QtGui.QPlainTextEdit())
        # sub_window.setWindowTitle('Ex000_Introduction.py')
        # sub_window.setWindowIcon(QtGui.QIcon(':/icons/applications-python.svg'))
        #
        # #mw.centralWidget().addSubWindow(sub_window)
        # mdiArea.addSubWindow(sub_window)

        ImportCQ.open(example_path)
        docname = os.path.splitext(os.path.basename(example_path))[0]
        FreeCAD.newDocument(docname)
        Command.CadQueryExecuteScript().Activated()

        #Get a nice view of our example
        FreeCADGui.activeDocument().activeView().viewAxometric()
        FreeCADGui.SendMsgToActiveView("ViewFit")
예제 #52
0
def main(args, g_params):
    parser = argparse.ArgumentParser(
        description='TOPCONS2_OCTOPUS workflow master script',
        formatter_class=argparse.RawDescriptionHelpFormatter,
        epilog='''\
Created 2015-05-05, updated 2018-02-16, Peters Christoph and Nanjiang Shu

Examples:
''')
    parser.add_argument(
        'inFile',
        metavar='inFile',
        help='Specify the input amino acid sequence file in FASTA format')
    parser.add_argument('out_path',
                        metavar='out_path',
                        help='Specify the outpath for result')
    parser.add_argument(
        'blastDir',
        metavar='blastDir',
        help='Specify the path for psiblast, which contains bin/blastpgp')
    parser.add_argument(
        'blastDB',
        metavar='blastDB',
        help='Specify the name of the blastdb, including the path')
    parser.add_argument(
        '-tmpdir',
        '--tmpdir',
        metavar='DIR',
        dest='TMPPATH',
        help=
        'Specify the directory where the temporary files will be written to')
    parser.add_argument('-debug',
                        '--debug',
                        action='store_true',
                        default=False,
                        dest='isDEBUG',
                        help='Output debug info')
    parser.add_argument('-RM',
                        '--remove-individual-files',
                        action='store_true',
                        default=False,
                        dest='isRemoveFile',
                        help='Delete result for individual sequences')

    args = parser.parse_args()

    g_params['DEBUG'] = args.isDEBUG
    g_params['REMOVE_IND_FILES'] = args.isRemoveFile
    inFile = os.path.abspath(args.inFile)
    out_path = os.path.abspath(args.out_path)
    blastDir = os.path.abspath(args.blastDir)
    blastDB = os.path.abspath(args.blastDB)
    if args.TMPPATH != None:
        g_params['TMPPATH'] = os.path.abspath(args.TMPPATH)

    if not os.access(g_params['TMPPATH'], os.W_OK):
        print >> sys.stderr, "Error. TMPPATH '%s' not writable. Exit." % (
            g_params['TMPPATH'])
        return 1
    if not os.access(out_path, os.W_OK):
        print >> sys.stderr, "Error. out_path '%s' not writable. Exit." % (
            out_path)
        return 1

    os.environ['TMPPATH'] = g_params['TMPPATH']

    DEBUG = g_params['DEBUG']
    TMPPATH = g_params['TMPPATH']
    if not os.path.exists(inFile):
        print >> sys.stderr, "inFile %s does not exist. Exit." % (inFile)
        sys.exit(1)
    if not os.path.exists(out_path):
        try:
            os.makedirs(out_path)
        except OSError:
            print >> sys.stderr, "Failed to create out_path %s. Exit." % (
                out_path)
            sys.exit(1)

    if not "BLASTDB" in os.environ:  # this fixed the warning message of unset 'BLASTDB'
        try:
            blastdbpath = os.path.realpath(os.path.dirname(blastDB))
            os.environ['BLASTDB'] = blastdbpath
        except:
            pass

    # Set the working dir to the script location
    my_path = module_locator.module_path()
    os.chdir(my_path)
    inFile_rootname = os.path.basename(os.path.splitext(inFile)[0])

    # Timing remove from final version
    #print "Timing remove from final version"
    timingfile = "%s/%s" % (out_path, "time.txt")
    topfile_OCTOPUS = "%s/%s.OCTOPUS.topfa" % (out_path, inFile_rootname)
    topfile_SPOCTOPUS = "%s/%s.SPOCTOPUS.topfa" % (out_path, inFile_rootname)
    fpout_OCTOPUS = open(topfile_OCTOPUS, "w")
    fpout_SPOCTOPUS = open(topfile_SPOCTOPUS, "w")
    with open(timingfile, "w") as timingFileOut:
        with open(inFile, "rU") as seqFile:
            for index, entry in enumerate(list(SeqIO.parse(seqFile, "fasta"))):
                # Timing remove from final version
                #                 print "Timing remove from final version"
                start = time.time()

                #Create folders for tmp data and output
                used_pfam = "pfam"
                tmpDir = tempfile.mkdtemp(prefix="%s/seq_" %
                                          (TMPPATH) + str(index) + "_") + "/"
                os.chmod(tmpDir, 0755)
                tmpDir_pfam = tmpDir
                tmpDir_cdd = ""
                tmpDir_uniref = ""

                protnamefile = "%s/query.fa.txt" % (tmpDir)
                try:
                    fpout = open(protnamefile, "w")
                    print >> fpout, "query"
                    fpout.close()
                except IOError:
                    print >> sys.stderr, "Failed to write to protnamefile %s. "\
                            "Exit."%(protnamefile)
                    sys.exit(1)

                outDir = "%s%s%s/" % (out_path, os.sep, "seq_%d" % (index))
                if os.path.exists(tmpDir) is False:
                    os.mkdir(tmpDir)

                if os.path.exists(outDir) is False:
                    os.mkdir(outDir)


#                 if os.path.exists(outDir + "Topcons/") is False:
#                     os.mkdir(outDir + "Topcons/")

#                 outfile = "%s/%s"%(tmpDir, "query.fa")
                with open(tmpDir + "query.fa", "w") as outFile:
                    outFile.write(">query" + "\n" + str(entry.seq))

                with open(outDir + "seq.fa", "w") as outFile:
                    outFile.write(">query" + "\n" + str(entry.seq))

                startDir = os.getcwd()

                # At the same time the profiles can be created
                cmd = ["./fa2prfs_pfamscan_v2.sh", tmpDir_pfam, blastDir]
                cmdline = " ".join(cmd)
                rmsg = ""
                try:
                    print "cmdline: ", cmdline
                    rmsg = subprocess.check_call(cmd, stderr=subprocess.STDOUT)
                except subprocess.CalledProcessError, e:
                    print "errmsg:", e
                    print "rmsg:", rmsg
                    pass
                query_seqdbfile = "%s/%s" % (tmpDir_pfam, "query.hits.db")
                filesize = 0
                try:
                    filesize = os.path.getsize(query_seqdbfile)
                except OSError:
                    filesize = -1
                    pass
                if DEBUG:
                    print "After fa2prfs_pfamscan_v2.sh filesize(%s)=%d" % (
                        query_seqdbfile, filesize)

                # In case we do not find a hit, we have to run hmmscan on the cdd database
                if filesize <= 0:
                    tmpDir_cdd = tempfile.mkdtemp(prefix="%s/seq_cdd_" %
                                                  (TMPPATH) + str(index) +
                                                  "_") + "/"
                    os.chmod(tmpDir_cdd, 0755)
                    with open(tmpDir_cdd + "query.fa", "w") as outFile:
                        outFile.write(">query" + "\n" + str(entry.seq))
                    used_pfam = "cdd"
                    cmd = ["./fa2prfs_hmmscan.sh", tmpDir_cdd, blastDir]
                    cmdline = " ".join(cmd)
                    try:
                        print "\ncmdline:", cmdline
                        rmsg = subprocess.check_call(cmd,
                                                     stderr=subprocess.STDOUT)
                    except subprocess.CalledProcessError, e:
                        print "errmsg:", e
                        print "rmsg:", rmsg
                        pass

                    tmpDir = tmpDir_cdd

                    query_seqdbfile = "%s/%s" % (tmpDir_cdd, "query.hits.db")
                    try:
                        filesize = os.path.getsize(query_seqdbfile)
                    except OSError:
                        filesize = -1
                        pass

                    if DEBUG:
                        print "After fa2prfs_hmmscan.sh filesize(%s)=%d" % (
                            query_seqdbfile, filesize)
                # In case we do not find a hit, we have to run the old script
                if filesize <= 0:
                    tmpDir_uniref = tempfile.mkdtemp(prefix="%s/seq_uniref_" %
                                                     (TMPPATH) + str(index) +
                                                     "_") + "/"
                    os.chmod(tmpDir_uniref, 0755)
                    with open(tmpDir_uniref + "query.fa", "w") as outFile:
                        outFile.write(">query" + "\n" + str(entry.seq))
                    used_pfam = "uniref"
                    cmd = [
                        "./fa2prfs_fallback_v2.sh", tmpDir_uniref, blastDir,
                        blastDB
                    ]
                    cmdline = " ".join(cmd)
                    try:
                        print "\ncmdline:", cmdline
                        rmsg = subprocess.check_call(cmd,
                                                     stderr=subprocess.STDOUT)
                    except subprocess.CalledProcessError, e:
                        print e
                        print rmsg
                        pass
                    tmpDir = tmpDir_uniref

                    query_seqdbfile = "%s/%s" % (tmpDir_uniref,
                                                 "query.hits.db")
                    try:
                        filesize = os.path.getsize(query_seqdbfile)
                    except OSError:
                        filesize = -1
                        pass

                    if DEBUG:
                        print "After fa2prfs_fallback_v2.sh filesize(%s)=%d" % (
                            query_seqdbfile, filesize)

                # Once the profile is created start all other predictors

                os.chdir(os.path.abspath("../predictors/spoctopus/"))
                outDir_SPOCTOPUS = outDir + os.sep + "SPOCTOPUS"
                if not os.path.exists(outDir_SPOCTOPUS):
                    os.makedirs(outDir_SPOCTOPUS)
                cmd = [
                    "./SPOCTOPUS.sh", protnamefile, tmpDir + "PSSM_PRF_FILES/",
                    tmpDir + "RAW_PRF_FILES/", outDir_SPOCTOPUS, "-N"
                ]  #output also the ANN result for SPOCTOPUS, changed 2016-01-26
                cmdline = " ".join(cmd)
                if DEBUG:
                    print "cmdline:", cmdline
                p_spoctopus = subprocess.Popen(cmd)
                os.chdir(startDir)

                os.chdir(os.path.abspath("../predictors/spoctopus/"))
                outDir_OCTOPUS = outDir + os.sep + "OCTOPUS"
                if not os.path.exists(outDir_OCTOPUS):
                    os.makedirs(outDir_OCTOPUS)
                cmd = [
                    "./OCTOPUS.sh", protnamefile, tmpDir + "PSSM_PRF_FILES/",
                    tmpDir + "RAW_PRF_FILES/", outDir_OCTOPUS, "-N"
                ]  #output also the ANN result for OCTOPUS, changed 2016-01-26
                cmdline = " ".join(cmd)
                if DEBUG:
                    print "cmdline:", cmdline

                p_octopus = subprocess.Popen(cmd)
                os.chdir(startDir)

                p_spoctopus.communicate()  #now wait for OCTOPUS
                p_octopus.communicate()  #now wait for SPOCTOPUS
                count_pred = 2

                end = time.time()
                lines = 0
                with open(tmpDir + "query.hits.db") as inFile:
                    for line in inFile:
                        if line.find(">") == -1:
                            lines += 1
                timingFileOut.write(
                    str(entry.id) + ";" + str(end - start) + ";" + used_pfam +
                    ";" + str(lines) + ";" + str(count_pred) + "\n")
                #Remove the tmpFolder

                if not DEBUG:  #debugging
                    if os.path.exists(tmpDir) is True:
                        p = subprocess.call(["rm", "-rf", tmpDir])
                    if os.path.exists(tmpDir_cdd) is True:
                        p = subprocess.call(["rm", "-rf", tmpDir_cdd])
                    if os.path.exists(tmpDir_uniref) is True:
                        p = subprocess.call(["rm", "-rf", tmpDir_uniref])
                    if os.path.exists(tmpDir_pfam) is True:
                        p = subprocess.call(["rm", "-rf", tmpDir_pfam])
                else:
                    print "tmpDir=%s" % (tmpDir)

                p = subprocess.call(["python", "correct_Topo.py", outDir])

                topfile = "%s/%s/%s" % (outDir, "OCTOPUS", "query.top")
                if os.path.exists(topfile):
                    top = myfunc.ReadFile(topfile).strip()
                    if top:
                        fpout_OCTOPUS.write(">%s\n" % (entry.description))
                        fpout_OCTOPUS.write("%s\n" % (top))

                topfile = "%s/%s/%s" % (outDir, "SPOCTOPUS", "query.top")
                if os.path.exists(topfile):
                    top = myfunc.ReadFile(topfile).strip()
                    if top:
                        fpout_SPOCTOPUS.write(">%s\n" % (entry.description))
                        fpout_SPOCTOPUS.write("%s\n" % (top))

                if g_params['REMOVE_IND_FILES']:
                    shutil.rmtree(outDir)
예제 #53
0
    def Activated(self):
        module_base_path = module_locator.module_path()
        templ_dir_path = os.path.join(module_base_path, 'Templates')

        # Use the library that FreeCAD can use as well to open CQ files
        ImportCQ.open(os.path.join(templ_dir_path, 'script_template.py'))
예제 #54
0
def main(args, g_params):
    parser = argparse.ArgumentParser(
            description='TOPCONS2 workflow master script',
            formatter_class=argparse.RawDescriptionHelpFormatter,
            epilog='''\
Created 2015-05-05, updated 2017-12-11, Peters Christoph and Nanjiang Shu

Examples:
''')
    parser.add_argument('inFile', metavar='inFile',
            help='Specify the input amino acid sequence file in FASTA format')
    parser.add_argument('out_path', metavar='out_path',
            help='Specify the outpath for result')
    parser.add_argument('blastDir', metavar='blastDir',
            help='Specify the path for psiblast, which contains bin/blastpgp')
    parser.add_argument('blastDB', metavar='blastDB',
            help='Specify the name of the blastdb, including the path')
    parser.add_argument('-tmpdir', '--tmpdir', metavar='DIR', dest='TMPPATH', 
            help='Specify the directory where the temporary files will be written to')
    parser.add_argument('-debug', '--debug', action='store_true', default=False,  dest='isDEBUG', 
            help='Output debug info')
    parser.add_argument('-plot','--plot', action='store', dest='isPlot', default='yes',
            choices=['yes', 'no'], help='Whether output figure (default = yes)' )


    args = parser.parse_args()

    g_params['DEBUG'] = args.isDEBUG
    inFile = os.path.abspath(args.inFile)
    out_path = os.path.abspath(args.out_path)
    blastDir = os.path.abspath(args.blastDir)
    blastDB = os.path.abspath(args.blastDB)
    g_params['isPlot'] = args.isPlot
    if args.TMPPATH != None:
        g_params['TMPPATH'] = os.path.abspath(args.TMPPATH)

    if not os.access(g_params['TMPPATH'], os.W_OK):
        print >> sys.stderr, "Error. TMPPATH '%s' not writable. Exit."%(g_params['TMPPATH'])
        return 1
    if not os.access(out_path, os.W_OK):
        print >> sys.stderr, "Error. out_path '%s' not writable. Exit."%(out_path)
        return 1

    os.environ['TMPPATH'] = g_params['TMPPATH']

    DEBUG = g_params['DEBUG']
    if not os.path.exists(inFile):
        print >> sys.stderr, "inFile %s does not exist. Exit."%(inFile)
        sys.exit(1)
    if not os.path.exists(out_path):
        try:
            os.makedirs(out_path)
        except OSError:
            print >> sys.stderr, "Failed to create out_path %s. Exit."%(out_path)
            sys.exit(1)

    if not "BLASTDB" in os.environ: # this fixed the warning message of unset 'BLASTDB'
        try:
            blastdbpath = os.path.realpath(os.path.dirname(blastDB))
            os.environ['BLASTDB'] = blastdbpath
        except:
            pass

    # Set the working dir to the script location
    my_path = module_locator.module_path()
    os.chdir(my_path)

    # Timing remove from final version
    #print "Timing remove from final version"
    timingfile = "%s/%s"%(out_path, "time.txt")
    with open(timingfile, "w") as timingFileOut:
        with open(inFile, "rU") as seqFile:
            for index, entry in enumerate(list(SeqIO.parse(seqFile, "fasta"))):
                # Timing remove from final version
#                 print "Timing remove from final version"
                start = time.time()


                #Create folders for tmp data and output
                used_pfam = "pfam"
                tmpDir = tempfile.mkdtemp(prefix="%s/seq_"%(g_params['TMPPATH']) + str(index) + "_") + "/"
                os.chmod(tmpDir, 0755)
                tmpDir_pfam = tmpDir
                tmpDir_cdd = ""
                tmpDir_uniref = ""

# Changed by Nanjiang at 2015-02-05 23:07:44, no random suffix in the folder,
# since the specified out_path should be exclusively for this query
                protnamefile = "%s/query.fa.txt"%(tmpDir)
                try:
                    fpout = open(protnamefile, "w")
                    print >> fpout, "query"
                    fpout.close()
                except IOError:
                    print >> sys.stderr, "Failed to write to protnamefile %s. "\
                            "Exit."%(protnamefile)
                    sys.exit(1)


                outDir = "%s%s%s/"%(out_path, os.sep, "seq_%d"%(index))
                if os.path.exists(tmpDir) is False:
                    os.mkdir(tmpDir)

                if os.path.exists(outDir) is False:
                    os.mkdir(outDir)

                if os.path.exists(outDir + "Topcons/") is False:
                    os.mkdir(outDir + "Topcons/")

#                 outfile = "%s/%s"%(tmpDir, "query.fa")
                with open(tmpDir + "query.fa", "w") as outFile:
                    outFile.write(">query" + "\n" + str(entry.seq))

                with open(outDir + "seq.fa", "w") as outFile:
                    outFile.write(">query" + "\n" + str(entry.seq))

                startDir = os.getcwd()

                # Run Philius because it does not need the profile
                os.chdir(os.path.abspath("../predictors/Philius/"))
                cmd = ["./runPhilius.sh", tmpDir + "query.fa", outDir]
                cmdline = " ".join(cmd)
                if DEBUG:
                    print "cmdline:", cmdline
                p_philius = subprocess.Popen(cmd)
                os.chdir(startDir)

                # At the same time the profiles can be created
                cmd = ["./fa2prfs_pfamscan_v2.sh", tmpDir_pfam, blastDir]
                cmdline = " ".join(cmd)
                rmsg = ""
                try:
                    print "cmdline: ", cmdline
                    rmsg = subprocess.check_call(cmd, stderr=subprocess.STDOUT)
                except subprocess.CalledProcessError, e:
                    print "errmsg:", e
                    print "rmsg:", rmsg
                    pass
                query_seqdbfile = "%s/%s"%(tmpDir_pfam, "query.hits.db")
                filesize = 0
                try:
                    filesize = os.path.getsize(query_seqdbfile)
                except OSError:
                    filesize = -1
                    pass
                if DEBUG:
                    print "After fa2prfs_pfamscan_v2.sh filesize(%s)=%d"%(query_seqdbfile, filesize)

                # In case we do not find a hit, we have to run hmmscan on the cdd database
                if filesize <= 0:
                    tmpDir_cdd = tempfile.mkdtemp(prefix="%s/seq_cdd_"%(g_params['TMPPATH']) + str(index) + "_") + "/"
                    os.chmod(tmpDir_cdd, 0755)
                    with open(tmpDir_cdd + "query.fa", "w") as outFile:
                        outFile.write(">query" + "\n" + str(entry.seq))
                    used_pfam = "cdd"
                    cmd = ["./fa2prfs_hmmscan.sh", tmpDir_cdd, blastDir]
                    cmdline = " ".join(cmd)
                    try:
                        print "\ncmdline:",cmdline
                        rmsg = subprocess.check_call(cmd, stderr=subprocess.STDOUT)
                    except subprocess.CalledProcessError, e:
                        print "errmsg:", e
                        print "rmsg:", rmsg
                        pass

                    tmpDir = tmpDir_cdd

                    query_seqdbfile = "%s/%s"%(tmpDir_cdd, "query.hits.db")
                    try:
                        filesize = os.path.getsize(query_seqdbfile)
                    except OSError:
                        filesize = -1
                        pass

                    if DEBUG:
                        print "After fa2prfs_hmmscan.sh filesize(%s)=%d"%(query_seqdbfile, filesize)
                # In case we do not find a hit, we have to run the old script
                if filesize <= 0:
                    tmpDir_uniref = tempfile.mkdtemp(prefix="%s/seq_uniref_"%(g_params['TMPPATH']) + str(index) + "_") + "/"
                    os.chmod(tmpDir_uniref, 0755)
                    with open(tmpDir_uniref + "query.fa", "w") as outFile:
                        outFile.write(">query" + "\n" + str(entry.seq))
                    used_pfam = "uniref"
                    cmd =  ["./fa2prfs_fallback_v2.sh", tmpDir_uniref, blastDir, blastDB]
                    cmdline = " ".join(cmd)
                    try:
                        print "\ncmdline:", cmdline
                        rmsg = subprocess.check_call(cmd, stderr=subprocess.STDOUT)
                    except subprocess.CalledProcessError, e:
                        print e
                        print rmsg
                        pass
                    tmpDir = tmpDir_uniref

                    query_seqdbfile = "%s/%s"%(tmpDir_uniref,"query.hits.db")
                    try:
                        filesize = os.path.getsize(query_seqdbfile)
                    except OSError:
                        filesize = -1
                        pass

                    if DEBUG:
                        print "After fa2prfs_fallback_v2.sh filesize(%s)=%d"%(query_seqdbfile, filesize)

                print "Final working dir: tmpdir=", tmpDir
                # Once the profile is created start all other predictors
                os.chdir(os.path.abspath("../predictors/scampi-msa/"))
                cmd = ["perl", "run_SCAMPI_MSA.pl", tmpDir , outDir]
                cmdline = " ".join(cmd)
                if DEBUG:
                    print "cmdline:", cmdline
                p_scampi = subprocess.Popen(cmd)
                os.chdir(startDir)

                os.chdir(os.path.abspath("../predictors/spoctopus/"))
                outDir_SPOCTOPUS = outDir + os.sep + "SPOCTOPUS"
                if not os.path.exists(outDir_SPOCTOPUS):
                    os.makedirs(outDir_SPOCTOPUS)
                cmd = ["./SPOCTOPUS.sh", protnamefile ,tmpDir + "PSSM_PRF_FILES/", tmpDir + "RAW_PRF_FILES/", outDir_SPOCTOPUS, "-N"] #output also the ANN result for SPOCTOPUS, changed 2016-01-26
                cmdline = " ".join(cmd)
                if DEBUG:
                    print "cmdline:", cmdline
                p_spoctopus = subprocess.Popen(cmd)
                os.chdir(startDir)

                os.chdir(os.path.abspath("../predictors/spoctopus/"))
                outDir_OCTOPUS = outDir + os.sep + "OCTOPUS"
                if not os.path.exists(outDir_OCTOPUS):
                    os.makedirs(outDir_OCTOPUS)
                cmd =  ["./OCTOPUS.sh", protnamefile,tmpDir + "PSSM_PRF_FILES/", tmpDir + "RAW_PRF_FILES/", outDir_OCTOPUS, "-N"] #output also the ANN result for OCTOPUS, changed 2016-01-26
                cmdline = " ".join(cmd)
                if DEBUG:
                    print "cmdline:", cmdline

                p_octopus = subprocess.Popen(cmd)
                os.chdir(startDir)

                os.chdir(os.path.abspath("../predictors/PolyPhobius/"))
                cmd =  ["perl", "run_polyphobius.pl", tmpDir, outDir]
                cmdline = " ".join(cmd)
                if DEBUG:
                    print "cmdline:", cmdline
                p_polyphobius = subprocess.Popen(cmd)
                os.chdir(startDir)

                p_philius.communicate() #now wait for philius
                p_scampi.communicate() #now wait for SCAMPI MSA
                p_spoctopus.communicate() #now wait for OCTOPUS
                p_octopus.communicate() #now wait for SPOCTOPUS
                p_polyphobius.communicate() #now wait for PolyPhobius

                # Kostas wants (SP)Octopus to be "o"*len when Scampi does not predict a membrane
                subprocess.call(["python","./check_if_ntm.py", outDir + "SCAMPI_MSA/query.top", outDir + "OCTOPUS/query.top", outDir + "SPOCTOPUS/query.top"])

                # When the predictors are done we can run topcons
                os.chdir(os.path.abspath("../predictors/topcons/"))
                results = []
                count_pred = 0
                try:
                    if os.stat(outDir + "OCTOPUS/query.top").st_size != 0:
                        results.append("%s/%s"%(outDir, "OCTOPUS/"))
                        count_pred += 1
                except OSError:
                    # In case of a random crash we predict without spoctopus
                    pass

                try:
                    if os.stat(outDir + "SPOCTOPUS/query.top").st_size != 0:
                        results.append("%s/%s"%(outDir , "SPOCTOPUS/"))
                        count_pred += 1
                except OSError:
                    # In case of a random crash we predict without octopus
                    pass

                try:
                    if os.stat(outDir + "philius/query.top").st_size != 0:
                        results.append("%s/%s"%( outDir, "philius/"))
                        count_pred += 1
                except OSError:
                    pass

                try:
                    if os.stat(outDir + "PolyPhobius/query.top").st_size != 0:
                        results.append("%s/%s"%(outDir, "PolyPhobius/"))
                        count_pred += 1
                except OSError:
                    pass


                if os.stat(outDir + "SCAMPI_MSA/query.top").st_size != 0:
                    results.append("%s/%s"%( outDir, "SCAMPI_MSA/"))
                    count_pred += 1

                outdir_topcons = "%s/Topcons/"%(outDir)
                #cmd = ["./TOPCONS.sh", protnamefile, outdir_topcons] + results
                # 2015-02-23, the syntax of TOPCONS.sh has been changed
                cmd = ["./TOPCONS.sh", protnamefile, outdir_topcons, outDir]
                cmdline = " ".join(cmd)
                #os.system("./TOPCONS.sh " + tmpDir + "query.fa.txt " + outDir + "Topcons/ " + results)
                #print "./TOPCONS.sh " + tmpDir + "query.fa.txt " + outDir + "Topcons/ " + results
                #subprocess.call(["./TOPCONS.sh", tmpDir + "query.fa.txt", outDir + "Topcons/", outDir + "OCTOPUS/", outDir + "philius/", outDir + "PolyPhobius/", outDir + "SPOCTOPUS/", outDir + "SCAMPI_MSA/"])

                if DEBUG:
                    print "cmdline: cmdline"
                try:
                    rmsg = subprocess.check_call(cmd)
                except subprocess.CalledProcessError, e:
                    print >> sys.stderr, str(e)
                    pass
예제 #55
0
parser.add_argument(
    '-clinicalInfoFile',
    '--clinicalInfoFile',
    help=
    'File with clinical hotspot and indel filenames per cancer type. If not wanted set to false! Default: clinicalCancerTypeFiles.txt',
    type=str,
    default="clinicalCancerTypeFiles.txt")

args = parser.parse_args()
info = {}

clinicalInfo = {}
# Go through file with info about different clinical files
if not args.clinicalInfoFile.lower() == "false":
    # Using module module_locator to determine the path of the pythonscript directory
    my_path = module_locator.module_path()
    my_pathParts = my_path.split("/")  # Split path on /
    # Get the path of the SERA_script folder
    ciFilePath = ""
    for i in range(1, (len(my_pathParts) - 2)):
        ciFilePath += "/" + my_pathParts[i]
    # Add the path to the file with info about files corresponding to different cancer types
    ciFilePath += "/res/" + args.clinicalInfoFile

    # Go through the cancer type file and add info about the corresponding files to a directory
    with open(ciFilePath, 'r') as cifile:
        for line in cifile:
            if not re.match('$', line):  # If line is not empty start working
                line = line.strip()
                infoParts = line.split("=")
                cancer = infoParts[1].lower()
예제 #56
0
import os
import subprocess
import sys
import shutil
import logging
import datetime
import dropbox
import zipfile
import errno

#Setting up logging and other housekeeping
myDate = datetime.datetime.now().strftime("%y-%m-%d")
myTime = datetime.datetime.now().strftime("%H:%M")
myDateTime = datetime.datetime.now().strftime("%y-%m-%d %H:%M")

scriptdir = module_locator.module_path()
logdir = scriptdir + '\\logs\\'
tempdir = 'C:\\temp\\Plex Backup-%s\\' % myDate
regbackupfile = tempdir + "PlexRegistry-" + myDate + ".reg"
PlexDBDir = os.environ['LOCALAPPDATA'] + "\\Plex Media Server\\"
PZtemp = tempdir + "PlexBackup-" + myDate + ".zip"
BackupFile = tempdir + "PB-" + myDate + ".zip"
BackupDir = tempdir
allowZip64 = True
DB_appkey = '2tenjnd5fxlxxzj'
DB_appsecret = '7jfpfvnx7seew3i'
ACCESS_TYPE = 'app_folder'
auth_token = 'bB7LjlOoHncAAAAAAAAkCLBdTWfmixI2IMiSy6lSLqAPD6YEgUHYCcFjFleqte6j'
db = dropbox.client.DropboxClient(auth_token)

logger = logging.getLogger('Plex Backup')
예제 #57
0
__author__ = 'naetech'

import os
import module_locator

from Classes.Settings import Settings
from Classes.PHP import PHP
from Classes.GUI import GUI

program_path = module_locator.module_path()

print("Program path is: %s" % program_path)

program_settings = Settings()

settings_file_path = "%s/%s" % (program_path, "settings.ini")

program_settings.load_settings(settings_file_path)

php_path = str(program_settings.read_setting("php_path"))

if not os.path.exists(php_path):
    # perhaps we should try something relative
    php_path = "%s/%s" % (program_path, php_path)

port = str(program_settings.read_setting("port"))

webroot = str(program_settings.read_setting("webroot"))

if not os.path.exists(webroot):
    # perhaps we should try something relative
예제 #58
0
파일: pong.py 프로젝트: janwilamowski/pong
#!/usr/bin/python

import sys
import pygame
from pygame.locals import *
from constants import BLACK, WHITE
from Player import Player
from Ball import Ball
import random
import os
import module_locator

base_dir = module_locator.module_path()
STATUS_FADE = USEREVENT + 1


class Game():
    def __init__(self, args):
        random.seed()
        pygame.init()
        self.use_ai = 'ai' in args
        self.no_sound = 'nosound' in args
        self.screenshot_counter = 0
        self.setup_sounds()
        self.status_msg = ''
        self.status_level = 0
        icon = pygame.image.load(os.path.join(base_dir, 'screenshot.png'))
        pygame.display.set_icon(icon)
        self.reset()

    def reset(self):