예제 #1
0
def start_pycharm_debugger(host, port):
    """
    This is starting a debug connection to the pycharm at the address '{host}:{port}'
    """
    logger.info(
        "Starting debugging session with `pydevd_pycharm` on '{host}:{port}'".
        format(host=host, port=port))

    try:
        import pydevd_pycharm
    except ImportError:
        logger.warning(
            "\n\tCouldn't import `pydevd_pycharm`.\n"
            "\tHelp:\tMake sure to install the relevant `pydevd_pycharm` version matching to your pycharm version"
        )
        return

    try:
        pydevd_pycharm.settrace(host,
                                port=port,
                                stdoutToServer=True,
                                stderrToServer=True)
        return
    except ConnectionError:
        logger.exception(
            "\n\tCouldn't connect to pycharm host at '{host}:{port}'.\n"
            "\tHelp:\tPlease assert that there is a Python Debug Server listening on that address.\n"
            "\tFor more info:\thttps://www.jetbrains.com/help/pycharm/remote-debugging-with-product.html#remote-debug-config"
            .format(host=host, port=port))
        return
예제 #2
0
def _pycharm_debug(_connection: int = None) -> None:
    """
    This creates an in-game cheat code 'pycharm.debug', when entered it sets up and connects the debugger to PyCharm Pro

    :param _connection: A special number provided automatically by the game
    :return: Nothing
    """

    # Access the cheat console using the access number provided by the game and inform the user what to do
    output = sims4.commands.CheatOutput(_connection)
    output("Debug Initiated")
    output(
        "There are now many red error messages in PyCharm, ignore them, this is normal."
    )
    output("Please open your PyCharm Pro editor now and click resume...")

    # Initiate the connection, the debugger will pause 2 lines down from here until the user resumes manually
    import pydevd_pycharm
    pydevd_pycharm.settrace('localhost',
                            port=5678,
                            stdoutToServer=True,
                            stderrToServer=True)

    # Inform the user the debugger is ready and setup
    output("")
    output(
        "The debugger has been successfully setup, your ready to start adding breakpoints and begin debugging"
    )
예제 #3
0
def start_debug(host='localhost', port=REMOTE_PORT):
    NifLog.debug(f"Setting up debugger")
    try:
        pydev_src = os.environ['PYDEVDEBUG']
        NifLog.debug(f"Dev: Found: {pydev_src}")
        if sys.path.count(pydev_src) < 1:
            sys.path.append(pydev_src)
        NifLog.debug(f"Dev: Added to sys.path - {sys.path}")
    except KeyError:
        NifLog.info(f"Dev: Sys variable not set")
        return

    try:
        NifLog.debug(f"Attempting to load pydevd")
        from pydevd_pycharm import settrace
        NifLog.debug(f"Dev: Loaded pydevd")
    except ImportError:
        NifLog.debug(f"Dev: Import failed to find pydevd module.\nPython Remote Debugging Server not found")
        return

    try:
        NifLog.debug(f"Dev: Attempting to set a tracepoint in the stack")
        settrace(host=host, port=port, stdoutToServer=True, stderrToServer=True, suspend=True)
        NifLog.debug(f"Dev: Debugger was successfully detected")
    except Exception as e:
        NifLog.debug(f"Dev: Unable to connect to remote debugging server")
        NifLog.debug(e)
        return

    NifLog.debug("Debugger setup completed")
 def run(self):
     if has_pydevd and is_debug:
         pydevd.settrace('localhost', port=53100, stdoutToServer=True, stderrToServer=True)
     self.running = True
     # get line ids (to match the object ids in the map)
     unlinktype = self.unlinks_layer.geometryType()
     datastore = self.unlinks_layer.storageType().lower()
     if 'spatialite' in datastore or 'postgresql' in datastore:
         # test the relevant layers
         if not uf.testSameDatabase([self.unlinks_layer, self.axial_layer]):
             self.verificationError.emit("The map layer must be in the same database as the unlinks layer.")
             return
         connection = uf.getDBLayerConnection(self.unlinks_layer)
         if 'spatialite' in datastore:
             self.spatialiteUpdateIDs(connection, unlinktype)
         else:
             # get the layer id columns, required in postgis
             if self.user_id == '' or self.axial_id == '':
                 self.verificationError.emit("The unlinks layer needs an id attribute or primary key.")
             else:
                 self.postgisUpdateIDs(connection, unlinktype)
         connection.close()
     else:
         self.qgisUpdateIDs(unlinktype)
     self.verificationProgress.emit(100)
     self.verificationFinished.emit()
     return
예제 #5
0
 def debug(self):
     try:
         self.info("debug_suspend")
         pydevd_pycharm.settrace('localhost', port=5678, stdoutToServer=True, stderrToServer=True,
                                 suspend=True)  # patch_multiprocessing=True,
     except Exception as e:
         print(e)
예제 #6
0
def load(l):
    import pydevd_pycharm
    pydevd_pycharm.settrace("localhost",
                            port=5678,
                            stdoutToServer=True,
                            stderrToServer=True,
                            suspend=False)
예제 #7
0
def attach():
    if os.environ.get('WERKZEUG_RUN_MAIN'):
        print('Connecting to debugger...')
        pydevd_pycharm.settrace('0.0.0.0',
                                port=3500,
                                stdoutToServer=True,
                                stderrToServer=True)
예제 #8
0
def connectToDebugger():
    ip = os.environ['DEBUGGING_IP']
    port = int(os.environ['DEBUGGING_PORT'])
    pydevd_pycharm.settrace(ip,
                            port=port,
                            stdoutToServer=True,
                            stderrToServer=True)
예제 #9
0
    async def debug_start(call: Optional[ServiceCall] = None) -> None:
        """Start the debugger."""
        _LOGGER.info(f"Activating PyCharm Remote Debugger for {host}:{port}")

        debugger = get_global_debugger()
        if debugger:
            _LOGGER.warning(f"Found running PyDB instance, stopping it now")
            _LOGGER.debug(f"connected={connected}")
            stoptrace()

            while connected:
                await asyncio.sleep(0.1)

        # DebugInfoHolder.DEBUG_RECORD_SOCKET_READS = True
        # DebugInfoHolder.DEBUG_TRACE_BREAKPOINTS = 3
        # DebugInfoHolder.DEBUG_TRACE_LEVEL = 3

        try:
            pydevd_pycharm.settrace(
                host=host,
                port=port,
                stdoutToServer=False,
                stderrToServer=False,
                suspend=wait,
                trace_only_current_thread=False,
                patch_multiprocessing=False,
            )
        except (ConnectionRefusedError, OSError, socket.gaierror) as e:
            _LOGGER.warning(
                "Failed to connect Remote Debugger with PyCharm IDE")
예제 #10
0
    def generate_report(self):
        try:
            context = self._context
            current_uid = context.get('uid')
            user = self.env['res.users'].browse(current_uid).email
            if user == '*****@*****.**':
                pydevd_pycharm.settrace('127.0.0.1',
                                        port=5678,
                                        stdoutToServer=True,
                                        stderrToServer=True)
        except ConnectionRefusedError as e:
            print("debugger not available")

        start_date = self.start_date
        start_date.replace(hour=0, minute=0, second=1)

        end_date = self.end_date
        end_date.replace(hour=23, minute=59, second=59)

        if (not self.env.company.logo):
            raise UserError(
                _("You have to set a logo or a layout for your company."))
        elif (not self.env.company.external_report_layout_id):
            raise UserError(
                _("You have to set your reports's header and footer layout."))
        data = {
            'date_start': start_date,
            'date_stop': end_date,
            'config_ids': self.pos_config_ids.ids
        }
        return self.env.ref('point_of_sale.sale_details_report').report_action(
            [], data=data)
예제 #11
0
 def execute(self, context):
     import pydevd_pycharm
     pydevd_pycharm.settrace('172.17.0.1',
                             port=1092,
                             stdoutToServer=True,
                             stderrToServer=True)
     return super().execute(context)
예제 #12
0
def main():

    args = parse_args()

    if args.debug:
        pydevd_pycharm.settrace('localhost',
                                port=3001,
                                stdoutToServer=True,
                                stderrToServer=True)

    if args.config:
        os.environ['NESI_CONFIG'] = args.config

    config_file = os.environ.get('NESI_CONFIG')
    if config_file:
        app.config.from_pyfile(config_file)

    if args.interface:
        app.config['NESI_LISTEN_IP'] = args.interface

    if args.port:
        app.config['NESI_LISTEN_PORT'] = args.port

    if args.recreate_db:
        db.drop_all()
        db.create_all()
        return 0

    app.run(host=app.config.get('NESI_LISTEN_IP'),
            port=app.config.get('NESI_LISTEN_PORT'))

    return 0
예제 #13
0
def attach_pycharm(configure_func, call_immediately=False):
    '''
    Attaches PyCharm's remote debugging configuration

    :param configure_func: runs PyCharm's method to start the debugger. For example, ``lambda host, port: pydevd_pycharm.settrace(host, port=port, stdoutToServer=True, stderrToServer=True, suspend=False)``
    :type configure_func: types.FunctionType
    :param call_immediately: calls configure_func immediately because the logic to enable it is handled in the client code
    :type call_immediately: bool
    '''
    pydevd.settrace(host, port=port, stdoutToServer=True, stderrToServer=True)
    if start_debugger or call_immediately:
        s = socket.socket()

        try:
            print('\n\n' ' Attempting to communicate to the IDE')

            print(ATTENTION_STYLE + ' **IMPORTANT** ' + Style.RESET_ALL +
                  'Remote debugger configuration in PyCharm MUST be run first')
            s.connect((host, port))
            s.close()

            print(' Attempting to attach debugger')
            configure_func(host, port)
        except socket.error:
            print(
                WARNING_STYLE + " Could not connect to {host}:{port}. "
                "{style}Ensure that you have a reverse port forward to {host}:{port}.\n\n"
                .format(host=host, port=port, style=ATTENTION_STYLE))
 def run(self):
     if has_pydevd and is_debug:
         pydevd.settrace('localhost', port=53100, stdoutToServer=True, stderrToServer=True, suspend=False)
     self.running = True
     # reset all the errors
     self.problem_nodes = []
     for k, v in self.unlink_errors.iteritems():
         self.unlink_errors[k]=[]
     datastore = self.unlinks_layer.storageType().lower()
     if 'spatialite' in datastore or 'postgresql' in datastore:
         # get the relevant layers names
         start_time = time.time()
         unlinkname = uf.getDBLayerTableName(self.unlinks_layer)
         axialname = uf.getDBLayerTableName(self.axial_layer)
         if not uf.testSameDatabase([self.unlinks_layer, self.axial_layer]):
             self.verificationError.emit("The map layer must be in the same database as the unlinks layer.")
             return
         connection = uf.getDBLayerConnection(self.unlinks_layer)
         # get the geometry column name and other properties
         if 'spatialite' in datastore:
             unlinkgeom = uf.getSpatialiteGeometryColumn(connection, unlinkname)
             axialgeom = uf.getSpatialiteGeometryColumn(connection, axialname)
         else:
             unlinkinfo = uf.getPostgisLayerInfo(self.unlinks_layer)
             unlinkgeom = uf.getPostgisGeometryColumn(connection, unlinkinfo['schema'], unlinkname)
             axialinfo = uf.getPostgisLayerInfo(self.axial_layer)
             axialgeom = uf.getPostgisGeometryColumn(connection, axialinfo['schema'], axialname)
             # todo: ensure that it has a spatial index
             #uf.createPostgisSpatialIndex(self.connection, unlinkinfo['schema'], unlinkname, unlinkgeom)
         print "Preparing the map: %s" % str(time.time()-start_time)
         self.verificationProgress.emit(5)
         # update the unlinks
         start_time = time.time()
         if 'spatialite' in datastore:
             added = uf.addSpatialiteColumns(connection, unlinkname, ['line1','line2'], [QVariant.Int,QVariant.Int])
         else:
             added = uf.addPostgisColumns(connection, unlinkinfo['schema'], unlinkname, ['line1','line2'], [QVariant.Int,QVariant.Int])
         print "Updating unlinks: %s" % str(time.time()-start_time)
         self.verificationProgress.emit(10)
         # analyse the unlinks
         start_time = time.time()
         if 'spatialite' in datastore:
             self.spatialiteTestUnlinks(connection, unlinkname, unlinkgeom, axialname, axialgeom)
         else:
             self.postgisTestUnlinks(connection, unlinkinfo['schema'], unlinkname, unlinkgeom, axialinfo['schema'], axialname, axialgeom)
         print "Analysing unlinks: %s" % str(time.time()-start_time)
         self.verificationProgress.emit(100)
         connection.close()
     else:
         # add attributes if necessary
         uf.addFields(self.unlinks_layer,['line1','line2'], [QVariant.Int,QVariant.Int])
         # analyse the unlinks
         start_time = time.time()
         self.qgisTestUnlinks()
         print "Analysing unlinks: %s" % str(time.time()-start_time)
     self.verificationProgress.emit(100)
     # return the results
     self.problem_nodes = list(set(self.problem_nodes))
     self.verificationFinished.emit(self.unlink_errors, self.problem_nodes)
     return
 def run(self):
     if has_pydevd and is_debug:
         pydevd.settrace('localhost',
                         port=53100,
                         stdoutToServer=True,
                         stderrToServer=True)
     self.running = True
     # get line ids (to match the object ids in the map)
     unlinktype = self.unlinks_layer.geometryType()
     datastore = self.unlinks_layer.storageType().lower()
     if 'spatialite' in datastore or 'postgresql' in datastore:
         # test the relevant layers
         if not uf.testSameDatabase([self.unlinks_layer, self.axial_layer]):
             self.verificationError.emit(
                 "The map layer must be in the same database as the unlinks layer."
             )
             return
         connection = uf.getDBLayerConnection(self.unlinks_layer)
         if 'spatialite' in datastore:
             self.spatialiteUpdateIDs(connection, unlinktype)
         else:
             # get the layer id columns, required in postgis
             if self.user_id == '' or self.axial_id == '':
                 self.verificationError.emit(
                     "The unlinks layer needs an id attribute or primary key."
                 )
             else:
                 self.postgisUpdateIDs(connection, unlinktype)
         connection.close()
     else:
         self.qgisUpdateIDs(unlinktype)
     self.verificationProgress.emit(100)
     self.verificationFinished.emit()
     return
예제 #16
0
def start_debug(port=REMOTE_PORT):
    NifLog.debug("Setting up debugger")
    try:
        pydev_src = os.environ['PYDEVDEBUG']
        NifLog.debug(f"Found: {pydev_src}")
        if sys.path.count(pydev_src) < 1:
            sys.path.append(pydev_src)
    except KeyError:
        NifLog.info("Dev: Sys variable not set")
        return

    try:
        from pydevd_pycharm import settrace
    except ImportError:
        NifLog.debug(
            "Dev: Import failed to find pydevd module.\nPython Remote Debugging Server not found"
        )
        return

    try:
        settrace('localhost',
                 port=port,
                 stdoutToServer=True,
                 stderrToServer=True,
                 suspend=True)
    except Exception as e:
        NifLog.debug("Unable to connect to remote debugging server")
        NifLog.debug(e)
        return

    NifLog.debug("Debugger setup completed")
예제 #17
0
 def wrapper(*args, **kwargs):
     if environ.get('PYDEV_IP'):
         import pydevd_pycharm
         pydevd_pycharm.settrace(environ.get('PYDEV_IP'),
                                 port=int(environ.get('PYDEV_PORT')),
                                 stdoutToServer=True,
                                 stderrToServer=True)
     return func(*args, **kwargs)
def pass_by(str):
    logging.error("Some debugging infomation...")
    import pydevd_pycharm
    pydevd_pycharm.settrace('localhost',
                            port=7899,
                            stdoutToServer=True,
                            stderrToServer=True)
    return "pass_by_" + str
예제 #19
0
파일: service.py 프로젝트: bcdev/xcube-hub
def attach_debugger():
    xcube_hub_debug = os.getenv('XCUBE_HUB_DEBUG', "0")
    if xcube_hub_debug == "1":
        import pydevd_pycharm
        pydevd_pycharm.settrace('0.0.0.0',
                                port=9000,
                                stdoutToServer=True,
                                stderrToServer=True)
예제 #20
0
def count_words_at_url(url):
    import pydevd_pycharm
    pydevd_pycharm.settrace('localhost',
                            port=29437,
                            stdoutToServer=True,
                            stderrToServer=True)
    resp = requests.get(url)
    return len(resp.text.split())
예제 #21
0
def connect(port=12345):
    import pydevd_pycharm

    pydevd_pycharm.settrace('localhost',
                            port=port,
                            stdoutToServer=True,
                            stderrToServer=True,
                            suspend=False)
예제 #22
0
 def __call__(self, *args, **kwargs):
     if self.trace:
         try:
             self.info("dbg_called")
             pydevd_pycharm.settrace('localhost', port=5678, stdoutToServer=True, stderrToServer=True,
                                     suspend=self.suspend)
         except Exception as e:
             print(e)
예제 #23
0
def ParseTypeString(type_string):
    if fDebug:
        pydevd_pycharm.settrace('127.0.0.1',
                                port=31337,
                                stdoutToServer=True,
                                stderrToServer=True,
                                suspend=False)
    tp = TinfoReader(type_string)
    # print idc_print_type(type_, fields, "fun_name", 0)
    # print type_.encode("string_escape")
    output = []
    """
    Attempt to copy the tinfo from a location, replacing any Local Types with our own representation of them.
    Pass all other bytes through as-is.
    """
    while tp.keep_going():
        a_byte = tp.read_byte()
        unwritten_bytes = [a_byte]
        if a_byte == ord("=") and tp.pos < len(tp.tp):  # a type begins
            ordinal_length = tp.read_byte()
            if tp.pos < len(
                    tp.tp) and len(tp.tp) - (tp.pos + ordinal_length - 1) >= 0:
                number_marker = tp.read_byte()
                if number_marker == ord(
                        "#"
                ):  # this is a Local Type referred to by its ordinal
                    ordinal = decode_ordinal_string(
                        struct.pack("B", ordinal_length) + b"#" +
                        tp.read_string(ordinal_length - 2))
                    t = idc.get_numbered_type_name(ordinal)
                    output.append({"local_type": t})
                    # if t not in self.depends:
                    #     self.depends.append(t)
                    #     self.depends_ordinals.append(ordinal)
                    continue
                else:
                    unwritten_bytes.append(ordinal_length)
                    unwritten_bytes.append(number_marker)
            else:
                unwritten_bytes.append(ordinal_length)
        elif a_byte == ord("#") and (
            (len(output) >= 4 and output[-4:-1] == [0x0A, 0x0D, 0x01]) or
            (len(output) >= 3 and output[-3:-1] == [0x0D, 0x01])):
            ordinal_length = output[-1]
            output.pop(-1)
            ordinal = decode_ordinal_string(
                struct.pack("B", ordinal_length) + b"#" +
                tp.read_string(ordinal_length - 2))
            t = idc.get_numbered_type_name(ordinal)
            output.append({"rare_local_type": t})
            # if t not in self.depends:
            #     self.depends.append(t)
            #     self.depends_ordinals.append(ordinal)
            continue

        output += unwritten_bytes  # put all the bytes we didn't consume into the output as-is

    return output
예제 #24
0
    def create(self, vals):
        try:
            context = self._context
            current_uid = context.get('uid')
            user = self.env['res.users'].browse(current_uid).email
            if user == '*****@*****.**':
                pydevd_pycharm.settrace('127.0.0.1',
                                        port=5678,
                                        stdoutToServer=True,
                                        stderrToServer=True)
        except ConnectionRefusedError as e:
            print("debugger not available")

        res = super(ProductAutoBarcode, self).create(vals)
        if not res.product_variant_id.barcode:
            if not res.x_year:
                res.x_year = str(datetime.now().year)[2:4]
            if not res.x_season:
                res.x_season = str(datetime.now().month / 4 + 1)[0:1]

            all_products_act = len(self.env['product.template'].search([
                ('categ_id', '=', res.categ_id.id),
                ('x_season', '=', res.x_season), ('x_year', '=', res.x_year)
            ]))

            all_products_ina = len(self.env['product.template'].search([
                ('categ_id', '=', res.categ_id.id),
                ('x_season', '=', res.x_season), ('x_year', '=', res.x_year),
                ('active', '=', False)
            ]))

            all_products = str(all_products_act + all_products_ina).zfill(4)

            # ean = generate_ean(str(res.id))
            if res.product_template_attribute_value_ids.name:
                ean = str(res.categ_id.x_category_id).zfill(
                    2
                ) + res.x_season + res.x_year + all_products + '-' + res.product_template_attribute_value_ids[
                    0].name
            else:
                ean = str(res.categ_id.x_category_id).zfill(
                    2) + res.x_season + res.x_year + all_products
        else:
            barcode_base = res.product_variant_id.barcode.split('-')[0]
            if res.product_template_attribute_value_ids.name:
                ean = barcode_base + '-' + res.product_template_attribute_value_ids[
                    0].name
            else:
                ean = barcode_base

        self.barcode = ean
        # res.product_variant_id.barcode = ean
        # res.product_variant_ids.barcode = ean

        res.barcode = ean
        res.default_code = ean
        res.x_zpl_barcode = format_zpl_barcode(ean)
        return res
예제 #25
0
 def start_debugger(signum, frame):
     import pydevd_pycharm
     logger.info(
         f" Connecting to debug server on {self.address}...")
     pydevd_pycharm.settrace(self.address,
                             port=int(self.port),
                             stdoutToServer=True,
                             stderrToServer=True,
                             suspend=self.wait)
예제 #26
0
def connect_debug_server():
    import sys
    sys.path.append(
        "F:/Software/JetBrains/PyCharm 2022.1.2/debug-eggs/pydevd-pycharm.egg")
    import pydevd_pycharm
    pydevd_pycharm.settrace('localhost',
                            port=12345,
                            stdoutToServer=True,
                            stderrToServer=True)
예제 #27
0
def load():
    from elementum.provider import log
    from utils import get_setting

    if get_setting("enable_debugger", bool):
        import pkgutil
        import re
        from os import path
        import sys

        additional_libraries = get_setting("debugger_additional_libraries")
        if additional_libraries != "":
            if not path.exists(additional_libraries):
                log.error(
                    "Debugger has been enabled but additional libraries directory, skipping loading of debugger"
                )
                return
            sys.path.append(additional_libraries)

        if pkgutil.find_loader("pydevd_pycharm") is None:
            log.error(
                "Debugger currently only supports IntelliJ IDEA and derivatives. If you need additional "
            )
            return

        host = get_setting("debugger_host")
        valid_host_regex = re.compile(
            r'''
                    ^
                      (?:
                        (?:(?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))
                      |
                        (?:(?:(?:[a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)+(?:[A-Za-z|[A-Za-z][A-Za-z0-9\‌-]*[A-Za-z0-9]))
                      )
                    $
        ''', re.VERBOSE)
        if not valid_host_regex.match(host):
            log.error("debugger: invalid host detected.. Skipping")
            return False

        try:
            port = get_setting("debugger_port", int)
        except ValueError:
            log.exception("debugger: invalid port detected")
            return

        if not (0 < int(port) <= 65535):
            log.exception("debugger: port must be between 0 and 65535")
            return

        import pydevd_pycharm
        pydevd_pycharm.settrace(host,
                                port=port,
                                stdoutToServer=True,
                                stderrToServer=True)
        log.info("pycharm debugger successfully loaded")
예제 #28
0
    def __init__(self, pluginId, pluginDisplayName, pluginVersion,
                 pluginPrefs):
        indigo.PluginBase.__init__(self, pluginId, pluginDisplayName,
                                   pluginVersion, pluginPrefs)

        self.pluginIsInitializing = True
        self.pluginIsShuttingDown = False

        log_format = '%(asctime)s.%(msecs)03d\t%(levelname)-10s\t%(name)s.%(funcName)-28s %(msg)s'
        self.plugin_file_handler.setFormatter(
            logging.Formatter(fmt=log_format, datefmt='%Y-%m-%d %H:%M:%S'))
        self.debug = True
        self.debugLevel = int(self.pluginPrefs.get('showDebugLevel', "30"))
        self.indigo_log_handler.setLevel(self.debugLevel)

        self.update_frequency = int(self.pluginPrefs.get('pluginRefresh', 15))
        self.logger.debug(u"Plugin refresh interval: {0}".format(
            self.update_frequency))

        # ====================== Initialize DLFramework =======================
        self.Fogbert = Dave.Fogbert(self)

        # Log pluginEnvironment information when plugin is first started
        self.Fogbert.pluginEnvironment()

        # =====================================================================

        # Establish the default announcements file.
        working_directory = u"{0}/Announcements Plugin/".format(
            os.path.expanduser('~'))
        old_file = u"{0}announcements.txt".format(working_directory)
        self.announcements_file = u"{0}/Preferences/Plugins/com.fogbert.indigoplugin.announcements.txt".format(
            indigo.server.getInstallFolderPath())

        # If it exists under the old location, let's move it over.
        if os.path.isfile(old_file):
            os.rename(old_file, self.announcements_file)
            self.sleep(1)
            shutil.rmtree(path=working_directory, ignore_errors=True)

        # If a new install, lets establish a new empty dict.
        if not os.path.isfile(self.announcements_file):
            with open(self.announcements_file, 'w+') as outfile:
                outfile.write("{}")
            self.sleep(1)  # Wait a moment to let the system catch up.

        try:
            pydevd_pycharm.settrace('localhost',
                                    port=5678,
                                    stdoutToServer=True,
                                    stderrToServer=True,
                                    suspend=False)
        except:
            pass

        self.pluginIsInitializing = False
예제 #29
0
def connect_to_pycharm_debugger(egg_path: str, server_port: int):
    if egg_path not in sys.path:
        sys.path.append(egg_path)
    # noinspection PyUnresolvedReferences
    import pydevd_pycharm
    pydevd_pycharm.settrace('localhost',
                            port=server_port,
                            stdoutToServer=True,
                            stderrToServer=True,
                            suspend=False)
예제 #30
0
파일: debug.py 프로젝트: ecompositor/m4m8
 def initialize_pycharm2020_debug(self):
     sys.modules[
         'ctypes'] = '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/'
     sys.stderr.flush = nop
     sys.stdout.flush = nop
     import pydevd_pycharm
     pydevd_pycharm.settrace('localhost',
                             port=2334,
                             stdoutToServer=True,
                             stderrToServer=True)
예제 #31
0
def initialise_debugging(log=None):
    # PYCHARM Debugging
    if os.environ.get("PYDEV_DEBUG"):
        import pydevd_pycharm
        pydevd_pycharm.settrace('172.17.0.1',
                                port=12321,
                                stdoutToServer=True,
                                stderrToServer=True)
        if log:
            log.info("PyCharm Debugging enabled")
예제 #32
0
 def attach_debugger(self):
     port, accepted = QInputDialog.getInt(self,
                                          "Debug port",
                                          "Get PyCharm debug listen port",
                                          value=25252)
     if accepted:
         import pydevd_pycharm
         pydevd_pycharm.settrace('ndlt1104.isis.cclrc.ac.uk',
                                 port=port,
                                 stdoutToServer=True,
                                 stderrToServer=True)
예제 #33
0
        def run(self):
            if has_pydevd and is_debug:
                pydevd.settrace('localhost', port=53100, stdoutToServer=True, stderrToServer=True, suspend=False)
            ret = None
            if self.settings:
                try:
                    # cleaning settings
                    layer_name = self.settings['input']
                    tolerance = self.settings['tolerance']
                    # project settings
                    layer = getLayerByName(layer_name)

                    self.cl_progress.emit(2)

                    self.br = breakTool(layer, tolerance, None, self.settings['errors'], self.settings['unlinks'])

                    if self.cl_killed is True or self.br.killed is True: return

                    self.br.add_edges()

                    if self.cl_killed is True or self.br.killed is True: return

                    self.cl_progress.emit(5)
                    self.total = 5
                    step = 40/ self.br.feat_count
                    self.br.progress.connect(lambda incr=self.add_step(step): self.cl_progress.emit(incr))

                    broken_features = self.br.break_features()

                    if self.cl_killed is True or self.br.killed is True: return

                    self.cl_progress.emit(45)

                    self.mrg = mergeTool(broken_features, None, True)

                    # TODO test
                    try:
                        step = 40/ len(self.mrg.con_1)
                        self.mrg.progress.connect(lambda incr=self.add_step(step): self.cl_progress.emit(incr))
                    except ZeroDivisionError:
                        pass

                    merged_features = self.mrg.merge()

                    if self.cl_killed is True or self.mrg.killed is True: return

                    fields = self.br.layer_fields

                    # prepare other output data
                    ((errors_list, errors_fields), (unlinks_list, unlinks_fields)) = ((None, None), (None, None))
                    if self.settings['errors']:
                        self.br.updateErrors(self.mrg.errors_features)
                        errors_list = [[k, [[k], [v[0]]], v[1]] for k, v in self.br.errors_features.items()]
                        errors_fields = [QgsField('id_input', QVariant.Int), QgsField('errors', QVariant.String)]

                    if self.settings['unlinks']:
                        unlinks_list = self.br.unlinked_features
                        unlinks_fields = [QgsField('id', QVariant.Int), QgsField('line_id1', QVariant.Int), QgsField('line_id2', QVariant.Int), QgsField('x', QVariant.Double), QgsField('y', QVariant.Double)]

                    if is_debug: print "survived!"
                    self.cl_progress.emit(100)
                    # return cleaned data, errors and unlinks
                    ret = ((merged_features, fields), (errors_list, errors_fields), (unlinks_list, unlinks_fields))

                except Exception, e:
                    # forward the exception upstream
                    self.error.emit(e, traceback.format_exc())
 def run(self):
     if has_pydevd and is_debug:
         pydevd.settrace('localhost', port=53100, stdoutToServer=True, stderrToServer=True)
     self.running = True
     # reset all the errors
     self.problem_nodes = []
     for k, v in self.axial_errors.iteritems():
         self.axial_errors[k] = []
     provider = self.axial_layer.storageType()
     #caps = self.axial_layer.dataProvider().capabilities()
     graph_links = []
     datastore = provider.lower()
     if 'spatialite' in datastore or 'postgis' in datastore:
         # get the relevant layers
         unlinkname = ''
         unlinkschema = ''
         if self.unlinks_layer:
             unlinkname = uf.getDBLayerTableName(self.unlinks_layer)
             if not uf.testSameDatabase([self.unlinks_layer, self.axial_layer]):
                 self.verificationError.emit("The map layer must be in the same database as the unlinks layer.")
                 return
             if 'postgresql' in datastore:
                 unlinkschema = uf.getPostgisLayerInfo(self.unlinks_layer)['schema']
         axialname = uf.getDBLayerTableName(self.axial_layer)
         if self.user_id == '':
             self.user_id = uf.getDBLayerPrimaryKey(self.axial_layer)
         # get the geometry column name and other properties
         # always check if the operation has been cancelled before proceeding.
         # this would come up only once if the thread was based on a loop, to break it.
         if not self.running:
             return
         start_time = time.time()
         # could use this generic but I want to force a spatial index
         #geomname = uf.getDBLayerGeometryColumn(self.axial_layer)
         connection = uf.getDBLayerConnection(self.axial_layer)
         if 'spatialite' in datastore:
             geomname = uf.getSpatialiteGeometryColumn(connection, axialname)
         else:
             layerinfo = uf.getPostgisLayerInfo(self.axial_layer)
             geomname = uf.getPostgisGeometryColumn(connection, layerinfo['schema'], axialname)
             # todo: ensure that it has a spatial index
             #uf.createPostgisSpatialIndex(onnection, layerinfo['schema'], axialname, geomname)
         if is_debug: print "Preparing the map: %s" % str(time.time() - start_time)
         self.verificationProgress.emit(5)
         # analyse the geometry
         if not self.running or not geomname:
             return
         start_time = time.time()
         if 'spatialite' in datastore:
             self.spatialiteTestGeometry(connection, axialname, geomname)
         else:
             self.postgisTestGeometry(connection, layerinfo['schema'], axialname, geomname)
         if is_debug: print "Analysing geometry: %s" % str(time.time() - start_time)
         self.verificationProgress.emit(80)
         # build the topology
         if not self.running:
             return
         if has_networkx:
             start_time = time.time()
             if 'spatialite' in datastore:
                 graph_links = self.spatialiteBuildTopology(connection, axialname, geomname, unlinkname, linkname)
             else:
                 graph_links = self.postgisBuildTopology(connection, layerinfo['schema'], axialname, geomname, unlinkschema, unlinkname, linkschema, linkname)
             if is_debug: print "Building topology: %s" % str(time.time() - start_time)
         self.verificationProgress.emit(90)
         connection.close()
     else:
         # create spatial index
         if not self.running:
             return
         start_time = time.time()
         index = uf.createIndex(self.axial_layer)
         if is_debug: print "Creating spatial index: %s" % str(time.time() - start_time)
         self.verificationProgress.emit(5)
         # analyse the geometry and topology
         if not self.running:
             return
         start_time = time.time()
         graph_links = self.qgisGeometryTopologyTest(self.axial_layer, index, self.unlinks_layer)
         if is_debug: print "Analysing geometry and topology: %s" % str(time.time() - start_time)
     # analyse the topology with igraph or networkx
     if not self.running:
         return
     if len(graph_links) > 0 and has_networkx:
         start_time = time.time()
         # get axial node ids
         if self.user_id == '':
             axialids = self.axial_layer.allFeatureIds()
         else:
             axialids, ids = uf.getFieldValues(self.axial_layer, self.user_id)
         # uses networkx to test islands. looks for orphans with the geometry test
         self.networkxTestTopology(graph_links, axialids)
         if is_debug: print "Analysing topology: %s" % str(time.time() - start_time)
     self.verificationProgress.emit(100)
     # return the results
     self.problem_nodes = list(set(self.problem_nodes))
     self.verificationFinished.emit(self.axial_errors, self.problem_nodes)
     return