Exemple #1
0
    def _verify_path(self, project_path):
        """
        Verifies the project path exists and is readable.

        project_path is the path to the Django project.
        """
        # Verify path exists
        if not os.access(project_path, os.F_OK):
            raise exceptions.OSError("Path %s doesn't exist." % project_path)
        # .. and that we can read it
        if not os.access(project_path, os.R_OK):
            raise exceptions.OSError("Path %s is not readable." % project_path)
        return True
Exemple #2
0
def ensuredir(path):
    if not path:
        # path component empty - using working directory.
        return
    if not os.path.isdir(path):
        try:
            os.makedirs(path)
        except exceptions.OSError:
            # the directory was created in the meantime.
            if not os.path.isdir(path):
                raise
    # check permissions
    if not os.access(path, os.X_OK | os.W_OK):
        raise exceptions.OSError("Directory '%s' not writable." % path)
Exemple #3
0
    def __init__(self, db_file_path):
        if not db_file_path:
            raise exceptions.ValueError("db_file_path")

        if not os.path.exists(db_file_path):
            raise exceptions.OSError("db_file_path")

        if not db_file_path.endswith('.db'):
            raise exceptions.ValueError("db_file_path")

        self.db_file_path = db_file_path
        self.zone = os.path.basename(db_file_path)[:-3]

        self._load_zone()
def download_parallel(links, num_processes=1):
    """ Downloads the list of :links: """
    start = time.time()
    pool = multiprocessing.Pool(processes=num_processes)

    results = pool.map(download, links)

    pool.close()
    pool.join()

    failed = [r[0] for r in results if not r[0]]

    print("Download with {} processes and {} links in {}, failed {} ".format(
        num_processes, len(links), (time.time() - start), len(failed)))

    if len(failed) == num_processes:
        raise exceptions.OSError("Failed {}".format(len(failed)))
Exemple #5
0
def remove_only_dir_recursively(path):
    sdirs = set()
    sfiles = set()
    for root, ldir, lfile in os.walk(path):
        lfile = [os.path.join(root, filename) for filename in lfile]
        ldir = [os.path.join(root, dirname) for dirname in ldir]
        sdirs = sdirs.union(set(ldir))
        sfiles = sfiles.union(set(lfile))
    lfile = list(sfiles)
    ldir = list(sdirs)
    if lfile:
        raise exceptions.OSError('[Errno 17] File exists: %s' %
                                 ', '.join(lfile))
    ldir.sort(cmpAlphaNum)
    ldir.reverse()
    for tmpdir in ldir:
        os.rmdir(tmpdir)
    os.rmdir(path)
Exemple #6
0
def actually_create_android_project(package_name, target_version, java_package_name, is_library):
    path = os.path.join(os.getcwd(), package_name.lower())
    console.pretty_println("\nCreating android project ", console.bold)
    console.pretty_print("  Name      : ", console.cyan)
    console.pretty_println("%s" % package_name, console.yellow)
    console.pretty_print("  Target Ver: ", console.cyan)
    console.pretty_println("%s" % target_version, console.yellow)
    console.pretty_print("  Java Name : ", console.cyan)
    console.pretty_println("%s" % java_package_name, console.yellow)
    if is_library:
        console.pretty_print("  Library   : ", console.cyan)
        console.pretty_println("yes\n", console.yellow)
        cmd = ['android', 'create', 'lib-project', '-n', package_name, '-p', path, '-k', java_package_name, '-t', 'android-' + target_version, ]
    else:
        activity_name = utils.camel_case(package_name)
        console.pretty_print("  Activity  : ", console.cyan)
        console.pretty_println("%s\n" % activity_name, console.yellow)
        cmd = ['android', 'create', 'project', '-n', package_name, '-p', path, '-k', java_package_name, '-t', 'android-' + target_version, '-a', activity_name]
        print("Command: %s" % cmd)
    try:
        subprocess.check_call(cmd)
        print("Command: %s" % cmd)
    except subprocess.CalledProcessError:
        print("Error")
        raise subprocess.CalledProcessError("failed to create android project.")
    except exceptions.OSError as e:
        print("OS error" + str(e))
        raise exceptions.OSError()

    # This is in the old form, let's shovel the shit around to the new form
    utils.mkdir_p(os.path.join(path, 'src', 'main', 'java'))
    os.remove(os.path.join(path, 'local.properties'))
    os.remove(os.path.join(path, 'project.properties'))
    os.remove(os.path.join(path, 'ant.properties'))
    os.remove(os.path.join(path, 'proguard-project.txt'))
    os.remove(os.path.join(path, 'build.xml'))
    os.rmdir(os.path.join(path, 'bin'))
    os.rmdir(os.path.join(path, 'libs'))
    shutil.move(os.path.join(path, 'AndroidManifest.xml'), os.path.join(path, 'src', 'main'))
    shutil.move(os.path.join(path, 'res'), os.path.join(path, 'src', 'main'))
    if not is_library:
        shutil.move(os.path.join(path, 'src', java_package_name.split('.')[0]), os.path.join(path, 'src', 'main', 'java'))
Exemple #7
0
def sh(cmd_fstring, args=None):
    if args is None:
        cur_frame = sys._getframe()
        back_frame = cur_frame.f_back
        args = back_frame.f_globals.copy()
        args.update(back_frame.f_locals)

    fmtdict = {}
    if isinstance(args, collections.Mapping):
        fmtdict.update(args)
    elif hasattr(args, "__dict__"):
        fmtdict.update(vars(args))
    cmd = cmd_fstring.format(args, **fmtdict)
    if env.COLD:
        logging.info(cmd)
    else:
        logging.debug(cmd)
        code = os.system(cmd)
        if code:
            raise exceptions.OSError(
                "Command finished with non-zero return value.")
#          optional tidal constituents
#          if verbose, create install log
#######################################################################################################################
import sys
import os
import exceptions
import platform
from subprocess import Popen, PIPE

# ------------------------------------------------------
#               Install DTU10 API
# 
# Linux: fortran compiler currently relies on f2py defaults
#        expect gunzip available
# ------------------------------------------------------

if platform.system() == 'Linux':
    # --- build dtu10API.so 
    h = Popen("f2py -c -m dtu10API fortran_sources/perth3.f", stdout=PIPE, stderr=PIPE, stdin=PIPE, shell=True)
    stdout, stderr = h.communicate()
    # --- install tidal constituents
    h = Popen("cat data/NorthSea_tidal_constituents.dat.gz | gunzip > tidal_constituents.dat", stdout=PIPE, stderr=PIPE, stdin=PIPE, shell=True)
    stdout, stderr = h.communicate()
else:
    raise exceptions.OSError("non-linux install not implemented")


print 63*"-"
print 10*">", " Installation of GridWetData successful  ", 10*"<"
print 63*"-"
Exemple #9
0
#

import os
import sys
import re
import operator
import exceptions
from subprocess import Popen, PIPE

if len(sys.argv) < 2:
    raise Exception('Specify domains list file')

domains_list_file = sys.argv[1]

if not os.path.exists(domains_list_file):
    raise exceptions.OSError("domains_list_file")

with open(domains_list_file, 'r') as f:
    ns_rating = {}

    for line in f:
        line = line.strip()

        print "Query domain: %s" % line
        output = Popen(["nslookup", "-q=ns", line, "8.8.8.8"],
                       stdout=PIPE).communicate()[0]

        for ns in re.finditer('nameserver\s+=\s+([^\s]+)', output.strip()):
            nserver = ns.group(1)

            if nserver not in ns_rating.keys():
Exemple #10
0
 def unlink_message(self, uid):
     status, foo = self.connection.uid("STORE", uid, "+FLAGS",
                                       r"(\Deleted)")
     if status != "OK":
         raise exceptions.OSError(2, "No such file or directory: '%s'" %
                                  "a")  # TODO more
Exemple #11
0
 def chdir(self, path):
     status, foo = self.connection.select(path, readonly=True)
     if status != "OK":
         print exceptions.OSError(2, "No such file or directory: '%s'" %
                                  "a")  # TODO more