Best Python code snippet using slash
take_snapshot.py
Source:take_snapshot.py  
1#!/usr/bin/env python2#############################################################################3#4# Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).5# Contact: http://www.qt-project.org/legal6#7# This file is part of the QtWebEngine module of the Qt Toolkit.8#9# $QT_BEGIN_LICENSE:LGPL$10# Commercial License Usage11# Licensees holding valid commercial Qt licenses may use this file in12# accordance with the commercial license agreement provided with the13# Software or, alternatively, in accordance with the terms contained in14# a written agreement between you and Digia.  For licensing terms and15# conditions see http://qt.digia.com/licensing.  For further information16# use the contact form at http://qt.digia.com/contact-us.17#18# GNU Lesser General Public License Usage19# Alternatively, this file may be used under the terms of the GNU Lesser20# General Public License version 2.1 as published by the Free Software21# Foundation and appearing in the file LICENSE.LGPL included in the22# packaging of this file.  Please review the following information to23# ensure the GNU Lesser General Public License version 2.1 requirements24# will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.25#26# In addition, as a special exception, Digia gives you certain additional27# rights.  These rights are described in the Digia Qt LGPL Exception28# version 1.1, included in the file LGPL_EXCEPTION.txt in this package.29#30# GNU General Public License Usage31# Alternatively, this file may be used under the terms of the GNU32# General Public License version 3.0 as published by the Free Software33# Foundation and appearing in the file LICENSE.GPL included in the34# packaging of this file.  Please review the following information to35# ensure the GNU General Public License version 3.0 requirements will be36# met: http://www.gnu.org/copyleft/gpl.html.37#38#39# $QT_END_LICENSE$40#41#############################################################################42import glob43import os44import subprocess45import sys46import imp47import errno48import shutil49from distutils.version import StrictVersion50import git_submodule as GitSubmodule51qtwebengine_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))52os.chdir(qtwebengine_root)53def isInGitBlacklist(file_path):54    # We do need all the gyp files.55    if file_path.endswith('.gyp') or file_path.endswith('.gypi') or file_path.endswith('.isolate'):56        False57    if ( '.gitignore' in file_path58        or '.gitmodules' in file_path59        or '.DEPS' in file_path ):60        return True61def isInChromiumBlacklist(file_path):62    # Filter out empty submodule directories.63    if (os.path.isdir(file_path)):64        return True65    # We do need all the gyp files.66    if file_path.endswith('.gyp') or file_path.endswith('.gypi') or file_path.endswith('.isolate'):67        return False68    if ( '_jni' in file_path69        or 'jni_' in file_path70        or 'testdata/' in file_path71        or (file_path.startswith('third_party/android_tools') and72            not 'android/cpufeatures' in file_path)73        or '/tests/' in file_path74        or ('/test/' in file_path and75            not '/webrtc/test/testsupport/' in file_path and76            not file_path.startswith('net/test/') and77            not file_path.endswith('mock_chrome_application_mac.h') and78            not file_path.endswith('perftimer.h') and79            not 'ozone' in file_path)80        or file_path.endswith('.java')81        or file_path.startswith('android_webview')82        or file_path.startswith('apps/')83        or file_path.startswith('ash/')84        or file_path.startswith('athena')85        or file_path.startswith('base/android/java')86        or file_path.startswith('breakpad')87        or file_path.startswith('build/android/')88        or (file_path.startswith('chrome/') and89            not file_path.startswith('chrome/VERSION') and90            not '/app/theme/' in file_path and91            not '/app/resources/' in file_path and92            not '/browser/resources/' in file_path and93            not '/renderer/resources/' in file_path and94            not 'repack_locales' in file_path and95            not 'third_party/chromevox' in file_path and96            not 'media/desktop_media_list.h' in file_path and97            not 'media/desktop_streams_registry.cc' in file_path and98            not 'media/desktop_streams_registry.h' in file_path and99            not 'net/net_error_info' in file_path and100            not 'common/localized_error' in file_path and101            not file_path.endswith('cf_resources.rc') and102            not file_path.endswith('version.py') and103            not file_path.endswith('.grd') and104            not file_path.endswith('.grdp') and105            not file_path.endswith('.json'))106        or file_path.startswith('chrome_frame')107        or file_path.startswith('chromeos')108        or file_path.startswith('cloud_print')109        or (file_path.startswith('components') and110            not file_path.startswith('components/tracing') and111            not file_path.startswith('components/visitedlink'))112        or file_path.startswith('content/public/android/java')113        or file_path.startswith('content/shell')114        or file_path.startswith('courgette')115        or (file_path.startswith('extensions') and116            # Included by generated sources of ui/accessibility/ax_enums.idl117            not 'browser/extension_function_registry.h' in file_path and118            not 'browser/extension_function_histogram_value.h' in file_path)119        or file_path.startswith('google_update')120        or file_path.startswith('ios')121        or file_path.startswith('media/base/android/java')122        or file_path.startswith('native_client')123        or file_path.startswith('net/android/java')124        or file_path.startswith('pdf')125        or file_path.startswith('remoting')126        or file_path.startswith('rlz')127        or file_path.startswith('sync')128        or file_path.startswith('testing/android')129        or file_path.startswith('testing/buildbot')130        or file_path.startswith('third_party/accessibility-developer-tools')131        or file_path.startswith('third_party/GTM')132        or file_path.startswith('third_party/WebKit/LayoutTests')133        or file_path.startswith('third_party/WebKit/ManualTests')134        or file_path.startswith('third_party/WebKit/PerformanceTests')135        or file_path.startswith('third_party/active_doc')136        or file_path.startswith('third_party/android_crazy_linker')137        or file_path.startswith('third_party/android_platform')138        or file_path.startswith('third_party/android_testrunner')139        or file_path.startswith('third_party/aosp')140        or file_path.startswith('third_party/apache-mime4j')141        or file_path.startswith('third_party/apache-win32')142        or file_path.startswith('third_party/apple_sample_code')143        or file_path.startswith('third_party/binutils')144        or file_path.startswith('third_party/bison')145        or (file_path.startswith('third_party/cacheinvalidation') and146            not file_path.endswith('isolate'))147        or file_path.startswith('third_party/chromite')148        or file_path.startswith('third_party/cld_2')149        or file_path.startswith('third_party/codesighs')150        or file_path.startswith('third_party/colorama')151        or file_path.startswith('third_party/cros_dbus_cplusplus')152        or file_path.startswith('third_party/cros_system_api')153        or file_path.startswith('third_party/cygwin')154        or file_path.startswith('third_party/elfutils')155        or file_path.startswith('third_party/eyesfree')156        or file_path.startswith('third_party/findbugs')157        or file_path.startswith('third_party/gperf')158        or file_path.startswith('third_party/gnu_binutils')159        or file_path.startswith('third_party/gtk+')160        or file_path.startswith('third_party/google_appengine_cloudstorage')161        or file_path.startswith('third_party/google_toolbox_for_mac')162        or file_path.startswith('third_party/guava/src')163        or file_path.startswith('third_party/httpcomponents-client')164        or file_path.startswith('third_party/httpcomponents-core')165        or file_path.startswith('third_party/hunspell')166        or file_path.startswith('third_party/hunspell_dictionaries')167        or file_path.startswith('third_party/instrumented_libraries')168        or file_path.startswith('third_party/jarjar')169        or file_path.startswith('third_party/jsr-305/src')170        or file_path.startswith('third_party/libphonenumber')171        or file_path.startswith('third_party/libaddressinput')172        or file_path.startswith('third_party/libc++')173        or file_path.startswith('third_party/libc++abi')174        or file_path.startswith('third_party/liblouis')175        or file_path.startswith('third_party/lighttpd')176        or file_path.startswith('third_party/markdown')177        or file_path.startswith('third_party/mingw-w64')178        or file_path.startswith('third_party/nacl_sdk_binaries')179        or file_path.startswith('third_party/pdfsqueeze')180        or file_path.startswith('third_party/pefile')181        or file_path.startswith('third_party/perl')182        or file_path.startswith('third_party/pdfium')183        or file_path.startswith('third_party/psyco_win32')184        or file_path.startswith('third_party/python_26')185        or file_path.startswith('third_party/scons-2.0.1')186        or file_path.startswith('third_party/syzygy')187        or file_path.startswith('third_party/swig')188        or file_path.startswith('third_party/webgl')189        or file_path.startswith('third_party/trace-viewer')190        or file_path.startswith('third_party/xulrunner-sdk')191        or (file_path.startswith('tools') and192           not file_path.startswith('tools/clang') and193           not file_path.startswith('tools/generate_library_loader') and194           not file_path.startswith('tools/generate_shim_headers') and195           not file_path.startswith('tools/generate_stubs') and196           not file_path.startswith('tools/grit') and197           not file_path.startswith('tools/gyp') and198           not file_path.startswith('tools/json_comment_eater') and199           not file_path.startswith('tools/json_schema_compiler') and200           not file_path.startswith('tools/idl_parser') and201           not file_path.startswith('tools/protoc_wrapper'))202        or file_path.startswith('ui/android/java')203        or file_path.startswith('ui/app_list')204        or file_path.startswith('ui/chromeos')205        or file_path.startswith('ui/display/chromeos')206        or file_path.startswith('ui/file_manager')207        ):208            return True209    return False210def printProgress(current, total):211    sys.stdout.write("\r{} of {}".format(current, total))212    sys.stdout.flush()213def copyFile(src, dst):214    src = os.path.abspath(src)215    dst = os.path.abspath(dst)216    dst_dir = os.path.dirname(dst)217    if not os.path.isdir(dst_dir):218        os.makedirs(dst_dir)219    if os.path.exists(dst):220        os.remove(dst)221    try:222        os.link(src, dst)223        # Qt uses LF-only but Chromium isn't.224        subprocess.call(['dos2unix', '--keep-bom', '--quiet', dst])225    except OSError as exception:226        if exception.errno == errno.ENOENT:227            print 'file does not exist:' + src228        else:229            raise230third_party_upstream = os.path.join(qtwebengine_root, 'src/3rdparty_upstream')231third_party = os.path.join(qtwebengine_root, 'src/3rdparty')232def clearDirectory(directory):233    currentDir = os.getcwd()234    os.chdir(directory)235    print 'clearing the directory:' + directory236    for direntry in os.listdir(directory):237        if not direntry == '.git':238            print 'clearing:' + direntry239            shutil.rmtree(direntry)240    os.chdir(currentDir)241def listFilesInCurrentRepository():242    currentRepo = GitSubmodule.Submodule(os.getcwd())243    files = subprocess.check_output(['git', 'ls-files']).splitlines()244    submodules = currentRepo.readSubmodules()245    for submodule in submodules:246        submodule_files = submodule.listFiles()247        for submodule_file in submodule_files:248            files.append(os.path.join(submodule.path, submodule_file))249    return files250def exportNinja():251    third_party_upstream_ninja = os.path.join(third_party_upstream, 'ninja')252    third_party_ninja = os.path.join(third_party, 'ninja')253    os.makedirs(third_party_ninja);254    print 'exporting contents of:' + third_party_upstream_ninja255    os.chdir(third_party_upstream_ninja)256    files = listFilesInCurrentRepository()257    print 'copying files to ' + third_party_ninja258    for i in xrange(len(files)):259        printProgress(i+1, len(files))260        f = files[i]261        if not isInGitBlacklist(f):262            copyFile(f, os.path.join(third_party_ninja, f))263    print("")264def exportChromium():265    third_party_upstream_chromium = os.path.join(third_party_upstream, 'chromium')266    third_party_chromium = os.path.join(third_party, 'chromium')267    os.makedirs(third_party_chromium);268    print 'exporting contents of:' + third_party_upstream_chromium269    os.chdir(third_party_upstream_chromium)270    files = listFilesInCurrentRepository()271    # Add LASTCHANGE files which are not tracked by git.272    files.append('build/util/LASTCHANGE')273    files.append('build/util/LASTCHANGE.blink')274    print 'copying files to ' + third_party_chromium275    for i in xrange(len(files)):276        printProgress(i+1, len(files))277        f = files[i]278        if not isInChromiumBlacklist(f) and not isInGitBlacklist(f):279            copyFile(f, os.path.join(third_party_chromium, f))280    print("")281commandNotFound = subprocess.call(['which', 'dos2unix'])282if not commandNotFound:283    dos2unixVersion = StrictVersion(subprocess.Popen(['dos2unix', '-V', '| true'], stdout=subprocess.PIPE).communicate()[0].splitlines()[0].split()[1])284if commandNotFound or dos2unixVersion < StrictVersion('6.0.6'):285    raise Exception("You need dos2unix version 6.0.6 minimum.")286clearDirectory(third_party)287exportNinja()288exportChromium()...integrator.py
Source:integrator.py  
1import os2EDLY_APP_NAME = "'openedx.features.openedx_edly_discussion'"3TAB_ENTRY_POINT = '"openedx_edly_discussion = openedx.features.openedx_edly_discussion.plugins:EdlyTab"'4EDLY_DISCUSSION_FLAG = 'ENABLE_EDLY_DISCUSSION'5def append_in_file(file_path, line_to_append='', list_starting='', indent=1):6    """7    Appends the given line in the specified list.8    """9    output_file_content = []10    with open(file_path, "r+") as input:11        is_appended = False12        while True:13            line = input.readline()14            if not line:15                break16            stripped_line = line.strip()17            if not stripped_line.startswith('#') and stripped_line.startswith(list_starting) and '[' in stripped_line:18                while not is_appended:19                    output_file_content.append(line)20                    line = input.readline()21                    if not line:22                        break23                    stripped_line = line.strip()24                    if line_to_append in stripped_line and not stripped_line.startswith('#'):25                        is_appended = True26                        break27                        28                    if not stripped_line.startswith('#') and '#' in stripped_line:29                        line_tokens = line.split('#',1)30                        stripped_appname = line_tokens[0].strip()31                        if not stripped_appname.endswith(','):32                            new_appname = stripped_appname + ','33                            line_tokens[0] = line_tokens[0].replace(stripped_appname, new_appname)34                            line = '#'.join(line_tokens)35                    elif (not stripped_line.endswith(',') and not stripped_line.startswith(']')36                            and not stripped_line.startswith('#') and not stripped_line == ''):37                        line = line.rstrip() + ',\n'38                    if stripped_line.startswith(']'):39                        output_file_content.append("{}{},\n".format(" " * 4 * indent, line_to_append))40                        is_appended = True41            output_file_content.append(line)42    with open(file_path, "w") as output:43        for line in output_file_content:44            output.write(line)45def update_aws_production_file(file_path):46    """47    Appends lines at the end (production.py and aws.py) of file which are responsible to get env and auth tokens48    from the json files.49    """50    is_appended_auth = False51    is_appended_env = False52    with open(file_path, 'r') as aws_file:53        for line in aws_file:54            stripped_line = line.strip()55            if not stripped_line.startswith('#') and 'EDLY_DISCUSSION_SECRETS = AUTH_TOKENS.get' in stripped_line:56                is_appended_auth = True57            if not stripped_line.startswith('#') and 'EDLY_DISCUSSION_SETTINGS = ENV_TOKENS.get' in stripped_line:58                is_appended_env = True59    if not is_appended_auth or not is_appended_env:60        with open(file_path, 'a') as aws_file:61            aws_file.seek(0)62            aws_file.write('\n')63            aws_file.write('##################### Openedx Edly Discussion Secrets ###########\n')64            if not is_appended_auth:65                aws_file.write('\n')66                aws_file.write("EDLY_DISCUSSION_SECRETS = AUTH_TOKENS.get('EDLY_DISCUSSION_SECRETS', {")67                aws_file.write("})\n")68            if not is_appended_env:69                aws_file.write('\n')70                aws_file.write("EDLY_DISCUSSION_SETTINGS = ENV_TOKENS.get('EDLY_DISCUSSION_SETTINGS', None)\n")71def update_urls_file(file_path):72    """73    Appends discussion app urls at the end of the given file (urls.py).74    """75    is_appended = False76    with open(file_path, 'r') as urls_file:77        for line in urls_file:78            stripped_line = line.strip()79            if (not stripped_line.startswith('#') and80                    "if settings.FEATURES.get('{}'):".format(EDLY_DISCUSSION_FLAG) in stripped_line):81                is_appended = True82    if not is_appended:83        with open(file_path, 'a') as urls_file:84            urls_file.seek(0)85            urls_file.write('\n')86            urls_file.write("if settings.FEATURES.get('{}'):\n".format(EDLY_DISCUSSION_FLAG))87            urls_file.write("{}urlpatterns += [\n{}url(\n".format(' ' * 4, ' ' * 8))88            urls_file.write("{}".format(' ' * 12))89            urls_file.write("r'^courses/{}/edly'.format(settings.COURSE_ID_PATTERN),\n")90            urls_file.write("{}include('openedx.features.openedx_edly_discussion.urls'),\n".format(' ' * 12))91            urls_file.write("{}name='edly_discussion_endpoints',\n{}".format(' ' * 12, ' ' * 8))92            urls_file.write("),\n\t]")93if __name__ == "__main__":94    file_path = 'cms/envs/common.py'95    append_in_file(file_path, EDLY_APP_NAME, 'INSTALLED_APPS', indent=1)96    print('{} has been configured successfully !!!'.format(file_path))97    file_path = 'lms/envs/common.py'98    append_in_file(file_path, EDLY_APP_NAME, 'INSTALLED_APPS', indent=1)99    print('{} has been configured successfully !!!'.format(file_path))100    file_path = 'setup.py'101    append_in_file(file_path, TAB_ENTRY_POINT, '"openedx.course_tab"', indent=3)102    print('{} has been configured successfully !!!'.format(file_path))103    file_path = 'lms/envs/production.py'104    if os.path.isfile(file_path):105        update_aws_production_file(file_path)106        print('{} has been configured successfully !!!'.format(file_path))107        file_path = 'cms/envs/production.py'108        update_aws_production_file(file_path)109        print('{} has been configured successfully !!!'.format(file_path))110    else:111        file_path = 'lms/envs/aws.py'112        update_aws_production_file(file_path)113        print('{} has been configured successfully !!!'.format(file_path))114        file_path = 'cms/envs/aws.py'115        update_aws_production_file(file_path)116        print('{} has been configured successfully !!!'.format(file_path))117    file_path = 'lms/urls.py'118    update_urls_file(file_path)...io.py
Source:io.py  
...20            self.file_path = os.path.join(self.root_path, self.folder_name, file_name)21        # else:22        #     log.error("IO class cannot initialized. At least a file name or file_path must be defined")23    @property24    def file_path(self):25        return self["file_path"]26    @file_path.setter27    def file_path(self, new_path):28        name, ext = os.path.splitext(new_path)29        directory, _ = os.path.split(new_path)30        if not ext:31            log.error("IO module needs to know the extension")32            raise Exception33        if ext not in self.valid_extensions:34            log.error("IO maya_modules does not support this extension (%s)" % ext)35            raise Exception36        if directory:37            self["file_path"] = self.folder_check(new_path)38        else:39            self["file_path"] = os.path.join(self.root_path, self.folder_name, new_path)40    def read(self, file_path=None):41        file_path = file_path if file_path else self.file_path...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
