def init_repo(path): """Clone the gh-pages repo to a given location.""" sh('git clone {} {}'.format(pages_repo, path)) here = os.getcwdu() cd(path) sh('git checkout gh-pages') cd(here)
def init_repo(path): """Clone the gh-pages repo to a given location.""" sh("git clone {} {}".format(pages_repo, path)) here = os.getcwdu() cd(path) sh("git checkout gh-pages") cd(here)
def __init__(self, sfilestr): # process the string into a list. sfilelist = [item for item in sfilestr.split(" ") if len(item) != 0 and item != " "] sfilelist_noquotations = [item.replace("\"","") for item in sfilelist] # Calling from VBA the home directory must be changed or else you will # get a write error or the output files will end up in the wrong location if len(sfilelist_noquotations) == 1: # we are using the spreadsheet multi-run process cd(dirname(sfilelist_noquotations[0])) file_extensions = ['.bat'] else: cd(dirname(sfilelist_noquotations[1])) file_extensions = ['.bat','.inp','',''] missing_file = [file+ext for file,ext in zip(sfilelist_noquotations,file_extensions) if not isfile(file+ext) and not isdir(file+ext)] if len(missing_file) != 0: print("The following files needed do not exist there is an error in the process") for item in missing_file: print("") print(item) p = Popen(sfilelist_noquotations,stdout=PIPE, stderr=PIPE, shell=True) output, errors = p.communicate() if not errors == b'': print("A batch script or a fortran DOE22.EXE error occurred!") print(errors) # this will give fortran severe error if any occur if len(sfilelist_noquotations)!=1: # indicates serial runs where we # want to wait. For the multi-processor application we do not want to wait! p.wait()
def init_repo(path): """clone the gh-pages repo if we haven't already.""" sh(f'git clone --branch gh-pages {pages_repo} {path} --depth 1') here = os.getcwd() cd(path) sh('git checkout gh-pages') cd(here)
def init_repo(path): """clone the gh-pages repo if we haven't already.""" sh("git clone %s %s"%(pages_repo, path)) here = os.getcwdu() cd(path) sh('git checkout gh-pages') cd(here)
def update(args=None): # move into the root directory of this repository cd(REPO_DIR) old_version = read_version() system_call('git pull --tags origin master') print('No updates found.' if old_version == ( new_version := read_version(True) ) else f'Updated the app from version {old_version} to {new_version}.')
def simulate(self): os.environ['EXPORT_ABNORMAL_FLOW'] = 'TRUE' if self.args.export_ano else 'FALSE' cd(self.ROOT + '/Simulator') sh('python fs.py %s -t %d' % (self.dot_file, self.sim_t)) dir = self.args.dir if dir: if not os.path.exists(dir): os.makedirs(dir) sh('cp *.txt %s' % (dir)) cd(self.ROOT)
def run(): '''pick a file/dir from the current directory. If it's a file, play it. Else (we picked a directory) cd into that directory and recurse.''' f = pickAFile() if '.' in f: # f is a file\ cmd('"C:\\Program Files\\VideoLAN\\VLC\\vlc.exe" "%s"&' %f) else: # f is a dir cd(f) run()
def play(rootDir, playerPath=None): cd(rootDir) files = [i for i in ls('.') if not ignore in i or not (isdir(i) and not(ls(i)))] choice = files[rand(0, len(files)-1)] if isdir(choice): play(choice) else: if not playerPath: cmd("%s %s" %(getPlayer(), choice)) else: cmd("%s %s" %(playerPath, choice))
def __init__(self, sd): print( "shell/INIT=>ExternalUse=>__init__():: Starting shell preparation..." ) print( "shell/INIT=>ExternalUse=>__init__():: Changin working directory to {}" .format("VAR__sd::" + sd)) self.standardDir = sd cd(sd) print( "shell/INIT=>ExternalUse=>__init__():: All shell preparation done! returning to function preparation()" )
def _setup_bzr_branches(self): memo = '%s_%s_%s' % (TESTDIR, self.__class__.__name__, TIMESTAMP) if os.path.exists(memo): rmdir(TESTDIR) shutil.copytree(memo, TESTDIR) else: # make a bzr branch to interact with rmdir(TESTDIR) mkdir(TESTDIR) cd(TESTDIR) bzr('init', BZRBRANCH) cd(BZRBRANCH) open('touch.txt', 'w').write('touch') bzr('add', '-v', 'touch.txt') bzr('commit', '-v', '-m', 'touch test') open('touch2.txt', 'w').write('touch2') bzr('add', 'touch2.txt') bzr('commit', '-m', 'touch2 test') bzr('tag', 'some_tag') # make another branch to test import later cd(TESTDIR) bzr('branch', BZRBRANCH, '%s_imported' % BZRBRANCH) # make a default clone cd(TESTDIR) gitbzr('clone', BZRBRANCH, '%s_cloned' % BZRBRANCHNAME) # clear old memos and copy it to our memo old_memo_glob = '%s_%s_*' % (TESTDIR, self.__class__.__name__) old_memos = glob.iglob(old_memo_glob) for path in old_memos: shutil.rmtree(path) shutil.copytree(TESTDIR, memo)
def _ensure_checkouts(self): if not os.path.exists(PYFASTIMPORT): cd(VENDOR) bzr('branch', 'lp:python-fastimport') if not os.path.exists(BZRFASTIMPORT): cd(VENDOR) bzr('branch', 'lp:bzr-fastimport', BZRFASTIMPORT) python_path = ('PYTHONPATH' in os.environ and os.environ['PYTHONPATH'] or '') if not python_path.startswith(PYFASTIMPORT): os.environ['PYTHONPATH'] = PYFASTIMPORT os.environ['BZR_PLUGIN_PATH'] = VENDOR os.environ['BZR_PDB'] = '1'
def load_files(pathin, extension='.cha'): """This function loads the raw contents of all files in the given directory with the given extension and returns it as a sorted list.""" cd(pathin) # change working directory to the data folder file_contents = [] # make empty list to store raw file contents # loop over all files in the folder with the .cha extension # sorted() is needed here; otherwise, the files will be in a random order for file in sorted(glob.glob('*' + extension)): with open(file,'r', encoding='utf-8') as f: text = f.read() # read in the contents of the file ... file_contents.append(text) # ... and append it to a list return file_contents
def filesystem_tree(): """Creates an isolated filesystem tree, with proper directory structure. isolated_filesystem is effectively a static method, so yielding `runner` is unnecessary!""" runner = CliRunner() with runner.isolated_filesystem(): mkdir(PROJECT) cd(PROJECT) mkdir(WAV) mkdir(AMK) # with pushd(AMK): # mkdir('samples') AMK_SAMPLES.mkdir() yield
def transform(self, grid_size=200, force=False, date_col="Date", type_col="Primary Type", loc_col="Location", out_fname="data_formated.csv"): """ transforms tabular data to quantized time series corpora, given the spatial and temporal quantization parameters Args: data: dataframe? spatial quantization parameters temporal quantization parameters Returns: quantized time series corpora, indexmap Raises: When quantization specified is impossible """ if self._meta_dict is None or force: self.meta_properties(date_col, type_col, loc_col, out_fname) cwd = os.getcwd() os.cd(self.__file_dir) assert os.path.isfile(out_fname), "Error: Please try again using force=True." command = self.__bin_path + " " + out_fname + "%Y-%m-%d %H:%M:%S" + " " command += (self._meta_dict["min_lat"] + " " + self._meta_dict["max_lat"] + " ") command += (self._meta_dict["min_lon"] + " " + self._meta_dict["max_lat"] + " ") command += (grid_size + " ") if os.path.isfile("out_ts" + str(grid_size) + ".csv"): os.remove("out_ts" + str(grid_size) + ".csv") command += ("out_ts" + str(grid_size) + ".csv") sp.Popen(command, shell=True, stderr=sp.STDOUT).wait() assert os.path.isfile("out_ts" + str(grid_size) + ".csv") and \ os.path.isfile("DATASTAT.dat"), "Error: please retry." loc_df = self.parse_loc() ts_df = self.parse_timeseries("out_ts" + str(grid_size) + ".csv") combined = pd.concat([loc_df, ts_df], axis=1) return combined
def test_push_relative_path(self): cd('%s_cloned' % BZRBRANCH) open('touch2.txt', 'w').write('CLONED') git('add', 'touch2.txt') git('commit', '-m', 'touched touch2') # push back to previous bzr branch gitbzr('push', '../%s' % BZRBRANCHNAME) self.assertEqual('CLONED', open('%s/touch2.txt' % BZRBRANCH).read()) open('touch2.txt', 'w').write('CLONED2') git('add', 'touch2.txt') git('commit', '-m', 'touched2 touch2') gitbzr('push') self.assertEqual('CLONED2', open('%s/touch2.txt' % BZRBRANCH).read()) # push to a new repo gitbzr('push', '../%s_new' % BZRBRANCHNAME) cd('%s_new' % BZRBRANCH) bzr('checkout', '.') self.assertEqual('CLONED2', open('%s_new/touch2.txt' % BZRBRANCH).read())
def exec(cmd): path = "" try: for cmd in cmd: #peace the path back together if not cmd == "cd": path = path + " " + cmd if path.startswith(" "): path = path.lstrip() try: if path == "~": cd(str(Path.home())) elif path.startswith("~"): home = str(Path.home()) path = path.replace("~", home) cd(path) else: cd(path) except FileNotFoundError: print("{0}Error: cd: no such file or directory '{1}'".format( Fore.LIGHTRED_EX, path)) except IndexError: print("{}Error: cd: cd requires 1 argument but 0 were given!".format( Fore.LIGHTRED_EX))
def gitclone(repo, setup_arg='install'): cd(CODE) # Clone the code. run('git clone %s' % repo) # Install requirements. _, folder = os.path.split(repo) folder, _ = os.path.splitext(folder) requirements = join(CODE, folder, 'requirements.txt') try: with open(requirements): pass except IOError: pass else: run('%s install -r %s' % (pip, requirements)) # Setup. cd(folder) run('%s setup.py %s' % (python, setup_arg))
def test_gitbzr_init_master(self): # make a new git repo INITGIT = os.path.join(TESTDIR, 'init_master_git') INITBZR = os.path.join(TESTDIR, 'init_master_bzr') cd(TESTDIR) git('init', INITGIT) cd(INITGIT) open('touch.txt', 'w').write('touch') git('add', 'touch.txt') git('commit', '-a', '-m', 'touch1') gitbzr('init') gitbzr('push', INITBZR) cd(TESTDIR) bzr('branch', INITBZR, '%s_working' % INITBZR) cd('%s_working' % INITBZR) self.assertEquals('touch', open('touch.txt').read())
def _setup_bzr_branches(self): # make a bzr branch to interact with rmdir(TESTDIR) mkdir(TESTDIR) cd(TESTDIR) bzr('init', BZRBRANCH) cd(BZRBRANCH) open('touch.txt', 'w').write('touch') print "hmm?" bzr('add', '-v', 'touch.txt') bzr('commit', '-v', '-m', 'touch test') print "hmm2?" open('touch2.txt', 'w').write('touch2') bzr('add', 'touch2.txt') bzr('commit', '-m', 'touch2 test') # make another branch to test import later cd(TESTDIR) bzr('branch', BZRBRANCH, '%s_imported' % BZRBRANCH) # make a default clone cd(TESTDIR) gitbzr('clone', BZRBRANCH, '%s_cloned' % BZRBRANCHNAME)
try: tag = sys.argv[1] except IndexError: try: tag = sh2('git describe --exact-match') except CalledProcessError: tag = "dev" # Fallback print("Using dev") startdir = os.getcwdu() if not os.path.exists(pages_dir): # init the repo init_repo(pages_dir) else: # ensure up-to-date before operating cd(pages_dir) sh('git checkout gh-pages') sh('git pull') cd(startdir) dest = pjoin(pages_dir, tag) # don't `make html` here, because gh-pages already depends on html in Makefile # sh('make html') if tag != 'dev': # only build pdf for non-dev targets #sh2('make pdf') pass # This is pretty unforgiving: we unconditionally nuke the destination # directory, and then copy the html tree in there
gen_num = 500 cost = 0 r = 0.5 r2 = 0.75 N1r = 0 N2r = 0 destination = '3segment' file2run = sys.argv[1] version = file2run[4:7] count = 0 for i in range(len(mu)): if version == '1.2': params = '%s %d %d %d %d %d %d %f %d %d %.5f %d %f %f %f' % ( destination, back, timestep, krecord, untilext, rep, L, s, N0, K, mu[i], gen_num, cost, r, N1r) elif version == '1.3': params = '%s %d %d %d %d %d %f %d %d %.5f %d %f %f %f' % ( destination, back, timestep, krecord, rep, L, s, N0, K, mu[i], gen_num, cost, r, N1r) elif version == '2.3': params = '%s %d %d %d %d %d %f %d %d %.5f %d %f %f %f %f %f' % ( destination, back, timestep, krecord, rep, L, s, N0, K, mu[i], gen_num, cost, r, r2, N1r, N2r) if file2run[-1] == "y": # file is .py cd('python %s %s' % (file2run, params)) else: # file is .c cd('gcc -Wall %s -o cfile -lm' % (file2run)) cd('./cfile %s %d' % (params, seed)) count += 1 print("%d/%d DONE\n" % (count, len(mu)))
# Suitable for any OS with Python installed. # This could be done using the git module. But why bother installing it. from os import chdir as cd from os.path import abspath, dirname, join, pardir, realpath from subprocess import CalledProcessError, check_output as execute from sys import exit, platform # Introduce ourselves. print('init.py called') # Get root directory of this repository. REPO_DIR = abspath(join(dirname(realpath(__file__)), pardir)) # And move there. cd(REPO_DIR) # Let's tell git to look for hooks in our custom hooks directory. # If something goes wrong, abort and tell user about it. try: execute(['git', 'config', 'core.hooksPath', 'hooks']) print('Hooks were configured successfully.') except CalledProcessError as e: print(f'Something went wrong.\n' f'Error code: {e.returncode}\n') exit(1) # If we are not on Linux, our job is completed. if not platform.startswith('linux'): exit(0) # If we are on Linux, we have to grant execute permissions to each hook.
def test_all(self): """Test most of the functionality. This test is a bit large, it is ported directly from a shell script. """ # TEST: clone with git-bzr-ng # it should guess the name correctly but notice that the directory already # exists and failed cd(TESTDIR) self.assertRaises(subprocess.CalledProcessError, gitbzr, 'clone', BZRBRANCH) # TEST: clone it again with a better name gitbzr('clone', BZRBRANCH, '%s_git' % BZRBRANCHNAME) # Check for the branches we want cd('%s_git' % BZRBRANCH) branches = git('branch', '-a') if 'bzr/master' not in branches: self.fail('no bzr/master branch') if '* master' not in branches: self.fail('not on master branch') # Check for files we expect self.assertEqual('touch', open('touch.txt').read()) # push to a new branch git('checkout', '-b', 'pushed') open('touch2.txt', 'w').write('touch3') git('add', 'touch2.txt') git('commit', '-m', 'touch3 test') gitbzr('push', '%s_pushed' % BZRBRANCH) # do it again open('touch2.txt', 'w').write('touch4') git('add', 'touch2.txt') git('commit', '-m', 'touch4 test') gitbzr('push') # update the bzr branch and sync the changes # that bzr repo is not a working tree repo so we need to branch it in bzr # and then push the changes back cd(TESTDIR) bzr('branch', '%s_pushed' % BZRBRANCH, '%s_branched' % BZRBRANCH) cd('%s_branched' % BZRBRANCH) open('touch2.txt', 'w').write('touch5') bzr('commit', '-m', 'touch5') bzr('push', '%s_pushed' % BZRBRANCH) cd('%s_git' % BZRBRANCH) gitbzr('sync') # try to push again from git, should fail because we have not merged the # changes self.assertEquals('touch4', open('touch2.txt').read()) self.assertRaises(subprocess.CalledProcessError, gitbzr, 'push') # this one should fail since there is nothing to commit git('pull', '.', '--', 'bzr/pushed') self.assertEquals('touch5', open('touch2.txt').read()) self.assertRaises(subprocess.CalledProcessError, gitbzr, 'push') # edit a file and try to push open('touch2.txt', 'w').write('touch6') git('add', 'touch2.txt') git('commit', '-m', 'touch6') gitbzr('push') # pull in our bzr branch and make sure we get the change cd('%s_branched' % BZRBRANCH) bzr('pull') self.assertEquals('touch6', open('touch2.txt').read()) # TEST: import another branch and pull changes from `pushed` cd('%s_git' % BZRBRANCH) gitbzr('import', '%s_imported' % BZRBRANCH, 'imported') git('checkout', 'imported') git('pull', '.', '--', 'pushed') gitbzr('push')
def cmake(*args): # Raise if unhappy! subprocess.check_call(['cmake'] + list(args)) # cd into the build directory def MakeIfNeeded(dir): try: os.makedirs(dir) except OSError as exception: if exception.errno != errno.EEXIST: raise MakeIfNeeded('obj') pwd = os.getcwd() instdir = pwd[:-3] + 'inst' cmake('../src', '-DCMAKE_INSTALL_PREFIX=' + instdir) cmake('--build', '.') os.cd('..') MakeIfNeeded('artifacts') os.cd('inst') gitcommit = os.environ['GIT_COMMIT'] tarfilename = '../artifacts/cling_' + gitcommit + '.tar.bz2' with tarfile.open(tarfilename, 'w:bz2') as tar: tar.add('.') # and recursively so.
def scan(self, codeURL, handler, runtime): codepath = handler.split(".")[0] zippath = self.downloads.joinpath('lambda.zip') zippath.write_bytes(requests.get(codeURL).content) if not is_zipfile(zippath): return # invalid zip zf = ZipFile(zippath) # Unzip Lambda source code for _ in zf.namelist(): if _.startswith(codepath): zf.extractall(self.downloads, members=[_]) # Configure sonar-project.properties if runtime.startswith('python'): language = 'py' elif runtime.startswith('node'): language = 'js' elif runtime.startswith('java'): language = 'java' else: return # unsupported language Path(self.downloads, 'sonar-project.properties').write_text( SONAR_PROJECT_PROPERTIES.format( self.config['url'], self.config['login'], self.config['password'], language ) ) # Run sonar-scanner cwd = Path('.').resolve() cd(self.downloads) sh(shsplit(self.config['command']), stdout=DEVNULL, stderr=DEVNULL) cd(cwd) # Get results curl = requests.Session() curl.auth = (self.config['login'], self.config['password']) while True: sleep(3) task = json.loads( curl.get(f'{self.config["url"]}/api/ce/activity').text )['tasks'][0] if task['status'] in ['SUCCESS', 'FAIL']: break issues = json.loads( curl.get(f'{self.config["url"]}/api/issues/search?project=lambdaguard').text )['issues'] curl.post(f'{self.config["url"]}/api/projects/delete', data={ 'project': 'lambdaguard' }) for issue in issues: if issue['status'] != 'OPEN': continue where = issue['component'].split(':', 1)[1] yield { 'level': 'high', 'text': f'{issue["message"]}\n{where} on line {issue["textRange"]["startLine"]}.' }
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ''' from os import getcwd as pwd, listdir as ls, system as cmd, chdir as cd from random import randint as rand def pickAFile(): '''Pick a random file or directory from the current directory and return it''' files = [i for i in ls('.') if not ignore in i] f = files[rand(0, (len(files) -1))] return f def run(): '''pick a file/dir from the current directory. If it's a file, play it. Else (we picked a directory) cd into that directory and recurse.''' f = pickAFile() if '.' in f: # f is a file\ cmd('"C:\\Program Files\\VideoLAN\\VLC\\vlc.exe" "%s"&' %f) else: # f is a dir cd(f) run() if __name__ == "__main__": ignore = pwd().split('\\')[-1] cd("..") run()
def produit(N): primes = premiers(N) for width in primes: if N % width == 0: for height in primes: if width * height == N: return (width, height) # N % height == 0 return (0, 0) print(produit(21)) from os import getcwd as dir, chdir as cd cd('U:\\') cd('C:\\Users\\Benjamin LOISON\\Desktop\\BensFolder\\School\\CPGE\\Fenelon\\MPSI\\IPT\\19\\02\\20' ) print(dir()) # print(type(octet)) # valeur = octet[0] source = open('message.bin', 'rb') octets = [source.read(1)] while octets[len(octets) - 1] != bytes(b''): octets += [source.read(1)] source.close() octets = octets[:len(octets) - 1] print(octets) taille = len(octets)
#!/usr/bin/python from os import system as call from os import chdir as cd from os import environ as env from getpass import getuser as user from sys import exit print 'Building map files...' cd(env['QIE10ROOT'] + '/src') call('./remap') print 'Building the analyzer core...' call('python generate.py') cd(env['QIE10ROOT']) print 'Compiling the analyzer...' call('scram b -j 8') print 'Analyzer compiled.' print 'Installion complete.'
elif args.op == 'list': print('\n'.join(selected)) elif args.op == 'show': text = '\n\n'.join(entries[k] for k in selected) if stdout.isatty(): temp_file = mkstemp(FILE_EXTENSION)[1] with open(temp_file, 'w') as fd: fd.write(text) chmod(temp_file, S_IRUSR) if fork(): wait() rm(temp_file) else: cd(args.directory) editor = environ.get('VISUAL', environ.get('EDITOR', 'nvim')) vim_args = [editor, temp_file, '-c', 'set hlsearch nospell'] if args.terms: vim_args[-1] += ' ' + ('nosmartcase' if args.icase else 'noignorecase') vim_args.extend(("-c", r'let @/="\\v' + "|".join("({})".format(term) for term in args.terms).replace('"', r'\"').replace("@", r"\\@") + "\"")) execvp('nvim', vim_args) else: print(text) elif args.op == 'update': for journal in journal_files: rel_path = relpath(journal, args.directory) with open(journal) as fd: lines = fd.read().splitlines() for line_number, line in enumerate(lines, start=1):
tag = sys.argv[1] except IndexError: tag = sh2('git describe') startdir = os.getcwd() dest = pjoin(gh_pages, tag) sh('make html') # This is pretty unforgiving: we unconditionally nuke the destination # directory, and then copy the html tree in there shutil.rmtree(dest, ignore_errors=True) shutil.copytree(html_dir, dest) try: cd(gh_pages) status = sh2('git status | head -1') branch = re.match('\# On branch (.*)$', status).group(1) if branch != 'gh-pages': e = 'On %r, git branch is %r, MUST be "gh-pages"' % (gh_pages, branch) raise RuntimeError(e) sh('git add %s' % tag) new_htmlindex('index.html', tag) sh('git add index.html') sh('git commit -m"Created new doc release, named: %s"' % tag) print print 'Most recent 3 commits:' sys.stdout.flush() sh('git --no-pager log --oneline HEAD~3..')
from src.game import game_world as game from os import chdir as cd if __name__ == '__main__': cd("src") # gamb mode-on game()
from os import chdir as cd from pickle import load from math import sqrt, exp from random import random import gzip from copy import deepcopy #cd("C:/Users/Asus/Desktop") cd("C:/Users/Benjamin LOISON/Desktop/BensFolder/School/CPGE/Fenelon/MPSI/TIPE/WIP/260519/old" ) ft = gzip.open('data_training', 'rb') TRAINING = load(ft) OLD_TRAINING = deepcopy(TRAINING[1]) ft.close() TMP_WORKING_ELEMENTS = 60000 #NB_ELEMENTS = len(TRAINING[0]) NB_ELEMENTS = TMP_WORKING_ELEMENTS THETA_NUMBER = int(len(TRAINING[0][0])) SIZE = int(sqrt(THETA_NUMBER)) STEP = 0.02 # / NB_ELEMENTS theta = [0] * THETA_NUMBER newTheta = [0] * THETA_NUMBER H_THETA = [0] * NB_ELEMENTS E_MY_SUM = [0] * NB_ELEMENTS for pic in range( NB_ELEMENTS): # x values here are 0 or 1, best way to prototype ?
def init_repo(path): """clone the gh-pages repo if we haven't already.""" sh("git clone %s %s" % (pages_repo, path)) cd(path) sh("git checkout %s" % dest_branch)
#!/usr/bin/python3 # The file recorded on-site (in train) is without commas. # Also, constants for single journey like date, day of week and # AM or PM are not recorded on every line to save time, but they # are written as a before the corresponding journey begins. # This program reads those comments, appends the information on # every line, and writes a separate .csv file from os import chdir as cd cd('/media/anand/Chiba/Users/Anand/Documents/home/python/self/TokyoMetro/textori') filnam = 'TokyoMetro_20180914E.txt' f0 = open(filnam, 'r') s0 = f0.readlines() ni = len(s0) f0.close() outfil = filnam[:filnam.index('.')] + '_modify.csv' f1 = open(outfil, 'w') for i in range(ni): s1 = (s0[i])[:-1] # print(s1) if (s1[0] == '#'): if (s1[1:5] != '2018'):
run('curl -o .gitignore https://raw.githubusercontent.com/github/gitignore/master/Node.gitignore') gitignore = open(name + '.gitignore', 'a') gitignore.write('lib\n') commands = [ "curl -u '" + user + "' https://api.github.com/user/repos -d '{\"name\":\"" + name + "\"}'", 'mkdir app', 'touch README' 'git init', "git remote add origin https://github.com/" + user + "/" + name + ".git", 'touch app/.bowerrc' 'touch app/index.html' 'mkdir app/css', 'touch app/css/main.css', 'mkdir app/js', 'touch app/js/main.js', 'mkdir app/lib', 'mkdir app/img', ] run('mkdir ' + name) cd(name) for command in commands: print(command) run(command) setup_bower() setup_gitignore()
retcode = p.returncode if retcode: raise CalledProcessError(retcode, cmd) else: return out.rstrip(), err.rstrip() ############################################################################### # Script starts ############################################################################### if __name__ == '__main__': # Get starting folder current_dir = os.getcwd() # Load source package cd(pkg_path) mod = __import__(pkg_name) if pjoin(pkg_path, pkg_name).lower() != \ os.path.dirname(mod.__file__).lower(): print(pjoin(pkg_path, pkg_name)) print(mod.__file__) raise RuntimeError("You should work with the source and not the " "installed package") # find the version number tag = "dev" if 'dev' or 'post' in mod.__version__ else mod.__version__ intro_msg = """ ##############################################
def _ensure_checkouts(self): exec_path = ('PATH' in os.environ and os.environ['PATH'] or '') if not exec_path.startswith(BZR): os.environ['PATH'] = '%s:%s' % (BZR, exec_path) download_url = 'http://launchpad.net/bzr/%s/%s/+download/bzr-%s.tar.gz' tarball = 'bzr-%s.tar.gz' for v in VERSIONS: if not os.path.exists(BZRPATH % v[1]): logging.info('Downloading %s', download_url % (v[0], v[1], v[1])) cd(VENDOR) check_output(['curl', '-O', '-L', download_url % (v[0], v[1], v[1]) ]) check_output(['tar', '-xzf', tarball % v[1]]) # we need a functional bzr on our path to get anything else self._symlink_bzr(BZRPATH % '2.3.1') bzr_head = BZRPATH % 'head' if not os.path.exists(bzr_head): logging.info('Getting HEAD of bzr') cd(VENDOR) bzr('branch', 'lp:bzr', BZRPATH % 'head') if not os.path.exists(PYFASTIMPORT): logging.info('Getting a HEAD of python-fastimport') cd(VENDOR) bzr('branch', 'lp:python-fastimport') if not os.path.exists(PLUGINDIR): os.mkdir(PLUGINDIR) if not os.path.exists(BZRFASTIMPORT_STABLE): logging.info('Getting revision 307 of bzr-fastimport') cd(VENDOR) bzr('branch', 'lp:bzr-fastimport', '-r', '307', BZRFASTIMPORT_STABLE) if not os.path.exists(BZRFASTIMPORT_HEAD): logging.info('Getting HEAD of bzr-fastimport') cd(VENDOR) bzr('branch', 'lp:bzr-fastimport', BZRFASTIMPORT_HEAD) if not os.path.exists(BZRFASTIMPORT_STABLE_TARBALL): logging.info('Downloading bzr-fastimport version 0.10') cd(VENDOR) check_output(['curl', '-O', '-L', 'http://launchpad.net/bzr-fastimport/trunk/' '0.10.0/+download/bzr-fastimport-0.10.0.tar.gz' ]) check_output(['tar', '-xzf', 'bzr-fastimport-0.10.0.tar.gz']) python_path = ('PYTHONPATH' in os.environ and os.environ['PYTHONPATH'] or '') if not python_path.startswith(PYFASTIMPORT): os.environ['PYTHONPATH'] = '%s:%s' % (PYFASTIMPORT, BZR) os.environ['BZR_PLUGIN_PATH'] = PLUGINDIR os.environ['BZR_PDB'] = '1'
def test_import_strip_tags(self): # assert that the imported repo has our tag cd(TESTDIR) cd('%s_cloned' % BZRBRANCHNAME) rv = git('tag') self.assert_('some_tag' in rv) # add an invalid tag and make sure it doesn't get imported cd('%s_imported' % BZRBRANCH) bzr('tag', 'some~invalid!tag') cd(TESTDIR) cd('%s_cloned' % BZRBRANCHNAME) # the first try should fail due to an invalid tag self.assertRaises(subprocess.CalledProcessError, gitbzr, 'import', '%s_imported' % BZRBRANCH, 'import_fail') gitbzr('import', '--strip_tags', '%s_imported' % BZRBRANCH, 'import_win') rv = git('tag') self.assert_('some~invalid!tag' not in rv) # test that clone supports the flag also cd(TESTDIR) self.assertRaises(subprocess.CalledProcessError, gitbzr, 'clone', '%s_imported' % BZRBRANCH, 'import_fail') gitbzr('clone', '--strip_tags', '%s_imported' % BZRBRANCH, 'import_win')
def clearPath(path): cd(path) command('del /q /f /s *')
[v.split("=")[1].strip(" '\n.") for v in info_lines if re.match("^_version_(major|minor|micro|extra)", v)] ) print("Source version: ", source_version) # check for dev tag if source_version.split(".")[-1] == "dev": dev = True print("Development Version detected") else: dev = False # pull current docs_repo if not os.path.exists(docs_repo_path): print("docs_repo not found, pulling from git..") sh("git clone %s %s" % (docs_repo_url, docs_repo_path)) cd(docs_repo_path) print("Moved to " + os.getcwd()) try: sh("git checkout gh-pages") except: while 1: print("\nLooks like gh-pages branch does not exist!") print("Do you want to create a new one? (y/n)") choice = str(input()).lower() if choice == "y": sh("git checkout -b gh-pages") sh("rm -rf *") sh("git add .") sh("git commit -m 'cleaning gh-pages branch'") sh("git push origin gh-pages") break
from os import system as cmd from os import chdir as cd from os.path import join from os.path import normcase as nc from os.path import normpath as np path = "C:\\" cd(path) while True: i = input('> ') if i.startswith('cd ') and not i == 'cd ': path = nc(np(join(path, i[3:]))) cd(path) else: cmd(i)
the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ''' from os import system as cmd, listdir as ls, chdir as cd def convertToTIFF(): for i in ls('.'): fname = i.split('.')[0].replace(" ", "\\ ") cmd('ddjvu -format=tiff %s.djvu %s_tiff.tiff' %(fname, fname)) cmd('rm -f "%s"' %i) def converToPDF(): for i in (_ for _ in ls('.') if _.endswith(".tiff")): fname = i.split('.')[0].replace(" ", "\\ ") cmd('tiff2pdf -j -o "%s.pdf" "%s_tiff.tiff"' %(fname, fname)) cmd('rm -f "%s"' %i) if __name__ == "__main__": cd('/home/ashwin/Desktop/Trying/') convertToTIFF() converToPDF()
Created on Aug 7, 2010 @author: ashwin Licensed to Ashwin Panchapakesan under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. Ashwin licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ''' from os.path import isdir from os import listdir as ls, chdir as cd import easygui, shutil easygui.msgbox("Uninstallation", "Ashwin's Badass Simpsons Player", ok_button="Begin Uninstallation") easygui.msgbox("By default, this program should be installed in: C:\\Program Files\\Random Player\\", \ "Ashwin's Badass Simpsons Player", ok_button="Begin Uninstallation") installpath = easygui.diropenbox("Where is the program installed?", "Ashwin's Badass Simpsons Player", "C:\\Program Files\\Random Player\\") cd(installpath) shutil.rmtree(installpath) easygui.msgbox("Uninstallation Finished", "Ashwin's Badass Simpsons Player")
def main(): with open('pyq.list', 'rb') as f: pyq = pickle.load(f) post_3 = [] for post in pyq: xml = post['rawXML'] root = ET.fromstring(xml) if root.find('ContentObject').find('contentStyle').text == '3': post_3.append(post) #=================================================================== # pprint(post) # display(ET.fromstring(post['rawXML']),False) # input() #=================================================================== cd('webpages') list_url = [] for post in post_3: root = ET.fromstring(post['rawXML']) list_url.append(root.find('ContentObject').find('contentUrl').text) master = {} counter = 0 jdt_ = jdt.CommJdt(len(list_url) // 8 + 1) pool = dummy.Pool() for i in range(len(list_url) // 8): jdt_.update(i) try: list_r = pool.map(requests.get, list_url[i * 8:i * 8 + 8]) except: list_r = [] for ii in range(8): try: list_r.append(requests.get(list_url[i * 8 + ii])) except: #=========================================================== # print('\n',list_url[i*8+ii]) #=========================================================== list_r.append(-1) for r in list_r: if r == -1: counter += 1 else: ext = 'html' with open(str(counter) + '.' + ext, 'wb') as f: f.write(r.content) master[list_url[counter]] = counter counter += 1 for i in range((len(list_url) // 8) * 8, len(list_url)): r = requests.get(list_url[i]) ext = 'html' with open(str(counter) + '.' + ext, 'wb') as f: f.write(r.content) master[list_url[counter]] = counter counter += 1 jdt_.complete() print(counter, len(list_url)) with open('master.dict', 'wb') as f: pickle.dump(master, f)
def setup_gitignore(): cd('app') run('curl -o .gitignore https://raw.githubusercontent.com/github/gitignore/master/Node.gitignore') gitignore = open(name + '.gitignore', 'a') gitignore.write('lib\n')
run('svn up') # create build dir for cmake if not exists('build'): md('build') # prepare bin dir and data files if not exists('bin'): md('bin') if not exists('bin/data'): md('bin/data') for i in ls('data'): src='data/'+i if isfile(src): print 'copying:', src copy(src, 'bin/data') # configure cmake cd('build') if osname=='nt': run('cmake .. -G "MinGW Makefiles"') else: run('cmake ..') # start make run('make') # for the first time, generate dict cd('../bin') if isfile('unit_test') and not isfile('data/core.ocd'): run('./unit_test')
def deploy(self): """ Build documentation in directory `root/target` and pushes it to `repo`. :Inputs: `root`: root directory where the `conf.py` file is. `repo`: remote repository where generated HTML content should be pushed to. `target`: directory relative to `root`, where generated HTML content should be written to. This directory **must** be added to the repository's `.gitignore` file. (default: `"site"`) `doc_branch`: branch where the generated documentation is pushed. (default: `"gh-pages"`) `latest`: branch that "tracks" the latest generated documentation. (default: `"develop"`) `local_upstream`: remote repository to fetch from. (default: `None`) `make`: list of commands to be used to convert the markdown files to HTML. (default: ['make', 'html']) """ sha = log_and_execute(["git", "rev-parse", "HEAD"]).strip() current_branch = environ['GIT_BRANCH'] logging.debug('current branch: %s' % current_branch) host_user, host_repo = get_github_username_repo(self.repo) logging.debug('host username: %s, host repo: %s', host_user, host_repo) self.upstream = "git@%s:%s/%s.git" % (HOST_URL[self.host], host_user, host_repo) logging.debug('upstream: %s' % self.upstream) if self.is_pull_request(): print_with_color("Skipping documentation deployment", 'magenta') return if self.local_upstream is not None: # Pull the documentation branch to avoid conflicts log_and_execute(["git", "checkout", self.doc_branch]) log_and_execute(["git", "branch"]) log_and_execute(["git", "pull", "origin", self.doc_branch]) log_and_execute(["git", "checkout", "-f", sha]) log_and_execute(["git", "branch"]) enc_key_file = abspath(joinpath(self.root, "docs", ".documenter.enc")) has_ssh_key = isfile(enc_key_file) with open(enc_key_file, "r") as enc_keyfile: enc_key = enc_keyfile.read() self.key_file, _ = splitext(enc_key_file) with open(self.key_file, "w") as keyfile: keyfile.write(b64decode(enc_key)) # Give READ/WRITE permissions chmod(self.key_file, stat.S_IREAD | stat.S_IWRITE) # self.create_ssh_config() tmp_dir = tempfile.mkdtemp() logging.debug("temporary directory is: %s" %tmp_dir) docs = joinpath(self.root, "docs") cd(docs) if not exists(self.target): mkdir(self.target) log_and_execute(self.make) # Versioned docs directories. latest_dir = joinpath(self.dirname, self.latest_dir) stable_dir = joinpath(self.dirname, self.stable_dir) target_dir = joinpath(docs, self.target) unstable_dir = joinpath(self.dirname, self.unstable_dir) # Setup git. cd(tmp_dir) log_and_execute(["git", "init"]) log_and_execute(["git", "config", "user.name", "'autodocs'"]) log_and_execute(["git", "config", "user.email", "'autodocs'"]) # Fetch from remote and checkout the branch. if self.local_upstream is not None: log_and_execute(["git", "remote", "add", "local_upstream", self.local_upstream]) log_and_execute(["git", "remote", "add", "upstream", self.upstream]) log_and_execute(["git", "fetch", "upstream"]) try: log_and_execute(["git", "checkout", "-b", self.doc_branch, "upstream/" + self.doc_branch]) except RuntimeError: try: log_and_execute(["git", "checkout", "--orphan", self.doc_branch]) log_and_execute(["git", "rm", "--cached", "-r", "."]) except: raise RuntimeError("could not checkout remote branch.") # Copy docs to `latest`, or `stable`, `<release>`, and `<version>` # directories. destination_dir = None if current_branch == 'origin/' + self.latest: destination_dir = latest_dir elif current_branch == 'origin/' + self.stable: destination_dir = stable_dir else: destination_dir = unstable_dir if destination_dir is not None: if exists(destination_dir): rm(destination_dir) logging.debug("Copying HTML folder to %s", destination_dir) mv(joinpath(target_dir, "html"), destination_dir) if 'GIT_TAG_NAME' in environ.keys(): logging.debug("This commit (%s) was tagged. A copy of the doc will be stored at %s.", sha, environ['GIT_TAG_NAME']) cp(destination_dir, environ['GIT_TAG_NAME']) # Create a .nojekyll file so that Github pages behaves correctly with folders starting # with an underscore. touch('.nojekyll') with open('index.html', 'w') as f: f.write('<meta http-equiv="refresh" content="0; url=http://%s.github.io/%s/stable"/>' % (host_user, host_repo)) # Add, commit, and push the docs to the remote. log_and_execute(["git", "add", "-A", "."]) log_and_execute(["git", "commit", "-m", "'build based on %s'" % sha]) log_and_execute(["git", "push", "-q", "upstream", "HEAD:%s" % self.doc_branch]) # Clean up temporary directories rm(target_dir) rm(tmp_dir)
import sys from collections import defaultdict from itertools import product from os import chdir as cd, environ from os.path import basename, dirname, join as join_path, realpath from shutil import copyfile from subprocess import run as run_process, PIPE, TimeoutExpired from tempfile import TemporaryDirectory from textwrap import dedent DGLIB = join_path(dirname(__file__), 'dglib.py') DEMOGRADER_ROOT = dirname(realpath(__file__)) django_site_root = join_path(DEMOGRADER_ROOT, '..') cd(django_site_root) sys.path.insert(0, django_site_root) environ.setdefault("DJANGO_SETTINGS_MODULE", "djangosite.settings") import django import django_rq DISPATCH_QUEUE = None EVALUATION_QUEUE = None def get_dispatch_queue(): return django_rq.get_queue('dispatch') def get_evaluation_queue(): return django_rq.get_queue('evaluation') def evaluate_submission(result):