check_config function

This commit is contained in:
Difrex(Denis Zheleztsov) 2014-04-28 12:04:17 +04:00
parent dc76c9e6f8
commit 2423a6d942
3 changed files with 40 additions and 8 deletions

View File

@ -1,15 +1,16 @@
package Database;
use DBI;
use GPG;
sub new {
my $class = shift;
# Get home dir
my $home = $ENV{HOME};
my $home = $ENV->{HOME};
my $self = {
_home => $home;
_home => $home,
};
bless $self, $class;
@ -27,7 +28,7 @@ sub connect {
}
sub mdo {
my ($self) = @_;
my ($self, $query, $type) = @_;
my $dbh = $self->{_dbh};
}
@ -37,7 +38,7 @@ sub create_base {
my $pm_dir = $home."/.PM/";
# Check dir
if !(-d $pm_dir) {
if (!(-d $pm_dir)) {
# Create dirrectory
@mkdir_cmd = ("mkdir", "$pm_dir");
system(@mkdir_cmd) == 0 or die "Cannot create dir $pm_dir: $!\n";
@ -50,6 +51,10 @@ sub create_base {
my $dbh = DBI->connect("dbi:SQLite:dbname=$pm_dir/db.sqlite","","");
print "Create database schema\n";
my $q_table = "create table passwords(name VARCHAR(32), resource TEXT, password TEXT)";
$dbh->do($q_table);
# Encrypt db
# TODO: write this
return 0;
}

View File

@ -6,15 +6,38 @@ use utf8;
use Database;
use PasswordSave;
use PasswordShow;
sub new {
my $class = shift;
my $db = Database->new();
my $p_save = PasswordSave->new();
my $p_show = PasswordShow->new();
my $self = {
_home => $home,
_db => $db,
_p_save => $p_save,
_p_show => $p_show,
};
bless $self, $class;
return $self;
}
# Check configuration. If it doesn't exist create it.
sub check_config {
my ($self) = @_;
if (-e $ENV->{HOME}."/.PM/db.sqlite") {
return 0;
}
else {
my $db = $self->{_db};
$db->create_base();
}
return 0;
}
1;

6
pm.pl
View File

@ -3,7 +3,7 @@
use Password;
use Getopt::Std;
our $VERSION = '0.0.0a';
our $VERSION = '0.0.0b';
# Debug
use Data::Dumper;
@ -54,3 +54,7 @@ sub init() {
# Parse cmd line
init();
my $pass = Password->new();
# Don't use it's before GPG and Database
# $pass->check_config() == 0 or die "$!\n";